KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
21  * PortTypeOperationNewType.java
22  *
23  * Created on September 8, 2006, 6:19 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype;
30
31
32 import java.awt.Dimension JavaDoc;
33 import java.io.IOException JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.List JavaDoc;
36 import java.util.Map JavaDoc;
37
38 import org.netbeans.api.project.FileOwnerQuery;
39 import org.netbeans.api.project.Project;
40 import org.netbeans.modules.xml.wsdl.model.Operation;
41 import org.netbeans.modules.xml.wsdl.model.PortType;
42 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
43 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
44 import org.netbeans.modules.xml.wsdl.ui.actions.ActionHelper;
45 import org.netbeans.modules.xml.wsdl.ui.view.OperationConfigurationPanel;
46 import org.netbeans.modules.xml.wsdl.ui.view.OperationType;
47 import org.netbeans.modules.xml.wsdl.ui.view.PartAndElementOrTypeTableModel;
48 import org.netbeans.modules.xml.wsdl.ui.wizard.OperationGenerator;
49 import org.netbeans.modules.xml.wsdl.ui.wizard.WizardPortTypeConfigurationStep;
50 import org.netbeans.modules.xml.xam.ModelSource;
51 import org.openide.DialogDescriptor;
52 import org.openide.DialogDisplayer;
53 import org.openide.filesystems.FileObject;
54 import org.openide.util.HelpCtx;
55 import org.openide.util.NbBundle;
56 import org.openide.util.datatransfer.NewType;
57
58 /**
59  *
60  * @author radval
61  */

62 public class PortTypeOperationNewType extends NewType {
63     private PortType mPortType = null;
64     
65     public PortTypeOperationNewType(WSDLComponent message) {
66         mPortType = (PortType) message;
67     }
68     
69
70     @Override JavaDoc
71     public String JavaDoc getName() {
72         return NbBundle.getMessage(PortTypeOperationNewType.class, "LBL_NewType_PortTypeOperation");
73     }
74
75
76     @Override JavaDoc
77   public void create() throws IOException JavaDoc {
78         WSDLModel model = mPortType.getModel();
79         
80
81         ModelSource modelSource = model.getModelSource();
82         FileObject wsdlFile = (FileObject) modelSource.getLookup().lookup(FileObject.class);
83         if(wsdlFile != null) {
84             Project project = FileOwnerQuery.getOwner(wsdlFile);
85             if(project != null) {
86                 OperationPanel panel = new OperationPanel(project, model);
87                 
88                 panel.setPreferredSize(new Dimension JavaDoc(550, 600));
89                 DialogDescriptor dd = new DialogDescriptor(panel,
90                                                            NbBundle.getMessage(PortTypeNewType.class, "LBL_Create_New_Operation"),
91                                                            true,
92                                                            DialogDescriptor.OK_CANCEL_OPTION,
93                                                            DialogDescriptor.OK_OPTION,
94                                                            DialogDescriptor.DEFAULT_ALIGN,
95                                                            new HelpCtx(PortTypeOperationNewType.class),
96                                                            null);
97                 panel.setDialogDescriptor(dd);
98                 
99                 if(DialogDisplayer.getDefault().notify(dd) == DialogDescriptor.OK_OPTION) {
100                     OperationConfigurationPanel opPanel = panel.getOperationConfigurationPanel();
101                     Map JavaDoc configurationMap = new HashMap JavaDoc();
102                     
103                     String JavaDoc operationName = opPanel.getOperationName();
104                     OperationType ot = opPanel.getOperationType();
105                     configurationMap.put(WizardPortTypeConfigurationStep.OPERATION_NAME, operationName);
106                     configurationMap.put(WizardPortTypeConfigurationStep.OPERATION_TYPE, ot);
107                     
108                     String JavaDoc inputMessageName = opPanel.getInputMessageName();
109                     String JavaDoc outputMessageName = opPanel.getOutputMessageName();
110                     String JavaDoc faultMessageName = opPanel.getFaultMessageName();
111                     
112                     configurationMap.put(WizardPortTypeConfigurationStep.OPERATION_INPUT_MESSAGE, inputMessageName);
113                     configurationMap.put(WizardPortTypeConfigurationStep.OPERATION_OUTPUT_MESSAGE, outputMessageName);
114                     configurationMap.put(WizardPortTypeConfigurationStep.OPERATION_FAULT_MESSAGE, faultMessageName);
115                     
116                     List JavaDoc<PartAndElementOrTypeTableModel.PartAndElementOrType> inputParts = opPanel.getInputMessageParts();
117                     List JavaDoc<PartAndElementOrTypeTableModel.PartAndElementOrType> outputParts = opPanel.getOutputMessageParts();
118                     List JavaDoc<PartAndElementOrTypeTableModel.PartAndElementOrType> faultParts = opPanel.getFaultMessageParts();
119                     Map JavaDoc<String JavaDoc, String JavaDoc> namespaceToPrefixMap = opPanel.getNamespaceToPrefixMap();
120                     
121                     configurationMap.put(WizardPortTypeConfigurationStep.NAMESPACE_TO_PREFIX_MAP, namespaceToPrefixMap);
122                    
123                     //if inputMessage Name is new not an existing message name then populate part names as well
124
if(opPanel.isNewInputMessage()) {
125                         configurationMap.put(WizardPortTypeConfigurationStep.OPERATION_INPUT, inputParts);
126                     }
127                     
128                     //if outputMessage Name is new not an existing message name then populate part names as well
129
if(opPanel.isNewOutputMessage()) {
130                         configurationMap.put(WizardPortTypeConfigurationStep.OPERATION_OUTPUT, outputParts);
131                     }
132                     
133                     //if faultMessage Name is new not an existing message name then populate part names as well
134
if(opPanel.isNewFaultMessage()) {
135                         configurationMap.put(WizardPortTypeConfigurationStep.OPERATION_FAULT, faultParts);
136                     }
137                     model.startTransaction();
138                     OperationGenerator opGen = new OperationGenerator(model, this.mPortType, configurationMap);
139                     opGen.execute();
140                     
141 // SchemaImportsGenerator schemaImportGenerator = new SchemaImportsGenerator(model, configurationMap);
142
// schemaImportGenerator.execute();
143
model.endTransaction();
144                     Operation operation = opGen.getOperation();
145                     ActionHelper.selectNode(operation);
146                 }
147             }
148         }
149     }
150 }
151
Popular Tags