KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > persistence > unit > PersistenceUnitPanel


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.unit;
21
22 import java.awt.CardLayout JavaDoc;
23 import java.util.List JavaDoc;
24 import javax.swing.DefaultListModel JavaDoc;
25 import javax.swing.text.JTextComponent JavaDoc;
26 import org.netbeans.api.db.explorer.ConnectionManager;
27 import org.netbeans.api.db.explorer.DatabaseConnection;
28 import org.netbeans.api.project.FileOwnerQuery;
29 import org.netbeans.api.project.Project;
30 import org.netbeans.api.project.ProjectUtils;
31 import org.netbeans.modules.j2ee.persistence.dd.persistence.model_1_0.PersistenceUnit;
32 import org.netbeans.modules.j2ee.persistence.dd.persistence.model_1_0.Properties;
33 import org.netbeans.modules.j2ee.persistence.dd.persistence.model_1_0.Property;
34 import org.netbeans.modules.j2ee.persistence.provider.DefaultProvider;
35 import org.netbeans.modules.j2ee.persistence.provider.Provider;
36 import org.netbeans.modules.j2ee.persistence.util.PersistenceProviderComboboxHelper;
37 import org.netbeans.modules.j2ee.persistence.wizard.Util;
38 import org.netbeans.modules.j2ee.persistence.wizard.unit.JdbcListCellRenderer;
39 import org.netbeans.modules.j2ee.persistence.provider.ProviderUtil;
40 import org.netbeans.modules.j2ee.persistence.spi.datasource.JPADataSource;
41 import org.netbeans.modules.j2ee.persistence.spi.datasource.JPADataSourcePopulator;
42 import org.netbeans.modules.j2ee.persistence.util.PersistenceProviderComboboxHelper;
43 import org.netbeans.modules.j2ee.persistence.wizard.library.PersistenceLibrarySupport;
44 import org.netbeans.modules.xml.multiview.ui.SectionInnerPanel;
45 import org.netbeans.modules.xml.multiview.ui.SectionView;
46 import org.netbeans.modules.xml.multiview.Error;
47 import org.openide.util.NbBundle;
48
49 /**
50  *
51  * @author Martin Adamek
52  */

