001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.bpel.nodes.actions;
020:
021: import org.netbeans.modules.bpel.nodes.actions.BpelNodeAction;
022: import org.netbeans.modules.bpel.editors.api.nodes.actions.ActionType;
023: import java.awt.event.KeyEvent;
024: import javax.swing.KeyStroke;
025: import org.netbeans.modules.bpel.model.api.BpelEntity;
026: import org.netbeans.modules.bpel.nodes.BpelNode;
027: import org.netbeans.modules.bpel.editors.api.utils.Util;
028: import org.openide.loaders.DataNode;
029: import org.openide.nodes.Node;
030: import org.openide.util.NbBundle;
031: import org.openide.windows.TopComponent;
032: import org.openide.windows.WindowManager;
033:
034: /**
035: *
036: * @author Vitaly Bychkov
037: * @version 21 April 2006
038: */
039: public class GoToDiagrammAction extends BpelNodeAction {
040: private static final long serialVersionUID = 1L;
041: public static final KeyStroke GOTODIAGRAMM_KEYSTROKE = KeyStroke
042: .getKeyStroke(KeyEvent.VK_D, KeyEvent.ALT_DOWN_MASK);
043:
044: //KeyStroke.getKeyStroke(
045: //NbBundle.getMessage(GoToDiagrammAction.class,"ACT_GoToDiagrammAction"));// NOI18N
046:
047: public GoToDiagrammAction() {
048: super ();
049: // putValue(GoToDiagrammAction.ACCELERATOR_KEY, GOTODIAGRAMM_KEYSTROKE);
050: }
051:
052: protected String getBundleName() {
053: return NbBundle
054: .getMessage(getClass(), "CTL_GoToDiagrammAction"); // NOI18N
055: }
056:
057: public ActionType getType() {
058: return ActionType.GO_TO_DIAGRAMM;
059: }
060:
061: //TODO m
062: @Override
063: public boolean enable(final Node[] nodes) {
064: if (nodes == null || nodes.length == 0) {
065: return false;
066: }
067: boolean isEnable = false;
068:
069: DataNode dataNode = null;
070: for (int i = 0; i < nodes.length; i++) {
071: if (nodes[i] instanceof BpelNode) {
072: isEnable = true;
073: }
074: if (nodes[i] instanceof DataNode) {
075: dataNode = (DataNode) nodes[i];
076: }
077: }
078:
079: // temporary hack, tc doesn't have nested mv tc activated nodes
080: if (dataNode != null) {
081: TopComponent activatedTc = WindowManager.getDefault()
082: .getRegistry().getActivated();
083: Node[] activatedNodes = WindowManager.getDefault()
084: .getRegistry().getActivatedNodes();
085: BpelEntity[] entities = getBpelEntities(activatedNodes);
086: isEnable = entities != null && entities.length > 0;
087: }
088: return isEnable;
089: }
090:
091: private boolean isDataNode(Node[] nodes) {
092: boolean isDataNode = true;
093: DataNode dataNode = null;
094: for (int i = 0; i < nodes.length; i++) {
095: if (nodes[i] instanceof BpelNode) {
096: isDataNode = false;
097: }
098: if (nodes[i] instanceof DataNode) {
099: dataNode = (DataNode) nodes[i];
100: }
101: }
102: isDataNode = isDataNode && dataNode != null;
103: return isDataNode;
104: }
105:
106: @Override
107: public void performAction(Node[] nodes) {
108: if (!enable(nodes)) {
109: return;
110: }
111:
112: if (isDataNode(nodes)) {
113: nodes = WindowManager.getDefault().getRegistry()
114: .getActivatedNodes();
115: }
116:
117: BpelEntity[] entities = getBpelEntities(nodes);
118: if (entities != null && entities.length > 0) {
119: performAction(entities);
120: }
121: }
122:
123: protected void performAction(BpelEntity[] bpelEntities) {
124: Util.goToDesign(bpelEntities[0]);
125: }
126:
127: @Override
128: public boolean isChangeAction() {
129: return false;
130: }
131: }
|