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: /*
043: * OperationConfigurationPanel.java
044: *
045: * Created on July 3, 2007, 10:33 AM
046: */
047:
048: package org.netbeans.modules.xml.wsdl.ui.view;
049:
050: import java.awt.CardLayout;
051: import java.awt.Component;
052: import java.awt.event.ActionEvent;
053: import java.awt.event.ActionListener;
054: import java.beans.PropertyChangeEvent;
055: import java.beans.PropertyChangeListener;
056: import java.util.HashMap;
057: import java.util.List;
058: import java.util.Map;
059:
060: import javax.swing.DefaultComboBoxModel;
061: import javax.swing.JComboBox;
062: import javax.swing.JTextField;
063: import javax.swing.text.Document;
064:
065: import org.netbeans.api.project.Project;
066: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
067: import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent;
068: import org.openide.util.NbBundle;
069:
070: /**
071: *
072: * @author skini
073: */
074: public class OperationConfigurationPanel extends javax.swing.JPanel {
075:
076: private Project mProject;
077:
078: private Document mCommonOperationTextFieldDocument = new JTextField()
079: .getDocument();
080: private Map<String, String> namespaceToPrefixMap;
081: private WSDLModel mModel;
082: private final boolean showPortType;
083: public static final String FAULT_PARTS_LISTENER = "FAULT_PARTS_LISTENER";
084:
085: private boolean mIsShowMessageComboBoxes = false;
086:
087: public OperationConfigurationPanel() {
088: showPortType = false;
089: initComponents();
090: }
091:
092: public OperationConfigurationPanel(Project project) {
093: this (project, false, null, true);
094: }
095:
096: /** Creates new form OperationConfigurationPanel */
097: public OperationConfigurationPanel(Project project,
098: boolean isShowMessageComboBoxes, WSDLModel model,
099: boolean showPortType) {
100: mProject = project;
101: this .mIsShowMessageComboBoxes = isShowMessageComboBoxes;
102: if (model != null) {
103: mModel = model;
104: namespaceToPrefixMap = new HashMap<String, String>();
105: Map<String, String> prefixes = ((AbstractDocumentComponent) model
106: .getDefinitions()).getPrefixes();
107: if (prefixes != null) {
108: for (String prefix : prefixes.keySet()) {
109: namespaceToPrefixMap.put(prefixes.get(prefix),
110: prefix);
111: }
112: }
113: } else {
114: namespaceToPrefixMap = new HashMap<String, String>();
115: if (!namespaceToPrefixMap.containsKey("xsd")) {
116: namespaceToPrefixMap.put(
117: "http://www.w3.org/2001/XMLSchema", "xsd");
118: }
119: }
120: this .showPortType = showPortType;
121: initComponents();
122: initGUI();
123: }
124:
125: /** This method is called from within the constructor to
126: * initialize the form.
127: * WARNING: Do NOT modify this code. The content of this method is
128: * always regenerated by the Form Editor.
129: */
130: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
131: private void initComponents() {
132:
133: requestReplyOperationPanel = new org.netbeans.modules.xml.wsdl.ui.view.RequestReplyOperationPanel(
134: this .mProject, this .mCommonOperationTextFieldDocument,
135: namespaceToPrefixMap, mIsShowMessageComboBoxes, mModel,
136: showPortType);
137: oneWayOperationPanel = new org.netbeans.modules.xml.wsdl.ui.view.OneWayOperationPanel(
138: this .mProject, this .mCommonOperationTextFieldDocument,
139: namespaceToPrefixMap, mIsShowMessageComboBoxes, mModel,
140: showPortType);
141:
142: setName("Form"); // NOI18N
143: setLayout(new java.awt.CardLayout());
144:
145: requestReplyOperationPanel
146: .setName("requestReplyOperationPanel"); // NOI18N
147: add(requestReplyOperationPanel, "OPERATION_REQUEST_REPLY");
148:
149: oneWayOperationPanel.setName("oneWayOperationPanel"); // NOI18N
150: add(oneWayOperationPanel, "OPERATION_ONE_WAY");
151: }// </editor-fold>//GEN-END:initComponents
152:
153: private void initGUI() {
154: OperationType op1 = new OperationType(
155: OperationType.OPERATION_REQUEST_REPLY,
156: NbBundle.getMessage(OperationConfigurationPanel.class,
157: "OperationConfigurationPanel.REQUEST_RESPONSE"));
158: OperationType op2 = new OperationType(
159: OperationType.OPERATION_ONE_WAY, NbBundle.getMessage(
160: OperationConfigurationPanel.class,
161: "OperationConfigurationPanel.ONE_WAY"));
162:
163: DefaultComboBoxModel model = new DefaultComboBoxModel(
164: new OperationType[] { op1, op2 });
165:
166: requestReplyOperationPanel.getOperationTypeComboBox().setModel(
167: model);
168: oneWayOperationPanel.getOperationTypeComboBox().setModel(model);
169:
170: ActionListener al = new ActionListener() {
171:
172: public void actionPerformed(ActionEvent e) {
173: if (e.getSource() instanceof JComboBox) {
174: JComboBox jcb = (JComboBox) e.getSource();
175: OperationType ot = (OperationType) jcb
176: .getSelectedItem();
177: String operationName = selectedOperationConfiguration
178: .getOperationName();
179: String portTypeName = selectedOperationConfiguration
180: .getPortTypeName();
181: boolean autoGenPLT = selectedOperationConfiguration
182: .isAutoGeneratePartnerLinkType();
183: CardLayout operationCardLayout = (CardLayout) getLayout();
184:
185: operationCardLayout.show(
186: OperationConfigurationPanel.this , ot
187: .getOperationType());
188: selectedOperationConfiguration = findVisibleConfiguration();
189: revalidate();
190: selectedOperationConfiguration
191: .setPortTypeName(portTypeName);
192: selectedOperationConfiguration
193: .setOperationName(operationName);
194: selectedOperationConfiguration
195: .setAutoGeneratePartnerLinkType(autoGenPLT);
196: selectedOperationType = ot;
197: selectedOperationConfiguration
198: .getOperationTypeComboBox().requestFocus();
199: }
200: }
201: };
202:
203: requestReplyOperationPanel.getOperationTypeComboBox()
204: .addActionListener(al);
205: requestReplyOperationPanel.addPropertyChangeListener(
206: FAULT_PARTS_LISTENER, new PropertyChangeListener() {
207:
208: public void propertyChange(PropertyChangeEvent evt) {
209: PropertyChangeListener[] changeListeners = getPropertyChangeListeners(FAULT_PARTS_LISTENER);
210: for (PropertyChangeListener listener : changeListeners) {
211: listener.propertyChange(evt);
212: }
213: }
214:
215: });
216: oneWayOperationPanel.getOperationTypeComboBox()
217: .addActionListener(al);
218:
219: this .selectedOperationType = op1;
220: selectedOperationConfiguration = requestReplyOperationPanel;
221: }
222:
223: private OperationConfiguration findVisibleConfiguration() {
224: OperationConfiguration conf = null;
225:
226: Component[] comps = getComponents();
227: for (int i = 0; i < comps.length; i++) {
228: if (comps[i].isVisible()) {
229: conf = (OperationConfiguration) comps[i];
230: break;
231: }
232: }
233:
234: return conf;
235: }
236:
237: public String getPortTypeName() {
238: return this .selectedOperationConfiguration.getPortTypeName();
239: }
240:
241: public void setPortTypeName(String portTypeName) {
242: this .selectedOperationConfiguration
243: .setPortTypeName(portTypeName);
244: }
245:
246: public JTextField getPortTypeNameTextField() {
247: return this .selectedOperationConfiguration
248: .getPortTypeNameTextField();
249: }
250:
251: public void setInputMessages(String[] existingMessages,
252: String newMessageName,
253: javax.swing.event.DocumentListener msgNameDocumentListener) {
254: this .requestReplyOperationPanel.setInputMessages(
255: existingMessages, newMessageName,
256: msgNameDocumentListener);
257: this .oneWayOperationPanel.setInputMessages(existingMessages,
258: newMessageName, msgNameDocumentListener);
259: }
260:
261: public void setOutputMessages(String[] existingMessages,
262: String newMessageName,
263: javax.swing.event.DocumentListener msgNameDocumentListener) {
264: this .requestReplyOperationPanel.setOutputMessages(
265: existingMessages, newMessageName,
266: msgNameDocumentListener);
267: }
268:
269: public void setFaultMessages(String[] existingMessages,
270: String newMessageName,
271: javax.swing.event.DocumentListener msgNameDocumentListener) {
272: this .requestReplyOperationPanel.setFaultMessages(
273: existingMessages, newMessageName,
274: msgNameDocumentListener);
275: }
276:
277: public boolean isNewOutputMessage() {
278: return selectedOperationConfiguration.isNewOutputMessage();
279: }
280:
281: public boolean isNewInputMessage() {
282: return selectedOperationConfiguration.isNewInputMessage();
283: }
284:
285: public boolean isNewFaultMessage() {
286: return selectedOperationConfiguration.isNewFaultMessage();
287: }
288:
289: public String getOperationName() {
290: return selectedOperationConfiguration.getOperationName();
291: }
292:
293: public Map<String, String> getNamespaceToPrefixMap() {
294: return namespaceToPrefixMap;
295: }
296:
297: public void setOperationName(String operationName) {
298: selectedOperationConfiguration.setOperationName(operationName);
299: }
300:
301: public OperationType getOperationType() {
302: return selectedOperationType;
303: }
304:
305: public List<PartAndElementOrTypeTableModel.PartAndElementOrType> getInputMessageParts() {
306: return selectedOperationConfiguration.getInputMessageParts();
307: }
308:
309: public List<PartAndElementOrTypeTableModel.PartAndElementOrType> getOutputMessageParts() {
310: return selectedOperationConfiguration.getOutputMessageParts();
311: }
312:
313: public List<PartAndElementOrTypeTableModel.PartAndElementOrType> getFaultMessageParts() {
314: return selectedOperationConfiguration.getFaultMessageParts();
315: }
316:
317: public String getOutputMessageName() {
318: return this .selectedOperationConfiguration
319: .getOutputMessageName();
320: }
321:
322: public String getInputMessageName() {
323: return this .selectedOperationConfiguration
324: .getInputMessageName();
325: }
326:
327: public String getFaultMessageName() {
328: return this .selectedOperationConfiguration
329: .getFaultMessageName();
330: }
331:
332: public JTextField getOperationNameTextField() {
333: return selectedOperationConfiguration
334: .getOperationNameTextField();
335: }
336:
337: public boolean isAutoGeneratePartnerLinkType() {
338: return selectedOperationConfiguration
339: .isAutoGeneratePartnerLinkType();
340: }
341:
342: private OperationConfiguration selectedOperationConfiguration;
343:
344: private OperationType selectedOperationType;
345:
346: // Variables declaration - do not modify//GEN-BEGIN:variables
347: private org.netbeans.modules.xml.wsdl.ui.view.OneWayOperationPanel oneWayOperationPanel;
348: private org.netbeans.modules.xml.wsdl.ui.view.RequestReplyOperationPanel requestReplyOperationPanel;
349: // End of variables declaration//GEN-END:variables
350: }
|