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.mapper.logging.multiview;
020:
021: import org.netbeans.modules.bpel.mapper.multiview.*;
022: import java.beans.PropertyChangeEvent;
023: import java.beans.PropertyChangeListener;
024: import org.netbeans.modules.soa.ui.nodes.InstanceRef;
025: import org.netbeans.modules.bpel.model.api.BpelEntity;
026: import org.netbeans.modules.bpel.model.api.BpelModel;
027: import org.openide.nodes.Node;
028: import org.openide.util.Lookup;
029: import org.openide.windows.TopComponent;
030:
031: /**
032: *
033: * @author nk160297
034: * @author Vitaly Bychkov
035: */
036: public class LoggingContextChangeListener implements
037: PropertyChangeListener {
038:
039: private DesignContextController mController;
040:
041: /** Creates a new instance of DesignContextChangeListener */
042: public LoggingContextChangeListener(
043: DesignContextController controller) {
044: assert controller != null;
045: mController = controller;
046: }
047:
048: public synchronized void propertyChange(PropertyChangeEvent evt) {
049: String propertyName = evt.getPropertyName();
050: BpelDesignContext newBpelContext = null;
051:
052: if (propertyName
053: .equals(TopComponent.Registry.PROP_ACTIVATED_NODES)) {
054: newBpelContext = getActivatedContext();
055: } else {
056: // Other properties are not supported
057: return;
058: }
059: //
060: if (mController != null && newBpelContext != null) {
061: mController.setContext(newBpelContext);
062: }
063: }
064:
065: // TODO r after implementation of logging design context factory
066: /**
067: * Don't chnage context in case non bpel entity were selected
068: *
069: * @return new context, null if context should be changed,
070: * bpel model changes are supported self by DesignContextController
071: */
072: public static BpelDesignContext getActivatedContext() {
073: Node[] nodes = TopComponent.getRegistry().getActivatedNodes();
074: if (nodes == null || nodes.length != 1) {
075: return null;
076: }
077: BpelEntity bpelEntity = null;
078: if (nodes[0] instanceof InstanceRef) {
079: Object entity = ((InstanceRef) nodes[0]).getReference();
080: if (entity instanceof BpelEntity) {
081: bpelEntity = (BpelEntity) entity;
082: }
083: } else {
084: return null;
085: }
086:
087: Lookup lookup = nodes[0].getLookup();
088: BpelDesignContext bpelContext = new BpelDesignContextImpl(
089: bpelEntity, bpelEntity, bpelEntity, nodes[0], lookup);
090: // new BpelDesignContext(bpelEntity, nodes[0], lookup);
091: return bpelContext;
092: }
093:
094: public static BpelDesignContext getActivatedContext(
095: BpelModel currentBpelModel) {
096: if (currentBpelModel == null) {
097: return null;
098: }
099:
100: Node[] nodes = TopComponent.getRegistry().getActivatedNodes();
101: if (nodes == null || nodes.length != 1) {
102: return null;
103: }
104: BpelEntity bpelEntity = null;
105: if (nodes[0] instanceof InstanceRef) {
106: Object entity = ((InstanceRef) nodes[0]).getReference();
107: if (entity instanceof BpelEntity
108: && currentBpelModel.equals(((BpelEntity) entity)
109: .getBpelModel())) {
110: bpelEntity = (BpelEntity) entity;
111: }
112: } else {
113: return null;
114: }
115:
116: Lookup lookup = nodes[0].getLookup();
117: BpelDesignContext bpelContext = new BpelDesignContextImpl(
118: bpelEntity, bpelEntity, bpelEntity, nodes[0], lookup);
119: return bpelContext;
120: }
121:
122: }
|