Skip to content

Commit

Permalink
Fixed issue in unregistering editable extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
mstahv committed Oct 17, 2015
1 parent c5f1e32 commit 533494f
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Expand Up @@ -7,7 +7,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<vaadin.version>7.5.4</vaadin.version>
<vaadin.version>7.5.6</vaadin.version>
<geotools.version>10.2</geotools.version>
</properties>

Expand Down Expand Up @@ -305,12 +305,12 @@
<dependency>
<groupId>org.vaadin.addon</groupId>
<artifactId>v-leaflet</artifactId>
<version>1.0.0-b1</version>
<version>1.0.0-b3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.peimari</groupId>
<artifactId>g-leaflet-editable</artifactId>
<version>1.0.0-b1</version>
<version>1.0.0-b2-SNAPSHOT</version>
<!-- Only needed during widgetset compilation, so provided scope would
be great for this, but with it is left out from widgetset compilation by
vaadin plugin -->
Expand Down
Expand Up @@ -3,7 +3,6 @@
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.vaadin.client.ServerConnector;
import com.vaadin.client.VConsole;
import com.vaadin.client.communication.RpcProxy;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.extensions.AbstractExtensionConnector;
Expand All @@ -26,7 +25,7 @@ public class EditableConnector extends AbstractExtensionConnector {
LeafletEditableResourceInjector.ensureInjected();
}

private EditableServerRcp rpc = RpcProxy.create(EditableServerRcp.class, this);
private final EditableServerRcp rpc = RpcProxy.create(EditableServerRcp.class, this);

private EditableFeature ef;

Expand Down Expand Up @@ -88,6 +87,7 @@ public EditableFeature getFeature() {
public void onUnregister() {
super.onUnregister();
ef.disableEdit();
ef.removeEditListener();
}

}
@@ -0,0 +1,121 @@
package org.vaadin.addon.leaflet.demoandtestapp;

import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Notification;
import org.vaadin.addon.leaflet.*;
import org.vaadin.addon.leaflet.editable.FeatureModifiedEvent;
import org.vaadin.addon.leaflet.editable.FeatureModifiedListener;
import org.vaadin.addon.leaflet.editable.LEditable;
import org.vaadin.addon.leaflet.shared.Point;
import org.vaadin.addonhelpers.AbstractTest;
import org.vaadin.viritin.layouts.MHorizontalLayout;

public class TogglingEditing extends AbstractTest implements
FeatureModifiedListener {

private LPolygon polygon;

@Override
public String getDescription() {
return "Test leaflet draws editing feature";
}

private LMap leafletMap;
private LEditable lEditing;

@Override
public Component getTestComponent() {
leafletMap = new LMap();
leafletMap.setCustomInitOption("editable", true);
leafletMap.setHeight("300px");
leafletMap.setCenter(0, 0);
leafletMap.setZoomLevel(0);
leafletMap.addLayer(new LTileLayer(
"http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"));


polygon = new LPolygon(new Point(0, 0), new Point(30, 30),
new Point(30, 0));

leafletMap.addComponents(polygon);

leafletMap.addClickListener(new LeafletClickListener() {

@Override
public void onClick(LeafletClickEvent event) {
System.out.println("Clicked");
}
});

return leafletMap;
}

@Override
protected void setup() {
super.setup();

HorizontalLayout tools = new MHorizontalLayout();

for (final Component c : leafletMap) {
if (c instanceof AbstractLeafletVector) {
Button button = new Button("Edit"
+ c.getClass().getSimpleName());
button.addClickListener(new ClickListener() {

@Override
public void buttonClick(ClickEvent event) {
if (lEditing != null && lEditing.getParent() != null) {
lEditing.remove();
}
lEditing = new LEditable((AbstractLeafletVector) c);
lEditing.addFeatureModifiedListener(new FeatureModifiedListener() {

@Override
public void featureModified(
FeatureModifiedEvent event) {
Notification.show("Modified :" + ((AbstractLeafletVector) c).getGeometry().toText());
}
});
}
});
tools.addComponent(button);
}
}

tools.addComponent(new Button("Stop editing",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
if (lEditing.getParent() != null) {
lEditing.remove();
}
}
}));

tools.addComponent(new Button("Add hole",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
lEditing = new LEditable(polygon);
lEditing.newHole();
leafletMap.zoomToContent(polygon);
}
}));

content.addComponent(tools);

leafletMap.setSizeFull();
content.setExpandRatio(leafletMap, 1);

}

@Override
public void featureModified(FeatureModifiedEvent event) {
Notification.show("Edited"
+ event.getModifiedFeature().getClass().getSimpleName());
}
}

0 comments on commit 533494f

Please sign in to comment.