01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.client.gui.explorer;
19:
20: import java.awt.Dimension;
21: import java.awt.Rectangle;
22: import java.awt.Toolkit;
23: import java.awt.event.ActionEvent;
24:
25: import javax.swing.AbstractAction;
26: import javax.swing.JOptionPane;
27:
28: import de.finix.contelligent.client.ContelligentClient;
29: import de.finix.contelligent.client.base.ComponentFactory;
30: import de.finix.contelligent.client.gui.ContelligentAction;
31: import de.finix.contelligent.client.gui.directory.RenameTypeDialog;
32: import de.finix.contelligent.client.i18n.Resources;
33: import de.finix.contelligent.client.remote.ActionResult;
34: import de.finix.contelligent.client.remote.Actions;
35: import de.finix.contelligent.client.remote.RemoteActionException;
36: import de.finix.contelligent.client.util.ExceptionDialog;
37:
38: public class RenameTypeAction extends AbstractAction implements
39: ContelligentAction {
40: /**
41: *
42: */
43: private final ExplorerEditor editor;
44:
45: public RenameTypeAction(ExplorerEditor editor) {
46: super (Resources.getLocalString("rename_type"),
47: Resources.defaultViewIcon);
48: this .editor = editor;
49: putValue(ROLLOVER_ICON, Resources.defaultViewIcon);
50: putValue(TYPE, PUSH_ACTION);
51: putValue(ACTION_TYPE, EDIT_ACTION);
52: putValue(ACTION_GROUP, EDIT_BLUEPRINT_GROUP);
53: putValue(ACTION_POS, EDIT_BLUEPRINT_RENAME);
54: putValue(MENU_TARGET, NO_MENU);
55: putValue(BUTTON_TARGET, NO_BUTTON);
56: putValue(POPUP_TARGET, POPUP_SUBMENU);
57: putValue(POPUP_PARENT_ACTION, this .editor.typeAction);
58: }
59:
60: public void actionPerformed(ActionEvent e) {
61: if (!this .editor.getView().isEditInProgress()) {
62: RenameTypeDialog dialog = new RenameTypeDialog(
63: ContelligentClient.getActiveFrame(), null);
64: dialog.pack();
65: // center dialog...
66: Dimension screenDim = Toolkit.getDefaultToolkit()
67: .getScreenSize();
68: Rectangle winDim = dialog.getBounds();
69: dialog.setLocation((screenDim.width - winDim.width) / 2,
70: (screenDim.height - winDim.height) / 2);
71: // ...and show it
72: dialog.setVisible(true);
73: if (dialog.getOption() == JOptionPane.OK_OPTION) {
74: try {
75: ActionResult response = Actions.renameType(editor
76: .getView().getEnvironment(), dialog
77: .getType(), dialog.getName());
78: response.showErrors();
79: } catch (RemoteActionException rae) {
80: ExceptionDialog.show(rae);
81: }
82: }
83: }
84: }
85:
86: public void update() {
87: setEnabled(!this.editor.getView().isEditInProgress()
88: && this.editor.getView().getAllowBlueprintDefinition()
89: && ComponentFactory.getInstance().isRootContext());
90: }
91: }
|