KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbjarproject > ui > wizards > PanelProjectAppVisual


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.j2ee.ejbjarproject.ui.wizards;
21
22 import java.io.File JavaDoc;
23 import java.text.MessageFormat JavaDoc;
24
25 import javax.swing.JFileChooser JavaDoc;
26 import javax.swing.event.DocumentEvent JavaDoc;
27 import javax.swing.event.DocumentListener JavaDoc;
28 import org.netbeans.modules.j2ee.ejbjarproject.ui.FoldersListSettings;
29 import org.netbeans.spi.project.support.ant.PropertyUtils;
30
31 import org.netbeans.spi.project.ui.support.ProjectChooser;
32
33 import org.openide.WizardDescriptor;
34 import org.openide.util.NbBundle;
35
36 public class PanelProjectAppVisual extends SettingsPanel implements DocumentListener JavaDoc {
37     
38     private PanelConfigureProjectApp panel;
39     
40     /** Creates new form PanelProjectLocationVisual */
41     public PanelProjectAppVisual(PanelConfigureProjectApp panel) {
42         initComponents();
43         this.panel = panel;
44         
45         // Register listener on the textFields to make the automatic updates
46
/// projectNameTextField.getDocument().addDocumentListener(this);
47
/// projectLocationTextField.getDocument().addDocumentListener(this);
48
}
49     
50     /** This method is called from within the constructor to
51      * initialize the form.
52      * WARNING: Do NOT modify this code. The content of this method is
53      * always regenerated by the Form Editor.
54      */

55     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
56
private void initComponents() {
57         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
58
59         Label = new javax.swing.JLabel JavaDoc();
60         setAsMainCheckBox = new javax.swing.JCheckBox JavaDoc();
61         jLabel1 = new javax.swing.JLabel JavaDoc();
62         Button = new javax.swing.JButton JavaDoc();
63         jList1 = new javax.swing.JList JavaDoc();
64         jButton1 = new javax.swing.JButton JavaDoc();
65
66         setLayout(new java.awt.GridBagLayout JavaDoc());
67
68         Label.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(PanelProjectAppVisual.class, "LBL_NWP1_ProjectName_LabelMnemonic").charAt(0));
69         org.openide.awt.Mnemonics.setLocalizedText(Label, java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("LBL_NWP1_SpecifyCreateApplication_Label"));
70         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
71         gridBagConstraints.gridx = 0;
72         gridBagConstraints.gridy = 0;
73         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
74         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
75         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 0);
76         add(Label, gridBagConstraints);
77
78         setAsMainCheckBox.setSelected(true);
79         org.openide.awt.Mnemonics.setLocalizedText(setAsMainCheckBox, java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("LBL_NWP1_AddToApplication_CheckBox"));
80         setAsMainCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
81         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
82         gridBagConstraints.gridx = 0;
83         gridBagConstraints.gridy = 1;
84         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
85         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
86         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 0);
87         add(setAsMainCheckBox, gridBagConstraints);
88
89         jLabel1.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("LBL_NWP1_CreatedProjectFolder_LablelMnemonic").charAt(0));
90         jLabel1.setLabelFor(jList1);
91         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("LBL_NWP1_CreatedProjectFolder_Lablel"));
92         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
93         gridBagConstraints.gridx = 0;
94         gridBagConstraints.gridy = 2;
95         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
96         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
97         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
98         add(jLabel1, gridBagConstraints);
99
100         org.openide.awt.Mnemonics.setLocalizedText(Button, java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("LBL_NWP1_BrowseLocation_Button"));
101         Button.setActionCommand("BROWSE");
102         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
103         gridBagConstraints.gridx = 2;
104         gridBagConstraints.gridy = 2;
105         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
106         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 5, 0);
107         add(Button, gridBagConstraints);
108
109         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
110         gridBagConstraints.gridx = 1;
111         gridBagConstraints.gridy = 2;
112         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
113         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
114         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
115         gridBagConstraints.weightx = 1.0;
116         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 0);
117         add(jList1, gridBagConstraints);
118
119         org.openide.awt.Mnemonics.setLocalizedText(jButton1, java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbjarproject/ui/wizards/Bundle").getString("LBL_NWP1_NewProject_Button"));
120         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
121         gridBagConstraints.gridx = 2;
122         gridBagConstraints.gridy = 3;
123         add(jButton1, gridBagConstraints);
124
125     }
126     // </editor-fold>//GEN-END:initComponents
127

