001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.xml.wsdl.ui.api.property;
043:
044: import java.util.HashMap;
045: import java.util.Map;
046:
047: import javax.swing.ComboBoxModel;
048: import javax.swing.DefaultComboBoxModel;
049: import javax.swing.JList;
050:
051: import org.openide.explorer.propertysheet.PropertyEnv;
052:
053: /**
054: *
055: * @author skini
056: */
057: public class PartsSelectorPanel extends javax.swing.JPanel {
058:
059: /**
060: *
061: */
062: private static final long serialVersionUID = 8696139559577226547L;
063: private int[] selectedIndices;
064:
065: /** Creates new form PartsSelectorPanel */
066: public PartsSelectorPanel(String[] parts,
067: String[] selectedPartNames, PropertyEnv env) {
068: mEnv = env;
069: mEnv.setState(PropertyEnv.STATE_INVALID);
070: mParts = parts;
071: if (selectedPartNames != null) {
072: if (selectedPartNames.length == 1
073: && selectedPartNames[0].trim().length() == 0) {
074: selectedIndices = null;
075: } else {
076: selectedIndices = new int[selectedPartNames.length];
077: Map<String, Integer> map = new HashMap<String, Integer>();
078: int j = 0;
079: for (String part : parts) {
080: map.put(part, new Integer(j++));
081: }
082:
083: for (int i = 0; i < selectedPartNames.length; i++) {
084: String partName = selectedPartNames[i];
085: if (map.containsKey(partName)) {
086: selectedIndices[i] = map.get(partName)
087: .intValue();
088: } else {
089: selectedIndices[i] = -1;
090: }
091: }
092: }
093: }
094: initComponents();
095:
096: }
097:
098: /** This method is called from within the constructor to
099: * initialize the form.
100: * WARNING: Do NOT modify this code. The content of this method is
101: * always regenerated by the Form Editor.
102: */
103: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
104: private void initComponents() {
105: jScrollPane1 = new javax.swing.JScrollPane();
106: jList1 = new javax.swing.JList();
107:
108: ComboBoxModel model = new DefaultComboBoxModel(mParts);
109: jList1.setModel(model);
110: if (selectedIndices != null)
111: jList1.setSelectedIndices(selectedIndices);
112: jList1.setToolTipText(org.openide.util.NbBundle.getMessage(
113: PartsSelectorPanel.class,
114: "PartsSelectorPanel.jList1.toolTipText")); // NOI18N
115: jList1
116: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
117: public void valueChanged(
118: javax.swing.event.ListSelectionEvent evt) {
119: jList1ValueChanged(evt);
120: }
121: });
122:
123: jScrollPane1.setViewportView(jList1);
124: jList1
125: .getAccessibleContext()
126: .setAccessibleName(
127: org.openide.util.NbBundle
128: .getMessage(PartsSelectorPanel.class,
129: "PartsSelectorPanel.jList1.AccessibleContext.accessibleName")); // NOI18N
130: jList1
131: .getAccessibleContext()
132: .setAccessibleDescription(
133: org.openide.util.NbBundle
134: .getMessage(PartsSelectorPanel.class,
135: "PartsSelectorPanel.jList1.AccessibleContext.accessibleDescription")); // NOI18N
136:
137: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
138: this );
139: this .setLayout(layout);
140: layout.setHorizontalGroup(layout.createParallelGroup(
141: org.jdesktop.layout.GroupLayout.LEADING).add(
142: jScrollPane1,
143: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 222,
144: Short.MAX_VALUE));
145: layout.setVerticalGroup(layout.createParallelGroup(
146: org.jdesktop.layout.GroupLayout.LEADING).add(
147: jScrollPane1,
148: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 220,
149: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE));
150: }// </editor-fold>//GEN-END:initComponents
151:
152: private void jList1ValueChanged(
153: javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged
154: enableOK();
155: JList list = (JList) evt.getSource();
156: if (!list.getValueIsAdjusting()) {
157: Object[] sv = list.getSelectedValues();
158: if (sv != null && sv.length > 0) {
159:
160: }
161: }
162: }//GEN-LAST:event_jList1ValueChanged
163:
164: private void enableOK() {
165: if (!okEnabled) {
166: mEnv.setState(PropertyEnv.STATE_NEEDS_VALIDATION);
167: okEnabled = true;
168: }
169:
170: }
171:
172: public String getParts() {
173: Object[] selectedValues = jList1.getSelectedValues();
174: StringBuffer strBuf = new StringBuffer();
175: for (Object selectedValue : selectedValues) {
176: strBuf.append((String) selectedValue).append(" ");
177: }
178: return strBuf.toString().trim();
179: }
180:
181: private boolean okEnabled = false;
182: private PropertyEnv mEnv;
183: private String[] mParts;
184: // Variables declaration - do not modify//GEN-BEGIN:variables
185: private javax.swing.JList jList1;
186: private javax.swing.JScrollPane jScrollPane1;
187: // End of variables declaration//GEN-END:variables
188:
189: }
|