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