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.event.ActionEvent;
21:
22: import javax.swing.AbstractAction;
23: import javax.swing.tree.DefaultMutableTreeNode;
24: import javax.swing.tree.TreePath;
25:
26: import de.finix.contelligent.client.base.ComponentNotFoundException;
27: import de.finix.contelligent.client.base.ComponentReference;
28: import de.finix.contelligent.client.base.ContelligentComponent;
29: import de.finix.contelligent.client.gui.ContelligentAction;
30: import de.finix.contelligent.client.i18n.Resources;
31: import de.finix.contelligent.client.remote.ActionResult;
32: import de.finix.contelligent.client.remote.Actions;
33: import de.finix.contelligent.client.remote.RemoteActionException;
34: import de.finix.contelligent.client.util.ExceptionDialog;
35:
36: final class ToggleFinalAction extends AbstractAction implements
37: ContelligentAction {
38: /**
39: *
40: */
41: private final ExplorerEditor editor;
42:
43: public ToggleFinalAction(ExplorerEditor editor) {
44: super ("toggleFinal_action", Resources.toggleFinalIcon);
45: this .editor = editor;
46: putValue(ROLLOVER_ICON, Resources.toggleFinalIconRollOver);
47: putValue(TYPE, PUSH_ACTION);
48: putValue(ACTION_TYPE, EDIT_ACTION);
49: putValue(ACTION_GROUP, EDIT_COPYPASTE_GROUP);
50: putValue(ACTION_POS, EDIT_COPYPASTE_FINAL);
51: putValue(MENU_TARGET, MENU);
52: putValue(BUTTON_TARGET, NO_BUTTON);
53: }
54:
55: public void actionPerformed(ActionEvent e) {
56: try {
57: if (!this .editor.getView().isEditInProgress()) {
58: final TreePath[] selectionPaths = this .editor.tree
59: .getSelectionPaths();
60: if (selectionPaths != null) {
61: if (selectionPaths.length > 0) {
62: DefaultMutableTreeNode firstNode = ((DefaultMutableTreeNode) selectionPaths[0]
63: .getLastPathComponent());
64: if (firstNode != null
65: && firstNode.getUserObject() instanceof ComponentReference) {
66: ContelligentComponent component = ((ComponentReference) firstNode
67: .getUserObject()).getComponent();
68: try {
69: ActionResult response = Actions
70: .toggleFinalFlag(editor
71: .getView()
72: .getEnvironment(),
73: component.getPath(),
74: !component.isFinal());
75: response.showErrors();
76: } catch (RemoteActionException rae) {
77: ExceptionDialog.show(rae);
78: }
79: }
80: }
81: }
82: } else {
83: setEnabled(false);
84: }
85: } catch (ComponentNotFoundException cnfe) {
86: ExceptionDialog.show(cnfe);
87: }
88: }
89: }
|