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.Action;
23: import javax.swing.KeyStroke;
24: import javax.swing.tree.DefaultMutableTreeNode;
25: import javax.swing.tree.DefaultTreeModel;
26:
27: import de.finix.contelligent.client.base.ComponentFactory;
28: import de.finix.contelligent.client.base.ComponentReference;
29: import de.finix.contelligent.client.base.ContelligentComponent;
30: import de.finix.contelligent.client.gui.ContelligentAction;
31: import de.finix.contelligent.client.i18n.Resources;
32: import de.finix.contelligent.client.util.ExceptionDialog;
33: import de.finix.contelligent.client.util.MnemonicAbstractAction;
34:
35: public class ReloadComponentAction extends MnemonicAbstractAction
36: implements ContelligentAction {
37: /**
38: *
39: */
40: private final ExplorerEditor editor;
41:
42: public ReloadComponentAction(ExplorerEditor editor) {
43: super ("reload_action", Resources.reloadComponentIcon);
44: this .editor = editor;
45: putValue(ROLLOVER_ICON, Resources.reloadIconRollOver);
46: putValue(TYPE, PUSH_ACTION);
47: putValue(ACTION_TYPE, VIEW_ACTION);
48: putValue(ACTION_GROUP, VIEW_RELOAD_GROUP);
49: putValue(MENU_TARGET, MENU);
50: putValue(BUTTON_TARGET, TOOLBAR);
51: putValue(POPUP_TARGET, NO_POPUP);
52: putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("F5"));
53: }
54:
55: public void actionPerformed(ActionEvent e) {
56: if (this .editor.isRootVisible) {
57: DefaultMutableTreeNode node = (DefaultMutableTreeNode) this .editor.tree
58: .getLastSelectedPathComponent();
59: reload(node);
60: } else {
61: // XXX if root is not visible you can not possibly reload it, so do
62: // it here
63: reload(this .editor.rootNode);
64: }
65: }
66:
67: private void reload(DefaultMutableTreeNode node) {
68: if (node != null
69: && node.getUserObject() instanceof ComponentReference) {
70: try {
71: // remove all children from this node
72: node.removeAllChildren();
73: ContelligentComponent component = ((ComponentReference) node
74: .getUserObject()).getComponent();
75: ComponentFactory.getInstance()
76: .invalidateSubtreeExcluding(component);
77: ComponentFactory.getInstance().reload(component);
78: this .editor.addSubcomponents(component, node);
79: ((DefaultTreeModel) this .editor.tree.getModel())
80: .reload(node);
81: this .editor.tree.revalidate();
82: this .editor.tree.repaint();
83: } catch (Throwable re) {
84: ExceptionDialog.show(re);
85: }
86: }
87: }
88: }
|