KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > librarydescriptor > SelectLibraryPanel


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project.ui.wizard.librarydescriptor;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import org.netbeans.api.project.libraries.LibrariesCustomizer;
28 import org.netbeans.api.project.libraries.Library;
29 import org.netbeans.modules.apisupport.project.ui.platform.LibrariesModel;
30 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
31 import org.openide.WizardDescriptor;
32 import org.openide.util.HelpCtx;
33 import org.openide.util.NbBundle;
34
35 /**
36  * Represents <em>Libraries</em> panel in J2SE Library Descriptor Wizard.
37  *
38  * @author Radek Matous
39  */

40 final class SelectLibraryPanel extends BasicWizardIterator.Panel {
41     
42     private NewLibraryDescriptor.DataModel data;
43     
44     /**
45      * Creates new form SelectLibraryPanel
46      */

47     public SelectLibraryPanel(WizardDescriptor setting, NewLibraryDescriptor.DataModel data) {
48         super(setting);
49         this.data = data;
50         initComponents();
51         initAccessibility();
52         putClientProperty("NewFileWizard_Title", getMessage("LBL_LibraryWizardTitle"));
53         
54     }
55     
56     private void initAccessibility() {
57         this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_SelectLibraryPanel"));
58         manageLibrariessButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ManageLibraries"));
59         librariesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_LBL_Library"));
60     }
61     
62     private void checkValidity() {
63         //TODO:
64
markValid();
65     }
66     
67     Library getSelectedLibrary() {
68         return (librariesValue != null) ?(Library)librariesValue.getSelectedItem() : null;
69     }
70     
71     protected void storeToDataModel() {
72         data.setLibrary(getSelectedLibrary());
73     }
74     
75     protected void readFromDataModel() {
76         checkValidity();
77     }
78     
79     protected String JavaDoc getPanelName() {
80         return getMessage("LBL_SelectLibraryPanel_Title");
81     }
82     
83     protected HelpCtx getHelp() {
84         return new HelpCtx(SelectLibraryPanel.class);
85     }
86     
87     private static String JavaDoc getMessage(String JavaDoc key) {
88         return NbBundle.getMessage(SelectLibraryPanel.class, key);
89     }
90     
91     /** This method is called from within the constructor to
92      * initialize the form.
93      * WARNING: Do NOT modify this code. The content of this method is
94      * always regenerated by the Form Editor.
95      */

96     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
97
private void initComponents() {
98         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
99
100         platformPanel = new javax.swing.JPanel JavaDoc();
101         library = new javax.swing.JLabel JavaDoc();
102         librariesValue = LibrariesModel.getComboBox();
103         manageLibrariessButton = new javax.swing.JButton JavaDoc();
104         fillerPanel = new javax.swing.JPanel JavaDoc();
105         fillerLabel = new javax.swing.JLabel JavaDoc();
106
107         setLayout(new java.awt.GridBagLayout JavaDoc());
108
109         platformPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
110
111         library.setLabelFor(librariesValue);
112         org.openide.awt.Mnemonics.setLocalizedText(library, org.openide.util.NbBundle.getMessage(SelectLibraryPanel.class, "LBL_Library"));
113         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
114         gridBagConstraints.gridx = 0;
115         gridBagConstraints.gridy = 0;
116         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
117         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
118         platformPanel.add(library, gridBagConstraints);
119
120         librariesValue.addItemListener(new java.awt.event.ItemListener JavaDoc() {
121             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
122                 librariesValueItemStateChanged(evt);
123             }
124         });
125
126         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
127         gridBagConstraints.gridx = 1;
128         gridBagConstraints.gridy = 0;
129         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
130         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
131         gridBagConstraints.weightx = 1.0;
132         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
133         platformPanel.add(librariesValue, gridBagConstraints);
134
135         org.openide.awt.Mnemonics.setLocalizedText(manageLibrariessButton, org.openide.util.NbBundle.getMessage(SelectLibraryPanel.class, "CTL_ManageLibraries"));
136         manageLibrariessButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
137             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
138                 manageLibraries(evt);
139             }
140         });
141
142         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
143         gridBagConstraints.gridx = 2;
144         gridBagConstraints.gridy = 0;
145         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
146         platformPanel.add(manageLibrariessButton, gridBagConstraints);
147
148         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
149         gridBagConstraints.gridx = 0;
150         gridBagConstraints.gridy = 0;
151         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
152         add(platformPanel, gridBagConstraints);
153
154         fillerPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
155
156         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
157         gridBagConstraints.gridx = 0;
158         gridBagConstraints.gridy = 2;
159         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
160         gridBagConstraints.weightx = 1.0;
161         gridBagConstraints.weighty = 1.0;
162         fillerPanel.add(fillerLabel, gridBagConstraints);
163
164         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
165         gridBagConstraints.gridx = 0;
166         gridBagConstraints.gridy = 2;
167         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
168         gridBagConstraints.weightx = 1.0;
169         gridBagConstraints.weighty = 1.0;
170         add(fillerPanel, gridBagConstraints);
171
172     }
173     // </editor-fold>//GEN-END:initComponents
174

175     private void librariesValueItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_librariesValueItemStateChanged
176
checkValidity();
177     }//GEN-LAST:event_librariesValueItemStateChanged
178

179     private void manageLibraries(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_manageLibraries
180
LibrariesModel model = (LibrariesModel) librariesValue.getModel();
181         Collection JavaDoc oldLibraries = Arrays.asList(model.getLibraries());
182         LibrariesCustomizer.showCustomizer((Library)librariesValue.getSelectedItem());
183         List JavaDoc currentLibraries = Arrays.asList(model.getLibraries());
184         Collection JavaDoc newLibraries = new ArrayList JavaDoc(currentLibraries);
185         
186         newLibraries.removeAll(oldLibraries);
187         int indexes[] = new int [newLibraries.size()];
188         
189         int i=0;
190         for (Iterator JavaDoc it = newLibraries.iterator(); it.hasNext();i++) {
191             Library lib = (Library) it.next();
192             indexes[i] = currentLibraries.indexOf(lib);
193         }
194         if (indexes.length > 0 && i > 0) {
195             librariesValue.setSelectedIndex(indexes[i-1]);
196         }
197     }//GEN-LAST:event_manageLibraries
198

199     // Variables declaration - do not modify//GEN-BEGIN:variables
200
private javax.swing.JLabel JavaDoc fillerLabel;
201     private javax.swing.JPanel JavaDoc fillerPanel;
202     private javax.swing.JComboBox JavaDoc librariesValue;
203     private javax.swing.JLabel JavaDoc library;
204     private javax.swing.JButton JavaDoc manageLibrariessButton;
205     private javax.swing.JPanel JavaDoc platformPanel;
206     // End of variables declaration//GEN-END:variables
207

208 }
209
Popular Tags