KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > winsys > 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.winsys;
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 topcomponent wizard.
37  *
38  * @author Milos Kleint
39  */

40 final class NameAndLocationPanel extends BasicWizardIterator.Panel {
41     
42     private NewTCIterator.DataModel data;
43     
44     /** Creates new NameAndLocationPanel */
45     public NameAndLocationPanel(final WizardDescriptor setting, final NewTCIterator.DataModel data) {
46         super(setting);
47         this.data = data;
48         initComponents();
49         initAccessibility();
50         putClientProperty("NewFileWizard_Title", getMessage("LBL_TCWizardTitle"));
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.setIcon(icon.length() == 0 ? (String JavaDoc)null : icon);
76         data.setName(txtPrefix.getText().trim());
77         NewTCIterator.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     
90     protected void readFromDataModel() {
91         txtPrefix.setText(data.getName());
92         txtIcon.setText(data.getIcon());
93         if (data.getPackageName() != null) {
94             comPackageName.setSelectedItem(data.getPackageName());
95         }
96         checkValidity();
97     }
98     
99     protected String JavaDoc getPanelName() {
100         return getMessage("LBL_NameLocation_Title");
101     }
102     
103     private boolean checkValidity() {
104         if (txtPrefix.getText().trim().length() == 0) {
105             setError(getMessage("ERR_Name_Prefix_Empty"));
106             return false;
107         }
108         if (!Utilities.isJavaIdentifier(txtPrefix.getText().trim())) {
109             setError(getMessage("ERR_Name_Prefix_Invalid"));
110             return false;
111         }
112         String JavaDoc path = txtIcon.getText().trim();
113         if (path.length() != 0) {
114             File JavaDoc fil = new File JavaDoc(path);
115             if (!fil.exists()) {
116                 setError(NbBundle.getMessage(getClass(), "ERR_Icon_Invalid"));
117                 return false;
118             }
119         }
120         String JavaDoc packageName = comPackageName.getEditor().getItem().toString().trim();
121         if (packageName.length() == 0 || !UIUtil.isValidPackageName(packageName)) {
122             setError(NbBundle.getMessage(getClass(), "ERR_Package_Invalid"));
123             return false;
124         }
125         
126         markValid();
127         return true;
128     }
129     
130     protected HelpCtx getHelp() {
131         return new HelpCtx(NameAndLocationPanel.class);
132     }
133     
134     private static String JavaDoc getMessage(String JavaDoc key) {
135         return NbBundle.getMessage(NameAndLocationPanel.class, key);
136     }
137     
138     /** This method is called from within the constructor to
139      * initialize the form.
140      * WARNING: Do NOT modify this code. The content of this method is
141      * always regenerated by the Form Editor.
142      */

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

308     private void initAccessibility() {
309         this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_NameAndLocationPanel"));
310         comPackageName.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_PackageName"));
311         txtIcon.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Icon"));
312         txtPrefix.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Prefix"));
313         btnIcon.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_IconButton"));
314         txtProjectName.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ProjectName"));
315         createdFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_CreatedFilesValue"));
316         modifiedFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ModifiedFilesValue"));
317     }
318     
319     private void btnIconActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_btnIconActionPerformed
320
JFileChooser JavaDoc chooser = UIUtil.getIconFileChooser(txtIcon.getText());
321         int ret = chooser.showDialog(this, getMessage("LBL_Select")); // NOI18N
322
if (ret == JFileChooser.APPROVE_OPTION) {
323             File JavaDoc file = chooser.getSelectedFile();
324             txtIcon.setText(file.getAbsolutePath());
325         }
326     }//GEN-LAST:event_btnIconActionPerformed
327

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

345 }
Popular Tags