KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jsf > wizards > PersistenceClientSetupPanelVisual


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.web.jsf.wizards;
21
22 import java.io.IOException JavaDoc;
23 import java.util.List JavaDoc;
24 import javax.swing.ComboBoxModel JavaDoc;
25 import javax.swing.JTextField JavaDoc;
26 import javax.swing.event.ChangeListener JavaDoc;
27 import javax.swing.event.DocumentEvent JavaDoc;
28 import javax.swing.event.DocumentListener JavaDoc;
29 import javax.swing.text.Document JavaDoc;
30 import javax.swing.text.JTextComponent JavaDoc;
31 import org.netbeans.api.project.Project;
32 import org.netbeans.api.project.ProjectUtils;
33 import org.netbeans.api.project.SourceGroup;
34 import org.netbeans.api.project.Sources;
35 //TODO: RETOUCHE
36
//import org.netbeans.modules.j2ee.common.FQNSearch;
37
//import org.netbeans.modules.j2ee.common.JMIUtils;
38
//import org.netbeans.modules.j2ee.persistence.dd.orm.model_1_0.Entity;
39
//import org.netbeans.modules.j2ee.persistence.wizard.fromdb.ChangeSupport;
40
//import org.netbeans.modules.j2ee.persistence.wizard.fromdb.SourceGroupSupport;
41
//import org.netbeans.modules.j2ee.persistence.wizard.fromdb.SourceGroupUISupport;
42
import org.netbeans.modules.web.api.webmodule.WebModule;
43 import org.netbeans.modules.web.api.webmodule.WebProjectConstants;
44 import org.netbeans.modules.web.jsf.JSFConfigUtilities;
45 import org.netbeans.modules.web.jsf.dialogs.BrowseFolders;
46 import org.netbeans.spi.java.project.support.ui.PackageView;
47 import org.netbeans.spi.project.ui.templates.support.Templates;
48 import org.openide.ErrorManager;
49 import org.openide.WizardDescriptor;
50 import org.openide.filesystems.FileObject;
51 import org.openide.filesystems.FileUtil;
52 import org.openide.util.NbBundle;
53
54 /**
55  *
56  * @author Pavel Buzek
57  */

