KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > persistence > wizard > fromdb > EntityClassesPanel


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.persistence.wizard.fromdb;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Dimension JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.util.logging.Level JavaDoc;
26 import java.util.logging.Logger JavaDoc;
27 import javax.swing.ComboBoxModel JavaDoc;
28 import javax.swing.event.ChangeEvent JavaDoc;
29 import javax.swing.event.ChangeListener JavaDoc;
30 import javax.swing.event.DocumentEvent JavaDoc;
31 import javax.swing.event.DocumentListener JavaDoc;
32 import javax.swing.text.Document JavaDoc;
33 import javax.swing.text.JTextComponent JavaDoc;
34 import org.netbeans.api.java.classpath.ClassPath;
35 import org.netbeans.api.project.Project;
36 import org.netbeans.api.project.ProjectUtils;
37 import org.netbeans.api.project.SourceGroup;
38 import org.netbeans.modules.j2ee.persistence.dd.persistence.model_1_0.PersistenceUnit;
39 import org.netbeans.modules.j2ee.persistence.provider.InvalidPersistenceXmlException;
40 import org.netbeans.modules.j2ee.persistence.provider.ProviderUtil;
41 import org.netbeans.modules.j2ee.persistence.wizard.Util;
42 import org.netbeans.modules.j2ee.persistence.wizard.library.PersistenceLibrarySupport;
43 import org.netbeans.modules.j2ee.persistence.wizard.unit.PersistenceUnitWizardPanel.TableGeneration;
44 import org.netbeans.spi.java.project.support.ui.PackageView;
45 import org.netbeans.spi.project.ui.templates.support.Templates;
46 import org.openide.ErrorManager;
47 import org.openide.WizardDescriptor;
48 import org.openide.awt.Mnemonics;
49 import org.openide.filesystems.FileObject;
50 import org.openide.util.HelpCtx;
51 import org.openide.util.NbBundle;
52
53 /**
54  *
55  * @author Andrei Badea
56  */

