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: public class MoveUpAction extends AbstractAction implements
37: ContelligentAction {
38: /**
39: *
40: */
41: private final ExplorerEditor editor;
42:
43: public MoveUpAction(ExplorerEditor editor) {
44: super ("move_up_action", Resources.moveUpIcon);
45: this .editor = editor;
46: putValue(ROLLOVER_ICON, Resources.moveUpIconRollOver);
47: putValue(TYPE, PUSH_ACTION);
48: putValue(ACTION_TYPE, EDIT_ACTION);
49: putValue(ACTION_GROUP, EDIT_MOVE_GROUP);
50: putValue(ACTION_POS, EDIT_MOVE_UP);
51: putValue(MENU_TARGET, MENU);
52: putValue(BUTTON_TARGET, TOOLBAR);
53: putValue(POPUP_TARGET, POPUP_SUBMENU);
54: putValue(POPUP_PARENT_ACTION, this .editor.moveAction);
55: }
56:
57: public void actionPerformed(ActionEvent e) {
58: DefaultMutableTreeNode node = (DefaultMutableTreeNode) this .editor.tree
59: .getLastSelectedPathComponent();
60: if (node != null
61: && node.getUserObject() instanceof ComponentReference) {
62: try {
63: ContelligentComponent component = ((ComponentReference) node
64: .getUserObject()).getComponent();
65: ActionResult response = Actions.sort(editor.getView()
66: .getEnvironment(), component.getPath(),
67: Actions.UP);
68: response.showErrors();
69: } catch (RemoteActionException rae) {
70: ExceptionDialog.show(rae);
71: } catch (ComponentNotFoundException cnfe) {
72: ExceptionDialog.show(cnfe);
73: }
74: }
75: }
76:
77: public void update() {
78: DefaultMutableTreeNode node = (DefaultMutableTreeNode) this .editor.tree
79: .getLastSelectedPathComponent();
80: if (node != null
81: && node.getUserObject() instanceof ComponentReference) {
82: TreePath selectionPath = this .editor.tree
83: .getSelectionPath();
84: if (selectionPath != null) {
85: DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node
86: .getParent();
87: if (parent != null) {
88: int index = parent.getIndex(node);
89: if (index != 0) {
90: setEnabled(true);
91: return;
92: }
93: }
94: }
95: }
96: setEnabled(false);
97: }
98: }
|