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.actions;
020:
021: import org.netbeans.modules.bpel.nodes.actions.BpelNodeAction;
022: import org.netbeans.modules.bpel.editors.api.nodes.actions.ActionType;
023: import java.awt.Dialog;
024: import java.util.concurrent.Callable;
025: import org.netbeans.modules.bpel.model.api.BPELElementsBuilder;
026: import org.netbeans.modules.bpel.model.api.PartnerLink;
027: import org.netbeans.modules.bpel.model.api.PartnerLinkContainer;
028: import org.netbeans.modules.bpel.model.api.Process;
029: import org.netbeans.modules.bpel.model.api.BaseScope;
030: import org.netbeans.modules.bpel.model.api.BpelEntity;
031: import org.netbeans.modules.bpel.model.api.CorrelationSet;
032: import org.netbeans.modules.bpel.model.api.CorrelationSetContainer;
033: import org.netbeans.modules.bpel.nodes.PartnerLinkNode;
034: import org.netbeans.modules.bpel.properties.editors.CorrelationSetMainPanel;
035: import org.netbeans.modules.bpel.properties.editors.FormBundle;
036: import org.netbeans.modules.bpel.properties.editors.PartnerLinkMainPanel;
037: import org.netbeans.modules.soa.ui.form.CustomNodeEditor.EditingMode;
038: import org.netbeans.modules.bpel.properties.editors.controls.SimpleCustomEditor;
039: import org.netbeans.modules.soa.ui.form.valid.SoaDialogDisplayer;
040: import org.netbeans.modules.bpel.editors.api.ui.valid.NodeEditorDescriptor;
041: import org.netbeans.modules.bpel.nodes.CorrelationSetNode;
042: import org.netbeans.modules.bpel.nodes.BpelNode;
043: import org.openide.nodes.Children;
044: import org.openide.nodes.Node;
045: import org.openide.util.Lookup;
046: import org.openide.util.NbBundle;
047:
048: /**
049: *
050: * @author Vitaly Bychkov
051: * @version 14 April 2006
052: *
053: */
054: public class AddPartnerLinkAction extends BpelNodeAction {
055: private static final long serialVersionUID = 1L;
056:
057: public AddPartnerLinkAction() {
058: putValue(SHORT_DESCRIPTION, NbBundle.getMessage(getClass(),
059: "CTL_DESC_AddPartnerLinkAction")); // NOI18N
060: }
061:
062: protected String getBundleName() {
063: return NbBundle.getMessage(BpelNodeAction.class,
064: "CTL_AddPartnerLinkAction"); // NOI18N
065: }
066:
067: public ActionType getType() {
068: return ActionType.ADD_PARTNER_LINK;
069: }
070:
071: protected void performAction(BpelEntity[] bpelEntities) {
072: }
073:
074: public void performAction(Node[] nodes) {
075: if (!enable(getBpelEntities(nodes))) {
076: return;
077: }
078: //
079: final Process bpelProcess;
080:
081: bpelProcess = (Process) ((BpelNode) nodes[0]).getReference();
082: if (bpelProcess == null) {
083: return;
084: }
085: final BPELElementsBuilder elementBuilder = bpelProcess
086: .getBpelModel().getBuilder();
087: final PartnerLink newPartnerLink = elementBuilder
088: .createPartnerLink();
089: //
090: Lookup lookup = nodes[0].getLookup();
091: PartnerLinkNode plNode = new PartnerLinkNode(newPartnerLink,
092: lookup);
093: //
094: String dialogTitle = NbBundle.getMessage(FormBundle.class,
095: "DLG_AddPartnerLink"); // NOI18N
096: SimpleCustomEditor customEditor = new SimpleCustomEditor<PartnerLink>(
097: plNode, PartnerLinkMainPanel.class,
098: EditingMode.CREATE_NEW_INSTANCE);
099: //
100: NodeEditorDescriptor descriptor = new NodeEditorDescriptor(
101: customEditor, dialogTitle);
102: descriptor.setOkButtonProcessor(new Callable<Boolean>() {
103: public Boolean call() throws Exception {
104: PartnerLinkContainer container = bpelProcess
105: .getPartnerLinkContainer();
106: if (container == null) {
107: container = elementBuilder
108: .createPartnerLinkContainer();
109: bpelProcess.setPartnerLinkContainer(container);
110: container = bpelProcess.getPartnerLinkContainer();
111: }
112: //
113: container.insertPartnerLink(newPartnerLink, 0);
114: return Boolean.TRUE;
115: }
116: });
117: //
118: Dialog dialog = SoaDialogDisplayer.getDefault().createDialog(
119: descriptor);
120: dialog.setVisible(true);
121: }
122:
123: protected boolean enable(BpelEntity[] bpelEntities) {
124: if (!super .enable(bpelEntities)) {
125: return false;
126: }
127:
128: BpelEntity bpelEntity = bpelEntities[0];
129:
130: return (bpelEntity instanceof Process);
131: }
132: }
|