xml.wsdl.bindingsupport/src/org/netbeans/modules/xml/wsdl/bindingsupport/configeditor/ui/ConfigurationEditorPanel.java
author Milutin Kristofic <mkristofic@netbeans.org>
Mon, 30 Jan 2017 14:30:54 +0100
changeset 1583 fe20f672a61a
parent 1305 619e3fca5c2f
permissions -rw-r--r--
Added Missing copyright information in source files
     1 /*
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3  *
     4  * Copyright 2009-2017 Oracle and/or its affiliates. All rights reserved.
     5  *
     6  * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
     7  * Other names may be trademarks of their respective owners.
     8  *
     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]"
    26  *
    27  * Contributor(s):
    28  *
    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.
    32  *
    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.
    43  */
    44 /*
    45  * ConfigurationEditorPanel.java
    46  *
    47  * Created on May 27, 2008, 12:21 PM
    48  */
    49 
    50 package org.netbeans.modules.xml.wsdl.bindingsupport.configeditor.ui;
    51 
    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;
    58 import java.util.Set;
    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;
    67 
    68 /**
    69  *
    70  * @author  skini
    71  */
    72 public class ConfigurationEditorPanel extends javax.swing.JPanel implements PropertyChangeListener {
    73 
    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;
    84     
    85     private String title;
    86 
    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;
    94         }
    95         initComponents();
    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));
   106             }
   107             operationCombobox.setModel(new DefaultComboBoxModel(operationList));
   108         }
   109     }
   110     
   111     public void setInnerPanel(JComponent innerComponent) {
   112         if (this.innerPane != null) {
   113             this.innerPane.removePropertyChangeListener(this);
   114             bindingConfigurationPanelHolder.remove(this.innerPane);
   115         }
   116         this.innerPane = innerComponent;
   117         if (innerComponent != null) {
   118             innerComponent.addPropertyChangeListener(this);
   119             bindingConfigurationPanelHolder.add(innerComponent);
   120         }
   121         messagePanel.setMessage("");
   122         revalidate();
   123         Window windowAncestor = SwingUtilities.getWindowAncestor(this);
   124         if (windowAncestor != null) {
   125             windowAncestor.pack();
   126         }
   127         
   128     }
   129 
   130     Operation getSelectedOperation() {
   131         return lastSelectedOperation;
   132     }
   133     
   134     Set<Operation> getAllConfiguredOperations() {
   135         return configuredOperations;
   136     }
   137 
   138     void setDialogDescriptor(DialogDescriptor descriptor) {
   139         this.descriptor = descriptor;
   140     }
   141 
   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);
   148             }
   149             ExtensibilityElementConfigurationEditorComponent component = provider.getOperationBasedEditorComponent(lastSelectedOperation);
   150             if (component == null) {
   151                 return false;
   152             }
   153             if (operations.size() > 1) {
   154                 return true;
   155             }
   156             setInnerPanel(component.getEditorPanel());
   157             title = component.getTitle();
   158         }
   159         return true;
   160     }
   161     
   162     public String getTitle() {
   163         return title;
   164     }
   165 
   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.
   170      */
   171     @SuppressWarnings("unchecked")
   172     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   173     private void initComponents() {
   174 
   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();
   182 
   183         setName("Form"); // NOI18N
   184 
   185         operationPanel.setName("operationPanel"); // NOI18N
   186 
   187         org.openide.awt.Mnemonics.setLocalizedText(operationLabel, org.openide.util.NbBundle.getMessage(ConfigurationEditorPanel.class, "ConfigurationEditorPanel.operationLabel.text")); // NOI18N
   188         operationLabel.setName("operationLabel"); // NOI18N
   189 
   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);
   195             }
   196         });
   197 
   198         org.openide.awt.Mnemonics.setLocalizedText(commentLabel, org.openide.util.NbBundle.getMessage(ConfigurationEditorPanel.class, "ConfigurationEditorPanel.commentLabel.text")); // NOI18N
   199         commentLabel.setName("commentLabel"); // NOI18N
   200 
   201         org.openide.awt.Mnemonics.setLocalizedText(multipleOperationCommentLabel, org.openide.util.NbBundle.getMessage(ConfigurationEditorPanel.class, "ConfigurationEditorPanel.multipleOperationCommentLabel.text")); // NOI18N
   202         multipleOperationCommentLabel.setName("multipleOperationCommentLabel"); // NOI18N
   203 
   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()
   209                 .addContainerGap()
   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()
   214                         .add(operationLabel)
   215                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
   216                         .add(operationCombobox, 0, 431, Short.MAX_VALUE)))
   217                 .addContainerGap())
   218         );
   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)
   223                 .add(commentLabel)
   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)
   228                     .add(operationLabel)
   229                     .add(operationCombobox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
   230         );
   231 
   232         bindingConfigurationPanelHolder.setName("bindingConfigurationPanelHolder"); // NOI18N
   233         bindingConfigurationPanelHolder.setLayout(new javax.swing.BoxLayout(bindingConfigurationPanelHolder, javax.swing.BoxLayout.Y_AXIS));
   234 
   235         commonMessagePanelHolder.setName("commonMessagePanelHolder"); // NOI18N
   236         commonMessagePanelHolder.setLayout(new javax.swing.BoxLayout(commonMessagePanelHolder, javax.swing.BoxLayout.LINE_AXIS));
   237 
   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()
   244                 .addContainerGap()
   245                 .add(commonMessagePanelHolder, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 487, Short.MAX_VALUE)
   246                 .addContainerGap())
   247             .add(layout.createSequentialGroup()
   248                 .addContainerGap()
   249                 .add(bindingConfigurationPanelHolder, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 487, Short.MAX_VALUE)
   250                 .addContainerGap())
   251         );
   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)
   256                 .add(18, 18, 18)
   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)
   260                 .addContainerGap())
   261         );
   262     }// </editor-fold>//GEN-END:initComponents
   263 
   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) {
   271                 setInnerPanel(null);
   272                 return;
   273             }
   274             setInnerPanel(component.getEditorPanel());
   275             if (!configuredOperations.contains(lastSelectedOperation)) {
   276                 configuredOperations.add(lastSelectedOperation);
   277             }
   278         } else {
   279             lastSelectedOperation = null;
   280             setInnerPanel(null);
   281         }
   282     }
   283 }//GEN-LAST:event_operationComboboxActionPerformed
   284 
   285 
   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
   295 
   296     public void propertyChange(PropertyChangeEvent evt) {
   297         if (evt == null) {
   298             return;
   299         }
   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);
   305                 valid = false;
   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);
   312             }
   313             descriptor.setValid(valid);
   314         }
   315     }
   316     
   317     class OperationItem {
   318 
   319         String name;
   320         Operation operation;
   321 
   322         public OperationItem(String name, Operation operation) {
   323             this.name = name;
   324             this.operation = operation;
   325         }
   326 
   327         public Operation getOperation() {
   328             return operation;
   329         }
   330 
   331         @Override
   332         public String toString() {
   333             return name;
   334         }
   335     }
   336 
   337 }