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 org.netbeans.modules.bpel.editors.api.utils.Util;
024: import org.netbeans.modules.bpel.mapper.logging.multiview.LoggingDesignContextFactory;
025: import org.netbeans.modules.bpel.model.api.BpelEntity;
026: import org.netbeans.modules.bpel.model.api.ExtensibleElements;
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: /**
035: *
036: * @author Vitaly Bychkov
037: * @version 1.0
038: *
039: */
040: public class GoToLoggingAction extends BpelNodeAction {
041:
042: private static final long serialVersionUID = 1L;
043:
044: // public static final KeyStroke GOTOLOGGING_KEYSTROKE = KeyStroke.getKeyStroke(
045: // NbBundle.getMessage(GoToLoggingAction.class,"ACT_GoToLoggingAction"));// NOI18N
046:
047: public GoToLoggingAction() {
048: super ();
049: // putValue(GoToLoggingAction.ACCELERATOR_KEY, GOTOLOGGING_KEYSTROKE);
050: }
051:
052: protected String getBundleName() {
053: return NbBundle.getMessage(GoToLoggingAction.class,
054: "CTL_GoToLoggingAction"); // NOI18N
055: }
056:
057: public ActionType getType() {
058: return ActionType.GO_TO_LOGGING;
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: Object ref = ((BpelNode) nodes[i]).getReference();
073:
074: isEnable = ref instanceof ExtensibleElements
075: && LoggingDesignContextFactory
076: .canExtend((ExtensibleElements) ref);
077: if (isEnable) {
078: break;
079: }
080: }
081: if (nodes[i] instanceof DataNode) {
082: dataNode = (DataNode) nodes[i];
083: }
084: }
085:
086: // temporary hack, tc doesn't have nested mv tc activated nodes
087: if (dataNode != null) {
088: TopComponent activatedTc = WindowManager.getDefault()
089: .getRegistry().getActivated();
090: Node[] activatedNodes = WindowManager.getDefault()
091: .getRegistry().getActivatedNodes();
092: BpelEntity[] entities = getBpelEntities(activatedNodes);
093: isEnable = entities != null
094: && entities.length > 0
095: && entities[0] instanceof ExtensibleElements
096: && LoggingDesignContextFactory
097: .canExtend((ExtensibleElements) entities[0]);
098: }
099: return isEnable;
100: }
101:
102: private boolean isDataNode(Node[] nodes) {
103: boolean isDataNode = true;
104: DataNode dataNode = null;
105: for (int i = 0; i < nodes.length; i++) {
106: if (nodes[i] instanceof BpelNode) {
107: isDataNode = false;
108: }
109: if (nodes[i] instanceof DataNode) {
110: dataNode = (DataNode) nodes[i];
111: }
112: }
113: isDataNode = isDataNode && dataNode != null;
114: return isDataNode;
115: }
116:
117: @Override
118: public void performAction(Node[] nodes) {
119: if (!enable(nodes)) {
120: return;
121: }
122:
123: if (isDataNode(nodes)) {
124: nodes = WindowManager.getDefault().getRegistry()
125: .getActivatedNodes();
126: }
127:
128: BpelEntity[] entities = getBpelEntities(nodes);
129: if (entities != null && entities.length > 0) {
130: performAction(entities);
131: }
132: }
133:
134: protected void performAction(BpelEntity[] bpelEntities) {
135: Util.goToLoggingAlerting(bpelEntities[0]);
136: }
137:
138: @Override
139: public boolean isChangeAction() {
140: return false;
141: }
142: }
|