KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > loader > NameAndLocationPanel


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.loader;
21
22 import java.io.File JavaDoc;
23 import javax.swing.JFileChooser JavaDoc;
24 import javax.swing.JTextField JavaDoc;
25 import javax.swing.event.DocumentEvent JavaDoc;
26 import javax.swing.event.DocumentListener JavaDoc;
27 import org.netbeans.api.project.ProjectUtils;
28 import org.netbeans.modules.apisupport.project.ui.UIUtil;
29 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
30 import org.openide.WizardDescriptor;
31 import org.openide.util.HelpCtx;
32 import org.openide.util.NbBundle;
33 import org.openide.util.Utilities;
34
35 /**
36  * the second panel in loaders wizard.
37  *
38  * @author Milos Kleint
39  */

40 final class NameAndLocationPanel extends BasicWizardIterator.Panel {
41     
42     private NewLoaderIterator.DataModel data;
43     
44     /** Creates new NameAndLocationPanel */
45     public NameAndLocationPanel(final WizardDescriptor setting, final NewLoaderIterator.DataModel data) {
46         super(setting);
47         this.data = data;
48         initComponents();
49         initAccessibility();
50         putClientProperty("NewFileWizard_Title", getMessage("LBL_LoaderWizardTitle"));
51         
52         DocumentListener JavaDoc dListener = new UIUtil.DocumentAdapter() {
53             public void insertUpdate(DocumentEvent JavaDoc e) {
54                 if (checkValidity()) {
55                     updateData();
56                 }
57             }
58         };
59         txtPrefix.getDocument().addDocumentListener(dListener);
60         txtIcon.getDocument().addDocumentListener(dListener);
61         
62         if (comPackageName.getEditor().getEditorComponent() instanceof JTextField JavaDoc) {
63             JTextField JavaDoc txt = (JTextField JavaDoc)comPackageName.getEditor().getEditorComponent();
64             txt.getDocument().addDocumentListener(dListener);
65         }
66     }
67     
68     protected void storeToDataModel() {
69         updateData();
70     }
71     
72     private void updateData() {
73         data.setPackageName(comPackageName.getEditor().getItem().toString());
74         String JavaDoc icon = txtIcon.getText().trim();
75         data.setIconPath(icon.length() == 0 ? (String JavaDoc)null : icon);
76         data.setPrefix(txtPrefix.getText().trim());
77         NewLoaderIterator.generateFileChanges(data);
78         createdFilesValue.setText(UIUtil.generateTextAreaContent(
79                 data.getCreatedModifiedFiles().getCreatedPaths()));
80         modifiedFilesValue.setText(UIUtil.generateTextAreaContent(
81                 data.getCreatedModifiedFiles().getModifiedPaths()));
82         //#68294 check if the paths for newly created files are valid or not..
83
String JavaDoc[] invalid = data.getCreatedModifiedFiles().getInvalidPaths();
84         if (invalid.length > 0) {
85             setError(NbBundle.getMessage(NameAndLocationPanel.class, "ERR_ToBeCreateFileExists", invalid[0]));
86         }
87     }
88     
89     protected void readFromDataModel() {
90         if (data.getPackageName() != null) {
91             comPackageName.setSelectedItem(data.getPackageName());
92         }
93         txtPrefix.setText(data.getPrefix());
94         txtIcon.setText(data.getPrefix());
95         checkValidity();
96     }
97     
98     protected String JavaDoc getPanelName() {
99         return getMessage("LBL_NameLocation_Title");
100     }
101     
102     private boolean checkValidity() {
103         if (txtPrefix.getText().trim().length() == 0) {
104             setError(getMessage("ERR_Name_Prefix_Empty"));
105             return false;
106         }
107         if (!Utilities.isJavaIdentifier(txtPrefix.getText().trim())) {
108             setError(getMessage("ERR_Name_Prefix_Invalid"));
109             return false;
110         }
111         String JavaDoc path = txtIcon.getText().trim();
112         if (path.length() != 0) {
113             File JavaDoc fil = new File JavaDoc(path);
114             if (!fil.exists()) {
115                 setError(NbBundle.getMessage(getClass(), "ERR_Icon_Invalid"));
116                 return false;
117             }
118         }
119         String JavaDoc packageName = comPackageName.getEditor().getItem().toString().trim();
120         
121         if (packageName.length() == 0 || !UIUtil.isValidPackageName(packageName)) { //NOI18N
122
setError(NbBundle.getMessage(getClass(), "ERR_Package_Invalid"));
123             return false;
124         }
125         
126         File JavaDoc icon = (path.length() == 0) ? null : new File JavaDoc(path);
127         if (icon == null || !icon.exists()) {
128             setWarning(UIUtil.getNoIconSelectedWarning(16,16));
129         } else if (!UIUtil.isValidIcon(icon,16,16)) {
130             setWarning(UIUtil.getIconDimensionWarning(icon,16,16));
131         } else {
132             markValid();
133         }
134         return true;
135     }
136     
137     protected HelpCtx getHelp() {
138         return new HelpCtx(NameAndLocationPanel.class);
139     }
140     
141     private static String JavaDoc getMessage(String JavaDoc key) {
142         return NbBundle.getMessage(NameAndLocationPanel.class, key);
143     }
144     
145     /** This method is called from within the constructor to
146      * initialize the form.
147      * WARNING: Do NOT modify this code. The content of this method is
148      * always regenerated by the Form Editor.
149      */

150     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
151
private void initComponents() {
152         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
153
154         lblPrefix = new javax.swing.JLabel JavaDoc();
155         txtPrefix = new javax.swing.JTextField JavaDoc();
156         lblIcon = new javax.swing.JLabel JavaDoc();
157         txtIcon = new javax.swing.JTextField JavaDoc();
158         btnIcon = new javax.swing.JButton JavaDoc();
159         lblProjectName = new javax.swing.JLabel JavaDoc();
160         txtProjectName = new JTextField JavaDoc(ProjectUtils.getInformation(this.data.getProject()).getDisplayName());
161         lblPackageName = new javax.swing.JLabel JavaDoc();
162         comPackageName = UIUtil.createPackageComboBox(data.getSourceRootGroup());
163         createdFiles = new javax.swing.JLabel JavaDoc();
164         modifiedFiles = new javax.swing.JLabel JavaDoc();
165         filler = new javax.swing.JLabel JavaDoc();
166         createdFilesValue = new javax.swing.JTextArea JavaDoc();
167         modifiedFilesValue = new javax.swing.JTextArea JavaDoc();
168
169         setLayout(new java.awt.GridBagLayout JavaDoc());
170
171         lblPrefix.setLabelFor(txtPrefix);
172         org.openide.awt.Mnemonics.setLocalizedText(lblPrefix, org.openide.util.NbBundle.getMessage(NameAndLocationPanel.class, "LBL_Prefix"));
173         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
174         gridBagConstraints.gridx = 0;
175         gridBagConstraints.gridy = 0;
176         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
177         gridBagConstraints.insets = new java.awt.Insets JavaDoc(1, 0, 6, 12);
178         add(lblPrefix, gridBagConstraints);
179
180         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
181         gridBagConstraints.gridx = 1;
182         gridBagConstraints.gridy = 0;
183         gridBagConstraints.gridwidth = 2;
184         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
185         gridBagConstraints.weightx = 1.0;
186         gridBagConstraints.insets = new java.awt.Insets JavaDoc(1, 0, 6, 0);
187         add(txtPrefix, gridBagConstraints);
188
189         lblIcon.setLabelFor(txtIcon);
190         org.openide.awt.Mnemonics.setLocalizedText(lblIcon, org.openide.util.NbBundle.getMessage(NameAndLocationPanel.class, "LBL_Icon"));
191         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
192         gridBagConstraints.gridx = 0;
193         gridBagConstraints.gridy = 1;
194         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
195         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
196         add(lblIcon, gridBagConstraints);
197
198         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
199         gridBagConstraints.gridx = 1;
200         gridBagConstraints.gridy = 1;
201         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
202         gridBagConstraints.weightx = 1.0;
203         add(txtIcon, gridBagConstraints);
204
205         org.openide.awt.Mnemonics.setLocalizedText(btnIcon, org.openide.util.NbBundle.getMessage(NameAndLocationPanel.class, "LBL_Icon_Browse"));
206         btnIcon.addActionListener(new java.awt.event.ActionListener JavaDoc() {
207             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
208                 btnIconActionPerformed(evt);
209             }
210         });
211
212         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
213         gridBagConstraints.gridx = 2;
214         gridBagConstraints.gridy = 1;
215         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
216         add(btnIcon, gridBagConstraints);
217
218         lblProjectName.setLabelFor(txtProjectName);
219         org.openide.awt.Mnemonics.setLocalizedText(lblProjectName, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_ProjectName"));
220         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
221         gridBagConstraints.gridx = 0;
222         gridBagConstraints.gridy = 2;
223         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
224         gridBagConstraints.insets = new java.awt.Insets JavaDoc(18, 0, 6, 12);
225         add(lblProjectName, gridBagConstraints);
226
227         txtProjectName.setEditable(false);
228         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
229         gridBagConstraints.gridx = 1;
230         gridBagConstraints.gridy = 2;
231         gridBagConstraints.gridwidth = 2;
232         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
233         gridBagConstraints.weightx = 1.0;
234         gridBagConstraints.insets = new java.awt.Insets JavaDoc(18, 0, 6, 0);
235         add(txtProjectName, gridBagConstraints);
236
237         lblPackageName.setLabelFor(comPackageName);
238         org.openide.awt.Mnemonics.setLocalizedText(lblPackageName, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_PackageName"));
239         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
240         gridBagConstraints.gridx = 0;
241         gridBagConstraints.gridy = 3;
242         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
243         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
244         add(lblPackageName, gridBagConstraints);
245
246         comPackageName.setEditable(true);
247         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
248         gridBagConstraints.gridx = 1;
249         gridBagConstraints.gridy = 3;
250         gridBagConstraints.gridwidth = 2;
251         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
252         gridBagConstraints.weightx = 1.0;
253         add(comPackageName, gridBagConstraints);
254
255         createdFiles.setLabelFor(createdFilesValue);
256         org.openide.awt.Mnemonics.setLocalizedText(createdFiles, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_CreatedFiles"));
257         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
258         gridBagConstraints.gridx = 0;
259         gridBagConstraints.gridy = 4;
260         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
261         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
262         gridBagConstraints.insets = new java.awt.Insets JavaDoc(36, 0, 6, 12);
263         add(createdFiles, gridBagConstraints);
264
265         modifiedFiles.setLabelFor(modifiedFilesValue);
266         org.openide.awt.Mnemonics.setLocalizedText(modifiedFiles, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_ModifiedFiles"));
267         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
268         gridBagConstraints.gridx = 0;
269         gridBagConstraints.gridy = 5;
270         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
271         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
272         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
273         add(modifiedFiles, gridBagConstraints);
274
275         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
276         gridBagConstraints.gridx = 0;
277         gridBagConstraints.gridy = 6;
278         gridBagConstraints.gridwidth = 3;
279         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
280         gridBagConstraints.weightx = 1.0;
281         gridBagConstraints.weighty = 1.0;
282         add(filler, gridBagConstraints);
283
284         createdFilesValue.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background"));
285         createdFilesValue.setColumns(20);
286         createdFilesValue.setEditable(false);
287         createdFilesValue.setRows(5);
288         createdFilesValue.setBorder(null);
289         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
290         gridBagConstraints.gridx = 1;
291         gridBagConstraints.gridy = 4;
292         gridBagConstraints.gridwidth = 2;
293         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
294         gridBagConstraints.weightx = 1.0;
295         gridBagConstraints.insets = new java.awt.Insets JavaDoc(36, 0, 6, 0);
296         add(createdFilesValue, gridBagConstraints);
297
298         modifiedFilesValue.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background"));
299         modifiedFilesValue.setColumns(20);
300         modifiedFilesValue.setEditable(false);
301         modifiedFilesValue.setRows(5);
302         modifiedFilesValue.setToolTipText("modifiedFilesValue");
303         modifiedFilesValue.setBorder(null);
304         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
305         gridBagConstraints.gridx = 1;
306         gridBagConstraints.gridy = 5;
307         gridBagConstraints.gridwidth = 2;
308         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
309         gridBagConstraints.weightx = 1.0;
310         add(modifiedFilesValue, gridBagConstraints);
311
312     }
313     // </editor-fold>//GEN-END:initComponents
314

315     private void btnIconActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_btnIconActionPerformed
316
JFileChooser JavaDoc chooser = UIUtil.getIconFileChooser(txtIcon.getText());
317         int ret = chooser.showDialog(this, getMessage("LBL_Select")); // NOI18N
318
if (ret == JFileChooser.APPROVE_OPTION) {
319             File JavaDoc file = chooser.getSelectedFile();
320             txtIcon.setText(file.getAbsolutePath());
321         }
322     }//GEN-LAST:event_btnIconActionPerformed
323

324     // Variables declaration - do not modify//GEN-BEGIN:variables
325
private javax.swing.JButton JavaDoc btnIcon;
326     private javax.swing.JComboBox JavaDoc comPackageName;
327     private javax.swing.JLabel JavaDoc createdFiles;
328     private javax.swing.JTextArea JavaDoc createdFilesValue;
329     private javax.swing.JLabel JavaDoc filler;
330     private javax.swing.JLabel JavaDoc lblIcon;
331     private javax.swing.JLabel JavaDoc lblPackageName;
332     private javax.swing.JLabel JavaDoc lblPrefix;
333     private javax.swing.JLabel JavaDoc lblProjectName;
334     private javax.swing.JLabel JavaDoc modifiedFiles;
335     private javax.swing.JTextArea JavaDoc modifiedFilesValue;
336     private javax.swing.JTextField JavaDoc txtIcon;
337     private javax.swing.JTextField JavaDoc txtPrefix;
338     private javax.swing.JTextField JavaDoc txtProjectName;
339     // End of variables declaration//GEN-END:variables
340

341     private void initAccessibility() {
342         this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_NameAndLocationPanel"));
343         comPackageName.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_PackageName"));
344         txtIcon.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Icon"));
345         txtPrefix.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Prefix"));
346         btnIcon.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_IconButton"));
347         txtProjectName.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ProjectName"));
348         createdFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_CreatedFilesValue"));
349         modifiedFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ModifiedFilesValue"));
350     }
351
352 }
Popular Tags