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: import java.util.logging.Logger;
24:
25: import javax.swing.AbstractAction;
26: import javax.swing.Action;
27: import javax.swing.KeyStroke;
28: import javax.swing.tree.DefaultMutableTreeNode;
29:
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.gui.ContelligentAction;
34: import de.finix.contelligent.client.i18n.Resources;
35:
36: public class CreateBookmarkAction extends AbstractAction implements
37: ContelligentAction {
38:
39: static Logger log = Logger.getLogger(CreateBookmarkAction.class
40: .getName());
41:
42: private final ExplorerEditor editor;
43:
44: public CreateBookmarkAction(ExplorerEditor editor) {
45:
46: super ("bookmarks_create_action", Resources.addBookmarkIcon);
47: this .editor = editor;
48:
49: putValue(ROLLOVER_ICON, Resources.addBookmarkIconRollOver);
50: putValue(TYPE, PUSH_ACTION);
51: putValue(ACTION_TYPE, BOOKMARK_ACTION);
52: putValue(ACTION_GROUP, BOOKMARKS_EDIT_BOOKMARKS_GROUP);
53: putValue(ACTION_POS, BOOKMARKS_CREATE_BOOKMARK);
54: putValue(MENU_TARGET, MENU);
55: putValue(BUTTON_TARGET, NO_BUTTON);
56: putValue(POPUP_TARGET, NO_POPUP);
57: putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
58: KeyEvent.VK_D, InputEvent.CTRL_MASK));
59: }
60:
61: public void actionPerformed(ActionEvent e) {
62: // get selected component
63: DefaultMutableTreeNode node = (DefaultMutableTreeNode) this .editor.tree
64: .getLastSelectedPathComponent();
65:
66: String componentPath = "";
67:
68: // and add selected component in the clients bookmarks list
69: if (node != null
70: && node.getUserObject() instanceof ComponentReference) {
71:
72: ContelligentComponent component;
73:
74: try {
75: component = ((ComponentReference) node.getUserObject())
76: .getComponent();
77:
78: // get path of that component
79: componentPath = component.getPath();
80:
81: } catch (ComponentNotFoundException e1) {
82: return;
83: }
84: }
85:
86: // add new bookmark which represents the path
87: if (componentPath == null || componentPath.length() < 2) {
88: return;
89: } else {
90: CreateBookmarkDialog createBookmarkDialog = new CreateBookmarkDialog(
91: componentPath);
92: createBookmarkDialog.setVisible(true);
93: }
94: }
95: }
|