Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added confirmation dialog
  • Loading branch information
svzdvd committed Jul 11, 2010
1 parent c0c3f49 commit e85008c
Showing 1 changed file with 43 additions and 10 deletions.
Expand Up @@ -3,8 +3,13 @@
import net.refractions.udig.ui.operations.IOp;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.neo4j.gis.spatial.SpatialDatabaseService;
import org.neo4j.gis.spatial.geotools.data.Neo4jSpatialDataStore;

Expand All @@ -15,16 +20,44 @@
public class DeleteNeo4jSpatialLayerOp implements IOp {

public void op(Display display, Object target, IProgressMonitor monitor) throws Exception {
if (monitor == null) monitor = new NullProgressMonitor();
ConfirmDialogRunnable dialog = new ConfirmDialogRunnable(display);
display.syncExec(dialog);

// TODO ask user confirmation!
if (dialog.returnValue == Window.OK) {
Neo4jSpatialGeoResource geoResource = (Neo4jSpatialGeoResource) target;
Neo4jSpatialDataStore dataStore = (Neo4jSpatialDataStore) geoResource.service().getDataStore(monitor);

SpatialDatabaseService spatialDatabase = dataStore.getSpatialDatabaseService();
spatialDatabase.deleteLayer(geoResource.getTypeName(),
new ProgressMonitorWrapper("Deleting Layer " + geoResource.getTypeName(), monitor));
}
}

class ConfirmDialogRunnable implements Runnable {

Neo4jSpatialGeoResource geoResource = (Neo4jSpatialGeoResource) target;
Neo4jSpatialDataStore dataStore = (Neo4jSpatialDataStore) geoResource.service().getDataStore(monitor);
public ConfirmDialogRunnable(Display display) {
this.display = display;
}

SpatialDatabaseService spatialDatabase = dataStore.getSpatialDatabaseService();
spatialDatabase.deleteLayer(geoResource.getTypeName(),
new ProgressMonitorWrapper("Deleting Layer " + geoResource.getTypeName(), monitor));
}
public void run() {
Dialog dialog = new Dialog(display.getActiveShell()) {
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false);
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, true);
}

protected Control createDialogArea(Composite parent) {
Control control = super.createDialogArea(parent);
// TODO how to display longer message inside Dialog?
control.getShell().setText("Confirm");
return control;
}
};

returnValue = dialog.open();
}

}
Display display;
int returnValue;
}
}

0 comments on commit e85008c

Please sign in to comment.