KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > treeeditor > newtype > PortTypeNewType


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype;
21
22 import java.awt.Dimension JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.Map JavaDoc;
27 import org.netbeans.api.project.FileOwnerQuery;
28 import org.netbeans.api.project.Project;
29
30 import org.netbeans.modules.xml.wsdl.model.PortType;
31 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
32 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
33 import org.netbeans.modules.xml.wsdl.ui.actions.ActionHelper;
34 import org.netbeans.modules.xml.wsdl.ui.view.OperationType;
35 import org.netbeans.modules.xml.wsdl.ui.view.PartAndElementOrTypeTableModel;
36 import org.netbeans.modules.xml.wsdl.ui.view.PortTypeConfigurationPanel;
37 import org.netbeans.modules.xml.wsdl.ui.wizard.PortTypeGenerator;
38 import org.netbeans.modules.xml.wsdl.ui.wizard.WizardPortTypeConfigurationStep;
39 import org.netbeans.modules.xml.xam.ModelSource;
40 import org.openide.DialogDescriptor;
41 import org.openide.DialogDisplayer;
42 import org.openide.filesystems.FileObject;
43 import org.openide.util.HelpCtx;
44 import org.openide.util.NbBundle;
45 import org.openide.util.datatransfer.NewType;
46
47 public class PortTypeNewType extends NewType {
48     private WSDLComponent mDef = null;
49
50     public PortTypeNewType(WSDLComponent def) {
51         mDef = def;
52     }
53     
54
55     @Override JavaDoc
56     public String JavaDoc getName() {
57         return NbBundle.getMessage(PortTypeNewType.class, "LBL_NewType_PortType");
58     }
59
60
61     @Override JavaDoc
62     public void create() throws IOException JavaDoc {
63         WSDLModel model = mDef.getModel();
64         
65
66         ModelSource modelSource = model.getModelSource();
67         FileObject wsdlFile = (FileObject) modelSource.getLookup().lookup(FileObject.class);
68         if(wsdlFile != null) {
69             Project project = FileOwnerQuery.getOwner(wsdlFile);
70             if(project != null) {
71                 PortTypePanel panel = new PortTypePanel(project, model);
72                 
73                 panel.setPreferredSize(new Dimension JavaDoc(550, 600));
74                 DialogDescriptor dd = new DialogDescriptor(panel,
75                                                            NbBundle.getMessage(PortTypeNewType.class, "LBL_Create_New_PortType"),
76                                                            true,
77                                                            DialogDescriptor.OK_CANCEL_OPTION,
78                                                            DialogDescriptor.OK_OPTION,
79                                                            DialogDescriptor.DEFAULT_ALIGN,
80                                                            new HelpCtx(PortTypeNewType.class),
81                                                            null);
82                 panel.setDialogDescriptor(dd);
83                 
84                 if(DialogDisplayer.getDefault().notify(dd) == DialogDescriptor.OK_OPTION) {
85                     PortTypeConfigurationPanel ptPanel = panel.getPortTypeConfiguration();
86                     Map JavaDoc configurationMap = new HashMap JavaDoc();
87                     
88                     String JavaDoc portTypeName = ptPanel.getPortTypeName();
89                     String JavaDoc operationName = ptPanel.getOperationName();
90                     OperationType ot = ptPanel.getOperationType();
91                     
92                     configurationMap.put(WizardPortTypeConfigurationStep.PORTTYPE_NAME, portTypeName);
93                     configurationMap.put(WizardPortTypeConfigurationStep.OPERATION_NAME, operationName);
94                     configurationMap.put(WizardPortTypeConfigurationStep.OPERATION_TYPE, ot);
95                     
96                     String JavaDoc inputMessageName = ptPanel.getNewInputMessageName();
97                     String JavaDoc outputMessageName = ptPanel.getNewOutputMessageName();
98                     String JavaDoc faultMessageName = ptPanel.getNewFaultMessageName();
99                           
100                     configurationMap.put(WizardPortTypeConfigurationStep.OPERATION_INPUT_MESSAGE, inputMessageName);
101                     configurationMap.put(WizardPortTypeConfigurationStep.OPERATION_OUTPUT_MESSAGE, outputMessageName);
102                     configurationMap.put(WizardPortTypeConfigurationStep.OPERATION_FAULT_MESSAGE, faultMessageName);
103                     
104                     List JavaDoc<PartAndElementOrTypeTableModel.PartAndElementOrType> inputParts = ptPanel.getInputMessageParts();
105                     List JavaDoc<PartAndElementOrTypeTableModel.PartAndElementOrType> outputParts = ptPanel.getOutputMessageParts();
106                     List JavaDoc<PartAndElementOrTypeTableModel.PartAndElementOrType> faultParts = ptPanel.getFaultMessageParts();
107                     Map JavaDoc<String JavaDoc, String JavaDoc> namespaceToPrefixMap = ptPanel.getNamespaceToPrefixMap();
108                     
109                     configurationMap.put(WizardPortTypeConfigurationStep.NAMESPACE_TO_PREFIX_MAP, namespaceToPrefixMap);
110                     
111                     //if inputMessage Name is new not an existing message name then populate part names as well
112
if(ptPanel.isNewInputMessage()) {
113                         configurationMap.put(WizardPortTypeConfigurationStep.OPERATION_INPUT, inputParts);
114                     }
115                     
116                     //if outputMessage Name is new not an existing message name then populate part names as well
117
if(ptPanel.isNewOutputMessage()) {
118                         configurationMap.put(WizardPortTypeConfigurationStep.OPERATION_OUTPUT, outputParts);
119                     }
120                     
121                     //if faultMessage Name is new not an existing message name then populate part names as well
122
if(ptPanel.isNewFaultMessage()) {
123                         configurationMap.put(WizardPortTypeConfigurationStep.OPERATION_FAULT, faultParts);
124                     }
125                     
126                     model.startTransaction();
127                     PortTypeGenerator ptGen = new PortTypeGenerator(model, configurationMap);
128                     ptGen.execute();
129                     
130 // SchemaImportsGenerator schemaImportGenerator = new SchemaImportsGenerator(model, configurationMap);
131
// schemaImportGenerator.execute();
132
//
133
model.endTransaction();
134                     PortType pt = ptGen.getPortType();
135                     ActionHelper.selectNode(pt);
136                 }
137             }
138         }
139     }
140 }
141
Popular Tags