57 public class EntityClassesPanel extends javax.swing.JPanel JavaDoc {
58
59     private final static Logger JavaDoc LOGGER = Logger.getLogger(EntityClassesPanel.class.getName());
60
61     private JTextComponent JavaDoc packageComboBoxEditor;
62
63     private PersistenceGenerator persistenceGen;
64     private Project project;
65     private boolean cmp;
66     private String JavaDoc tableSourceName; //either Datasource or a connection
67

68     private SelectedTables selectedTables;
69
70     private ChangeSupport changeSupport = new ChangeSupport(this);
71
72     private PersistenceUnit persistenceUnit;
73
74     public EntityClassesPanel() {
75         initComponents();
76
77         classNamesTable.getParent().setBackground(classNamesTable.getBackground());
78         classNamesTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); // NOI18N
79

80         packageComboBoxEditor = ((JTextComponent JavaDoc)packageComboBox.getEditor().getEditorComponent());
81         Document JavaDoc packageComboBoxDocument = packageComboBoxEditor.getDocument();
82         packageComboBoxDocument.addDocumentListener(new DocumentListener JavaDoc() {
83
84             public void removeUpdate(DocumentEvent JavaDoc e) {
85                 packageChanged();
86             }
87
88             public void insertUpdate(DocumentEvent JavaDoc e) {
89                 packageChanged();
90             }
91
92             public void changedUpdate(DocumentEvent JavaDoc e) {
93                 packageChanged();
94             }
95         });
96     }
97
98     public void addChangeListener(ChangeListener JavaDoc listener) {
99         changeSupport.addChangeListener(listener);
100     }
101
102     public void initialize(PersistenceGenerator persistenceGen, Project project, boolean cmp, FileObject targetFolder) {
103         this.persistenceGen = persistenceGen;
104         this.project = project;
105         this.cmp = cmp;
106
107         projectTextField.setText(ProjectUtils.getInformation(project).getDisplayName());
108
109         SourceGroup[] sourceGroups = SourceGroupSupport.getJavaSourceGroups(project);
110         SourceGroupUISupport.connect(locationComboBox, sourceGroups);
111
112         packageComboBox.setRenderer(PackageView.listRenderer());
113
114         updatePackageComboBox();
115
116         if (targetFolder != null) {
117             // set default source group and package cf. targetFolder
118
SourceGroup targetSourceGroup = SourceGroupSupport.getFolderSourceGroup(sourceGroups, targetFolder);
119             if (targetSourceGroup != null) {
120                 locationComboBox.setSelectedItem(targetSourceGroup);
121                 String JavaDoc targetPackage = SourceGroupSupport.getPackageForFolder(targetSourceGroup, targetFolder);
122                 if (targetPackage != null) {
123                     packageComboBoxEditor.setText(targetPackage);
124                 }
125             }
126         }
127
128         if (!cmp) {
129             // change text of named query/finder checkbox
130
Mnemonics.setLocalizedText(generateFinderMethodsCheckBox,
131                     NbBundle.getMessage(EntityClassesPanel.class, "TXT_GenerateNamedQueryAnnotations"));
132             // hide local interface checkbox
133
cmpFieldsInInterfaceCheckBox.setVisible(false);
134         }
135
136         if (cmp) {
137             classNamesLabel.setVisible(false);
138             classNamesScrollPane.setVisible(false);
139             spacerPanel.setVisible(false);
140
141             Mnemonics.setLocalizedText(specifyNamesLabel, org.openide.util.NbBundle.getMessage(EntityClassesPanel.class, "LBL_SpecifyBeansLocation"));
142         }
143
144         updatePersistenceUnitButton();
145     }
146
147     public void update(TableClosure tableClosure, String JavaDoc tableSourceName) {
148         try {
149             if (selectedTables == null) {
150                 selectedTables = new SelectedTables(persistenceGen, tableClosure, getLocationValue(), getPackageName());
151                 selectedTables.addChangeListener(new ChangeListener JavaDoc() {
152                     public void stateChanged(ChangeEvent JavaDoc event) {
153                         changeSupport.fireChange();
154                     }
155                 });
156             } else {
157                 selectedTables.setTableClosureAndTargetFolder(tableClosure, getLocationValue(), getPackageName());
158             }
159             selectedTables.ensureUniqueClassNames();
160         } catch (IOException JavaDoc e) {
161             ErrorManager.getDefault().notify(e);
162         }
163
164         TableUISupport.connectClassNames(classNamesTable, selectedTables);
165         this.tableSourceName = tableSourceName;
166     }
167
168     public SelectedTables getSelectedTables() {
169         return selectedTables;
170     }
171
172     public SourceGroup getLocationValue() {
173         return (SourceGroup)locationComboBox.getSelectedItem();
174     }
175
176     public String JavaDoc getPackageName() {
177         return packageComboBoxEditor.getText();
178     }
179
180     public boolean getCmpFieldsInInterface() {
181         return cmpFieldsInInterfaceCheckBox.isSelected();
182     }
183
184     public boolean getGenerateFinderMethods() {
185         return generateFinderMethodsCheckBox.isSelected();
186     }
187
188     public PersistenceUnit getPersistenceUnit() {
189         return persistenceUnit;
190     }
191
192     private void locationChanged() {
193         updatePackageComboBox();
194         updateSelectedTables();
195         changeSupport.fireChange();
196     }
197
198     private void packageChanged() {
199         updateSelectedTables();
200         changeSupport.fireChange();
201     }
202
203     private void updatePackageComboBox() {
204         SourceGroup sourceGroup = (SourceGroup)locationComboBox.getSelectedItem();
205         if (sourceGroup != null) {
206             ComboBoxModel JavaDoc model = PackageView.createListView(sourceGroup);
207             if (model.getSelectedItem()!= null && model.getSelectedItem().toString().startsWith("META-INF")
208                     && model.getSize() > 1) { // NOI18N
209
model.setSelectedItem(model.getElementAt(1));
210             }
211             packageComboBox.setModel(model);
212         }
213     }
214
215     private void updatePersistenceUnitButton() {
216         String JavaDoc warning = " ";
217         try{
218
219             boolean showWarning = !cmp
220                     && !ProviderUtil.persistenceExists(project)
221                     && getPersistenceUnit() == null;
222
223             createPUButton.setVisible(showWarning);
224
225             if (showWarning) {
226                 warning = NbBundle.getMessage(EntityClassesPanel.class, "ERR_NoPersistenceUnit");
227             }
228
229         } catch (InvalidPersistenceXmlException ipx){
230             createPUButton.setVisible(false);
231             warning = NbBundle.getMessage(EntityClassesPanel.class, "ERR_InvalidPersistenceUnit", ipx.getPath());
232         }
233
234         createPUWarningLabel.setText(warning);
235         createPUWarningLabel.setToolTipText(warning);
236     }
237
238     private void updateSelectedTables() {
239         if (selectedTables != null) {
240             try {
241                 selectedTables.setTargetFolder(getLocationValue(), getPackageName());
242             } catch (IOException JavaDoc e) {
243                 ErrorManager.getDefault().notify(e);
244             }
245         }
246     }
247
248     public void doLayout() {
249         // preventing the PU warning label from enlarging the wizard
250
Dimension JavaDoc size = createPUWarningLabel.getPreferredSize();
251         size.width = getWidth();
252         createPUWarningLabel.setPreferredSize(size);
253
254         super.doLayout();
255     }
256
257     /** This method is called from within the constructor to
258      * initialize the form.
259      * WARNING: Do NOT modify this code. The content of this method is
260      * always regenerated by the Form Editor.
261      */

