1 19 20 package org.netbeans.modules.j2ee.persistence.wizard.entity; 21 import javax.swing.SwingUtilities ; 22 import javax.swing.event.ChangeListener ; 23 import javax.swing.event.DocumentEvent ; 24 import javax.swing.event.DocumentListener ; 25 import org.netbeans.api.project.Project; 26 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 35 public class EntityWizardPanel extends javax.swing.JPanel { 36 37 private Project project; 38 private ChangeListener listener; 39 private PersistenceUnit persistenceUnit; 40 41 static final String IS_VALID = "EntityWizardPanel_isValid"; 43 public EntityWizardPanel(ChangeListener changeListener) { 44 this.setProject(project); 45 this.listener = changeListener; 46 initComponents(); 47 48 setPersistenceUnitButtonVisibility(false); 49 50 primaryKeyTextField.getDocument().addDocumentListener(new DocumentListener () { 51 public void changedUpdate(DocumentEvent e) { 52 listener.stateChanged(null); 53 } 54 public void insertUpdate(DocumentEvent e) { 55 listener.stateChanged(null); 56 } 57 public void removeUpdate(DocumentEvent e) { 58 listener.stateChanged(null); 59 } 60 }); 61 62 } 63 64 public String 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 86 private void initComponents() { 88 persistenceGroup = new javax.swing.ButtonGroup (); 89 accessTypeGroup = new javax.swing.ButtonGroup (); 90 jLabel1 = new javax.swing.JLabel (); 91 primaryKeyTextField = new javax.swing.JTextField (); 92 createPUButton = new javax.swing.JButton (); 93 searchButton = new javax.swing.JButton (); 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 () { 105 public void actionPerformed(java.awt.event.ActionEvent 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 () { 114 public void actionPerformed(java.awt.event.ActionEvent 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 } 143 private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) { SwingUtilities.invokeLater(new Runnable () { 145 public void run() { 146 } 149 }); 150 } 152 private void createPUButtonActionPerformed(java.awt.event.ActionEvent evt) { persistenceUnit = Util.buildPersistenceUnitUsingWizard(project, null, TableGeneration.CREATE); 154 if (persistenceUnit != null){ 155 firePropertyChange(IS_VALID, false, true); 156 setPersistenceUnitButtonVisibility(false); 157 } 158 } 160 161 private javax.swing.ButtonGroup accessTypeGroup; 163 private javax.swing.JButton createPUButton; 164 private javax.swing.JLabel jLabel1; 165 private javax.swing.ButtonGroup persistenceGroup; 166 private javax.swing.JTextField primaryKeyTextField; 167 private javax.swing.JButton searchButton; 168 170 } 171 | Popular Tags |