KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > options > OptionsPanel


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.options;
21
22 import java.awt.Component JavaDoc;
23 import javax.swing.JTextField JavaDoc;
24 import javax.swing.event.DocumentEvent JavaDoc;
25 import javax.swing.event.DocumentListener JavaDoc;
26 import javax.swing.text.JTextComponent 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.netbeans.modules.apisupport.project.ui.wizard.options.NewOptionsIterator.DataModel;
31 import org.openide.WizardDescriptor;
32 import org.openide.util.HelpCtx;
33 import org.openide.util.NbBundle;
34
35 /**
36  * @author Radek Matous
37  */

38 final class OptionsPanel extends BasicWizardIterator.Panel {
39     
40     private final DataModel data;
41     private DocumentListener JavaDoc updateListener;
42     
43     /** Creates new NameAndLocationPanel */
44     public OptionsPanel(final WizardDescriptor setting, final DataModel data) {
45         super(setting);
46         this.data = data;
47         initComponents();
48         initAccessibility();
49         if (data.getPackageName() != null) {
50             packageName.setSelectedItem(data.getPackageName());
51         }
52         putClientProperty("NewFileWizard_Title", getMessage("LBL_OptionsWizardTitle"));
53         
54     }
55     
56     private void addListeners() {
57         if (updateListener == null) {
58             updateListener = new UIUtil.DocumentAdapter() {
59                 public void insertUpdate(DocumentEvent JavaDoc e) {
60                     updateData();
61                 }
62             };
63             
64             txtPrefix.getDocument().addDocumentListener(updateListener);
65             Component JavaDoc editorComp = packageName.getEditor().getEditorComponent();
66             if (editorComp instanceof JTextComponent JavaDoc) {
67                 ((JTextComponent JavaDoc) editorComp).getDocument().addDocumentListener(updateListener);
68             }
69         }
70     }
71     
72     private void removeListeners() {
73         if (updateListener != null) {
74             txtPrefix.getDocument().removeDocumentListener(updateListener);
75             Component JavaDoc editorComp = packageName.getEditor().getEditorComponent();
76             if (editorComp instanceof JTextComponent JavaDoc) {
77                 ((JTextComponent JavaDoc) editorComp).getDocument().removeDocumentListener(updateListener);
78             }
79             updateListener = null;
80         }
81     }
82     
83     protected void storeToDataModel() {
84         removeListeners();
85         updateData();
86     }
87     
88     protected void readFromDataModel() {
89         addListeners();
90         txtPrefix.setText(data.getClassNamePrefix());
91     }
92
93     public void removeNotify() {
94         super.removeNotify();
95         removeListeners();
96     }
97     
98     public void addNotify() {
99         super.addNotify();
100         addListeners();
101         updateData();
102     }
103     
104     private void updateData() {
105         int errCode = data.setPackageAndPrefix(
106                 packageName.getEditor().getItem().toString(),txtPrefix.getText());
107         data.getCreatedModifiedFiles();
108         createdFilesValue.setText(UIUtil.generateTextAreaContent(
109                 data.getCreatedModifiedFiles().getCreatedPaths()));
110         modifiedFilesValue.setText(UIUtil.generateTextAreaContent(
111                 data.getCreatedModifiedFiles().getModifiedPaths()));
112         
113         //#68294 check if the paths for newly created files are valid or not..
114
String JavaDoc[] invalid = data.getCreatedModifiedFiles().getInvalidPaths();
115          if (data.isErrorCode(errCode)) {
116             setError(data.getErrorMessage(errCode));//NOI18N
117
} else if (invalid.length > 0) {
118             setError(NbBundle.getMessage(OptionsPanel.class, "ERR_ToBeCreateFileExists", invalid[0]));//NOI18N
119
} else if (data.isSuccessCode(errCode)) {
120             markValid();
121         }
122     }
123     
124     
125     protected String JavaDoc getPanelName() {
126         return getMessage("LBL_OptionsPanel1_Title");
127     }
128     
129     protected HelpCtx getHelp() {
130         return new HelpCtx(OptionsPanel.class);
131     }
132     
133     private static String JavaDoc getMessage(String JavaDoc key) {
134         return NbBundle.getMessage(OptionsPanel.class, key);
135     }
136     
137     private void initAccessibility() {
138         this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_OptionsPanel"));
139         projectNameValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ProjectName"));
140         packageName.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_PackageName"));
141         createdFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_CreatedFilesValue"));
142         modifiedFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ModifiedFilesValue"));
143         txtPrefix.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL__ClassNamePrefix"));
144     }
145     
146     /** This method is called from within the constructor to
147      * initialize the form.
148      * WARNING: Do NOT modify this code. The content of this method is
149      * always regenerated by the Form Editor.
150      */

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

281     // Variables declaration - do not modify//GEN-BEGIN:variables
282
private javax.swing.JLabel JavaDoc createdFiles;
283     private javax.swing.JTextArea JavaDoc createdFilesValue;
284     private javax.swing.JScrollPane JavaDoc createdFilesValueS;
285     private javax.swing.JLabel JavaDoc lblPrefix;
286     private javax.swing.JLabel JavaDoc modifiedFiles;
287     private javax.swing.JTextArea JavaDoc modifiedFilesValue;
288     private javax.swing.JScrollPane JavaDoc modifiedFilesValueS;
289     private javax.swing.JComboBox JavaDoc packageName;
290     private javax.swing.JLabel JavaDoc packageNameTxt;
291     private javax.swing.JLabel JavaDoc projectName;
292     private javax.swing.JTextField JavaDoc projectNameValue;
293     private javax.swing.JTextField JavaDoc txtPrefix;
294     // End of variables declaration//GEN-END:variables
295

296 }
297
Popular Tags