262     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
263
private void initComponents() {
264         specifyNamesLabel = new javax.swing.JLabel JavaDoc();
265         classNamesLabel = new javax.swing.JLabel JavaDoc();
266         classNamesScrollPane = new javax.swing.JScrollPane JavaDoc();
267         classNamesTable = new javax.swing.JTable JavaDoc();
268         projectLabel = new javax.swing.JLabel JavaDoc();
269         projectTextField = new javax.swing.JTextField JavaDoc();
270         locationLabel = new javax.swing.JLabel JavaDoc();
271         locationComboBox = new javax.swing.JComboBox JavaDoc();
272         packageLabel = new javax.swing.JLabel JavaDoc();
273         packageComboBox = new javax.swing.JComboBox JavaDoc();
274         createPUButton = new javax.swing.JButton JavaDoc();
275         generateFinderMethodsCheckBox = new javax.swing.JCheckBox JavaDoc();
276         cmpFieldsInInterfaceCheckBox = new javax.swing.JCheckBox JavaDoc();
277         spacerPanel = new javax.swing.JPanel JavaDoc();
278         createPUWarningLabel = new javax.swing.JLabel JavaDoc();
279
280         setName(org.openide.util.NbBundle.getMessage(EntityClassesPanel.class, "LBL_EntityClasses"));
281         org.openide.awt.Mnemonics.setLocalizedText(specifyNamesLabel, org.openide.util.NbBundle.getMessage(EntityClassesPanel.class, "LBL_SpecifyEntityClassNames"));
282
283         org.openide.awt.Mnemonics.setLocalizedText(classNamesLabel, org.openide.util.NbBundle.getMessage(EntityClassesPanel.class, "LBL_ClassNames"));
284
285         classNamesScrollPane.setViewportView(classNamesTable);
286
287         org.openide.awt.Mnemonics.setLocalizedText(projectLabel, org.openide.util.NbBundle.getMessage(EntityClassesPanel.class, "LBL_Project"));
288
289         projectTextField.setEditable(false);
290
291         org.openide.awt.Mnemonics.setLocalizedText(locationLabel, org.openide.util.NbBundle.getMessage(EntityClassesPanel.class, "LBL_SrcLocation"));
292
293         locationComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
294             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
295                 locationComboBoxActionPerformed(evt);
296             }
297         });
298
299         org.openide.awt.Mnemonics.setLocalizedText(packageLabel, org.openide.util.NbBundle.getMessage(EntityClassesPanel.class, "LBL_Package"));
300
301         packageComboBox.setEditable(true);
302
303         org.openide.awt.Mnemonics.setLocalizedText(createPUButton, org.openide.util.NbBundle.getMessage(EntityClassesPanel.class, "LBL_CreatePersistenceUnit"));
304         createPUButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
305             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
306                 createPUButtonActionPerformed(evt);
307             }
308         });
309
310         generateFinderMethodsCheckBox.setSelected(true);
311         org.openide.awt.Mnemonics.setLocalizedText(generateFinderMethodsCheckBox, org.openide.util.NbBundle.getMessage(EntityClassesPanel.class, "TXT_GenerateFinderMethods"));
312         generateFinderMethodsCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
313         generateFinderMethodsCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
314
315         cmpFieldsInInterfaceCheckBox.setSelected(true);
316         org.openide.awt.Mnemonics.setLocalizedText(cmpFieldsInInterfaceCheckBox, org.openide.util.NbBundle.getMessage(EntityClassesPanel.class, "TXT_AddFieldsToInterface"));
317         cmpFieldsInInterfaceCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
318         cmpFieldsInInterfaceCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
319
320         org.jdesktop.layout.GroupLayout spacerPanelLayout = new org.jdesktop.layout.GroupLayout(spacerPanel);
321         spacerPanel.setLayout(spacerPanelLayout);
322         spacerPanelLayout.setHorizontalGroup(
323             spacerPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
324             .add(0, 388, Short.MAX_VALUE)
325         );
326         spacerPanelLayout.setVerticalGroup(
327             spacerPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
328             .add(0, 9, Short.MAX_VALUE)
329         );
330
331         org.openide.awt.Mnemonics.setLocalizedText(createPUWarningLabel, " ");
332
333         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
334         this.setLayout(layout);
335         layout.setHorizontalGroup(
336             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
337             .add(specifyNamesLabel)
338             .add(layout.createSequentialGroup()
339                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
340                     .add(classNamesLabel)
341                     .add(projectLabel)
342                     .add(locationLabel)
343                     .add(packageLabel))
344                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
345                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
346                     .add(spacerPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
347                     .add(packageComboBox, 0, 388, Short.MAX_VALUE)
348                     .add(locationComboBox, 0, 388, Short.MAX_VALUE)
349                     .add(org.jdesktop.layout.GroupLayout.TRAILING, projectTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)
350                     .add(classNamesScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)))
351             .add(cmpFieldsInInterfaceCheckBox)
352             .add(generateFinderMethodsCheckBox)
353             .add(createPUButton)
354             .add(createPUWarningLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)
355         );
356         layout.setVerticalGroup(
357             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
358             .add(layout.createSequentialGroup()
359                 .add(specifyNamesLabel)
360                 .add(11, 11, 11)
361                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
362                     .add(classNamesLabel)
363                     .add(classNamesScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE))
364                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
365                 .add(spacerPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
366                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
367                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
368                     .add(projectTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
369                     .add(projectLabel))
370                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
371                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
372                     .add(locationComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
373                     .add(locationLabel))
374                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
375                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
376                     .add(packageComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
377                     .add(packageLabel))
378                 .add(21, 21, 21)
379                 .add(generateFinderMethodsCheckBox)
380                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
381                 .add(cmpFieldsInInterfaceCheckBox)
382                 .add(21, 21, 21)
383                 .add(createPUWarningLabel)
384                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
385                 .add(createPUButton))
386         );
387     }// </editor-fold>//GEN-END:initComponents
388