53 public class PersistenceUnitPanel extends SectionInnerPanel {
54     
55     private final PersistenceUnit persistenceUnit;
56     private PUDataObject dObj;
57     private Project project;
58     private boolean isContainerManaged;
59     
60     public PersistenceUnitPanel(SectionView view, final PUDataObject dObj, final PersistenceUnit persistenceUnit) {
61         super(view);
62         this.dObj=dObj;
63         this.persistenceUnit=persistenceUnit;
64         this.project = FileOwnerQuery.getOwner(this.dObj.getPrimaryFile());
65         
66         assert project != null : "Could not resolve project for " + dObj.getPrimaryFile(); //NOI18N
67

68         if (PersistenceLibrarySupport.getLibrary(persistenceUnit) != null && ProviderUtil.getConnection(persistenceUnit) != null) {
69             isContainerManaged = false;
70         } else if (persistenceUnit.getJtaDataSource() != null || persistenceUnit.getNonJtaDataSource() != null) {
71             isContainerManaged = true;
72         } else {
73             isContainerManaged = Util.isSupportedJavaEEVersion(project);
74         }
75         
76         initComponents();
77         
78         PersistenceProviderComboboxHelper comboHelper = new PersistenceProviderComboboxHelper(project);
79         if (isContainerManaged){
80             comboHelper.connect(providerCombo);
81             Provider provider = ProviderUtil.getProvider(persistenceUnit);
82             providerCombo.setSelectedItem(provider);
83         } else {
84             comboHelper.connect(libraryComboBox);
85             setSelectedLibrary();
86         }
87         
88         setVisiblePanel();
89         initIncludeAllEntities();
90         initEntityList();
91         
92         initDataSource();
93         
94         initJdbcComboBox();
95         nameTextField.setText(persistenceUnit.getName());
96         setTableGeneration();
97         handleCmAmSelection();
98         
99         registerModifiers();
100         
101     }
102     
103     /**
104      * Registers the components that modify the model. Should be called after
105      * these components have been initialized (otherwise the underlying file will
106      * be marked as modified immediately upon opening it).
107      */

108     private void registerModifiers(){
109         if (isContainerManaged){
110             addImmediateModifier(dsCombo);
111             addImmediateModifier(providerCombo);
112             addImmediateModifier(jtaCheckBox);
113             
114         } else {
115             addImmediateModifier(jdbcComboBox);
116             addImmediateModifier(libraryComboBox);
117         }
118         addImmediateModifier(nameTextField);
119         addImmediateModifier(ddDropCreate);
120         addImmediateModifier(ddCreate);
121         addImmediateModifier(ddUnknown);
122         addImmediateModifier(includeAllEntities);
123         
124     }
125     
126     
127     /**
128      * Sets which panel (container/application) is visible.
129      */

130     private void setVisiblePanel(){
131         String JavaDoc panelName = isContainerManaged ? "container" : "application";//NOI18N
132
((CardLayout JavaDoc)jPanel3.getLayout()).show(jPanel3, panelName);
133     }
134     
135     private void initDataSource(){
136         jtaCheckBox.setEnabled(!Util.isJavaSE(project));
137         if (isContainerManaged && ProviderUtil.isValidServerInstanceOrNone(project)) {
138             String JavaDoc jtaDataSource = persistenceUnit.getJtaDataSource();
139             String JavaDoc nonJtaDataSource = persistenceUnit.getNonJtaDataSource();
140             
141             JPADataSourcePopulator dsPopulator = project.getLookup().lookup(JPADataSourcePopulator.class);
142             if (dsPopulator != null){
143                 dsPopulator.connect(dsCombo);
144                 addModifier((JTextComponent JavaDoc)dsCombo.getEditor().getEditorComponent(), false);
145             }
146             
147             String JavaDoc jndiName = (jtaDataSource != null ? jtaDataSource : nonJtaDataSource);
148             selectDatasource(jndiName);
149             
150             jtaCheckBox.setSelected(jtaDataSource != null);
151             
152             String JavaDoc provider = persistenceUnit.getProvider();
153             for (int i = 0; i < providerCombo.getItemCount(); i++) {
154                 Object JavaDoc item = providerCombo.getItemAt(i);
155                 if (item instanceof Provider){
156                     if (((Provider) item).getProviderClass().equals(provider)) {
157                         providerCombo.setSelectedIndex(i);
158                         break;
159                     }
160                 }
161             }
162         } else if (!isContainerManaged){
163             setSelectedConnection();
164             setSelectedLibrary();
165             jtaCheckBox.setSelected(false);
166         }
167     }
168     
169     private void initJdbcComboBox(){
170         DatabaseConnection[] connections = ConnectionManager.getDefault().getConnections();
171         for (int i = 0; i < connections.length; i++) {
172             jdbcComboBox.addItem(connections[i]);
173         }
174         setSelectedConnection();
175     }
176     
177     private void initIncludeAllEntities(){
178         boolean javaSE = Util.isJavaSE(project);
179         includeAllEntities.setEnabled(!javaSE);
180         includeAllEntities.setSelected(!javaSE && !persistenceUnit.isExcludeUnlistedClasses());
181         includeAllEntities.setText(NbBundle.getMessage(PersistenceUnitPanel.class,
182                 "LBL_IncludeAllEntities",
183                 new Object JavaDoc[]{ProjectUtils.getInformation(project).getDisplayName()}));
184     }
185     
186     private void initEntityList(){
187         DefaultListModel JavaDoc listedClassesModel = new DefaultListModel JavaDoc();
188         for (String JavaDoc elem : persistenceUnit.getClass2()) {
189             listedClassesModel.addElement(elem);
190         }
191         entityList.setModel(listedClassesModel);
192         
193     }
194     
195     /**
196      * Sets selected item in library combo box.
197      */

198     private void setSelectedLibrary(){
199         Provider selected = ProviderUtil.getProvider(persistenceUnit);
200         if (selected == null){
201             return;
202         }
203         for(int i = 0; i < libraryComboBox.getItemCount(); i++){
204             Object JavaDoc item = libraryComboBox.getItemAt(i);
205             Provider provider = (Provider) (item instanceof Provider ? item : null);
206             if (provider!= null && provider.equals(selected)){
207                 libraryComboBox.setSelectedIndex(i);
208                 break;
209             }
210         }
211     }
212     
213     private Provider getSelectedProvider(){
214         if (isContainerManaged){
215             return (Provider) providerCombo.getSelectedItem();
216         }
217         Object JavaDoc selectedItem = libraryComboBox.getSelectedItem();
218         Provider provider = (Provider) (selectedItem instanceof Provider ? selectedItem : null);
219         if (provider != null) {
220             return provider;
221         }
222         return ProviderUtil.getProvider(persistenceUnit.getProvider(), project);
223     }
224     
225     /**
226      * Selects appropriate table generation radio button.
227      */

228     private void setTableGeneration(){
229         Provider provider = getSelectedProvider();
230         Property tableGeneration = ProviderUtil.getProperty(persistenceUnit, provider.getTableGenerationPropertyName());
231         if (tableGeneration != null){
232             if (provider.getTableGenerationCreateValue().equals(tableGeneration.getValue())){
233                 ddCreate.setSelected(true);
234             } else if (provider.getTableGenerationDropCreateValue().equals(tableGeneration.getValue())){
235                 ddDropCreate.setSelected(true);
236             }
237         } else {
238             ddUnknown.setSelected(true);
239         }
240         boolean toggle = provider.supportsTableGeneration();
241         
242         ddCreate.setEnabled(toggle);
243         ddDropCreate.setEnabled(toggle);
244         ddUnknown.setEnabled(toggle);
245     }
246     
247     /**
248      * Sets the selected item in connection combo box.
249      */

250     private void setSelectedConnection(){
251         DatabaseConnection connection = ProviderUtil.getConnection(persistenceUnit);
252         if (connection != null){
253             jdbcComboBox.setSelectedItem(connection);
254         } else {
255             // custom connection (i.e. connection not registered in netbeans)
256
Properties props = persistenceUnit.getProperties();
257             if (props != null){
258                 Property[] properties = props.getProperty2();
259                 String JavaDoc url = "custom";
260                 Provider provider = ProviderUtil.getProvider(persistenceUnit);
261                 for (int i = 0; i < properties.length; i++) {
262                     String JavaDoc key = properties[i].getName();
263                     if (key.equals(provider.getJdbcUrl())) {
264                         url = properties[i].getValue();
265                         break;
266                     }
267                 }
268                 jdbcComboBox.addItem(url);
269                 jdbcComboBox.setSelectedItem(url);
270             }
271         }
272     }
273     
274     public void setValue(javax.swing.JComponent JavaDoc source, Object JavaDoc value) {
275         if (source == nameTextField) {
276             persistenceUnit.setName((String JavaDoc) value);
277         } else if (source == dsCombo){
278             setDataSource();
279         } else if (source == dsCombo.getEditor().getEditorComponent()) {
280             setDataSource((String JavaDoc)value);
281         } else if (source == jdbcComboBox){
282             if (value instanceof DatabaseConnection){
283                 ProviderUtil.setDatabaseConnection(persistenceUnit, (DatabaseConnection) value);
284             }
285         } else if (source == libraryComboBox){
286             setProvider();
287             setTableGeneration();
288         } else if (providerCombo == source){
289             setProvider();
290             setDataSource();
291         } else if (source == ddCreate || source == ddDropCreate || source == ddUnknown){
292             ProviderUtil.setTableGeneration(persistenceUnit, getTableGeneration(), ProviderUtil.getProvider(persistenceUnit.getProvider(), project));
293         } else if (source == includeAllEntities){
294             persistenceUnit.setExcludeUnlistedClasses(!includeAllEntities.isSelected());
295         } else if (source == jtaCheckBox){
296             setDataSource();
297         }
298         performValidation();
299     }
300     
301     private void performValidation(){
302         PersistenceValidator validator = new PersistenceValidator(dObj);
303         List JavaDoc<Error JavaDoc> result = validator.validate();
304         if (!result.isEmpty()){
305             getSectionView().getErrorPanel().setError(result.get(0));
306         } else {
307             getSectionView().getErrorPanel().clearError();
308         }
309         
310     }
311     
312     private void setDataSource() {
313         setDataSource(null);
314     }
315     
316     private void setProvider(){
317         
318         if (isContainerManaged && providerCombo.getSelectedItem() instanceof Provider) {
319             Provider provider = (Provider) providerCombo.getSelectedItem();
320             ProviderUtil.removeProviderProperties(persistenceUnit);
321             
322             if (!(provider instanceof DefaultProvider)) {
323                 persistenceUnit.setProvider(provider.getProviderClass());
324                 setTableGeneration();
325             }
326             ProviderUtil.makePortableIfPossible(project, persistenceUnit);
327             
328         } else if (libraryComboBox.getSelectedItem() instanceof Provider){
329             Provider provider = (Provider) libraryComboBox.getSelectedItem();
330             ProviderUtil.removeProviderProperties(persistenceUnit);
331             if (!(provider instanceof DefaultProvider)) {
332                 ProviderUtil.setProvider(persistenceUnit, provider, getSelectedConnection(), getTableGeneration());
333             }
334         }
335     }
336     
337     private void setDataSource(String JavaDoc name) {
338         
339         String JavaDoc jndiName = name;
340         
341         if (jndiName == null) {
342             int itemIndex = dsCombo.getSelectedIndex();
343             Object JavaDoc item = dsCombo.getSelectedItem();
344             if (item instanceof JPADataSource)
345                 jndiName = ((JPADataSource)item).getJndiName();
346             else if (itemIndex == -1 && item != null){ // user input
347
jndiName = item.toString();
348             }
349         }
350         
351         if (jndiName == null){
352             return;
353         }
354         
355         if (isJta()){
356             persistenceUnit.setJtaDataSource(jndiName);
357             persistenceUnit.setNonJtaDataSource(null);
358         } else {
359             persistenceUnit.setJtaDataSource(null);
360             persistenceUnit.setNonJtaDataSource(jndiName);
361         }
362     }
363     
364     private boolean isJta(){
365         return jtaCheckBox.isEnabled() && jtaCheckBox.isSelected();
366     }
367     
368     /**
369      *@return selected table generation strategy.
370      */

371     private String JavaDoc getTableGeneration(){
372         if (ddCreate.isSelected()){
373             return Provider.TABLE_GENERATION_CREATE;
374         } else if (ddDropCreate.isSelected()){
375             return Provider.TABLE_GENERATION_DROPCREATE;
376         } else {
377             return Provider.TABLE_GENERATTION_UNKOWN;
378         }
379     }
380     
381     private DatabaseConnection getSelectedConnection(){
382         DatabaseConnection connection = null;
383         if (jdbcComboBox.getSelectedItem() instanceof DatabaseConnection){
384             connection = (DatabaseConnection) jdbcComboBox.getSelectedItem();
385         }
386         return connection;
387         
388     }
389     
390     public void rollbackValue(javax.swing.text.JTextComponent JavaDoc source) {
391         if (nameTextField == source) {
392             nameTextField.setText(persistenceUnit.getName());
393         } else if (dsCombo.getEditor().getEditorComponent() == source){
394             String JavaDoc jndiName = (isJta() ? persistenceUnit.getJtaDataSource() : persistenceUnit.getNonJtaDataSource());
395             selectDatasource(jndiName);
396         }
397     }
398     
399     private void selectDatasource(String JavaDoc jndiName) {
400         
401         Object JavaDoc item = findDatasource(jndiName);
402         dsCombo.setSelectedItem(item);
403         if (dsCombo.getEditor() != null) { // item must be set in the editor
404
dsCombo.configureEditor(dsCombo.getEditor(), item);
405         }
406     }
407     
408     private Object JavaDoc findDatasource(String JavaDoc jndiName) {
409         
410         if (jndiName != null) {
411             int nItems = dsCombo.getItemCount();
412             for (int i = 0; i < nItems; i++) {
413                 Object JavaDoc item = dsCombo.getItemAt(i);
414                 if (item instanceof JPADataSource && jndiName.equals(((JPADataSource)item).getJndiName())) {
415                     return (JPADataSource)item;
416                 }
417             }
418         }
419         
420         return jndiName;
421     }
422     
423     protected void endUIChange() {
424         dObj.modelUpdatedFromUI();
425     }
426     
427     public void linkButtonPressed(Object JavaDoc ddBean, String JavaDoc ddProperty) {
428     }
429     
430     public javax.swing.JComponent JavaDoc getErrorComponent(String JavaDoc errorId) {
431         if ("name".equals(errorId)) {
432             return nameTextField;
433         }
434         return null;
435     }
436     
437     private void handleCmAmSelection() {
438         boolean isCm = isContainerManaged;
439         datasourceLabel.setEnabled(isCm);
440         dsCombo.setEnabled(isCm);
441         jtaCheckBox.setEnabled(isCm && !Util.isJavaSE(project));
442         libraryLabel.setEnabled(!isCm);
443         libraryComboBox.setEnabled(!isCm);
444         jdbcLabel.setEnabled(!isCm);
445         jdbcComboBox.setEnabled(!isCm);
446         setTableGeneration();
447     }
448     
449     /** This method is called from within the constructor to
450      * initialize the form.
451      * WARNING: Do NOT modify this code. The content of this method is
452      * always regenerated by the Form Editor.
453      */

454     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
455
private void initComponents() {
456         buttonGroup2 = new javax.swing.ButtonGroup JavaDoc();
457         jPanel2 = new javax.swing.JPanel JavaDoc();
458         includeAllEntities = new javax.swing.JCheckBox JavaDoc();
459         jPanel4 = new javax.swing.JPanel JavaDoc();
460         jScrollPane2 = new javax.swing.JScrollPane JavaDoc();
461         entityList = new javax.swing.JList JavaDoc();
462         addClassButton = new javax.swing.JButton JavaDoc();
463         removeClassButton = new javax.swing.JButton JavaDoc();
464         jLabel1 = new javax.swing.JLabel JavaDoc();
465         jPanel7 = new javax.swing.JPanel JavaDoc();
466         jLabel2 = new javax.swing.JLabel JavaDoc();
467         nameTextField = new javax.swing.JTextField JavaDoc();
468         jPanel3 = new javax.swing.JPanel JavaDoc();
469         jPanel6 = new javax.swing.JPanel JavaDoc();
470         datasourceLabel = new javax.swing.JLabel JavaDoc();
471         jtaCheckBox = new javax.swing.JCheckBox JavaDoc();
472         dsCombo = new javax.swing.JComboBox JavaDoc();
473         providerCombo = new javax.swing.JComboBox JavaDoc();
474         jLabel3 = new javax.swing.JLabel JavaDoc();
475         jPanel5 = new javax.swing.JPanel JavaDoc();
476         libraryLabel = new javax.swing.JLabel JavaDoc();
477         jdbcLabel = new javax.swing.JLabel JavaDoc();
478         libraryComboBox = new javax.swing.JComboBox JavaDoc();
479         jdbcComboBox = new javax.swing.JComboBox JavaDoc();
480         jPanel1 = new javax.swing.JPanel JavaDoc();
481         tableGenerationLabel = new javax.swing.JLabel JavaDoc();
482         ddCreate = new javax.swing.JRadioButton JavaDoc();
483         ddDropCreate = new javax.swing.JRadioButton JavaDoc();
484         ddUnknown = new javax.swing.JRadioButton JavaDoc();
485
486         jPanel2.setOpaque(false);
487         includeAllEntities.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/persistence/unit/Bundle").getString("LBL_IncludeAllEntities"));
488         includeAllEntities.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
489         includeAllEntities.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
490         includeAllEntities.setOpaque(false);
491
492         org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
493         jPanel2.setLayout(jPanel2Layout);
494         jPanel2Layout.setHorizontalGroup(
495             jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
496             .add(jPanel2Layout.createSequentialGroup()
497                 .addContainerGap()
498                 .add(includeAllEntities)
499                 .addContainerGap(395, Short.MAX_VALUE))
500         );
501         jPanel2Layout.setVerticalGroup(
502             jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
503             .add(jPanel2Layout.createSequentialGroup()
504                 .add(includeAllEntities)
505                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
506         );
507
508         jPanel4.setOpaque(false);
509         jScrollPane2.setViewportView(entityList);
510
511         addClassButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/persistence/unit/Bundle").getString("LBL_AddClasses"));
512         addClassButton.setOpaque(false);
513         addClassButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
514             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
515                 addClassButtonActionPerformed(evt);
516             }
517         });
518
519         removeClassButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/persistence/unit/Bundle").getString("LBL_RemoveClass"));
520         removeClassButton.setOpaque(false);
521         removeClassButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
522             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
523                 removeClassButtonActionPerformed(evt);
524             }
525         });
526
527         jLabel1.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/persistence/unit/Bundle").getString("LBL_IncludeEntityClasses"));
528
529         org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
530         jPanel4.setLayout(jPanel4Layout);
531         jPanel4Layout.setHorizontalGroup(
532             jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
533             .add(jPanel4Layout.createSequentialGroup()
534                 .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
535                     .add(jPanel4Layout.createSequentialGroup()
536                         .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 449, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
537                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
538                         .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
539                             .add(addClassButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
540                             .add(removeClassButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE))
541                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 20, Short.MAX_VALUE))
542                     .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 600, Short.MAX_VALUE))
543                 .addContainerGap())
544         );
545         jPanel4Layout.setVerticalGroup(
546             jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
547             .add(jPanel4Layout.createSequentialGroup()
548                 .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 17, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
549                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
550                 .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
551                     .add(jPanel4Layout.createSequentialGroup()
552                         .add(addClassButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
553                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
554                         .add(removeClassButton))
555                     .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 96, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
556                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
557         );
558
559         jPanel7.setOpaque(false);
560         jLabel2.setText(org.openide.util.NbBundle.getMessage(PersistenceUnitPanel.class, "LBL_UnitName"));
561
562         org.jdesktop.layout.GroupLayout jPanel7Layout = new org.jdesktop.layout.GroupLayout(jPanel7);
563         jPanel7.setLayout(jPanel7Layout);
564         jPanel7Layout.setHorizontalGroup(
565             jPanel7Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
566             .add(jPanel7Layout.createSequentialGroup()
567                 .addContainerGap()
568                 .add(jLabel2)
569                 .add(32, 32, 32)
570                 .add(nameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 440, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
571                 .addContainerGap(27, Short.MAX_VALUE))
572         );
573         jPanel7Layout.setVerticalGroup(
574             jPanel7Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
575             .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel7Layout.createSequentialGroup()
576                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
577                 .add(jPanel7Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
578                     .add(jLabel2)
579                     .add(nameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
580                 .addContainerGap())
581         );
582
583         jPanel3.setLayout(new java.awt.CardLayout JavaDoc());
584
585         jPanel3.setOpaque(false);
586         jPanel6.setOpaque(false);
587         datasourceLabel.setText(org.openide.util.NbBundle.getMessage(PersistenceUnitPanel.class, "LBL_DatasourceName"));
588
589         jtaCheckBox.setSelected(true);
590         jtaCheckBox.setText(org.openide.util.NbBundle.getMessage(PersistenceUnitPanel.class, "LBL_JTA"));
591         jtaCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
592         jtaCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
593         jtaCheckBox.setOpaque(false);
594
595         dsCombo.setEditable(true);
596
597         providerCombo.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(new String JavaDoc[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
598
599         jLabel3.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/persistence/wizard/unit/Bundle").getString("LBL_Provider"));
600
601         org.jdesktop.layout.GroupLayout jPanel6Layout = new org.jdesktop.layout.GroupLayout(jPanel6);
602         jPanel6.setLayout(jPanel6Layout);
603         jPanel6Layout.setHorizontalGroup(
604             jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
605             .add(jPanel6Layout.createSequentialGroup()
606                 .addContainerGap()
607                 .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
608                     .add(jPanel6Layout.createSequentialGroup()
609                         .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
610                             .add(jLabel3)
611                             .add(datasourceLabel))
612                         .add(43, 43, 43)
613                         .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
614                             .add(providerCombo, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
615                             .add(dsCombo, 0, 436, Short.MAX_VALUE)))
616                     .add(jtaCheckBox))
617                 .add(79, 79, 79))
618         );
619         jPanel6Layout.setVerticalGroup(
620             jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
621             .add(jPanel6Layout.createSequentialGroup()
622                 .addContainerGap()
623                 .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
624                     .add(jLabel3)
625                     .add(providerCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
626                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
627                 .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
628                     .add(datasourceLabel)
629                     .add(dsCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
630                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
631                 .add(jtaCheckBox)
632                 .add(48, 48, 48))
633         );
634         jPanel3.add(jPanel6, "container");
635
636         jPanel5.setOpaque(false);
637         libraryLabel.setText(org.openide.util.NbBundle.getMessage(PersistenceUnitPanel.class, "LBL_PersistenceLibrary"));
638
639         jdbcLabel.setText(org.openide.util.NbBundle.getMessage(PersistenceUnitPanel.class, "LBL_JdbcConnection"));
640
641         libraryComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
642             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
643                 libraryComboBoxActionPerformed(evt);
644             }
645         });
646
647         jdbcComboBox.setRenderer(new JdbcListCellRenderer());
648
649         org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(jPanel5);
650         jPanel5.setLayout(jPanel5Layout);
651         jPanel5Layout.setHorizontalGroup(
652             jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
653             .add(jPanel5Layout.createSequentialGroup()
654                 .addContainerGap()
655                 .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
656                     .add(libraryLabel)
657                     .add(jdbcLabel))
658                 .add(47, 47, 47)
659                 .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
660                     .add(jdbcComboBox, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
661                     .add(libraryComboBox, 0, 442, Short.MAX_VALUE))
662                 .addContainerGap(26, Short.MAX_VALUE))
663         );
664         jPanel5Layout.setVerticalGroup(
665             jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
666             .add(jPanel5Layout.createSequentialGroup()
667                 .addContainerGap()
668                 .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
669                     .add(libraryLabel)
670                     .add(libraryComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
671                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
672                 .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
673                     .add(jdbcLabel)
674                     .add(jdbcComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
675                 .addContainerGap(37, Short.MAX_VALUE))
676         );
677         jPanel3.add(jPanel5, "application");
678
679         jPanel1.setOpaque(false);
680         tableGenerationLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/persistence/unit/Bundle").getString("LBL_TableGeneration"));
681
682         buttonGroup2.add(ddCreate);
683         ddCreate.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/persistence/unit/Bundle").getString("LBL_Create"));
684         ddCreate.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
685         ddCreate.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
686         ddCreate.setOpaque(false);
687
688         buttonGroup2.add(ddDropCreate);
689         ddDropCreate.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/persistence/unit/Bundle").getString("LBL_DropCreate"));
690         ddDropCreate.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
691         ddDropCreate.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
692         ddDropCreate.setOpaque(false);
693
694         buttonGroup2.add(ddUnknown);
695         ddUnknown.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/persistence/unit/Bundle").getString("LBL_None"));
696         ddUnknown.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
697         ddUnknown.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
698         ddUnknown.setOpaque(false);
699
700         org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
701         jPanel1.setLayout(jPanel1Layout);
702         jPanel1Layout.setHorizontalGroup(
703             jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
704             .add(jPanel1Layout.createSequentialGroup()
705                 .addContainerGap()
706                 .add(tableGenerationLabel)
707                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
708                 .add(ddCreate)
709                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
710                 .add(ddDropCreate)
711                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
712                 .add(ddUnknown)
713                 .addContainerGap(272, Short.MAX_VALUE))
714         );
715         jPanel1Layout.setVerticalGroup(
716             jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
717             .add(jPanel1Layout.createSequentialGroup()
718                 .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
719                     .add(ddCreate)
720                     .add(ddDropCreate)
721                     .add(ddUnknown)
722                     .add(tableGenerationLabel))
723                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
724         );
725
726         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
727         this.setLayout(layout);
728         layout.setHorizontalGroup(
729             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
730             .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
731                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
732                     .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE)
733                     .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
734                     .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
735                     .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel7, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
736                     .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
737                         .addContainerGap()
738                         .add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
739                 .addContainerGap())
740         );
741         layout.setVerticalGroup(
742             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
743             .add(layout.createSequentialGroup()
744                 .addContainerGap()
745                 .add(jPanel7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
746                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
747                 .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 98, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
748                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
749                 .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
750                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
751                 .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
752                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
753                 .add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
754                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
755         );
756     }// </editor-fold>//GEN-END:initComponents
757

758     private void removeClassButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_removeClassButtonActionPerformed
759
Object JavaDoc[] values = entityList.getSelectedValues();
760         for (Object JavaDoc value : values) {
761             dObj.removeClass(persistenceUnit, (String JavaDoc)value);
762             ((DefaultListModel JavaDoc)entityList.getModel()).removeElement(value);
763         }
764     }//GEN-LAST:event_removeClassButtonActionPerformed
765

766     private void addClassButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_addClassButtonActionPerformed
767
String JavaDoc[] existingClasses = persistenceUnit.getClass2();
768         AddEntityDialog dialog = new AddEntityDialog(project, existingClasses);
769         for (String JavaDoc entityClass : dialog.open()) {
770             if (dObj.addClass(persistenceUnit, entityClass)){
771                 ((DefaultListModel JavaDoc)entityList.getModel()).addElement(entityClass);
772             }
773         }
774     }//GEN-LAST:event_addClassButtonActionPerformed
775

776     private void libraryComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_libraryComboBoxActionPerformed
777
// setProvider();
778
//// setSelectedLibrary();
779
// setTableGeneration();
780
}//GEN-LAST:event_libraryComboBoxActionPerformed
781

