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.util.Collection;
023:
024: import org.netbeans.modules.bpel.model.api.Activity;
025: import org.netbeans.modules.bpel.model.api.Catch;
026: import org.netbeans.modules.bpel.design.geometry.FBounds;
027: import org.netbeans.modules.bpel.design.geometry.FDimension;
028: import org.netbeans.modules.bpel.design.layout.LayoutManager;
029: import org.netbeans.modules.bpel.design.model.DiagramModel;
030: import org.netbeans.modules.bpel.design.model.elements.GroupBorder;
031: import org.netbeans.modules.bpel.design.model.elements.PlaceHolderElement;
032: import org.netbeans.modules.bpel.design.model.elements.VisualElement;
033: import org.netbeans.modules.bpel.editors.api.nodes.NodeType;
034: import org.netbeans.modules.bpel.design.selection.PlaceHolder;
035:
036: public class CatchPattern extends CompositePattern {
037:
038: private PlaceHolderElement placeHolder;
039:
040: public CatchPattern(DiagramModel model) {
041: super (model);
042: placeHolder = new PlaceHolderElement();
043: }
044:
045: protected void onAppendPattern(Pattern nestedPattern) {
046: removeElement(placeHolder);
047: }
048:
049: protected void onRemovePattern(Pattern nestedPattern) {
050: appendElement(placeHolder);
051: }
052:
053: public VisualElement getFirstElement() {
054: return getBorder();
055: }
056:
057: public VisualElement getLastElement() {
058: return getBorder();
059: }
060:
061: public FBounds layoutPattern(LayoutManager manager) {
062:
063: double width;
064: double height;
065:
066: Activity a = (Activity) ((Catch) getOMReference())
067: .getActivity();
068:
069: if (a == null) {
070: placeHolder.setLocation(0, 0);
071: width = placeHolder.getWidth();
072: height = placeHolder.getHeight();
073: } else {
074: Pattern p = getNestedPattern(a);
075: manager.setPatternPosition(p, 0, 0);
076: FBounds bounds = p.getBounds();
077: width = bounds.width;
078: height = bounds.height;
079: }
080: getBorder().setClientRectangle(0, 0, width, height);
081: return getBorder().getBounds();
082: }
083:
084: protected void createElementsImpl() {
085: setBorder(new GroupBorder());
086: getBorder().setLabelText(getDefaultName());
087:
088: appendElement(placeHolder);
089:
090: Activity a = (Activity) ((Catch) getOMReference())
091: .getActivity();
092:
093: if (a != null) {
094: Pattern p = getModel().createPattern(a);
095: p.setParent(this );
096: }
097: }
098:
099: public String getDefaultName() {
100: return "Catch"; // NOI18N
101: }
102:
103: public void createPlaceholders(Pattern draggedPattern,
104: Collection<PlaceHolder> placeHolders) {
105: if (!(draggedPattern.getOMReference() instanceof Activity))
106: return;
107:
108: if (placeHolder.getPattern() != null) {
109: placeHolders.add(new InnerPlaceHolder(draggedPattern));
110: }
111: }
112:
113: public NodeType getNodeType() {
114: return NodeType.CATCH;
115: }
116:
117: private class InnerPlaceHolder extends PlaceHolder {
118: public InnerPlaceHolder(Pattern draggedPattern) {
119: super (CatchPattern.this , draggedPattern, placeHolder
120: .getCenterX(), placeHolder.getCenterY());
121: }
122:
123: public void drop() {
124: Pattern p = getDraggedPattern();
125: ((Catch) getOMReference()).setActivity((Activity) p
126: .getOMReference());
127: }
128: }
129: }
|