001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.compapp.casaeditor.nodes.actions;
043:
044: import java.awt.Dialog;
045: import java.awt.Dimension;
046: import java.awt.Point;
047: import java.awt.event.ActionEvent;
048: import java.awt.event.ActionListener;
049: import java.util.*;
050: import javax.swing.*;
051:
052: import org.netbeans.modules.compapp.casaeditor.nodes.CasaNode;
053: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaWrapperModel;
054: import org.netbeans.modules.compapp.casaeditor.CasaDataNode;
055: import org.netbeans.modules.compapp.casaeditor.CasaDataObject;
056: import org.netbeans.modules.compapp.casaeditor.CasaDataEditorSupport;
057: import org.netbeans.modules.compapp.projects.jbi.api.JbiBindingInfo;
058: import org.netbeans.modules.compapp.projects.jbi.api.JbiDefaultComponentInfo;
059: import org.netbeans.modules.xml.wsdl.bindingsupport.template.ExtensibilityElementTemplateFactory;
060: import org.netbeans.modules.xml.wsdl.bindingsupport.template.TemplateGroup;
061: import org.netbeans.modules.xml.wsdl.bindingsupport.template.localized.LocalizedTemplateGroup;
062: import org.openide.DialogDescriptor;
063: import org.openide.DialogDisplayer;
064: import org.openide.nodes.Node;
065: import org.openide.util.NbBundle;
066: import org.openide.util.HelpCtx;
067: import org.openide.util.actions.NodeAction;
068:
069: /**
070: *
071: * @author jsandusky
072: */
073: public class AddWSDLPortsAction extends NodeAction {
074:
075: protected boolean enable(Node[] activatedNodes) {
076: return true;
077: }
078:
079: protected boolean asynchronous() {
080: return false;
081: }
082:
083: public String getName() {
084: return NbBundle.getMessage(LoadWSDLPortsAction.class,
085: "LBL_AddWSDLPortsAction_Name"); // NOI18N
086: }
087:
088: public HelpCtx getHelpCtx() {
089: return HelpCtx.DEFAULT_HELP;
090: }
091:
092: public Action getAction() {
093: return this ;
094: }
095:
096: /*
097: public void actionPerformed(ActionEvent e) {
098: if (e.getSource() instanceof CanvasNodeProxyContext) {
099: CanvasNodeProxyContext context = (CanvasNodeProxyContext) e.getSource();
100: performAction(context.getLocalLocation());
101: } else {
102: performAction(new Point(-1, -1));
103: }
104: }
105: */
106:
107: private Map<String, LocalizedTemplateGroup> getWsdlTemplates() {
108: ExtensibilityElementTemplateFactory factory = new ExtensibilityElementTemplateFactory();
109: Collection<TemplateGroup> groups = factory
110: .getExtensibilityElementTemplateGroups();
111: Vector<LocalizedTemplateGroup> protocols = new Vector<LocalizedTemplateGroup>();
112: LocalizedTemplateGroup ltg = null;
113: Map<String, LocalizedTemplateGroup> temps = new HashMap<String, LocalizedTemplateGroup>();
114: for (TemplateGroup group : groups) {
115: ltg = factory.getLocalizedTemplateGroup(group);
116: protocols.add(ltg);
117: temps.put(ltg.getName(), ltg);
118: }
119:
120: return temps;
121: }
122:
123: public void performAction(Node[] activatedNodes) { // final Point location) {
124:
125: if (activatedNodes.length < 1) {
126: return;
127: }
128: CasaWrapperModel cmodel = null;
129: if (activatedNodes[0] instanceof CasaDataNode) {
130: final CasaDataNode node = ((CasaDataNode) activatedNodes[0]);
131: CasaDataObject obj = (CasaDataObject) node.getDataObject();
132: CasaDataEditorSupport es = obj.getLookup().lookup(
133: CasaDataEditorSupport.class);
134: if (es != null) {
135: cmodel = es.getModel();
136: }
137: } else if (activatedNodes[0] instanceof CasaNode) {
138: final CasaNode node = ((CasaNode) activatedNodes[0]);
139: cmodel = node.getModel();
140: }
141:
142: if (cmodel == null) {
143: return;
144: }
145:
146: final Point location = new Point(-1, -1);
147: final CasaWrapperModel model = cmodel;
148: SwingUtilities.invokeLater(new Runnable() {
149: public void run() {
150: showDialog(model, location);
151: }
152: });
153: }
154:
155: private void showDialog(final CasaWrapperModel model,
156: final Point location) {
157:
158: final Map<String, JbiBindingInfo> portMap = new HashMap<String, JbiBindingInfo>();
159:
160: JbiDefaultComponentInfo bcinfo = JbiDefaultComponentInfo
161: .getJbiDefaultComponentInfo();
162: if (bcinfo != null) {
163: Map<String, LocalizedTemplateGroup> bcTemplates = getWsdlTemplates();
164: List<JbiBindingInfo> bclist = bcinfo.getBindingInfoList();
165: for (JbiBindingInfo bi : bclist) {
166: String bindingType = bi.getBindingType().toUpperCase();
167: if (bcTemplates.get(bindingType) != null) {
168: portMap.put(bi.getBindingType(), bi);
169: }
170: }
171: }
172: String[] ports = portMap.keySet().toArray(new String[0]);
173: Arrays.sort(ports);
174:
175: final LoadWsdlPortPanel panel = new LoadWsdlPortPanel(NbBundle
176: .getMessage(getClass(), "LBL_AllAvailableWSDLPorts"),
177: ports);
178: DialogDescriptor descriptor = new DialogDescriptor(panel,
179: NbBundle.getMessage(LoadWsdlPortPanel.class,
180: "LBL_WsdlPort_Selection_Panel"), // NOI18N
181: true, new ActionListener() {
182: public void actionPerformed(ActionEvent evt) {
183: if (evt.getSource().equals(
184: DialogDescriptor.OK_OPTION)) {
185: int x = location.x;
186: int y = location.y;
187: for (String selectedItem : panel
188: .getSelectedItems()) {
189: JbiBindingInfo info = portMap
190: .get(selectedItem);
191: model.addCasaPort(
192: info.getBindingType(),
193: info.getBindingComponentName(),
194: x, y);
195: }
196: }
197: }
198: });
199:
200: Dialog dlg = DialogDisplayer.getDefault().createDialog(
201: descriptor);
202: dlg.setPreferredSize(new Dimension(400, 400));
203: dlg.setVisible(true);
204: }
205:
206: }
|