389     private void locationComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_locationComboBoxActionPerformed
390
locationChanged();
391     }//GEN-LAST:event_locationComboBoxActionPerformed
392

393     private void createPUButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_createPUButtonActionPerformed
394
persistenceUnit = Util.buildPersistenceUnitUsingWizard(project, tableSourceName, TableGeneration.NONE);
395         if (persistenceUnit != null){
396             updatePersistenceUnitButton();
397             changeSupport.fireChange();
398         }
399     }//GEN-LAST:event_createPUButtonActionPerformed
400

401
402     // Variables declaration - do not modify//GEN-BEGIN:variables
403
private javax.swing.JLabel JavaDoc classNamesLabel;
404     private javax.swing.JScrollPane JavaDoc classNamesScrollPane;
405     private javax.swing.JTable JavaDoc classNamesTable;
406     private javax.swing.JCheckBox JavaDoc cmpFieldsInInterfaceCheckBox;
407     private javax.swing.JButton JavaDoc createPUButton;
408     private javax.swing.JLabel JavaDoc createPUWarningLabel;
409     private javax.swing.JCheckBox JavaDoc generateFinderMethodsCheckBox;
410     private javax.swing.JComboBox JavaDoc locationComboBox;
411     private javax.swing.JLabel JavaDoc locationLabel;
412     private javax.swing.JComboBox JavaDoc packageComboBox;
413     private javax.swing.JLabel JavaDoc packageLabel;
414     private javax.swing.JLabel JavaDoc projectLabel;
415     private javax.swing.JTextField JavaDoc projectTextField;
416     private javax.swing.JPanel JavaDoc spacerPanel;
417     private javax.swing.JLabel JavaDoc specifyNamesLabel;
418     // End of variables declaration//GEN-END:variables
419

