KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > librarydescriptor > 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.librarydescriptor;
21
22 import javax.swing.JTextField JavaDoc;
23 import javax.swing.event.DocumentEvent JavaDoc;
24 import javax.swing.event.DocumentListener JavaDoc;
25 import org.netbeans.api.project.ProjectUtils;
26 import org.netbeans.modules.apisupport.project.CreatedModifiedFiles;
27 import org.netbeans.modules.apisupport.project.ui.UIUtil;
28 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
29 import org.openide.WizardDescriptor;
30 import org.openide.util.HelpCtx;
31 import org.openide.util.NbBundle;
32
33 /**
34  * Represents <em>Name and Location</em> panel in J2SE Library Descriptor Wizard.
35  *
36  * @author Radek Matous
37  */

38 final class NameAndLocationPanel extends BasicWizardIterator.Panel {
39     
40     private NewLibraryDescriptor.DataModel data;
41     
42     /** Creates new NameAndLocationPanel */
43     public NameAndLocationPanel(final WizardDescriptor setting, final NewLibraryDescriptor.DataModel data) {
44         super(setting);
45         this.data = data;
46         initComponents();
47         initAccessibility();
48         putClientProperty("NewFileWizard_Title",// NOI18N
49
NbBundle.getMessage(NameAndLocationPanel.class,"LBL_LibraryWizardTitle")); // NOI18N
50

51         DocumentListener JavaDoc dListener = new UIUtil.DocumentAdapter() {
52             public void insertUpdate(DocumentEvent JavaDoc e) {
53                 NewLibraryDescriptor.DataModel _data = getTemporaryDataModel();
54                 setEnabledForFilesInfo(checkValidity(_data));
55                 setFilesInfoIntoTextAreas(_data);
56             }
57         };
58         libraryNameVale.getDocument().addDocumentListener(dListener);
59         libraryDisplayNameValue.getDocument().addDocumentListener(dListener);
60     }
61     
62     private static String JavaDoc getMessage(String JavaDoc key) {
63         return NbBundle.getMessage(NameAndLocationPanel.class, key);
64     }
65     
66     private void initAccessibility() {
67         this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_NameIconLocationPanel"));
68         createdFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_LBL_CreatedFiles"));
69         modifiedFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_LBL_ModifiedFiles"));
70         libraryDisplayNameValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_LBL_DisplayName"));
71         libraryNameVale.getAccessibleContext().setAccessibleDescription(getMessage("ACS_LBL_Name"));
72         projectNameValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_LBL_ProjectName"));
73     }
74     
75     protected void storeToDataModel() {
76         NewLibraryDescriptor.DataModel _temp = getTemporaryDataModel();
77         data.setLibraryName(_temp.getLibraryName());
78         data.setLibraryDisplayName(_temp.getLibraryDisplayName());
79         data.setCreatedModifiedFiles(_temp.getCreatedModifiedFiles());
80     }
81     
82     private NewLibraryDescriptor.DataModel getTemporaryDataModel() {
83         NewLibraryDescriptor.DataModel _temp = data.cloneMe(getSettings());
84         _temp.setLibraryName(libraryNameVale.getText());
85         _temp.setLibraryDisplayName(libraryDisplayNameValue.getText());
86         if (_temp.isValidLibraryDisplayName() && _temp.isValidLibraryName()) {
87             CreatedModifiedFiles files = CreatedModifiedFilesProvider.createInstance(_temp);
88             _temp.setCreatedModifiedFiles(files);
89         }
90         return _temp;
91     }
92     
93     private void setEnabledForFilesInfo(boolean enabled) {
94         createdFilesValue.setEnabled(enabled);
95         modifiedFilesValue.setEnabled(enabled);
96     }
97
98     private void setFilesInfoIntoTextAreas(final NewLibraryDescriptor.DataModel _temp) {
99         if (_temp.getCreatedModifiedFiles() != null) {
100             createdFilesValue.setText(UIUtil.generateTextAreaContent(
101                     _temp.getCreatedModifiedFiles().getCreatedPaths()));
102             modifiedFilesValue.setText(UIUtil.generateTextAreaContent(
103                     _temp.getCreatedModifiedFiles().getModifiedPaths()));
104         }
105     }
106     
107     protected void readFromDataModel() {
108         libraryNameVale.setText(this.data.getLibrary().getName());
109         libraryDisplayNameValue.setText(this.data.getLibrary().getDisplayName());
110         checkValidity(getTemporaryDataModel());
111     }
112     
113     protected String JavaDoc getPanelName() {
114         return NbBundle.getMessage(NameAndLocationPanel.class,"LBL_NameAndLocation_Title"); // NOI18N
115
}
116
117     
118     private boolean checkValidity(final NewLibraryDescriptor.DataModel _data) {
119         if (!_data.isValidLibraryName()) {
120             setError(NbBundle.getMessage(NameAndLocationPanel.class,"ERR_EmptyName")); // NOI18N
121
return false;
122         } else if (!_data.isValidLibraryDisplayName()) {
123             setError(NbBundle.getMessage(NameAndLocationPanel.class,"ERR_EmptyDescName")); // NOI18N
124
return false;
125         }else if (_data.libraryAlreadyExists()) {
126             setError(NbBundle.getMessage(NameAndLocationPanel.class,
127                     "ERR_LibraryExists", _data.getLibraryName()));
128             return false;
129         }
130         markValid();
131         return true;
132     }
133     
134     protected HelpCtx getHelp() {
135         return new HelpCtx(NameAndLocationPanel.class);
136     }
137     
138     public void addNotify() {
139         super.addNotify();
140         checkValidity(getTemporaryDataModel());
141     }
142     
143     /** This method is called from within the constructor to
144      * initialize the form.
145      * WARNING: Do NOT modify this code. The content of this method is
146      * always regenerated by the Form Editor.
147      */

148     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
149
private void initComponents() {
150         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
151
152         libraryName = new javax.swing.JLabel JavaDoc();
153         libraryNameVale = new javax.swing.JTextField JavaDoc();
154         libraryDisplayName = new javax.swing.JLabel JavaDoc();
155         libraryDisplayNameValue = new javax.swing.JTextField JavaDoc();
156         projectName = new javax.swing.JLabel JavaDoc();
157         projectNameValue = new JTextField JavaDoc(ProjectUtils.getInformation(this.data.getProject()).getDisplayName());
158         createdFiles = new javax.swing.JLabel JavaDoc();
159         modifiedFiles = new javax.swing.JLabel JavaDoc();
160         createdFilesValueS = new javax.swing.JScrollPane JavaDoc();
161         createdFilesValue = new javax.swing.JTextArea JavaDoc();
162         modifiedFilesValueS = new javax.swing.JScrollPane JavaDoc();
163         modifiedFilesValue = new javax.swing.JTextArea JavaDoc();
164
165         setLayout(new java.awt.GridBagLayout JavaDoc());
166
167         libraryName.setLabelFor(libraryNameVale);
168         org.openide.awt.Mnemonics.setLocalizedText(libraryName, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_LibraryName"));
169         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
170         gridBagConstraints.gridx = 0;
171         gridBagConstraints.gridy = 0;
172         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
173         gridBagConstraints.insets = new java.awt.Insets JavaDoc(1, 0, 6, 12);
174         add(libraryName, gridBagConstraints);
175
176         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
177         gridBagConstraints.gridx = 1;
178         gridBagConstraints.gridy = 0;
179         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
180         gridBagConstraints.weightx = 1.0;
181         gridBagConstraints.insets = new java.awt.Insets JavaDoc(1, 0, 6, 0);
182         add(libraryNameVale, gridBagConstraints);
183
184         libraryDisplayName.setLabelFor(libraryDisplayNameValue);
185         org.openide.awt.Mnemonics.setLocalizedText(libraryDisplayName, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_LibraryDisplayName"));
186         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
187         gridBagConstraints.gridx = 0;
188         gridBagConstraints.gridy = 1;
189         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
190         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
191         add(libraryDisplayName, gridBagConstraints);
192
193         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
194         gridBagConstraints.gridx = 1;
195         gridBagConstraints.gridy = 1;
196         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
197         gridBagConstraints.weightx = 1.0;
198         add(libraryDisplayNameValue, gridBagConstraints);
199
200         projectName.setLabelFor(projectNameValue);
201         org.openide.awt.Mnemonics.setLocalizedText(projectName, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_ProjectName"));
202         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
203         gridBagConstraints.gridx = 0;
204         gridBagConstraints.gridy = 2;
205         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
206         gridBagConstraints.insets = new java.awt.Insets JavaDoc(18, 0, 6, 12);
207         add(projectName, gridBagConstraints);
208
209         projectNameValue.setEditable(false);
210         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
211         gridBagConstraints.gridx = 1;
212         gridBagConstraints.gridy = 2;
213         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
214         gridBagConstraints.weightx = 1.0;
215         gridBagConstraints.insets = new java.awt.Insets JavaDoc(18, 0, 6, 0);
216         add(projectNameValue, gridBagConstraints);
217
218         createdFiles.setLabelFor(createdFilesValue);
219         org.openide.awt.Mnemonics.setLocalizedText(createdFiles, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_CreatedFiles"));
220         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
221         gridBagConstraints.gridx = 0;
222         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
223         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
224         gridBagConstraints.insets = new java.awt.Insets JavaDoc(36, 0, 6, 12);
225         add(createdFiles, gridBagConstraints);
226
227         modifiedFiles.setLabelFor(modifiedFilesValue);
228         org.openide.awt.Mnemonics.setLocalizedText(modifiedFiles, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_ModifiedFiles"));
229         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
230         gridBagConstraints.gridx = 0;
231         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
232         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
233         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
234         add(modifiedFiles, gridBagConstraints);
235
236         createdFilesValue.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background"));
237         createdFilesValue.setColumns(20);
238         createdFilesValue.setEditable(false);
239         createdFilesValue.setRows(5);
240         createdFilesValue.setBorder(null);
241         createdFilesValueS.setViewportView(createdFilesValue);
242
243         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
244         gridBagConstraints.gridx = 1;
245         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
246         gridBagConstraints.weightx = 1.0;
247         gridBagConstraints.weighty = 1.0;
248         gridBagConstraints.insets = new java.awt.Insets JavaDoc(36, 0, 6, 0);
249         add(createdFilesValueS, gridBagConstraints);
250
251         modifiedFilesValue.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background"));
252         modifiedFilesValue.setColumns(20);
253         modifiedFilesValue.setEditable(false);
254         modifiedFilesValue.setRows(5);
255         modifiedFilesValue.setToolTipText("modifiedFilesValue");
256         modifiedFilesValue.setBorder(null);
257         modifiedFilesValueS.setViewportView(modifiedFilesValue);
258
259         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
260         gridBagConstraints.gridx = 1;
261         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
262         gridBagConstraints.weightx = 1.0;
263         add(modifiedFilesValueS, gridBagConstraints);
264
265     }// </editor-fold>//GEN-END:initComponents
266

267     // Variables declaration - do not modify//GEN-BEGIN:variables
268
private javax.swing.JLabel JavaDoc createdFiles;
269     private javax.swing.JTextArea JavaDoc createdFilesValue;
270     private javax.swing.JScrollPane JavaDoc createdFilesValueS;
271     private javax.swing.JLabel JavaDoc libraryDisplayName;
272     private javax.swing.JTextField JavaDoc libraryDisplayNameValue;
273     private javax.swing.JLabel JavaDoc libraryName;
274     private javax.swing.JTextField JavaDoc libraryNameVale;
275     private javax.swing.JLabel JavaDoc modifiedFiles;
276     private javax.swing.JTextArea JavaDoc modifiedFilesValue;
277     private javax.swing.JScrollPane JavaDoc modifiedFilesValueS;
278     private javax.swing.JLabel JavaDoc projectName;
279     private javax.swing.JTextField JavaDoc projectNameValue;
280     // End of variables declaration//GEN-END:variables
281

282 }
283
Popular Tags