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