782     // Variables declaration - do not modify//GEN-BEGIN:variables
783
private javax.swing.JButton JavaDoc addClassButton;
784     private javax.swing.ButtonGroup JavaDoc buttonGroup2;
785     private javax.swing.JLabel JavaDoc datasourceLabel;
786     private javax.swing.JRadioButton JavaDoc ddCreate;
787     private javax.swing.JRadioButton JavaDoc ddDropCreate;
788     private javax.swing.JRadioButton JavaDoc ddUnknown;
789     private javax.swing.JComboBox JavaDoc dsCombo;
790     private javax.swing.JList JavaDoc entityList;
791     private javax.swing.JCheckBox JavaDoc includeAllEntities;
792     private javax.swing.JLabel JavaDoc jLabel1;
793     private javax.swing.JLabel JavaDoc jLabel2;
794     private javax.swing.JLabel JavaDoc jLabel3;
795     private javax.swing.JPanel JavaDoc jPanel1;
796     private javax.swing.JPanel JavaDoc jPanel2;
797     private javax.swing.JPanel JavaDoc jPanel3;
798     private javax.swing.JPanel JavaDoc jPanel4;
799     private javax.swing.JPanel JavaDoc jPanel5;
800     private javax.swing.JPanel JavaDoc jPanel6;
801     private javax.swing.JPanel JavaDoc jPanel7;
802     private javax.swing.JScrollPane JavaDoc jScrollPane2;
803     private javax.swing.JComboBox JavaDoc jdbcComboBox;
804     private javax.swing.JLabel JavaDoc jdbcLabel;
805     private javax.swing.JCheckBox JavaDoc jtaCheckBox;
806     private javax.swing.JComboBox JavaDoc libraryComboBox;
807     private javax.swing.JLabel JavaDoc libraryLabel;
808     private javax.swing.JTextField JavaDoc nameTextField;
809     private javax.swing.JComboBox JavaDoc providerCombo;
810     private javax.swing.JButton JavaDoc removeClassButton;
811     private javax.swing.JLabel JavaDoc tableGenerationLabel;
812     // End of variables declaration//GEN-END:variables
813

814 }
815
816
Popular Tags