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.util.logging.Level;
22:
23: import javax.swing.AbstractAction;
24: import javax.swing.Action;
25: import javax.swing.KeyStroke;
26:
27: import de.finix.contelligent.client.MainPanel;
28: import de.finix.contelligent.client.base.ContelligentComponent;
29: import de.finix.contelligent.client.base.Description;
30: import de.finix.contelligent.client.base.TypeFactory;
31: import de.finix.contelligent.client.base.TypeNotFoundException;
32: import de.finix.contelligent.client.gui.ContelligentAction;
33: import de.finix.contelligent.client.i18n.Resources;
34:
35: final class HelpAction extends AbstractAction implements
36: ContelligentAction {
37: /**
38: *
39: */
40: private final ExplorerEditor editor;
41:
42: public HelpAction(ExplorerEditor editor) {
43: super ("help_action", Resources.helpIcon);
44: this .editor = editor;
45: putValue(TYPE, PUSH_ACTION);
46: putValue(ACTION_TYPE, HELP_ACTION);
47: putValue(MENU_TARGET, MENU);
48: putValue(POPUP_TARGET, POPUP_MENU);
49: putValue(BUTTON_TARGET, TOOLBAR);
50: putValue(Action.ACCELERATOR_KEY, KeyStroke
51: .getKeyStroke("shift F1"));
52: }
53:
54: public void actionPerformed(ActionEvent e) {
55: ContelligentComponent selectedComponent = this .editor
56: .getSelectedComponent();
57: if (selectedComponent != null) {
58: Description description = getDescription(selectedComponent);
59: if (description != null) {
60: MainPanel.showURL(description.getHelpURL());
61: }
62: }
63: }
64:
65: private Description getDescription(ContelligentComponent component) {
66: Description description = null;
67: if (component.isBlueprint()) {
68: try {
69: description = TypeFactory.getInstance().getType(
70: component.getDefinedBlueprintType())
71: .getDescription(Resources.getLocale());
72: } catch (TypeNotFoundException e) {
73: ExplorerEditor.logger.log(Level.SEVERE,
74: "Defined type for blueprint component "
75: + component.getPath() + " not found!",
76: e);
77: return null;
78: }
79: } else {
80: description = component.getType().getDescription(
81: Resources.getLocale());
82: }
83: return description;
84: }
85:
86: public void update() {
87: ContelligentComponent component = this .editor
88: .getSelectedComponent();
89: if (component != null) {
90: Description description = getDescription(component);
91: if (description != null && description.getHelpURL() != null
92: && description.getHelpURL().length() > 1) {
93: this .editor.helpAction.setEnabled(true);
94: } else {
95: this .editor.helpAction.setEnabled(false);
96: }
97: }
98: }
99: }
|