KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > moduleinstall > ModuleInstallPanel


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.moduleinstall;
21
22 import java.awt.Component JavaDoc;
23 import java.io.IOException JavaDoc;
24 import javax.swing.JTextField JavaDoc;
25 import javax.swing.event.DocumentEvent JavaDoc;
26 import javax.swing.event.DocumentListener JavaDoc;
27 import javax.swing.text.JTextComponent JavaDoc;
28 import org.netbeans.api.project.ProjectUtils;
29 import org.netbeans.modules.apisupport.project.EditableManifest;
30 import org.netbeans.modules.apisupport.project.Util;
31 import org.netbeans.modules.apisupport.project.ui.UIUtil;
32 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
33 import org.openide.WizardDescriptor;
34 import org.openide.util.HelpCtx;
35 import org.openide.util.NbBundle;
36
37 /**
38  * @author Martin Krauskopf
39  */

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

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

265     // Variables declaration - do not modify//GEN-BEGIN:variables
266
private javax.swing.JLabel JavaDoc createdFiles;
267     private javax.swing.JTextArea JavaDoc createdFilesValue;
268     private javax.swing.JScrollPane JavaDoc createdFilesValueS;
269     private javax.swing.JLabel JavaDoc modifiedFiles;
270     private javax.swing.JTextArea JavaDoc modifiedFilesValue;
271     private javax.swing.JScrollPane JavaDoc modifiedFilesValueS;
272     private javax.swing.JComboBox JavaDoc packageName;
273     private javax.swing.JLabel JavaDoc packageNameTxt;
274     private javax.swing.JLabel JavaDoc projectName;
275     private javax.swing.JTextField JavaDoc projectNameValue;
276     // End of variables declaration//GEN-END:variables
277

278 }
279
Popular Tags