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: import java.awt.event.InputEvent;
22: import java.awt.event.KeyEvent;
23:
24: import javax.swing.AbstractAction;
25: import javax.swing.Action;
26: import javax.swing.KeyStroke;
27: import javax.swing.tree.DefaultMutableTreeNode;
28:
29: import de.finix.contelligent.client.base.ComponentFactory;
30: import de.finix.contelligent.client.base.ComponentNotFoundException;
31: import de.finix.contelligent.client.base.ComponentReference;
32: import de.finix.contelligent.client.base.ContelligentComponent;
33: import de.finix.contelligent.client.base.Type;
34: import de.finix.contelligent.client.gui.ContelligentAction;
35: import de.finix.contelligent.client.i18n.Resources;
36: import de.finix.contelligent.client.util.ExceptionDialog;
37:
38: public class GoToLinkTargetAction extends AbstractAction implements
39: ContelligentAction {
40: /**
41: *
42: */
43: private final ExplorerEditor editor;
44:
45: public GoToLinkTargetAction(ExplorerEditor editor) {
46: super ("follow_link_action", Resources.followLinkIcon);
47: this .editor = editor;
48: putValue(TYPE, PUSH_ACTION);
49: putValue(ACTION_TYPE, NAVIGATION_ACTION);
50: putValue(ACTION_GROUP, NAVIGATION_REFERENCES_GROUP);
51: putValue(ACTION_POS, NAVIGATION_REFERENCES_LINK);
52: putValue(MENU_TARGET, MENU);
53: putValue(BUTTON_TARGET, TOOLBAR);
54: putValue(POPUP_TARGET, POPUP_SUBMENU);
55: putValue(POPUP_PARENT_ACTION, this .editor.goToAction);
56: putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
57: KeyEvent.VK_T, InputEvent.CTRL_MASK));
58: }
59:
60: public void actionPerformed(ActionEvent e) {
61: DefaultMutableTreeNode node = (DefaultMutableTreeNode) this .editor.tree
62: .getLastSelectedPathComponent();
63: if (node != null
64: && node.getUserObject() instanceof ComponentReference) {
65: try {
66: ContelligentComponent component = ((ComponentReference) node
67: .getUserObject()).getComponent();
68: // is link?
69: if (component.getType().getName().equals(Type.LINK)) {
70: // get icon of the linked component
71: // get linkedComponent (don't follow links in this request)
72: ContelligentComponent linkedComponent = ComponentFactory
73: .getInstance()
74: .getComponent(
75: component.getPath(),
76: component
77: .getPropertyValue(ContelligentComponent.TARGET_PATH));
78: this .editor.selectComponent(linkedComponent);
79: }
80: } catch (ComponentNotFoundException cnfe) {
81: ExceptionDialog.show(cnfe);
82: }
83: }
84: }
85: }
|