001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.gui.explorer;
019:
020: import java.awt.event.ActionEvent;
021: import java.awt.event.InputEvent;
022: import java.awt.event.KeyEvent;
023: import java.util.Collection;
024:
025: import javax.swing.AbstractAction;
026: import javax.swing.Action;
027: import javax.swing.KeyStroke;
028: import javax.swing.tree.DefaultMutableTreeNode;
029: import javax.swing.tree.TreePath;
030:
031: import de.finix.contelligent.client.base.ComponentNotFoundException;
032: import de.finix.contelligent.client.base.ComponentReference;
033: import de.finix.contelligent.client.base.ContelligentComponent;
034: import de.finix.contelligent.client.gui.ContelligentAction;
035: import de.finix.contelligent.client.i18n.Resources;
036: import de.finix.contelligent.client.remote.ActionResult;
037: import de.finix.contelligent.client.remote.Actions;
038: import de.finix.contelligent.client.remote.RemoteActionException;
039: import de.finix.contelligent.client.util.ExceptionDialog;
040:
041: public class FindUsagesAction extends AbstractAction implements
042: ContelligentAction {
043: /**
044: *
045: */
046: private final ExplorerEditor editor;
047:
048: public FindUsagesAction(ExplorerEditor editor) {
049: super ("usages_action", Resources.defaultViewIcon);
050: this .editor = editor;
051: putValue(ROLLOVER_ICON, Resources.defaultViewIcon);
052: putValue(TYPE, PUSH_ACTION);
053: putValue(ACTION_TYPE, EDIT_ACTION);
054: putValue(ACTION_GROUP, EDIT_SEARCH_GROUP);
055: putValue(ACTION_POS, EDIT_SEARCH_SHOWUSAGES);
056: putValue(MENU_TARGET, MENU);
057: putValue(BUTTON_TARGET, NO_BUTTON);
058: putValue(POPUP_TARGET, POPUP_SUBMENU);
059: putValue(POPUP_PARENT_ACTION, this .editor.findAction);
060: putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
061: KeyEvent.VK_U, InputEvent.CTRL_MASK));
062: }
063:
064: public void actionPerformed(ActionEvent e) {
065: try {
066: if (!this .editor.getView().isEditInProgress()) {
067: final TreePath[] selectionPaths = this .editor.tree
068: .getSelectionPaths();
069: if (selectionPaths.length > 0) {
070: DefaultMutableTreeNode firstNode = ((DefaultMutableTreeNode) selectionPaths[0]
071: .getLastPathComponent());
072: if (firstNode != null
073: && firstNode.getUserObject() instanceof ComponentReference) {
074: ContelligentComponent component = ((ComponentReference) firstNode
075: .getUserObject()).getComponent();
076: ActionResult response = Actions.usages(
077: component.getPath(), false, false);
078: Collection paths = response.getPaths();
079: if (this .editor.pathSelectionManager != null) {
080: this .editor.pathSelectionManager
081: .setPaths(
082: Resources
083: .getLocalString("show_usages"),
084: paths, new Action[0]);
085: this .editor.pathSelectionManager
086: .showPaths();
087: }
088: }
089: }
090: } else {
091: setEnabled(false);
092: }
093: } catch (RemoteActionException rae) {
094: ExceptionDialog.show(rae);
095: } catch (ComponentNotFoundException cnfe) {
096: ExceptionDialog.show(cnfe);
097: }
098: }
099:
100: public void update() {
101: ContelligentComponent component = this.editor
102: .getSelectedComponent();
103: setEnabled(component != null && component.isBlueprint());
104: }
105: }
|