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: package org.netbeans.modules.bpel.nodes;
020:
021: import org.netbeans.modules.bpel.nodes.BpelNode;
022: import java.awt.Component;
023: import java.util.concurrent.Callable;
024: import javax.xml.namespace.QName;
025: import org.netbeans.modules.bpel.model.api.FromPartContainer;
026: import org.netbeans.modules.soa.ui.nodes.InstanceRef;
027: import org.netbeans.modules.bpel.editors.api.nodes.NodeType;
028: import org.netbeans.modules.bpel.model.api.BpelEntity;
029: import org.netbeans.modules.bpel.model.api.CorrelationContainer;
030: import org.netbeans.modules.bpel.model.api.FromPart;
031: import org.netbeans.modules.bpel.model.api.MessageTypeReference;
032: import org.netbeans.modules.bpel.model.api.OnEvent;
033: import org.netbeans.modules.bpel.model.api.OperationReference;
034: import org.netbeans.modules.bpel.model.api.PartnerLinkReference;
035: import org.netbeans.modules.bpel.model.api.PortTypeReference;
036: import org.netbeans.modules.bpel.model.api.VariableReference;
037: import org.netbeans.modules.bpel.model.api.events.ChangeEvent;
038: import org.netbeans.modules.bpel.model.api.events.PropertyUpdateEvent;
039: import org.netbeans.modules.bpel.model.api.references.SchemaReference;
040: import org.netbeans.modules.bpel.model.api.references.WSDLReference;
041: import org.netbeans.modules.bpel.properties.Constants;
042: import org.netbeans.modules.bpel.editors.api.nodes.actions.ActionType;
043: import org.netbeans.modules.bpel.properties.ImportRegistrationHelper;
044: import org.netbeans.modules.bpel.properties.PropertyType;
045: import org.netbeans.modules.bpel.properties.props.CustomEditorProperty;
046: import org.netbeans.modules.bpel.properties.props.PropertyUtils;
047: import static org.netbeans.modules.bpel.properties.PropertyType.*;
048: import org.openide.nodes.Children;
049: import org.openide.nodes.Node;
050: import org.openide.nodes.Sheet;
051: import org.openide.util.Lookup;
052: import org.netbeans.modules.bpel.properties.editors.OnEventCustomEditor;
053: import org.netbeans.modules.soa.ui.form.CustomNodeEditor;
054: import org.netbeans.modules.xml.schema.model.GlobalElement;
055: import org.netbeans.modules.xml.schema.model.SchemaModel;
056: import org.netbeans.modules.xml.wsdl.model.Input;
057: import org.netbeans.modules.xml.wsdl.model.Message;
058: import org.netbeans.modules.xml.wsdl.model.Operation;
059: import org.netbeans.modules.xml.xam.dom.NamedComponentReference;
060:
061: public class OnEventNode extends BpelNode<OnEvent> {
062:
063: public OnEventNode(OnEvent onEvent, Lookup lookup) {
064: super (onEvent, lookup);
065: }
066:
067: public OnEventNode(OnEvent onEvent, Children children, Lookup lookup) {
068: super (onEvent, children, lookup);
069: }
070:
071: public NodeType getNodeType() {
072: return NodeType.ON_EVENT;
073: }
074:
075: @Override
076: protected boolean isEventRequreUpdate(ChangeEvent event) {
077: if (super .isEventRequreUpdate(event)) {
078: return true;
079: }
080:
081: //CorrelationContainer
082: BpelEntity entity = event.getParent();
083: if (entity == null) {
084: return false;
085: }
086: Object ref = getReference();
087: return ref != null
088: && ref == entity.getParent()
089: && entity.getElementType() == CorrelationContainer.class;
090: }
091:
092: protected Sheet createSheet() {
093: Sheet sheet = super .createSheet();
094:
095: if (getReference() == null) {
096: return sheet;
097: }
098: //
099: Sheet.Set messagePropertySet = getPropertySet(sheet,
100: Constants.PropertiesGroups.MESSAGE_SET);
101: //
102: Sheet.Set mainPropertySet = getPropertySet(sheet,
103: Constants.PropertiesGroups.MAIN_SET);
104: //
105: CustomEditorProperty customizer = new CustomEditorProperty(this );
106: messagePropertySet.put(customizer);
107: //
108: Node.Property property;
109: //
110: property = PropertyUtils.registerAttributeProperty(this ,
111: messagePropertySet, PartnerLinkReference.PARTNER_LINK,
112: PropertyType.PARTNER_LINK, "getPartnerLink",
113: "setPartnerLink", null); // NOI18N
114: property.setValue("suppressCustomEditor", Boolean.TRUE); // NOI18N
115: property.setValue("canEditAsText", Boolean.FALSE); // NOI18N
116: //
117: property = PropertyUtils.registerAttributeProperty(this ,
118: messagePropertySet, PortTypeReference.PORT_TYPE,
119: PropertyType.PORT_TYPE, "getPortType", "setPortType",
120: "removePortType"); // NOI18N
121: property.setValue("suppressCustomEditor", Boolean.TRUE); // NOI18N
122: property.setValue("canEditAsText", Boolean.FALSE); // NOI18N
123: //
124: InstanceRef selfReference = new InstanceRef() {
125: public Object getReference() {
126: return OnEventNode.this .getReference();
127: }
128:
129: public Object getAlternativeReference() {
130: return OnEventNode.this ;
131: }
132: };
133: //
134: property = PropertyUtils.registerAttributeProperty(
135: selfReference, messagePropertySet,
136: OperationReference.OPERATION, PropertyType.OPERATION,
137: "getOperation", "setOperationLocal", null); // NOI18N
138: property.setValue("suppressCustomEditor", Boolean.TRUE); // NOI18N
139: property.setValue("canEditAsText", Boolean.FALSE); // NOI18N
140: //
141: property = PropertyUtils.registerAttributeProperty(
142: selfReference, messagePropertySet,
143: VariableReference.VARIABLE,
144: PropertyType.EVENT_VARIABLE_NAME, "getVariable",
145: "setVariableLocal", "removeVariableLocal"); // NOI18N
146: property.setValue("canEditAsText", Boolean.TRUE); // NOI18N
147: //
148: property = PropertyUtils.registerAttributeProperty(
149: selfReference, messagePropertySet,
150: MessageTypeReference.MESSAGE_TYPE,
151: PropertyType.VARIABLE_TYPE_QNAME,
152: "getVariableTypeQName", null, null); // NOI18N
153: property.setValue("canEditAsText", Boolean.FALSE); // NOI18N
154: //
155: PropertyUtils.registerProperty(this , mainPropertySet,
156: DOCUMENTATION, "getDocumentation", "setDocumentation",
157: "removeDocumentation"); // NOI18N
158: //
159: return sheet;
160: }
161:
162: public Component getCustomizer(
163: CustomNodeEditor.EditingMode editingMode) {
164: return new OnEventCustomEditor(this , editingMode);
165: }
166:
167: protected ActionType[] getActionsArray() {
168: return new ActionType[] {
169: ActionType.ADD_FROM_PALETTE,
170: ActionType.SEPARATOR,
171: // ActionType.GO_TO_SOURCE,
172: // ActionType.GO_TO_DIAGRAMM,
173: ActionType.GO_TO, ActionType.SEPARATOR,
174: ActionType.TOGGLE_BREAKPOINT,
175: ActionType.SEPARATOR,
176: // ActionType.CYCLE_MEX, // Issue 85553
177: // ActionType.SEPARATOR,
178: ActionType.SHOW_POPERTY_EDITOR, ActionType.SEPARATOR,
179:
180: ActionType.DEFINE_CORRELATION, ActionType.SEPARATOR,
181:
182: ActionType.REMOVE, ActionType.SEPARATOR,
183: ActionType.PROPERTIES };
184: }
185:
186: public void setOperationLocal(final WSDLReference<Operation> value)
187: throws Exception {
188: final OnEvent event = getReference();
189: if (event != null) {
190: //
191:
192: event.getBpelModel().invoke(new Callable() {
193: public Object call() throws Exception {
194: event.setOperation(value);
195: updateVarTypeAttribute(event);
196: return null;
197: }
198: }, this );
199: }
200: }
201:
202: public void setVariableLocal(final String newValue)
203: throws Exception {
204: if (newValue == null || newValue.length() == 0) {
205: removeVariableLocal();
206: return;
207: }
208: //
209: final OnEvent event = getReference();
210: if (event != null) {
211: //
212: // TODO: Check if it necessary to remove the FromParts
213: // it maybe worth to ask if user wants to remove them before at the
214: // validation time.
215: //
216: event.getBpelModel().invoke(new Callable() {
217: public Object call() throws Exception {
218: event.setVariable(newValue);
219: //
220: // Remove all FromPart elements
221: FromPartContainer fromPartContainer = event
222: .getFromPartContaner();
223:
224: FromPart[] fromPartArr = fromPartContainer == null ? null
225: : fromPartContainer.getFromParts();
226: if (fromPartArr != null) {
227: for (int index = 0; index < fromPartArr.length; index++) {
228: fromPartContainer.removeFromPart(index);
229: }
230: }
231: //
232: updateVarTypeAttribute(event);
233: return null;
234: }
235: }, this );
236: }
237: }
238:
239: public void removeVariableLocal() throws Exception {
240: final OnEvent event = getReference();
241: if (event != null) {
242: event.getBpelModel().invoke(new Callable() {
243: public Object call() throws Exception {
244: event.removeVariable();
245: event.removeMessageType();
246: event.removeElement();
247: return null;
248: }
249: }, this );
250: }
251: }
252:
253: public static void updateVarTypeAttribute(OnEvent event) {
254: String varName = event.getVariable();
255: if (varName != null && varName.length() != 0) {
256: WSDLReference<Operation> operRef = event.getOperation();
257: if (operRef != null) {
258: Operation oper = operRef.get();
259: if (oper != null) {
260: Input input = oper.getInput();
261: if (input != null) {
262: NamedComponentReference<Message> msgRef = input
263: .getMessage();
264: if (msgRef != null) {
265: Message msg = msgRef.get();
266: if (msg != null) {
267: addTypeAttributes(event, msg);
268: }
269: }
270: }
271: }
272: }
273: } else {
274: event.removeMessageType();
275: event.removeElement();
276: }
277: }
278:
279: private static void addTypeAttributes(final OnEvent event,
280: final Message newMsg) {
281: GlobalElement newElement = null;
282: GlobalElement oldElement = null;
283: Message oldMessage = null;
284: //
285: // TODO: Uncomment when the runtime will support the element attribute
286: //
287: // // Try to calculate the new Element type
288: // Collection<Part> parts = newMsg.getParts();
289: // if (parts.size() == 1){
290: // Part part = parts.iterator().next();
291: // if (part != null) {
292: // NamedComponentReference<GlobalElement> elementRef = part.getElement();
293: // if (elementRef != null) {
294: // newElement = elementRef.get();
295: // }
296: // }
297: // }
298: // //
299: // // Try to calculate the old Element type
300: // SchemaReference<GlobalElement> elementRef = event.getElement();
301: // if (elementRef != null) {
302: // oldElement = elementRef.get();
303: // }
304: //
305: // Tyr to calculate the old Message type
306: WSDLReference<Message> msgRef = event.getMessageType();
307: if (msgRef != null) {
308: oldMessage = msgRef.get();
309: }
310: //
311:
312: if ((oldMessage == null && oldElement == null)
313: || oldMessage != null && oldElement != null) {
314: if (newElement != null) {
315: setElementType(event, newElement);
316: } else if (newMsg != null) {
317: setMessageType(event, newMsg);
318: }
319: } else if (oldMessage == null && oldElement != null) {
320: if (newElement != null) {
321: if (!oldElement.equals(newElement)) {
322: setElementType(event, newElement);
323: }
324: } else if (newMsg != null) {
325: setMessageType(event, newMsg);
326: }
327: } else if (oldMessage != null && oldElement == null) {
328: if (newMsg != null) {
329: if (!oldMessage.equals(newMsg)) {
330: setMessageType(event, newMsg);
331: }
332: } else if (newElement != null) {
333: setElementType(event, newElement);
334: }
335: }
336: }
337:
338: private static void setMessageType(final OnEvent event,
339: final Message message) {
340: WSDLReference<Message> msgRef = event.createWSDLReference(
341: message, Message.class);
342: event.setMessageType(msgRef);
343: //
344: event.removeElement();
345: }
346:
347: private static void setElementType(final OnEvent event,
348: final GlobalElement element) {
349: SchemaReference<GlobalElement> elementBpelRef = event
350: .createSchemaReference(element, GlobalElement.class);
351: event.setElement(elementBpelRef);
352: //
353: event.removeMessageType();
354: //
355: SchemaModel model = element.getModel();
356: if (model != null) {
357: new ImportRegistrationHelper(event.getBpelModel())
358: .addImport(model);
359: }
360: }
361:
362: public QName getVariableTypeQName() {
363: QName result = null;
364: OnEvent event = getReference();
365: if (event != null) {
366: WSDLReference<Message> msgRef = event.getMessageType();
367: if (msgRef != null) {
368: result = msgRef.getQName();
369: if (result != null) {
370: return result;
371: }
372: }
373: //
374: SchemaReference<GlobalElement> elementRef = event
375: .getElement();
376: if (elementRef != null) {
377: result = elementRef.getQName();
378: if (result != null) {
379: return result;
380: }
381: }
382: }
383: //
384: return null;
385: }
386:
387: protected void updateComplexProperties(ChangeEvent event) {
388: if (event instanceof PropertyUpdateEvent) {
389: BpelEntity parentEvent = event.getParent();
390: if (parentEvent != null
391: && parentEvent.equals(this .getReference())) {
392: String propName = event.getName();
393: if (MessageTypeReference.MESSAGE_TYPE.equals(propName)) {
394: updateProperty(PropertyType.MESSAGE_TYPE);
395: }
396: }
397: }
398: }
399:
400: public String getHelpId() {
401: return "org.netbeans.modules.bpel.properties.editors.OnEventCustomEditor"; //NOI18N
402: }
403: }
|