01: /*
02: * uDig - User Friendly Desktop Internet GIS client
03: * http://udig.refractions.net
04: * (C) 2004, Refractions Research Inc.
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: */
17: package net.refractions.udig.printing.ui.actions;
18:
19: import java.util.List;
20:
21: import net.refractions.udig.printing.model.Box;
22: import net.refractions.udig.printing.model.impl.MapBoxPrinter;
23: import net.refractions.udig.printing.ui.internal.Messages;
24:
25: import org.eclipse.gef.EditPart;
26: import org.eclipse.gef.Request;
27: import org.eclipse.gef.commands.Command;
28: import org.eclipse.gef.commands.CompoundCommand;
29: import org.eclipse.gef.ui.actions.SelectionAction;
30: import org.eclipse.ui.IWorkbenchPart;
31:
32: /**
33: * Action that allows the map, that is part of the page, to be edited.
34: * @author Richard Gould
35: * @since 0.3
36: */
37: public class EditMapAction extends SelectionAction {
38:
39: public static final String EDIT_MAP_REQUEST = "EDIT_MAP"; //$NON-NLS-1$
40: public static final String EDIT_MAP = EDIT_MAP_REQUEST;
41: private Request request;
42:
43: /**
44: * Construct <code>EditMapAction</code>.
45: *
46: * @param part
47: */
48: public EditMapAction(IWorkbenchPart part) {
49: super (part);
50: request = new Request(EDIT_MAP_REQUEST);
51: setText(Messages.EditMapAction_action_text);
52: setId(EDIT_MAP);
53: setToolTipText(Messages.EditMapAction_action_tooltip);
54:
55: }
56:
57: /**
58: * TODO summary sentence for calculateEnabled ...
59: *
60: * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
61: * @return
62: */
63: protected boolean calculateEnabled() {
64: if (getSelectedObjects().isEmpty())
65: return false;
66: List parts = getSelectedObjects();
67: for (int i = 0; i < parts.size(); i++) {
68: Object o = parts.get(i);
69: if (!(o instanceof EditPart))
70: return false;
71: EditPart part = (EditPart) o;
72: if (!(part.getModel() instanceof Box))
73: if (!(((Box) part.getModel()).getBoxPrinter() instanceof MapBoxPrinter))
74: return false;
75: }
76: return true;
77: }
78:
79: private Command getCommand() {
80: List editparts = getSelectedObjects();
81: CompoundCommand cc = new CompoundCommand();
82: cc.setDebugLabel("Edit Maps");//$NON-NLS-1$
83: for (int i = 0; i < editparts.size(); i++) {
84: EditPart part = (EditPart) editparts.get(i);
85: cc.add(part.getCommand(request));
86: }
87: return cc;
88: }
89:
90: /**
91: * TODO summary sentence for run ...
92: *
93: * @see org.eclipse.jface.action.IAction#run()
94: *
95: */
96: public void run() {
97: execute(getCommand());
98: }
99: }
|