58 public class PersistenceClientSetupPanelVisual extends javax.swing.JPanel JavaDoc implements DocumentListener JavaDoc {
59     
60     private WizardDescriptor wizard;
61     private Project project;
62     private JTextComponent JavaDoc packageComboBoxEditor;
63 // private ChangeSupport changeSupport = new ChangeSupport(this);
64

65     /** Creates new form CrudSetupPanel */
66     public PersistenceClientSetupPanelVisual(WizardDescriptor wizard) {
67         this.wizard = wizard;
68         initComponents();
69         
70         packageComboBoxEditor = ((JTextComponent JavaDoc)packageComboBox.getEditor().getEditorComponent());
71         Document JavaDoc packageComboBoxDocument = packageComboBoxEditor.getDocument();
72         packageComboBoxDocument.addDocumentListener(this);
73     }
74     
75     /** This method is called from within the constructor to
76      * initialize the form.
77      * WARNING: Do NOT modify this code. The content of this method is
78      * always regenerated by the Form Editor.
79      */

80     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
81
private void initComponents() {
82         jLabel2 = new javax.swing.JLabel JavaDoc();
83         jsfFolder = new javax.swing.JTextField JavaDoc();
84         browseFolderButton = new javax.swing.JButton JavaDoc();
85         jLabel3 = new javax.swing.JLabel JavaDoc();
86         jLabel4 = new javax.swing.JLabel JavaDoc();
87         jLabel5 = new javax.swing.JLabel JavaDoc();
88         projectLabel = new javax.swing.JLabel JavaDoc();
89         projectTextField = new javax.swing.JTextField JavaDoc();
90         locationLabel = new javax.swing.JLabel JavaDoc();
91         locationComboBox = new javax.swing.JComboBox JavaDoc();
92         packageLabel = new javax.swing.JLabel JavaDoc();
93         packageComboBox = new javax.swing.JComboBox JavaDoc();
94
95         setName(org.openide.util.NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "LBL_JSFPagesAndClasses"));
96         jLabel2.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("ACS_JSF_Pages").charAt(0));
97         jLabel2.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("LBL_JSF_pages_folder"));
98
99         browseFolderButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("ACS_Browse2").charAt(0));
100         browseFolderButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("LBL_Browse"));
101         browseFolderButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
102             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
103                 browseFolderButtonActionPerformed(evt);
104             }
105         });
106
107         jLabel3.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("ACS_Controller").charAt(0));
108         jLabel3.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("LBL_JSF_Managed_bean"));
109
110         jLabel4.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("MSG_Jsf_Pages_Location"));
111
112         jLabel5.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("MSG_Folders"));
113
114         projectLabel.setText(org.openide.util.NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "LBL_Project"));
115
116         projectTextField.setEditable(false);
117
118         org.openide.awt.Mnemonics.setLocalizedText(locationLabel, org.openide.util.NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "LBL_SrcLocation"));
119
120         locationComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
121             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
122                 locationComboBoxActionPerformed(evt);
123             }
124         });
125
126         packageLabel.setText(org.openide.util.NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "LBL_Package"));
127
128         packageComboBox.setEditable(true);
129
130         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
131         this.setLayout(layout);
132         layout.setHorizontalGroup(
133             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
134             .add(layout.createSequentialGroup()
135                 .add(jLabel4)
136                 .addContainerGap(321, Short.MAX_VALUE))
137             .add(layout.createSequentialGroup()
138                 .add(jLabel2)
139                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
140                 .add(jsfFolder, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE)
141                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
142                 .add(browseFolderButton))
143             .add(layout.createSequentialGroup()
144                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
145                     .add(projectLabel)
146                     .add(locationLabel)
147                     .add(packageLabel))
148                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
149                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
150                     .add(org.jdesktop.layout.GroupLayout.TRAILING, locationComboBox, 0, 462, Short.MAX_VALUE)
151                     .add(projectTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE)
152                     .add(packageComboBox, 0, 462, Short.MAX_VALUE)))
153             .add(layout.createSequentialGroup()
154                 .add(jLabel3)
155                 .addContainerGap())
156             .add(layout.createSequentialGroup()
157                 .add(jLabel5)
158                 .addContainerGap())
159         );
160         layout.setVerticalGroup(
161             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
162             .add(layout.createSequentialGroup()
163                 .add(jLabel4)
164                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
165                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
166                     .add(jLabel2)
167                     .add(jsfFolder, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
168                     .add(browseFolderButton))
169                 .add(27, 27, 27)
170                 .add(jLabel5)
171                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
172                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
173                     .add(projectLabel)
174                     .add(projectTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
175                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
176                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
177                     .add(locationLabel)
178                     .add(locationComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
179                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
180                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
181                     .add(packageLabel)
182                     .add(packageComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
183                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
184                 .add(jLabel3)
185                 .addContainerGap(70, Short.MAX_VALUE))
186         );
187     }// </editor-fold>//GEN-END:initComponents
188

189     private void locationComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_locationComboBoxActionPerformed
190
locationChanged();
191     }//GEN-LAST:event_locationComboBoxActionPerformed
192

193     private void browseFolderButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseFolderButtonActionPerformed
194
Sources s = (Sources) Templates.getProject(wizard).getLookup().lookup(Sources.class);
195         org.netbeans.api.project.SourceGroup[] groups = s.getSourceGroups(WebProjectConstants.TYPE_DOC_ROOT);
196         org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups);
197         if (fo!=null) {
198             String JavaDoc res = "/"+JSFConfigUtilities.getResourcePath(groups,fo,'/',true);
199             jsfFolder.setText(res);
200         }
201     }//GEN-LAST:event_browseFolderButtonActionPerformed
202

203     
204     // Variables declaration - do not modify//GEN-BEGIN:variables
205
private javax.swing.JButton JavaDoc browseFolderButton;
206     private javax.swing.JLabel JavaDoc jLabel2;
207     private javax.swing.JLabel JavaDoc jLabel3;
208     private javax.swing.JLabel JavaDoc jLabel4;
209     private javax.swing.JLabel JavaDoc jLabel5;
210     private javax.swing.JTextField JavaDoc jsfFolder;
211     private javax.swing.JComboBox JavaDoc locationComboBox;
212     private javax.swing.JLabel JavaDoc locationLabel;
213     private javax.swing.JComboBox JavaDoc packageComboBox;
214     private javax.swing.JLabel JavaDoc packageLabel;
215     private javax.swing.JLabel JavaDoc projectLabel;
216     private javax.swing.JTextField JavaDoc projectTextField;
217     // End of variables declaration//GEN-END:variables
218

