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 java.awt.geom.Area;
023: import java.util.Collection;
024: import org.netbeans.modules.bpel.design.geometry.FBounds;
025: import org.netbeans.modules.bpel.design.geometry.FDimension;
026: import org.netbeans.modules.bpel.design.geometry.FRectangle;
027: import org.netbeans.modules.bpel.design.layout.LayoutManager;
028: import org.netbeans.modules.bpel.design.model.DiagramModel;
029: import org.netbeans.modules.bpel.design.model.connections.Connection;
030: import org.netbeans.modules.bpel.design.model.connections.Direction;
031: import org.netbeans.modules.bpel.design.model.elements.ContentElement;
032: import org.netbeans.modules.bpel.design.model.elements.PlaceHolderElement;
033: import org.netbeans.modules.bpel.design.model.elements.SubprocessBorder;
034: import org.netbeans.modules.bpel.design.model.elements.VisualElement;
035: import org.netbeans.modules.bpel.editors.api.nodes.NodeType;
036: import org.netbeans.modules.bpel.design.selection.PlaceHolder;
037: import org.netbeans.modules.bpel.model.api.Activity;
038: import org.netbeans.modules.bpel.model.api.RepeatUntil;
039:
040: public class RepeatUntilPattern extends CompositePattern {
041:
042: private VisualElement gateway;
043: private PlaceHolderElement placeHolder;
044: private Connection connection1;
045: private Connection connection2;
046:
047: public RepeatUntilPattern(DiagramModel model) {
048: super (model);
049: }
050:
051: public VisualElement getFirstElement() {
052: return getBorder();
053: }
054:
055: public VisualElement getLastElement() {
056: return getBorder();
057: }
058:
059: protected void createElementsImpl() {
060: connection1 = new Connection(this );
061: connection2 = new Connection(this );
062:
063: setBorder(new SubprocessBorder());
064: registerTextElement(getBorder());
065:
066: gateway = ContentElement.createRepeatUntilGateway();
067: appendElement(gateway);
068:
069: placeHolder = new PlaceHolderElement();
070: appendElement(placeHolder);
071:
072: RepeatUntil repeatUntilOM = (RepeatUntil) getOMReference();
073:
074: Activity activity = (Activity) repeatUntilOM.getActivity();
075:
076: if (activity != null) {
077: Pattern p = getModel().createPattern(activity);
078: p.setParent(this );
079: }
080: }
081:
082: public void createPlaceholders(Pattern draggedPattern,
083: Collection<PlaceHolder> placeHolders) {
084: if (!(draggedPattern.getOMReference() instanceof Activity))
085: return;
086:
087: if (placeHolder.getPattern() != null) {
088: placeHolders.add(new InnerPlaceHolder(draggedPattern));
089: }
090: }
091:
092: public FBounds layoutPattern(LayoutManager manager) {
093: double width;
094: double height;
095:
096: if (getNestedPatterns().isEmpty()) {
097: placeHolder.setLocation(0, 0);
098:
099: width = placeHolder.getWidth();
100: height = placeHolder.getHeight();
101:
102: } else {
103: Pattern p = getNestedPattern();
104: FBounds pSize = p.getBounds();
105: manager.setPatternPosition(p, 0, 0);
106:
107: width = pSize.width;
108: height = pSize.height;
109: }
110:
111: double x0 = -gateway.getWidth() - LayoutManager.HSPACING;
112: double y0 = 0;
113:
114: gateway.setLocation(x0, height + LayoutManager.VSPACING);
115:
116: width += gateway.getWidth() + LayoutManager.HSPACING;
117: height += gateway.getHeight() + LayoutManager.VSPACING;
118:
119: setOrigin(x0 + width / 2, y0 + height / 2);
120:
121: getBorder().setClientRectangle(x0, y0, width, height);
122:
123: return getBorder().getBounds();
124: }
125:
126: public String getDefaultName() {
127: return "RepeatUntil"; // NOI18N
128: }
129:
130: protected void onAppendPattern(Pattern nestedPattern) {
131: removeElement(placeHolder);
132: }
133:
134: protected void onRemovePattern(Pattern nestedPattern) {
135: appendElement(placeHolder);
136: }
137:
138: public void reconnectElements() {
139: Pattern p = getNestedPattern();
140:
141: if (p != null) {
142: connection1.connect(gateway, Direction.TOP, p
143: .getFirstElement(), Direction.LEFT);
144:
145: connection2.connect(p.getLastElement(), Direction.BOTTOM,
146: gateway, Direction.RIGHT);
147: } else {
148: connection1.connect(gateway, Direction.TOP, placeHolder,
149: Direction.LEFT);
150:
151: connection2.connect(placeHolder, Direction.BOTTOM, gateway,
152: Direction.RIGHT);
153: }
154: }
155:
156: public NodeType getNodeType() {
157: return NodeType.REPEAT_UNTIL;
158: }
159:
160: public Area createSelection() {
161: Area res = new Area(getBorder().getShape());
162: res.subtract(new Area(gateway.getShape()));
163: return res;
164: }
165:
166: class InnerPlaceHolder extends PlaceHolder {
167: public InnerPlaceHolder(Pattern draggedPattern) {
168: super (RepeatUntilPattern.this , draggedPattern, placeHolder
169: .getCenterX(), placeHolder.getCenterY());
170: }
171:
172: public void drop() {
173: Pattern p = getDraggedPattern();
174: ((RepeatUntil) getOMReference()).setActivity((Activity) p
175: .getOMReference());
176: }
177: }
178:
179: }
|