KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > wizard > CreateBindingFromPortTypeWizardPanel1


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.wizard;
21
22 import java.util.HashSet JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Set JavaDoc;
25
26 import javax.swing.event.ChangeEvent JavaDoc;
27 import javax.swing.event.ChangeListener JavaDoc;
28
29 import org.netbeans.modules.xml.wsdl.model.PortType;
30 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator;
31 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElements;
32 import org.openide.WizardDescriptor;
33 import org.openide.WizardValidationException;
34 import org.openide.util.HelpCtx;
35 import org.openide.util.NbBundle;
36
37
38 public class CreateBindingFromPortTypeWizardPanel1 implements WizardDescriptor.ValidatingPanel, ChangeListener JavaDoc{
39     
40     /**
41      * The visual component that displays this panel. If you need to access the
42      * component from this class, just use getComponent().
43      */

44     private CreateBindingFromPortTypeVisualPanel1 component;
45     
46     
47     
48     private WizardDescriptor wiz = null;
49     
50     private PortType mPortType = null;
51     
52     private WSDLExtensibilityElements mElements;
53     
54     public CreateBindingFromPortTypeWizardPanel1(PortType portType, WSDLExtensibilityElements elements) {
55         mPortType = portType;
56         mElements = elements;
57     }
58     
59     // Get the visual component for the panel. In this template, the component
60
// is kept separate. This can be more efficient: if the wizard is created
61
// but never displayed, or not all panels are displayed, it is better to
62
// create only those which really need to be visible.
63
public CreateBindingFromPortTypeVisualPanel1 getComponent() {
64         if (component == null) {
65             component = new CreateBindingFromPortTypeVisualPanel1(mPortType, mElements);
66         }
67         component.addChangeListener(this);
68         return component;
69     }
70     
71     public HelpCtx getHelp() {
72         // Show no Help button for this panel:
73
return HelpCtx.DEFAULT_HELP;
74         // If you have context help:
75
// return new HelpCtx(SampleWizardPanel1.class);
76
}
77     
78     public boolean isValid() {
79         // If it is always OK to press Next or Finish, then:
80

81         String JavaDoc errorMessage = getAnyErrors();
82         wiz.putProperty ("WizardPanel_errorMessage", errorMessage); // NOI18N
83
return errorMessage == null;
84         // If it depends on some condition (form filled out...), then:
85
// return someCondition();
86
// and when this condition changes (last form field filled in...) then:
87
// fireChangeEvent();
88
// and uncomment the complicated stuff below.
89
}
90     
91     private String JavaDoc getAnyErrors() {
92         String JavaDoc errorMessage = null;
93         errorMessage = validateOperations();
94         errorMessage = validateBindingName();
95         return errorMessage;
96     }
97     
98     private String JavaDoc validateBindingName() {
99         String JavaDoc bindingName = component.getBindingName();
100
101         if (NameGenerator.getInstance().isBindingExists(bindingName, mPortType.getModel())) {
102             return NbBundle.getMessage(CreateBindingFromPortTypeWizardPanel1.class, "CreateBindingFromPortTypeWizardPanel1_BINDING_NAME_EXISTS", new Object JavaDoc[] {bindingName});
103         }
104         return null;
105         
106     }
107     
108     private String JavaDoc validateOperations() {
109         
110         Object JavaDoc[] operations = component.getSelectedOperations();
111         if (operations == null || operations.length == 0) {
112             return NbBundle.getMessage(CreateBindingFromPortTypeWizardPanel1.class, "CreateBindingFromPortTypeWizardPanel1_SELECT_OPERATIONS");
113         }
114         return null;
115     }
116     
117     private final Set JavaDoc<ChangeListener JavaDoc> listeners = new HashSet JavaDoc<ChangeListener JavaDoc>(1);
118     public final void addChangeListener(ChangeListener JavaDoc l) {
119         synchronized (listeners) {
120             listeners.add(l);
121         }
122     }
123     public final void removeChangeListener(ChangeListener JavaDoc l) {
124         synchronized (listeners) {
125             listeners.remove(l);
126         }
127     }
128     protected final void fireChangeEvent() {
129         Iterator JavaDoc<ChangeListener JavaDoc> it;
130         synchronized (listeners) {
131             it = new HashSet JavaDoc<ChangeListener JavaDoc>(listeners).iterator();
132         }
133         ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc(this);
134         while (it.hasNext()) {
135             it.next().stateChanged(ev);
136         }
137     }
138      
139     
140     // You can use a settings object to keep track of state. Normally the
141
// settings object will be the WizardDescriptor, so you can use
142
// WizardDescriptor.getProperty & putProperty to store information entered
143
// by the user.
144
public void readSettings(Object JavaDoc settings) {
145         wiz = (WizardDescriptor) settings;
146     }
147     public void storeSettings(Object JavaDoc settings) {
148         if ( WizardDescriptor.PREVIOUS_OPTION.equals( ((WizardDescriptor)settings).getValue() ) ) {
149             return;
150         }
151         if (isValid()) {
152             ;
153         }
154         component.storeValues((WizardDescriptor) settings);
155     }
156
157
158
159     public void stateChanged(ChangeEvent JavaDoc e) {
160           isValid();
161         
162     }
163
164     public void validate() throws WizardValidationException {
165        String JavaDoc errorMessage = validateBindingName();
166        if (errorMessage != null) {
167            throw new WizardValidationException(component.getBindingNameComponent(), errorMessage, errorMessage);
168        }
169        
170        errorMessage = validateOperations();
171        if (errorMessage != null) {
172            throw new WizardValidationException(component.getOperationsComponent(), errorMessage, errorMessage);
173        }
174         
175     }
176     
177 }
178
179
Popular Tags