KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > api > property > PartsSelectorPanel


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.api.property;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import javax.swing.ComboBoxModel JavaDoc;
27 import javax.swing.DefaultComboBoxModel JavaDoc;
28 import javax.swing.JList JavaDoc;
29
30 import org.openide.explorer.propertysheet.PropertyEnv;
31
32 /**
33  *
34  * @author skini
35  */

36 public class PartsSelectorPanel extends javax.swing.JPanel JavaDoc {
37     
38     /**
39      *
40      */

41     private static final long serialVersionUID = 8696139559577226547L;
42     private int[] selectedIndices;
43     
44     /** Creates new form PartsSelectorPanel */
45     public PartsSelectorPanel(String JavaDoc[] parts, String JavaDoc[] selectedPartNames, PropertyEnv env) {
46         mEnv = env;
47         mEnv.setState(PropertyEnv.STATE_INVALID);
48         mParts = parts;
49         if (selectedPartNames != null && selectedPartNames.length == 1 && selectedPartNames[0].trim().length() == 0) {
50             selectedIndices = null;
51         } else {
52             selectedIndices = new int[selectedPartNames.length];
53             Map JavaDoc<String JavaDoc, Integer JavaDoc> map = new HashMap JavaDoc<String JavaDoc, Integer JavaDoc>();
54             int j = 0;
55             for (String JavaDoc part : parts) {
56                 map.put(part, new Integer JavaDoc(j++));
57             }
58
59             for (int i = 0; i < selectedPartNames.length; i++) {
60                 String JavaDoc partName = selectedPartNames[i];
61                 if (map.containsKey(partName)) {
62                     selectedIndices[i] = map.get(partName).intValue();
63                 } else {
64                     selectedIndices[i] = -1;
65                 }
66             }
67         }
68         initComponents();
69         
70     }
71     
72     /** This method is called from within the constructor to
73      * initialize the form.
74      * WARNING: Do NOT modify this code. The content of this method is
75      * always regenerated by the Form Editor.
76      */

77     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
78
private void initComponents() {
79         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
80         jList1 = new javax.swing.JList JavaDoc();
81
82         ComboBoxModel JavaDoc model = new DefaultComboBoxModel JavaDoc(mParts);
83         jList1.setModel(model);
84         if (selectedIndices != null)
85         jList1.setSelectedIndices(selectedIndices);
86         jList1.setToolTipText(org.openide.util.NbBundle.getMessage(PartsSelectorPanel.class, "PartsSelectorPanel.jList1.toolTipText")); // NOI18N
87
jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
88             public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {
89                 jList1ValueChanged(evt);
90             }
91         });
92
93         jScrollPane1.setViewportView(jList1);
94         jList1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PartsSelectorPanel.class, "PartsSelectorPanel.jList1.AccessibleContext.accessibleName")); // NOI18N
95
jList1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PartsSelectorPanel.class, "PartsSelectorPanel.jList1.AccessibleContext.accessibleDescription")); // NOI18N
96

97         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
98         this.setLayout(layout);
99         layout.setHorizontalGroup(
100             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
101             .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
102         );
103         layout.setVerticalGroup(
104             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
105             .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 220, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
106         );
107     }// </editor-fold>//GEN-END:initComponents
108

109     private void jList1ValueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {//GEN-FIRST:event_jList1ValueChanged
110
enableOK();
111         JList JavaDoc list = (JList JavaDoc) evt.getSource();
112         if (!list.getValueIsAdjusting()) {
113             Object JavaDoc[] sv = list.getSelectedValues();
114             if (sv != null && sv.length > 0) {
115                 
116             }
117         }
118     }//GEN-LAST:event_jList1ValueChanged
119

120     private void enableOK() {
121         if (!okEnabled) {
122             mEnv.setState(PropertyEnv.STATE_VALID);
123             okEnabled = true;
124         }
125         
126     }
127     
128     @Override JavaDoc
129     public void removeNotify() {
130         if (mEnv.getState().equals(PropertyEnv.STATE_VALID)) {
131             Object JavaDoc[] selectedValues = jList1.getSelectedValues();
132             StringBuffer JavaDoc strBuf = new StringBuffer JavaDoc();
133             for (Object JavaDoc selectedValue : selectedValues) {
134                 strBuf.append((String JavaDoc) selectedValue).append(" ");
135             }
136             this.firePropertyChange(PartsSelectorPropertyEditor.PROP_NAME, null, strBuf.toString().trim());
137         }
138         super.removeNotify();
139     }
140     
141     private boolean okEnabled = false;
142     private PropertyEnv mEnv;
143     private String JavaDoc[] mParts;
144     // Variables declaration - do not modify//GEN-BEGIN:variables
145
private javax.swing.JList JavaDoc jList1;
146     private javax.swing.JScrollPane JavaDoc jScrollPane1;
147     // End of variables declaration//GEN-END:variables
148

149     
150 }
151
Popular Tags