KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > persistence > wizard > entity > EntityWizardPanel


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.entity;
21 import javax.swing.SwingUtilities JavaDoc;
22 import javax.swing.event.ChangeListener JavaDoc;
23 import javax.swing.event.DocumentEvent JavaDoc;
24 import javax.swing.event.DocumentListener JavaDoc;
25 import org.netbeans.api.project.Project;
26 //import org.netbeans.modules.j2ee.common.FQNSearch;
27
import org.netbeans.modules.j2ee.persistence.dd.persistence.model_1_0.PersistenceUnit;
28 import org.netbeans.modules.j2ee.persistence.wizard.Util;
29 import org.netbeans.modules.j2ee.persistence.wizard.unit.PersistenceUnitWizardPanel.TableGeneration;
30
31 /**
32  *
33  * @author Martin Adamek
34  */

35 public class EntityWizardPanel extends javax.swing.JPanel JavaDoc {
36     
37     private Project project;
38     private ChangeListener JavaDoc listener;
39     private PersistenceUnit persistenceUnit;
40     
41     static final String JavaDoc IS_VALID = "EntityWizardPanel_isValid"; //NOI18N
42

43     public EntityWizardPanel(ChangeListener JavaDoc changeListener) {
44         this.setProject(project);
45         this.listener = changeListener;
46         initComponents();
47         
48         setPersistenceUnitButtonVisibility(false);
49         
50         primaryKeyTextField.getDocument().addDocumentListener(new DocumentListener JavaDoc() {
51             public void changedUpdate(DocumentEvent JavaDoc e) {
52                 listener.stateChanged(null);
53             }
54             public void insertUpdate(DocumentEvent JavaDoc e) {
55                 listener.stateChanged(null);
56             }
57             public void removeUpdate(DocumentEvent JavaDoc e) {
58                 listener.stateChanged(null);
59             }
60         });
61         
62     }
63     
64     public String JavaDoc getPrimaryKeyClassName() {
65         return primaryKeyTextField.getText();
66     }
67     
68     void setPersistenceUnitButtonVisibility(boolean visible) {
69         createPUButton.setVisible(visible);
70     }
71     
72     void setProject(Project project) {
73         this.project = project;
74     }
75
76     public PersistenceUnit getPersistenceUnit() {
77         return persistenceUnit;
78     }
79     
80
81     /** This method is called from within the constructor to
82      * initialize the form.
83      * WARNING: Do NOT modify this code. The content of this method is
84      * always regenerated by the Form Editor.
85      */

86     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
87
private void initComponents() {
88         persistenceGroup = new javax.swing.ButtonGroup JavaDoc();
89         accessTypeGroup = new javax.swing.ButtonGroup JavaDoc();
90         jLabel1 = new javax.swing.JLabel JavaDoc();
91         primaryKeyTextField = new javax.swing.JTextField JavaDoc();
92         createPUButton = new javax.swing.JButton JavaDoc();
93         searchButton = new javax.swing.JButton JavaDoc();
94
95         jLabel1.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/persistence/wizard/entity/Bundle").getString("MN_PrimaryKeyType").charAt(0));
96         jLabel1.setLabelFor(primaryKeyTextField);
97         jLabel1.setText(org.openide.util.NbBundle.getBundle(EntityWizardPanel.class).getString("LBL_PrimaryKeyClass"));
98
99         primaryKeyTextField.setText("Long");
100         primaryKeyTextField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/persistence/wizard/entity/Bundle").getString("LBL_PrimaryKeyClass"));
101
102         createPUButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/persistence/wizard/entity/Bundle").getString("MN_CreatePersistenceUnit").charAt(0));
103         createPUButton.setText(org.openide.util.NbBundle.getMessage(EntityWizardPanel.class, "LBL_CreatePersistenceUnit"));
104         createPUButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
105             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
106                 createPUButtonActionPerformed(evt);
107             }
108         });
109
110         createPUButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/persistence/wizard/entity/Bundle").getString("LBL_CreatePersistenceUnit"));
111
112         searchButton.setText("...");
113         searchButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
114             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
115                 searchButtonActionPerformed(evt);
116             }
117         });
118
119         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
120         this.setLayout(layout);
121         layout.setHorizontalGroup(
122             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
123             .add(layout.createSequentialGroup()
124                 .add(jLabel1)
125                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
126                 .add(primaryKeyTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE)
127                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
128                 .add(searchButton))
129             .add(createPUButton)
130         );
131         layout.setVerticalGroup(
132             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
133             .add(layout.createSequentialGroup()
134                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
135                     .add(jLabel1)
136                     .add(searchButton)
137                     .add(primaryKeyTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
138                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 155, Short.MAX_VALUE)
139                 .add(createPUButton))
140         );
141     }// </editor-fold>//GEN-END:initComponents
142

143     private void searchButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_searchButtonActionPerformed
144
SwingUtilities.invokeLater(new Runnable JavaDoc() {
145             public void run() {
146                 // TODO: RETOUCHE
147
// FQNSearch.showFastOpen(primaryKeyTextField);
148
}
149         });
150     }//GEN-LAST:event_searchButtonActionPerformed
151

152     private void createPUButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_createPUButtonActionPerformed
153
persistenceUnit = Util.buildPersistenceUnitUsingWizard(project, null, TableGeneration.CREATE);
154         if (persistenceUnit != null){
155             firePropertyChange(IS_VALID, false, true);
156             setPersistenceUnitButtonVisibility(false);
157         }
158     }//GEN-LAST:event_createPUButtonActionPerformed
159

160     
161     // Variables declaration - do not modify//GEN-BEGIN:variables
162
private javax.swing.ButtonGroup JavaDoc accessTypeGroup;
163     private javax.swing.JButton JavaDoc createPUButton;
164     private javax.swing.JLabel JavaDoc jLabel1;
165     private javax.swing.ButtonGroup JavaDoc persistenceGroup;
166     private javax.swing.JTextField JavaDoc primaryKeyTextField;
167     private javax.swing.JButton JavaDoc searchButton;
168     // End of variables declaration//GEN-END:variables
169

170 }
171
Popular Tags