public boolean isEnabled() { boolean isEnabled = false; MapEditorPlugIn mapEditor = null; if ((mapEditor = getPlugInContext().getMapEditor()) != null) { MapContext map = (MapContext) mapEditor.getElement().getObject(); ILayer activeLayer = map.getActiveLayer(); if (activeLayer != null && activeLayer.getSelection().length > 0) isEnabled = true; } btn.setEnabled(isEnabled); return isEnabled; }
public boolean execute(PlugInContext context) throws Exception { IEditor editor = getPlugInContext().getActiveEditor(); MapContext map = (MapContext) editor.getElement().getObject(); ILayer activeLayer = map.getActiveLayer(); int[] sel = activeLayer.getSelection().clone(); Arrays.sort(sel); DataSource dataSource = activeLayer.getDataSource(); try { dataSource.setDispatchingMode(DataSource.STORE); for (int i = sel.length - 1; i >= 0; i--) { dataSource.deleteRow(sel[i]); } dataSource.setDispatchingMode(DataSource.DISPATCH); } catch (DriverException e) { ErrorMessages.error(ErrorMessages.CannotDeleteSelectedRow, e); } return true; }
@Override protected void polygonDone(com.vividsolutions.jts.geom.Polygon pol, MapContext mc, ToolManager tm) throws TransitionException { Geometry g = pol; if (ToolUtilities.geometryTypeIs(mc, GeometryConstraint.MULTI_POLYGON)) { g = ToolManager.toolsGeometryFactory.createMultiPolygon(new Polygon[] {pol}); } SpatialDataSourceDecorator sds = mc.getActiveLayer().getDataSource(); try { Value[] row = new Value[sds.getMetadata().getFieldCount()]; row[sds.getSpatialFieldIndex()] = ValueFactory.createValue(g); row = ToolUtilities.populateNotNullFields(sds, row); sds.insertFilledRow(row); } catch (DriverException e) { throw new TransitionException("Cannot insert polygon", e); } }