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.EventHandlers;
025: import org.netbeans.modules.bpel.model.api.OnAlarmEvent;
026: import org.netbeans.modules.bpel.model.api.OnEvent;
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 EventHandlersPattern extends CompositePattern {
035:
036: public EventHandlersPattern(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: public boolean isDraggable() {
055: return false;
056: }
057:
058: public FBounds layoutPattern(LayoutManager manager) {
059:
060: float xPosition = 0;
061: float height = 0;
062:
063: EventHandlers eventHandlers = (EventHandlers) getOMReference();
064:
065: OnEvent[] onEvents = eventHandlers.getOnEvents();
066: OnAlarmEvent[] onAlarms = eventHandlers.getOnAlarms();
067:
068: for (OnEvent onEvent : onEvents) {
069: Pattern p = getNestedPattern(onEvent);
070: FDimension patternSize = p.getBounds().getSize();
071:
072: manager.setPatternPosition(p, xPosition, 0);
073:
074: xPosition += patternSize.width + LayoutManager.HSPACING;
075: height = Math.max(height, patternSize.height);
076: }
077:
078: for (OnAlarmEvent onAlarm : onAlarms) {
079: Pattern p = getNestedPattern(onAlarm);
080: FDimension patternSize = p.getBounds().getSize();
081:
082: manager.setPatternPosition(p, xPosition, 0);
083:
084: xPosition += patternSize.width + LayoutManager.HSPACING;
085: height = Math.max(height, patternSize.height);
086: }
087:
088: float width = xPosition - LayoutManager.HSPACING;
089:
090: height = Math.max(height, 20);
091: width = Math.max(width, 20);
092:
093: getBorder().setClientRectangle(0, 0, width, height);
094:
095: return getBorder().getBounds();
096: }
097:
098: protected void createElementsImpl() {
099: setBorder(new GroupBorder());
100: getBorder().setLabelText(getDefaultName());
101:
102: EventHandlers handlers = (EventHandlers) getOMReference();
103:
104: OnEvent[] onEvents = handlers.getOnEvents();
105: OnAlarmEvent[] onAlarms = handlers.getOnAlarms();
106:
107: for (OnEvent onEvent : onEvents) {
108: Pattern p = getModel().createPattern(onEvent);
109: p.setParent(this );
110: }
111:
112: for (OnAlarmEvent onAlarm : onAlarms) {
113: Pattern p = getModel().createPattern(onAlarm);
114: p.setParent(this );
115: }
116: }
117:
118: public String getDefaultName() {
119: return "Event Handlers"; // NOI18N
120: }
121:
122: public NodeType getNodeType() {
123: return NodeType.EVENT_HANDLERS;
124: }
125:
126: }
|