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: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.workbench.ui.plugin;
034:
035: import java.util.Arrays;
036: import java.util.Iterator;
037:
038: import javax.swing.JCheckBoxMenuItem;
039: import javax.swing.JComponent;
040:
041: import com.vividsolutions.jump.I18N;
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.EnableCheck;
046: import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
047: import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
048: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
049: import com.vividsolutions.jump.workbench.ui.cursortool.editing.EditingPlugIn;
050:
051: public class EditablePlugIn extends AbstractPlugIn {
052:
053: private EditingPlugIn editingPlugIn;
054:
055: public boolean execute(PlugInContext context) throws Exception {
056: reportNothingToUndoYet(context);
057: boolean makeEditable = !context.getSelectedLayer(0)
058: .isEditable();
059: for (Iterator i = Arrays.asList(context.getSelectedLayers())
060: .iterator(); i.hasNext();) {
061: Layer selectedLayer = (Layer) i.next();
062: selectedLayer.setEditable(makeEditable);
063: }
064: if (makeEditable
065: && !editingPlugIn.getToolbox(
066: context.getWorkbenchContext()).isVisible()) {
067: editingPlugIn.execute(context);
068: }
069: return true;
070: }
071:
072: public EnableCheck createEnableCheck(
073: final WorkbenchContext workbenchContext) {
074: EnableCheckFactory checkFactory = new EnableCheckFactory(
075: workbenchContext);
076: MultiEnableCheck mec = new MultiEnableCheck();
077:
078: mec.add(checkFactory
079: .createWindowWithLayerNamePanelMustBeActiveCheck());
080: mec
081: .add(checkFactory
082: .createAtLeastNLayersMustBeSelectedCheck(1));
083:
084: mec.add(new EnableCheck() {
085: public String check(JComponent component) {
086: ((JCheckBoxMenuItem) component)
087: .setSelected(workbenchContext
088: .createPlugInContext()
089: .getSelectedLayer(0).isEditable());
090: return null;
091: }
092: });
093:
094: mec.add(new EnableCheck() {
095: public String check(JComponent component) {
096: String errMsg = null;
097: if (workbenchContext.createPlugInContext()
098: .getSelectedLayer(0).isReadonly()) {
099: errMsg = I18N
100: .get("ui.plugin.EditablePlugIn.The-selected-layer-cannot-be-made-editable");
101: }
102: return errMsg;
103: }
104: });
105:
106: return mec;
107: }
108:
109: public EditablePlugIn(EditingPlugIn editingPlugIn) {
110: this.editingPlugIn = editingPlugIn;
111: }
112:
113: }
|