public boolean execute(PlugInContext context) throws Exception { reportNothingToUndoYet(context); layer = (Layer) context.getSelectedLayer(0); saveDatasetDialog.setLayer(layer); saveDatasetDialog.setVisible(true); return saveDatasetDialog.wasOKPressed(); }
public boolean execute(final PlugInContext context) throws Exception { reportNothingToUndoYet(context); Collection features; Transferable transferable = GUIUtil.getContents(Toolkit.getDefaultToolkit().getSystemClipboard()); if (transferable.isDataFlavorSupported( CollectionOfFeaturesTransferable.COLLECTION_OF_FEATURES_FLAVOR)) { features = (Collection) GUIUtil.getContents(Toolkit.getDefaultToolkit().getSystemClipboard()) .getTransferData(CollectionOfFeaturesTransferable.COLLECTION_OF_FEATURES_FLAVOR); } else { // Allow the user to paste features using WKT. [Jon Aquino] features = reader .read( new StringReader((String) transferable.getTransferData(DataFlavor.stringFlavor))) .getFeatures(); } final SelectionManager selectionManager = context.getLayerViewPanel().getSelectionManager(); final Layer layer = context.getSelectedLayer(0); final Collection featureCopies = conform(features, layer.getFeatureCollectionWrapper().getFeatureSchema()); Feature feature = ((Feature) featureCopies.iterator().next()); Coordinate firstPoint = feature.getGeometry().getCoordinate(); Coordinate cursorPt = context .getLayerViewPanel() .getViewport() .toModelCoordinate(context.getLayerViewPanel().getLastMouseLocation()); Coordinate displacement = CoordUtil.subtract(cursorPt, firstPoint); moveAll(featureCopies, displacement); execute( new UndoableCommand(getName()) { public void execute() { layer.getFeatureCollectionWrapper().addAll(featureCopies); selectionManager.clear(); selectionManager.getFeatureSelection().selectItems(layer, featureCopies); } public void unexecute() { layer.getFeatureCollectionWrapper().removeAll(featureCopies); } }, context); return true; }