420     public static final class WizardPanel implements WizardDescriptor.Panel, ChangeListener JavaDoc {
421
422         private EntityClassesPanel component;
423         private boolean componentInitialized;
424
425         private WizardDescriptor wizardDescriptor;
426         private Project project;
427         private boolean cmp;
428
429         private ChangeSupport changeSupport = new ChangeSupport(this);
430
431         public Component JavaDoc getComponent() {
432             return getTypedComponent();
433         }
434
435         private EntityClassesPanel getTypedComponent() {
436             if (component == null) {
437                 component = new EntityClassesPanel();
438                 component.addChangeListener(this);
439             }
440             return component;
441         }
442
443         public void removeChangeListener(ChangeListener JavaDoc listener) {
444             changeSupport.removeChangeListener(listener);
445         }
446
447         public void addChangeListener(ChangeListener JavaDoc listener) {
448             changeSupport.addChangeListener(listener);
449         }
450
451         public HelpCtx getHelp() {
452             if (cmp) {
453                 return new HelpCtx("org.netbeans.modules.j2ee.ejbcore.ejb.wizard.cmp." + EntityClassesPanel.class.getSimpleName()); // NOI18N
454
} else {
455                 return new HelpCtx(EntityClassesPanel.class);
456             }
457         }
458
459         public void readSettings(Object JavaDoc settings) {
460             wizardDescriptor = (WizardDescriptor)settings;
461             RelatedCMPHelper helper = RelatedCMPWizard.getHelper(wizardDescriptor);
462
463             if (!componentInitialized) {
464                 componentInitialized = true;
465
466                 PersistenceGenerator persistenceGen = helper.getPersistenceGenerator();
467                 project = Templates.getProject(wizardDescriptor);
468                 cmp = RelatedCMPWizard.isCMP(wizardDescriptor);
469                 FileObject targetFolder = Templates.getTargetFolder(wizardDescriptor);
470
471                 getTypedComponent().initialize(persistenceGen, project, cmp, targetFolder);
472             }
473
474             TableSource tableSource = helper.getTableSource();
475             String JavaDoc tableSourceName = null;
476             if (tableSource != null) {
477                 // the name of the table source is only relevant if the source
478
// was a data source of connection, since it will be sent to the
479
// persistence unit panel, which only deals with data sources
480
// or connections
481
TableSource.Type tableSourceType = tableSource.getType();
482                 if (tableSourceType == TableSource.Type.DATA_SOURCE || tableSourceType == TableSource.Type.CONNECTION) {
483                     tableSourceName = tableSource.getName();
484                 }
485             }
486
487             getTypedComponent().update(helper.getTableClosure(), tableSourceName);
488         }
489
490         public boolean isValid() {
491             SourceGroup sourceGroup = getTypedComponent().getLocationValue();
492             if (sourceGroup == null) {
493                 setErrorMessage(NbBundle.getMessage(EntityClassesPanel.class, "ERR_JavaTargetChooser_SelectSourceGroup"));
494                 return false;
495             }
496
497             String JavaDoc packageName = getTypedComponent().getPackageName();
498             if (packageName.trim().equals("")) { // NOI18N
499
setErrorMessage(NbBundle.getMessage(EntityClassesPanel.class, "ERR_JavaTargetChooser_CantUseDefaultPackage"));
500                 return false;
501             }
502
503             if (!SourceGroupSupport.isValidPackageName(packageName)) {
504                 setErrorMessage(NbBundle.getMessage(EntityClassesPanel.class,"ERR_JavaTargetChooser_InvalidPackage")); //NOI18N
505
return false;
506             }
507
508             if (!SourceGroupSupport.isFolderWritable(sourceGroup, packageName)) {
509                 setErrorMessage(NbBundle.getMessage(EntityClassesPanel.class, "ERR_JavaTargetChooser_UnwritablePackage")); //NOI18N
510
return false;
511             }
512
513             // issue 92192: need to check that we will have a persistence provider
514
// available to add to the classpath while generating entity classes (unless
515
// the classpath already contains one)
516
ClassPath classPath = null;
517             try {
518                 FileObject packageFO = SourceGroupSupport.getFolderForPackage(sourceGroup, packageName, false);
519                 if (packageFO == null) {
520                     packageFO = sourceGroup.getRootFolder();
521                 }
522                 classPath = ClassPath.getClassPath(packageFO, ClassPath.COMPILE);
523             } catch (IOException JavaDoc e) {
524                 LOGGER.log(Level.WARNING, null, e);
525             }
526             if (classPath != null) {
527                 if (classPath.findResource("javax/persistence/EntityManager.class") == null && // NOI18N
528
PersistenceLibrarySupport.getProvidersFromLibraries().size() == 0) {
529                     setErrorMessage(NbBundle.getMessage(EntityClassesPanel.class, "ERR_NoJavaPersistenceAPI")); // NOI18N
530
return false;
531                 }
532             } else {
533                 LOGGER.warning("Cannot get a classpath for package " + packageName + " in " + sourceGroup); // NOI18N
534
}
535
536             SelectedTables selectedTables = getTypedComponent().getSelectedTables();
537             // check for null needed since isValid() can be called when
538
// EntityClassesPanel.update() has not been called yet, e.g. from within
539
// EntityClassesPanel.initialize()
540
if (selectedTables != null) {
541                 String JavaDoc problem = selectedTables.getFirstProblemDisplayName();
542                 if (problem != null) {
543                     setErrorMessage(problem);
544                     return false;
545                 }
546             }
547
548             setErrorMessage(" "); // NOI18N
549
return true;
550         }
551
552         public void storeSettings(Object JavaDoc settings) {
553             Object JavaDoc buttonPressed = ((WizardDescriptor)settings).getValue();
554             if (buttonPressed.equals(WizardDescriptor.NEXT_OPTION) ||
555                     buttonPressed.equals(WizardDescriptor.FINISH_OPTION)) {
556
557                 RelatedCMPHelper helper = RelatedCMPWizard.getHelper(wizardDescriptor);
558
559                 helper.setSelectedTables(getTypedComponent().getSelectedTables());
560                 helper.setLocation(getTypedComponent().getLocationValue());
561                 helper.setPackageName(getTypedComponent().getPackageName());
562                 helper.setCmpFieldsInInterface(getTypedComponent().getCmpFieldsInInterface());
563                 helper.setGenerateFinderMethods(getTypedComponent().getGenerateFinderMethods());
564                 helper.setPersistenceUnit(getTypedComponent().getPersistenceUnit());
565             }
566         }
567
568         public void stateChanged(ChangeEvent JavaDoc event) {
569             changeSupport.fireChange(event);
570         }
571
572         private void setErrorMessage(String JavaDoc errorMessage) {
573             wizardDescriptor.putProperty("WizardPanel_errorMessage", errorMessage); // NOI18N
574
}
575     }
576 }
577
Popular Tags