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 javax.swing.KeyStroke;
024: import org.netbeans.modules.bpel.editors.api.utils.Util;
025: import org.netbeans.modules.bpel.mapper.multiview.BpelDesignContextFactory;
026: import org.netbeans.modules.bpel.model.api.BpelEntity;
027: import org.netbeans.modules.bpel.nodes.BpelNode;
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: //import org.netbeans.modules.bpel.mapper.topcomp.BpelMapperTopComponent;
035:
036: /**
037: *
038: * @author Vitaly Bychkov
039: * @version 1.0
040: *
041: */
042: public class ShowBpelMapperAction extends BpelNodeAction {
043:
044: private static final long serialVersionUID = 1L;
045:
046: // public static final KeyStroke GOTOMAPPER_KEYSTROKE = KeyStroke.getKeyStroke(
047: // NbBundle.getMessage(ShowBpelMapperAction.class,"ACT_GoToMapperAction"));// NOI18N
048:
049: public ShowBpelMapperAction() {
050: super ();
051: // putValue(ShowBpelMapperAction.ACCELERATOR_KEY, GOTOMAPPER_KEYSTROKE);
052: }
053:
054: protected String getBundleName() {
055: return NbBundle.getMessage(ShowBpelMapperAction.class,
056: "CTL_ShowBpelMapperAction"); // NOI18N
057: }
058:
059: public ActionType getType() {
060: return ActionType.SHOW_BPEL_MAPPER;
061: }
062:
063: //TODO m
064: @Override
065: public boolean enable(final Node[] nodes) {
066: if (nodes == null || nodes.length == 0) {
067: return false;
068: }
069: boolean isEnable = false;
070:
071: DataNode dataNode = null;
072: for (int i = 0; i < nodes.length; i++) {
073: if (nodes[i] instanceof BpelNode) {
074: Object ref = ((BpelNode) nodes[i]).getReference();
075:
076: isEnable = ref instanceof BpelEntity
077: && BpelDesignContextFactory.getInstance()
078: .isMappableEntity((BpelEntity) ref);
079: if (isEnable) {
080: break;
081: }
082: }
083: if (nodes[i] instanceof DataNode) {
084: dataNode = (DataNode) nodes[i];
085: }
086: }
087:
088: // temporary hack, tc doesn't have nested mv tc activated nodes
089: if (dataNode != null) {
090: TopComponent activatedTc = WindowManager.getDefault()
091: .getRegistry().getActivated();
092: Node[] activatedNodes = WindowManager.getDefault()
093: .getRegistry().getActivatedNodes();
094: BpelEntity[] entities = getBpelEntities(activatedNodes);
095: isEnable = entities != null
096: && entities.length > 0
097: && BpelDesignContextFactory.getInstance()
098: .isMappableEntity(entities[0]);
099: }
100: return isEnable;
101: }
102:
103: private boolean isDataNode(Node[] nodes) {
104: boolean isDataNode = true;
105: DataNode dataNode = null;
106: for (int i = 0; i < nodes.length; i++) {
107: if (nodes[i] instanceof BpelNode) {
108: isDataNode = false;
109: }
110: if (nodes[i] instanceof DataNode) {
111: dataNode = (DataNode) nodes[i];
112: }
113: }
114: isDataNode = isDataNode && dataNode != null;
115: return isDataNode;
116: }
117:
118: @Override
119: public void performAction(Node[] nodes) {
120: if (!enable(nodes)) {
121: return;
122: }
123:
124: if (isDataNode(nodes)) {
125: nodes = WindowManager.getDefault().getRegistry()
126: .getActivatedNodes();
127: }
128:
129: BpelEntity[] entities = getBpelEntities(nodes);
130: if (entities != null && entities.length > 0) {
131: performAction(entities);
132: }
133: }
134:
135: protected void performAction(BpelEntity[] bpelEntities) {
136: Util.goToBusinessRules(bpelEntities[0]);
137: /** TopComponent mapperTC = WindowManager.getDefault().
138: findTopComponent(BpelMapperTopComponent.ID);
139: if (mapperTC == null) {
140: return;
141: }
142:
143: if (!(mapperTC.isOpened())) {
144: mapperTC.open();
145: }
146: mapperTC.requestVisible();
147: mapperTC.requestActive();
148: */
149: }
150:
151: @Override
152: public boolean isChangeAction() {
153: return false;
154: }
155: }
|