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.project.ui.internal.actions;
18:
19: import net.refractions.udig.project.internal.Layer;
20: import net.refractions.udig.project.internal.Project;
21: import net.refractions.udig.project.internal.ProjectElement;
22: import net.refractions.udig.project.ui.UDIGGenericAction;
23: import net.refractions.udig.project.ui.internal.Messages;
24:
25: import org.eclipse.jface.dialogs.Dialog;
26: import org.eclipse.jface.dialogs.InputDialog;
27: import org.eclipse.swt.widgets.Display;
28:
29: /**
30: * An action for renaming objects in UDIG
31: *
32: * @author jeichar
33: * @since 0.6.0
34: */
35: public class Rename extends UDIGGenericAction {
36: /**
37: * Construct <code>Rename</code>.
38: */
39: public Rename() {
40: super ();
41: }
42:
43: protected void operate(Layer layer) {
44: layer.setName(getNewName(layer.getName()));
45: layer.getContextModel().getMap().getProjectInternal()
46: .eResource().setModified(true);
47: }
48:
49: @Override
50: protected void operate(Layer[] layers) {
51: if (layers != null)
52: operate(layers[0]);
53: }
54:
55: protected void operate(ProjectElement element) {
56: element.setName(getNewName(element.getName()));
57: element.getProjectInternal().eResource().setModified(true);
58: }
59:
60: protected void operate(Project project) {
61: project.setName(getNewName(project.getName()));
62: project.eResource().setModified(true);
63: }
64:
65: /**
66: * Opens a dialog asking the user for a new name.
67: *
68: * @return The new name of the element.
69: */
70: private String getNewName(String oldName) {
71: InputDialog dialog = new InputDialog(Display.getDefault()
72: .getActiveShell(), Messages.Rename_enterNewName,
73: "", oldName, null); //$NON-NLS-1$
74: int result = dialog.open();
75: if (result == Dialog.CANCEL)
76: return oldName;
77: return dialog.getValue();
78: }
79:
80: }
|