001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * JUMP is Copyright (C) 2003 Vivid Solutions
006: *
007: * This program implements extensions to JUMP and is
008: * Copyright (C) 2004 Integrated Systems Analysts, Inc.
009: *
010: * This program is free software; you can redistribute it and/or
011: * modify it under the terms of the GNU General Public License
012: * as published by the Free Software Foundation; either version 2
013: * of the License, or (at your option) any later version.
014: *
015: * This program is distributed in the hope that it will be useful,
016: * but WITHOUT ANY WARRANTY; without even the implied warranty of
017: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
018: * GNU General Public License for more details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with this program; if not, write to the Free Software
022: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
023: *
024: * For more information, contact:
025: *
026: * Integrated Systems Analysts, Inc.
027: * 630C Anchors St., Suite 101
028: * Fort Walton Beach, Florida
029: * USA
030: *
031: * (850)862-7321
032: */
033:
034: package org.openjump.core.ui.plugin.tools;
035:
036: import java.util.ArrayList;
037: import java.util.Collection;
038: import java.util.Iterator;
039:
040: import com.vividsolutions.jump.I18N;
041: import com.vividsolutions.jump.feature.Feature;
042: import com.vividsolutions.jump.workbench.WorkbenchContext;
043: import com.vividsolutions.jump.workbench.model.Layer;
044: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
045: import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
046: import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
047: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
048: import com.vividsolutions.jump.workbench.ui.AbstractSelection;
049: import com.vividsolutions.jump.workbench.ui.MenuNames;
050: import com.vividsolutions.jump.workbench.ui.MultiInputDialog;
051:
052: public class DeleteEmptyGeometriesPlugIn extends AbstractPlugIn {
053: private WorkbenchContext workbenchContext;
054: private MultiInputDialog dialog;
055: private boolean exceptionThrown = false;
056: private boolean selectEmpty = false;
057: private boolean selectPoint = false;
058: private boolean selectMultiPoint = false;
059: private boolean selectLineString = false;
060: private boolean selectLinearRing = false;
061: private boolean selectMultiLineString = false;
062: private boolean selectPolygon = false;
063: private boolean selectMultiPolygon = false;
064: private boolean selectGeometryCollection = false;
065: private boolean selectedLayersOnly = true;
066: protected AbstractSelection selection;
067:
068: String sDeleteEmptyGeometries = I18N
069: .get("org.openjump.core.ui.plugin.tools.DeleteEmptyGeometriesPlugIn.Delete-Empty-Geometries-in-Selection");
070:
071: public void initialize(PlugInContext context) throws Exception {
072: workbenchContext = context.getWorkbenchContext();
073: context.getFeatureInstaller().addMainMenuItemWithJava14Fix(
074: this ,
075: new String[] { MenuNames.TOOLS, MenuNames.TOOLS_QA },
076: sDeleteEmptyGeometries, false, null,
077: this .createEnableCheck(workbenchContext));
078: }
079:
080: public boolean execute(final PlugInContext context)
081: throws Exception {
082: String sDeleteEmptyGeometries = I18N
083: .get("org.openjump.core.ui.plugin.tools.DeleteEmptyGeometriesPlugIn.Delete-Empty-Geometries-in-Selection");
084:
085: reportNothingToUndoYet(context);
086: ArrayList featuresToDelete = new ArrayList();
087: Collection layers = context.getLayerViewPanel()
088: .getSelectionManager().getLayersWithSelectedItems();
089:
090: for (Iterator j = layers.iterator(); j.hasNext();) {
091: Layer layer = (Layer) j.next();
092:
093: Collection selectedFeatures = context.getLayerViewPanel()
094: .getSelectionManager()
095: .getFeaturesWithSelectedItems(layer);
096: for (Iterator i = selectedFeatures.iterator(); i.hasNext();) {
097: Feature feature = (Feature) i.next();
098: if (feature.getGeometry().isEmpty())
099: featuresToDelete.add(feature);
100: }
101: layer.getFeatureCollectionWrapper().removeAll(
102: featuresToDelete);
103: featuresToDelete.clear();
104: }
105: return true;
106: }
107:
108: public MultiEnableCheck createEnableCheck(
109: final WorkbenchContext workbenchContext) {
110: EnableCheckFactory checkFactory = new EnableCheckFactory(
111: workbenchContext);
112: return new MultiEnableCheck()
113: .add(
114: checkFactory
115: .createWindowWithLayerViewPanelMustBeActiveCheck())
116: .add(
117: checkFactory
118: .createAtLeastNFeaturesMustHaveSelectedItemsCheck(1));
119: }
120: }
|