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:
020: package org.netbeans.modules.bpel.design.model.patterns;
021:
022: import javax.swing.SwingUtilities;
023: import org.netbeans.modules.bpel.design.DnDHandler;
024: import org.netbeans.modules.bpel.design.model.DiagramModel;
025: import org.netbeans.modules.bpel.design.model.PartnerLinkHelper;
026: import org.netbeans.modules.bpel.design.model.elements.ContentElement;
027: import org.netbeans.modules.bpel.design.model.elements.VisualElement;
028: import org.netbeans.modules.bpel.editors.api.nodes.NodeType;
029: import org.netbeans.modules.bpel.model.api.BpelContainer;
030: import org.netbeans.modules.bpel.model.api.BpelEntity;
031: import org.netbeans.modules.bpel.model.api.BpelModel;
032: import org.netbeans.modules.bpel.model.api.CreateInstanceActivity;
033: import org.netbeans.modules.bpel.model.api.Receive;
034: import org.netbeans.modules.bpel.model.api.support.TBoolean;
035:
036: /**
037: *
038: * @author Alexey Yarmolenko
039: */
040: public class ReceivePattern extends BasicActivityPattern {
041: /**
042: * Creates a new instance of BasicActivityPattern.
043: * @param view - DesignView used to draw diagram
044: */
045:
046: public ReceivePattern(DiagramModel model) {
047: super (model);
048: }
049:
050: protected void createElementsImpl() {
051: VisualElement element = ContentElement.createReceive();
052: appendElement(element);
053: registerTextElement(element);
054: }
055:
056: public String getDefaultName() {
057: return "Receive"; // NOI18N
058: }
059:
060: public NodeType getNodeType() {
061: return NodeType.RECEIVE;
062: }
063:
064: public void reconnectElements() {
065: clearConnections();
066: new PartnerLinkHelper(getModel()).updateMessageFlowLinks(this );
067: }
068:
069: public void setParent(CompositePattern newParent) {
070: final Receive r = (Receive) getOMReference();
071: if (r != null
072: && r.getCookie(DnDHandler.class) == DnDHandler.class) {
073:
074: r.removeCookie(DnDHandler.class);
075:
076: SwingUtilities.invokeLater(new Runnable() {
077: public void run() {
078: BpelModel model = getBpelModel();
079: CreateInstanceActivity first = findCreateInstance(model
080: .getProcess().getActivity());
081: if (r.equals(first)) {
082: r.setCreateInstance(TBoolean.YES);
083: }
084: }
085: });
086: }
087: super .setParent(newParent);
088: }
089:
090: private static CreateInstanceActivity findCreateInstance(
091: BpelEntity entity) {
092: if (entity instanceof CreateInstanceActivity) {
093: return (CreateInstanceActivity) entity;
094: }
095: if (entity instanceof BpelContainer) {
096: for (BpelEntity e : ((BpelContainer) entity).getChildren()) {
097: CreateInstanceActivity res = findCreateInstance(e);
098: if (res != null) {
099: return res;
100: }
101: }
102: }
103: return null;
104: }
105: }
|