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 org.netbeans.modules.bpel.editors.api.nodes.NodeType;
023:
024: import org.netbeans.modules.bpel.model.api.Catch;
025: import org.netbeans.modules.bpel.model.api.CompensatableActivityHolder;
026: import org.netbeans.modules.bpel.model.api.FaultHandlers;
027: import org.netbeans.modules.bpel.design.geometry.FBounds;
028: import org.netbeans.modules.bpel.design.geometry.FDimension;
029: import org.netbeans.modules.bpel.design.layout.LayoutManager;
030: import org.netbeans.modules.bpel.design.model.DiagramModel;
031: import org.netbeans.modules.bpel.design.model.elements.GroupBorder;
032: import org.netbeans.modules.bpel.design.model.elements.VisualElement;
033:
034: public class FaultHandlersPattern extends CompositePattern {
035:
036: public FaultHandlersPattern(DiagramModel model) {
037: super (model);
038: }
039:
040: protected void onAppendPattern(Pattern nestedPattern) {
041: }
042:
043: protected void onRemovePattern(Pattern nestedPattern) {
044: }
045:
046: public VisualElement getFirstElement() {
047: return getBorder();
048: }
049:
050: public VisualElement getLastElement() {
051: return getBorder();
052: }
053:
054: protected void createElementsImpl() {
055: setBorder(new GroupBorder());
056: getBorder().setLabelText(getDefaultName());
057:
058: FaultHandlers faultHandlers = (FaultHandlers) getOMReference();
059:
060: Catch[] catches = faultHandlers.getCatches();
061: CompensatableActivityHolder catchAll = faultHandlers
062: .getCatchAll();
063:
064: for (Catch c : catches) {
065: Pattern p = getModel().createPattern(c);
066: p.setParent(this );
067: }
068:
069: if (catchAll != null) {
070: Pattern p = getModel().createPattern(catchAll);
071: p.setParent(this );
072: }
073: }
074:
075: public FBounds layoutPattern(LayoutManager manager) {
076: FaultHandlers faultHandlers = (FaultHandlers) getOMReference();
077:
078: Catch[] catches = faultHandlers.getCatches();
079: CompensatableActivityHolder catchAll = faultHandlers
080: .getCatchAll();
081:
082: float xPosition = 0;
083:
084: float width;
085: float height = 0;
086:
087: if (catchAll != null) {
088: Pattern p = getNestedPattern(catchAll);
089: manager.setPatternPosition(p, xPosition, 0);
090:
091: FDimension size = p.getBounds().getSize();
092:
093: height = size.height;
094: xPosition += size.width + LayoutManager.HSPACING;
095: }
096:
097: for (Catch c : catches) {
098: Pattern p = getNestedPattern(c);
099: manager.setPatternPosition(p, xPosition, 0);
100:
101: FDimension size = p.getBounds().getSize();
102:
103: height = Math.max(height, size.height);
104: xPosition += size.width + LayoutManager.HSPACING;
105: }
106:
107: height = Math.max(height, 20);
108: width = Math.max(xPosition - LayoutManager.HSPACING, 20);
109:
110: getBorder().setClientRectangle(0, 0, width, height);
111: return getBorder().getBounds();
112:
113: }
114:
115: public String getDefaultName() {
116: return "Fault Handlers"; // NOI18N
117: }
118:
119: public NodeType getNodeType() {
120: return NodeType.FAULT_HANDLERS;
121: }
122: }
|