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) Stefan Steiniger.
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: * Stefan Steiniger
026: * perriger@gmx.de
027: */
028: /*****************************************************
029: * created: 16.05.2005
030: * last modified:
031: *
032: * description:
033: * selects all items of the actual layer
034: * and informs about the number of selected items
035: *
036: *****************************************************/package org.openjump.core.ui.plugin.edit;
037:
038: import java.util.ArrayList;
039: import java.util.Collection;
040: import java.util.Iterator;
041:
042: import com.vividsolutions.jump.I18N;
043: import com.vividsolutions.jump.feature.Feature;
044: import com.vividsolutions.jump.feature.FeatureCollection;
045: import com.vividsolutions.jump.workbench.WorkbenchContext;
046: import com.vividsolutions.jump.workbench.model.Layer;
047: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
048: import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
049: import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
050: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
051: import com.vividsolutions.jump.workbench.ui.MenuNames;
052:
053: /**
054: * @description:
055: * selects all items of the actual layer
056: * and informs about the number of selected items
057: *
058: * @author sstein
059: *
060: */
061: public class SelectAllLayerItemsPlugIn extends AbstractPlugIn {
062:
063: public void initialize(PlugInContext context) throws Exception {
064:
065: context
066: .getFeatureInstaller()
067: .addPopupMenuItem(
068: context.getWorkbenchContext().getWorkbench()
069: .getFrame().getLayerNamePopupMenu(),
070: this ,
071: I18N
072: .get("org.openjump.core.ui.plugin.edit.SelectAllLayerItemsPlugIn.select-current-layer-items"),
073: false,
074: null,
075: createEnableCheck(context.getWorkbenchContext()));
076:
077: context
078: .getFeatureInstaller()
079: .addMainMenuItemWithJava14Fix(
080: this ,
081: new String[] { MenuNames.EDIT },
082: I18N
083: .get("org.openjump.core.ui.plugin.edit.SelectAllLayerItemsPlugIn.select-layer-items")
084: + "{pos:8}",
085: false,
086: null,
087: createEnableCheck(context.getWorkbenchContext())); //enable check
088: }
089:
090: public static MultiEnableCheck createEnableCheck(
091: WorkbenchContext workbenchContext) {
092: EnableCheckFactory checkFactory = new EnableCheckFactory(
093: workbenchContext);
094: return new MultiEnableCheck().add(checkFactory
095: .createAtLeastNLayersMustBeSelectedCheck(1));
096: }
097:
098: public boolean execute(PlugInContext context) throws Exception {
099:
100: int count = 0;
101: Layer[] selectedLayers = context.getLayerNamePanel()
102: .getSelectedLayers();
103: for (int i = 0; i < selectedLayers.length; i++) {
104: Layer actualLayer = selectedLayers[i];
105: FeatureCollection fc = context.getSelectedLayer(i)
106: .getFeatureCollectionWrapper().getWrappee();
107: Collection features = new ArrayList();
108:
109: for (Iterator iter = fc.iterator(); iter.hasNext();) {
110: Feature element = (Feature) iter.next();
111: features.add(element);
112: count++;
113: }
114: context.getLayerViewPanel().getSelectionManager()
115: .getFeatureSelection().selectItems(actualLayer,
116: features);
117: }
118: final Collection myf = context.getLayerViewPanel()
119: .getSelectionManager().getFeaturesWithSelectedItems();
120: context
121: .getWorkbenchFrame()
122: .setTimeMessage(
123: I18N
124: .get("org.openjump.core.ui.plugin.edit.SelectAllLayerItemsPlugIn.layer-items")
125: + ": "
126: + count
127: + ", "
128: + I18N
129: .get("org.openjump.core.ui.plugin.edit.SelectAllLayerItemsPlugIn.selected-items")
130: + ": " + myf.size());
131: System.gc();
132: return true;
133: }
134:
135: }
|