128     public void addNotify() {
129         super.addNotify();
130         //same problem as in 31086, initial focus on Cancel button
131
/// projectNameTextField.requestFocus();
132
}
133     
134     boolean valid(WizardDescriptor wizardDescriptor) {
135 /// if (projectNameTextField.getText().length() == 0) {
136
/// wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(PanelProjectLocationVisual.class,"MSG_IllegalProjectName")); //NOI18N
137
/// return false; // Display name not specified
138
/// }
139

140 /// File destFolder = new File(createdFolderTextField.getText());
141
/// File[] children = destFolder.listFiles();
142
/// if (destFolder.exists() && children != null && children.length > 0) {
143
// Folder exists and is not empty
144
/// wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(PanelProjectLocationVisual.class,"MSG_ProjectFolderExists")); //NOI18N
145
/// return false;
146
/// }
147

148 /// wizardDescriptor.putProperty("WizardPanel_errorMessage", ""); //NOI18N
149
return true;
150     }
151     
152     void store(WizardDescriptor d) {
153 /// String name = projectNameTextField.getText().trim();
154

155 /// d.putProperty(WizardProperties.PROJECT_DIR, new File(createdFolderTextField.getText().trim()));
156
/// d.putProperty(WizardProperties.NAME, name);
157

158 /// File projectsDir = new File(this.projectLocationTextField.getText());
159
/// if (projectsDir.isDirectory()) {
160
/// ProjectChooser.setProjectsFolder (projectsDir);
161
/// }
162
}
163         
164     void read (WizardDescriptor settings) {
165 /// File projectLocation = (File) settings.getProperty(WizardProperties.PROJECT_DIR);
166
/// if (projectLocation == null)
167
/// projectLocation = ProjectChooser.getProjectsFolder();
168
/// else
169
/// projectLocation = projectLocation.getParentFile();
170

171 /// projectLocationTextField.setText(projectLocation.getAbsolutePath());
172

173 /// String projectName = (String) settings.getProperty(WizardProperties.NAME);
174
/// if (projectName == null) {
175
/// int baseCount = FoldersListSettings.getDefault().getNewProjectCount() + 1;
176
/// String formater = NbBundle.getMessage(PanelProjectLocationVisual.class, "LBL_NPW1_DefaultProjectName");
177
/// while ((projectName = validFreeProjectName(projectLocation, formater, baseCount)) == null)
178
/// baseCount++;
179
/// settings.putProperty(NewEjbJarProjectWizardIterator.PROP_NAME_INDEX, new Integer(baseCount));
180
/// }
181

182 /// projectNameTextField.setText(projectName);
183
/// projectNameTextField.selectAll();
184
}
185
186     // Variables declaration - do not modify//GEN-BEGIN:variables
187
private javax.swing.JButton JavaDoc Button;
188     private javax.swing.JLabel JavaDoc Label;
189     private javax.swing.JButton JavaDoc jButton1;
190     private javax.swing.JLabel JavaDoc jLabel1;
191     private javax.swing.JList JavaDoc jList1;
192     private javax.swing.JCheckBox JavaDoc setAsMainCheckBox;
193     // End of variables declaration//GEN-END:variables
194

195     private static JFileChooser JavaDoc createChooser() {
196         JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
197         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
198         chooser.setAcceptAllFileFilterUsed(false);
199         
200         return chooser;
201     }
202
203     private String JavaDoc validFreeProjectName(final File JavaDoc parentFolder, final String JavaDoc formater, final int index) {
204         String JavaDoc name = MessageFormat.format(formater, new Object JavaDoc[] {new Integer JavaDoc (index)});
205         File JavaDoc file = new File JavaDoc(parentFolder, name);
206         return file.exists() ? null : name;
207     }
208
209     // Implementation of DocumentListener --------------------------------------
210
public void changedUpdate(DocumentEvent JavaDoc e) {
211         updateTexts(e);
212     }
213     
214     public void insertUpdate(DocumentEvent JavaDoc e) {
215         updateTexts(e);
216     }
217     
218     public void removeUpdate(DocumentEvent JavaDoc e) {
219         updateTexts(e);
220     }
221     // End if implementation of DocumentListener -------------------------------
222

223     
224     /** Handles changes in the project name and project directory
225      */

226     private void updateTexts(DocumentEvent JavaDoc e) {
227 /// createdFolderTextField.setText(getCreatedFolderPath());
228

229 /// panel.fireChangeEvent(); // Notify that the panel changed
230
}
231     
232 /// private String getCreatedFolderPath() {
233
/// StringBuffer folder = new StringBuffer(projectLocationTextField.getText().trim());
234
/// if (!projectLocationTextField.getText().endsWith(File.separator))
235
/// folder.append(File.separatorChar);
236
/// folder.append(projectNameTextField.getText().trim());
237

238 /// return folder.toString();
239
/// }
240

241 }
242
243 //TODO implement check for project folder name and location
244
Popular Tags