xml.wsdl.bindingsupport/src/org/netbeans/modules/xml/wsdl/bindingsupport/configeditor/ui/ConfigurationEditorPanel.java
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 2009-2017 Oracle and/or its affiliates. All rights reserved.
6 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7 * Other names may be trademarks of their respective owners.
9 * The contents of this file are subject to the terms of either the GNU
10 * General Public License Version 2 only ("GPL") or the Common
11 * Development and Distribution License("CDDL") (collectively, the
12 * "License"). You may not use this file except in compliance with the
13 * License. You can obtain a copy of the License at
14 * http://www.netbeans.org/cddl-gplv2.html
15 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16 * specific language governing permissions and limitations under the
17 * License. When distributing the software, include this License Header
18 * Notice in each file and include the License file at
19 * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20 * particular file as subject to the "Classpath" exception as provided
21 * by Oracle in the GPL Version 2 section of the License file that
22 * accompanied this code. If applicable, add the following below the
23 * License Header, with the fields enclosed by brackets [] replaced by
24 * your own identifying information:
25 * "Portions Copyrighted [year] [name of copyright owner]"
29 * The Original Software is NetBeans. The Initial Developer of the Original
30 * Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun
31 * Microsystems, Inc. All Rights Reserved.
33 * If you wish your version of this file to be governed by only the CDDL
34 * or only the GPL Version 2, indicate your decision by adding
35 * "[Contributor] elects to include this software in this distribution
36 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37 * single choice of license, a recipient has the option to distribute
38 * your version of this file under either the CDDL, the GPL Version 2 or
39 * to extend the choice of license to its licensees as provided above.
40 * However, if you add GPL Version 2 code and therefore, elected the GPL
41 * Version 2 license, then the option applies only if the new code is
42 * made subject to such option by the copyright holder.
45 * ConfigurationEditorPanel.java
47 * Created on May 27, 2008, 12:21 PM
50 package org.netbeans.modules.xml.wsdl.bindingsupport.configeditor.ui;
52 import org.netbeans.modules.xml.wsdl.bindingsupport.common.CommonMessagePanel;
53 import java.awt.Window;
54 import java.beans.PropertyChangeEvent;
55 import java.beans.PropertyChangeListener;
56 import java.util.Collection;
57 import java.util.HashSet;
59 import java.util.Vector;
60 import javax.swing.DefaultComboBoxModel;
61 import javax.swing.JComponent;
62 import javax.swing.SwingUtilities;
63 import org.netbeans.modules.xml.wsdl.bindingsupport.spi.ExtensibilityElementConfigurationEditorComponent;
64 import org.netbeans.modules.xml.wsdl.bindingsupport.spi.ExtensibilityElementConfigurationEditorProvider;
65 import org.netbeans.modules.xml.wsdl.model.Operation;
66 import org.openide.DialogDescriptor;
72 public class ConfigurationEditorPanel extends javax.swing.JPanel implements PropertyChangeListener {
74 private CommonMessagePanel messagePanel;
75 private DialogDescriptor descriptor;
76 private boolean showOperations;
77 //private ExtensibilityElementConfigurationEditorComponent editorComponent;
78 private ExtensibilityElementConfigurationEditorProvider provider;
79 private JComponent innerPane;
80 private Collection<Operation> operations;
81 private Set<Operation> configuredOperations;
82 private Operation lastSelectedOperation;
83 boolean multipleOperationConfigurationSupported;
87 /** Creates new form ConfigurationEditorPanel */
88 public ConfigurationEditorPanel(Collection<Operation> operations, boolean multipleOperationSupported) {
89 this.operations = operations;
90 this.multipleOperationConfigurationSupported = multipleOperationSupported;
91 configuredOperations = new HashSet<Operation>();
92 if (operations != null && operations.size() > 1) {
93 showOperations = true;
96 multipleOperationCommentLabel.setVisible(multipleOperationSupported);
97 messagePanel = new CommonMessagePanel();
98 commonMessagePanelHolder.add(messagePanel);
99 operationPanel.setEnabled(showOperations);
100 operationPanel.setVisible(showOperations);
101 if (showOperations) {
102 Vector operationList = new Vector();
103 operationList.add("");
104 for (Operation operation : operations) {
105 operationList.add(new OperationItem(operation.getName(), operation));
107 operationCombobox.setModel(new DefaultComboBoxModel(operationList));
111 public void setInnerPanel(JComponent innerComponent) {
112 if (this.innerPane != null) {
113 this.innerPane.removePropertyChangeListener(this);
114 bindingConfigurationPanelHolder.remove(this.innerPane);
116 this.innerPane = innerComponent;
117 if (innerComponent != null) {
118 innerComponent.addPropertyChangeListener(this);
119 bindingConfigurationPanelHolder.add(innerComponent);
121 messagePanel.setMessage("");
123 Window windowAncestor = SwingUtilities.getWindowAncestor(this);
124 if (windowAncestor != null) {
125 windowAncestor.pack();
130 Operation getSelectedOperation() {
131 return lastSelectedOperation;
134 Set<Operation> getAllConfiguredOperations() {
135 return configuredOperations;
138 void setDialogDescriptor(DialogDescriptor descriptor) {
139 this.descriptor = descriptor;
142 boolean setProvider(ExtensibilityElementConfigurationEditorProvider provider) {
143 this.provider = provider;
144 if (operations != null && operations.size() > 0) {
145 lastSelectedOperation = operations.iterator().next();
146 if (!configuredOperations.contains(lastSelectedOperation)) {
147 configuredOperations.add(lastSelectedOperation);
149 ExtensibilityElementConfigurationEditorComponent component = provider.getOperationBasedEditorComponent(lastSelectedOperation);
150 if (component == null) {
153 if (operations.size() > 1) {
156 setInnerPanel(component.getEditorPanel());
157 title = component.getTitle();
162 public String getTitle() {
166 /** This method is called from within the constructor to
167 * initialize the form.
168 * WARNING: Do NOT modify this code. The content of this method is
169 * always regenerated by the Form Editor.
171 @SuppressWarnings("unchecked")
172 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
173 private void initComponents() {
175 operationPanel = new javax.swing.JPanel();
176 operationLabel = new javax.swing.JLabel();
177 operationCombobox = new javax.swing.JComboBox();
178 commentLabel = new javax.swing.JLabel();
179 multipleOperationCommentLabel = new javax.swing.JLabel();
180 bindingConfigurationPanelHolder = new javax.swing.JPanel();
181 commonMessagePanelHolder = new javax.swing.JPanel();
183 setName("Form"); // NOI18N
185 operationPanel.setName("operationPanel"); // NOI18N
187 org.openide.awt.Mnemonics.setLocalizedText(operationLabel, org.openide.util.NbBundle.getMessage(ConfigurationEditorPanel.class, "ConfigurationEditorPanel.operationLabel.text")); // NOI18N
188 operationLabel.setName("operationLabel"); // NOI18N
190 operationCombobox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
191 operationCombobox.setName("operationCombobox"); // NOI18N
192 operationCombobox.addActionListener(new java.awt.event.ActionListener() {
193 public void actionPerformed(java.awt.event.ActionEvent evt) {
194 operationComboboxActionPerformed(evt);
198 org.openide.awt.Mnemonics.setLocalizedText(commentLabel, org.openide.util.NbBundle.getMessage(ConfigurationEditorPanel.class, "ConfigurationEditorPanel.commentLabel.text")); // NOI18N
199 commentLabel.setName("commentLabel"); // NOI18N
201 org.openide.awt.Mnemonics.setLocalizedText(multipleOperationCommentLabel, org.openide.util.NbBundle.getMessage(ConfigurationEditorPanel.class, "ConfigurationEditorPanel.multipleOperationCommentLabel.text")); // NOI18N
202 multipleOperationCommentLabel.setName("multipleOperationCommentLabel"); // NOI18N
204 org.jdesktop.layout.GroupLayout operationPanelLayout = new org.jdesktop.layout.GroupLayout(operationPanel);
205 operationPanel.setLayout(operationPanelLayout);
206 operationPanelLayout.setHorizontalGroup(
207 operationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
208 .add(operationPanelLayout.createSequentialGroup()
210 .add(operationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
211 .add(commentLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 487, Short.MAX_VALUE)
212 .add(multipleOperationCommentLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 487, Short.MAX_VALUE)
213 .add(operationPanelLayout.createSequentialGroup()
215 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
216 .add(operationCombobox, 0, 431, Short.MAX_VALUE)))
219 operationPanelLayout.setVerticalGroup(
220 operationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
221 .add(operationPanelLayout.createSequentialGroup()
222 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
224 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
225 .add(multipleOperationCommentLabel)
226 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
227 .add(operationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
229 .add(operationCombobox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
232 bindingConfigurationPanelHolder.setName("bindingConfigurationPanelHolder"); // NOI18N
233 bindingConfigurationPanelHolder.setLayout(new javax.swing.BoxLayout(bindingConfigurationPanelHolder, javax.swing.BoxLayout.Y_AXIS));
235 commonMessagePanelHolder.setName("commonMessagePanelHolder"); // NOI18N
236 commonMessagePanelHolder.setLayout(new javax.swing.BoxLayout(commonMessagePanelHolder, javax.swing.BoxLayout.LINE_AXIS));
238 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
239 this.setLayout(layout);
240 layout.setHorizontalGroup(
241 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
242 .add(operationPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
243 .add(layout.createSequentialGroup()
245 .add(commonMessagePanelHolder, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 487, Short.MAX_VALUE)
247 .add(layout.createSequentialGroup()
249 .add(bindingConfigurationPanelHolder, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 487, Short.MAX_VALUE)
252 layout.setVerticalGroup(
253 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
254 .add(layout.createSequentialGroup()
255 .add(operationPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
257 .add(bindingConfigurationPanelHolder, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 15, Short.MAX_VALUE)
258 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
259 .add(commonMessagePanelHolder, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
262 }// </editor-fold>//GEN-END:initComponents
264 private void operationComboboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_operationComboboxActionPerformed
265 if (provider != null) {
266 Object object = operationCombobox.getSelectedItem();
267 if (object instanceof OperationItem) {
268 lastSelectedOperation = ((OperationItem) object).getOperation();
269 ExtensibilityElementConfigurationEditorComponent component = provider.getOperationBasedEditorComponent(lastSelectedOperation);
270 if (component == null) {
274 setInnerPanel(component.getEditorPanel());
275 if (!configuredOperations.contains(lastSelectedOperation)) {
276 configuredOperations.add(lastSelectedOperation);
279 lastSelectedOperation = null;
283 }//GEN-LAST:event_operationComboboxActionPerformed
286 // Variables declaration - do not modify//GEN-BEGIN:variables
287 private javax.swing.JPanel bindingConfigurationPanelHolder;
288 private javax.swing.JLabel commentLabel;
289 private javax.swing.JPanel commonMessagePanelHolder;
290 private javax.swing.JLabel multipleOperationCommentLabel;
291 private javax.swing.JComboBox operationCombobox;
292 private javax.swing.JLabel operationLabel;
293 private javax.swing.JPanel operationPanel;
294 // End of variables declaration//GEN-END:variables
296 public void propertyChange(PropertyChangeEvent evt) {
300 if (evt.getNewValue() instanceof String) {
301 String message = (String) evt.getNewValue();
302 boolean valid = true;
303 if (evt.getPropertyName().equals(ExtensibilityElementConfigurationEditorComponent.PROPERTY_ERROR_EVT)) {
304 messagePanel.setErrorMessage(message);
306 } else if (evt.getPropertyName().equals(ExtensibilityElementConfigurationEditorComponent.PROPERTY_WARNING_EVT)) {
307 messagePanel.setWarningMessage(message);
308 } else if (evt.getPropertyName().equals(ExtensibilityElementConfigurationEditorComponent.PROPERTY_CLEAR_MESSAGES_EVT)) {
309 messagePanel.setMessage("");
310 } else if (evt.getPropertyName().equals(ExtensibilityElementConfigurationEditorComponent.PROPERTY_NORMAL_MESSAGE_EVT)) {
311 messagePanel.setMessage(message);
313 descriptor.setValid(valid);
317 class OperationItem {
322 public OperationItem(String name, Operation operation) {
324 this.operation = operation;
327 public Operation getOperation() {
332 public String toString() {