219     public void addChangeListener(ChangeListener JavaDoc listener) {
220 // changeSupport.addChangeListener(listener);
221
}
222     
223     boolean valid(WizardDescriptor wizard) {
224 // List<Entity> entities = (List<Entity>) wizard.getProperty(WizardProperties.ENTITY_CLASS);
225
// String controllerPkg = getPackage();
226
//
227
// boolean filesAlreadyExist = false;
228
// String troubleMaker = "";
229
// for (Entity entity : entities) {
230
// String entityClass = entity.getClass2();
231
// String simpleClassName = JSFClientGenerator.simpleClassName(entityClass);
232
// String firstLower = simpleClassName.substring(0, 1).toLowerCase() + simpleClassName.substring(1);
233
// String folder = jsfFolder.getText().endsWith("/") ? jsfFolder.getText() : jsfFolder.getText() + "/";
234
// folder = folder + firstLower;
235
// String controller = controllerPkg + "." + simpleClassName + "Controller";
236
// String fqn = getPackage().length() > 0 ? getPackage().replace('.', '/') + "/" + simpleClassName : simpleClassName;
237
// if (getLocationValue().getRootFolder().getFileObject(fqn + "Controller.java") != null) {
238
// filesAlreadyExist = true;
239
// troubleMaker = controllerPkg + "." + simpleClassName + "Controller.java";
240
// break;
241
// }
242
// if (getLocationValue().getRootFolder().getFileObject(fqn + "Converter.java") != null) {
243
// filesAlreadyExist = true;
244
// troubleMaker = controllerPkg + "." + simpleClassName + "Converter.java";
245
// break;
246
// }
247
// }
248
// if (filesAlreadyExist) {
249
// wizard.putProperty("WizardPanel_errorMessage", // NOI18N
250
// NbBundle.getMessage(PersistenceClientSetupPanelVisual.class, "MSG_FilesAlreadyExist", troubleMaker));
251
// return false;
252
// }
253
// wizard.putProperty("WizardPanel_errorMessage", null); // NOI18N
254
return true;
255     }
256     
257     public SourceGroup getLocationValue() {
258         return (SourceGroup)locationComboBox.getSelectedItem();
259     }
260
261     public String JavaDoc getPackage() {
262         return packageComboBoxEditor.getText();
263     }
264
265     private void locationChanged() {
266         updateSourceGroupPackages();
267 // changeSupport.fireChange();
268
}
269     
270     void read(WizardDescriptor settings) {
271         jsfFolder.setText((String JavaDoc) settings.getProperty(WizardProperties.JSF_FOLDER));
272         
273         project = Templates.getProject(settings);
274         FileObject targetFolder = Templates.getTargetFolder(settings);
275         
276         projectTextField.setText(ProjectUtils.getInformation(project).getDisplayName());
277
278 // SourceGroup[] sourceGroups = SourceGroupSupport.getJavaSourceGroups(project);
279
// SourceGroupUISupport.connect(locationComboBox, sourceGroups);
280

281         packageComboBox.setRenderer(PackageView.listRenderer());
282
283         updateSourceGroupPackages();
284
285         // set default source group and package cf. targetFolder
286
if (targetFolder != null) {
287 // SourceGroup targetSourceGroup = SourceGroupSupport.getFolderSourceGroup(sourceGroups, targetFolder);
288
// if (targetSourceGroup != null) {
289
// locationComboBox.setSelectedItem(targetSourceGroup);
290
// String targetPackage = SourceGroupSupport.getPackageForFolder(targetSourceGroup, targetFolder);
291
// if (targetPackage != null) {
292
// packageComboBoxEditor.setText(targetPackage);
293
// }
294
// }
295
if (FileUtil.isParentOf(WebModule.getWebModule(
296                     targetFolder).getDocumentBase(), targetFolder)) {
297                 Sources s = (Sources) Templates.getProject(wizard).getLookup().lookup(Sources.class);
298                 SourceGroup[] groups = s.getSourceGroups(WebProjectConstants.TYPE_DOC_ROOT);
299                 jsfFolder.setText("/"+JSFConfigUtilities.getResourcePath(groups,targetFolder,'/',true));
300             }
301         }
302     }
303     
304     void store(WizardDescriptor settings) {
305         settings.putProperty(WizardProperties.JSF_FOLDER, jsfFolder.getText());
306         settings.putProperty(WizardProperties.JSF_CLASSES_PACKAGE, getPackage());
307 // try {
308
//// Templates.setTargetFolder(settings, SourceGroupSupport.getFolderForPackage(getLocationValue(), getPackage()));
309
// } catch (IOException ex) {
310
// ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
311
// }
312
}
313
314     private void updateSourceGroupPackages() {
315         SourceGroup sourceGroup = (SourceGroup)locationComboBox.getSelectedItem();
316         ComboBoxModel JavaDoc model = PackageView.createListView(sourceGroup);
317         if (model.getSelectedItem()!= null && model.getSelectedItem().toString().startsWith("META-INF")
318                 && model.getSize() > 1) { // NOI18N
319
model.setSelectedItem(model.getElementAt(1));
320         }
321         packageComboBox.setModel(model);
322     }
323     
324     public void insertUpdate(DocumentEvent JavaDoc e) {
325 // changeSupport.fireChange();
326
}
327
328     public void removeUpdate(DocumentEvent JavaDoc e) {
329 // changeSupport.fireChange();
330
}
331
332     public void changedUpdate(DocumentEvent JavaDoc e) {
333 // changeSupport.fireChange();
334
}
335     
336 }
337
Popular Tags