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 FindInstancesAction extends AbstractAction implements
042: ContelligentAction {
043: /**
044: *
045: */
046: private final ExplorerEditor editor;
047:
048: public FindInstancesAction(ExplorerEditor editor) {
049: super ("blueprint_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_FINDINSTANCES);
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_I, 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: String typeName;
077: if (component.isBlueprint()) {
078: typeName = component
079: .getDefinedBlueprintType();
080: } else {
081: typeName = component.getTypeName();
082: }
083: ActionResult response = Actions.typeUsages(
084: typeName, true);
085: Collection paths = response.getPaths();
086: if (this .editor.pathSelectionManager != null) {
087: this .editor.pathSelectionManager
088: .setPaths(
089: Resources
090: .getLocalString("show_blueprint_instances"),
091: paths, new Action[0]);
092: this .editor.pathSelectionManager
093: .showPaths();
094: }
095: }
096: }
097: } else {
098: setEnabled(false);
099: }
100: } catch (RemoteActionException rae) {
101: ExceptionDialog.show(rae);
102: } catch (ComponentNotFoundException cnfe) {
103: ExceptionDialog.show(cnfe);
104: }
105: }
106:
107: public void update() {
108: ContelligentComponent component = this.editor
109: .getSelectedComponent();
110: setEnabled(component != null);
111: }
112: }
|