01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * When distributing Covered Code, include this CDDL Header Notice in each file
10: * and include the License file at http://www.netbeans.org/cddl.txt.
11: * If applicable, add the following below the CDDL Header, with the fields
12: * enclosed by brackets [] replaced by your own identifying information:
13: * "Portions Copyrighted [year] [name of copyright owner]"
14: *
15: * The Original Software is NetBeans. The Initial Developer of the Original
16: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17: * Microsystems, Inc. All Rights Reserved.
18: */
19: package org.netbeans.modules.bpel.nodes.actions;
20:
21: import org.netbeans.modules.refactoring.spi.ui.UI;
22: import org.netbeans.modules.xml.refactoring.ui.WhereUsedQueryUI;
23: import org.openide.nodes.Node;
24: import org.netbeans.modules.xml.xam.Referenceable;
25: import org.netbeans.modules.bpel.nodes.BpelNode;
26: import org.openide.text.CloneableEditorSupport;
27: import org.openide.util.HelpCtx;
28: import org.openide.util.actions.CookieAction;
29: import org.openide.windows.TopComponent;
30:
31: /**
32: * @author Vladimir Yaroslavskiy
33: * @version 2006.10.27
34: */
35: public class FindUsagesAction extends CookieAction {
36: private static final long serialVersionUID = 1L;
37: private static final Class[] COOKIE_ARRAY = new Class[] {};
38:
39: public FindUsagesAction() {
40: super ();
41: }
42:
43: public boolean enable(Node[] nodes) {
44: return nodes != null && nodes.length == 1
45: && nodes[0] instanceof BpelNode;
46: }
47:
48: protected Referenceable getReferenceable(Node[] nodes) {
49: if (nodes.length != 1) {
50: return null;
51: }
52: Node node = nodes[0];
53:
54: if (!(node instanceof BpelNode)) {
55: return null;
56: }
57: Object object = ((BpelNode) node).getReference();
58:
59: if (object instanceof Referenceable) {
60: return (Referenceable) object;
61: }
62: return null;
63: }
64:
65: public String getName() {
66: return "Find Usages"; // NOI18N
67: }
68:
69: public HelpCtx getHelpCtx() {
70: return new HelpCtx(getClass());
71: }
72:
73: protected boolean asynchronous() {
74: return false;
75: }
76:
77: public void performAction(Node[] nodes) {
78: assert nodes.length == 1 : "Length of nodes array should be 1";
79: Referenceable ref = getReferenceable(nodes);
80: assert ref != null : "The node's NamedReferenceable should not be null";
81: WhereUsedQueryUI ui = new WhereUsedQueryUI(ref);
82: TopComponent activetc = TopComponent.getRegistry()
83: .getActivated();
84:
85: if (activetc instanceof CloneableEditorSupport.Pane) {
86: UI.openRefactoringUI(ui, activetc);
87: } else {
88: UI.openRefactoringUI(ui);
89: }
90: }
91:
92: protected int mode() {
93: return CookieAction.MODE_EXACTLY_ONE;
94: }
95:
96: protected Class[] cookieClasses() {
97: return COOKIE_ARRAY;
98: }
99: }
|