1 19 20 package org.netbeans.modules.j2ee.persistence.unit; 21 22 import java.awt.CardLayout ; 23 import java.util.List ; 24 import javax.swing.DefaultListModel ; 25 import javax.swing.text.JTextComponent ; 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 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(); 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 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 130 private void setVisiblePanel(){ 131 String panelName = isContainerManaged ? "container" : "application"; ((CardLayout )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 jtaDataSource = persistenceUnit.getJtaDataSource(); 139 String nonJtaDataSource = persistenceUnit.getNonJtaDataSource(); 140 141 JPADataSourcePopulator dsPopulator = project.getLookup().lookup(JPADataSourcePopulator.class); 142 if (dsPopulator != null){ 143 dsPopulator.connect(dsCombo); 144 addModifier((JTextComponent )dsCombo.getEditor().getEditorComponent(), false); 145 } 146 147 String jndiName = (jtaDataSource != null ? jtaDataSource : nonJtaDataSource); 148 selectDatasource(jndiName); 149 150 jtaCheckBox.setSelected(jtaDataSource != null); 151 152 String provider = persistenceUnit.getProvider(); 153 for (int i = 0; i < providerCombo.getItemCount(); i++) { 154 Object 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 []{ProjectUtils.getInformation(project).getDisplayName()})); 184 } 185 186 private void initEntityList(){ 187 DefaultListModel listedClassesModel = new DefaultListModel (); 188 for (String elem : persistenceUnit.getClass2()) { 189 listedClassesModel.addElement(elem); 190 } 191 entityList.setModel(listedClassesModel); 192 193 } 194 195 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 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 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 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 250 private void setSelectedConnection(){ 251 DatabaseConnection connection = ProviderUtil.getConnection(persistenceUnit); 252 if (connection != null){ 253 jdbcComboBox.setSelectedItem(connection); 254 } else { 255 Properties props = persistenceUnit.getProperties(); 257 if (props != null){ 258 Property[] properties = props.getProperty2(); 259 String url = "custom"; 260 Provider provider = ProviderUtil.getProvider(persistenceUnit); 261 for (int i = 0; i < properties.length; i++) { 262 String 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 source, Object value) { 275 if (source == nameTextField) { 276 persistenceUnit.setName((String ) value); 277 } else if (source == dsCombo){ 278 setDataSource(); 279 } else if (source == dsCombo.getEditor().getEditorComponent()) { 280 setDataSource((String )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 <Error > 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 name) { 338 339 String jndiName = name; 340 341 if (jndiName == null) { 342 int itemIndex = dsCombo.getSelectedIndex(); 343 Object item = dsCombo.getSelectedItem(); 344 if (item instanceof JPADataSource) 345 jndiName = ((JPADataSource)item).getJndiName(); 346 else if (itemIndex == -1 && item != null){ 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 371 private String 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 source) { 391 if (nameTextField == source) { 392 nameTextField.setText(persistenceUnit.getName()); 393 } else if (dsCombo.getEditor().getEditorComponent() == source){ 394 String jndiName = (isJta() ? persistenceUnit.getJtaDataSource() : persistenceUnit.getNonJtaDataSource()); 395 selectDatasource(jndiName); 396 } 397 } 398 399 private void selectDatasource(String jndiName) { 400 401 Object item = findDatasource(jndiName); 402 dsCombo.setSelectedItem(item); 403 if (dsCombo.getEditor() != null) { dsCombo.configureEditor(dsCombo.getEditor(), item); 405 } 406 } 407 408 private Object findDatasource(String jndiName) { 409 410 if (jndiName != null) { 411 int nItems = dsCombo.getItemCount(); 412 for (int i = 0; i < nItems; i++) { 413 Object 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 ddBean, String ddProperty) { 428 } 429 430 public javax.swing.JComponent getErrorComponent(String 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 454 private void initComponents() { 456 buttonGroup2 = new javax.swing.ButtonGroup (); 457 jPanel2 = new javax.swing.JPanel (); 458 includeAllEntities = new javax.swing.JCheckBox (); 459 jPanel4 = new javax.swing.JPanel (); 460 jScrollPane2 = new javax.swing.JScrollPane (); 461 entityList = new javax.swing.JList (); 462 addClassButton = new javax.swing.JButton (); 463 removeClassButton = new javax.swing.JButton (); 464 jLabel1 = new javax.swing.JLabel (); 465 jPanel7 = new javax.swing.JPanel (); 466 jLabel2 = new javax.swing.JLabel (); 467 nameTextField = new javax.swing.JTextField (); 468 jPanel3 = new javax.swing.JPanel (); 469 jPanel6 = new javax.swing.JPanel (); 470 datasourceLabel = new javax.swing.JLabel (); 471 jtaCheckBox = new javax.swing.JCheckBox (); 472 dsCombo = new javax.swing.JComboBox (); 473 providerCombo = new javax.swing.JComboBox (); 474 jLabel3 = new javax.swing.JLabel (); 475 jPanel5 = new javax.swing.JPanel (); 476 libraryLabel = new javax.swing.JLabel (); 477 jdbcLabel = new javax.swing.JLabel (); 478 libraryComboBox = new javax.swing.JComboBox (); 479 jdbcComboBox = new javax.swing.JComboBox (); 480 jPanel1 = new javax.swing.JPanel (); 481 tableGenerationLabel = new javax.swing.JLabel (); 482 ddCreate = new javax.swing.JRadioButton (); 483 ddDropCreate = new javax.swing.JRadioButton (); 484 ddUnknown = new javax.swing.JRadioButton (); 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 (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 () { 514 public void actionPerformed(java.awt.event.ActionEvent 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 () { 522 public void actionPerformed(java.awt.event.ActionEvent 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 ()); 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 (0, 0, 0, 0)); 593 jtaCheckBox.setOpaque(false); 594 595 dsCombo.setEditable(true); 596 597 providerCombo.setModel(new javax.swing.DefaultComboBoxModel (new String [] { "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 () { 642 public void actionPerformed(java.awt.event.ActionEvent 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 (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 (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 (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 } 758 private void removeClassButtonActionPerformed(java.awt.event.ActionEvent evt) { Object [] values = entityList.getSelectedValues(); 760 for (Object value : values) { 761 dObj.removeClass(persistenceUnit, (String )value); 762 ((DefaultListModel )entityList.getModel()).removeElement(value); 763 } 764 } 766 private void addClassButtonActionPerformed(java.awt.event.ActionEvent evt) { String [] existingClasses = persistenceUnit.getClass2(); 768 AddEntityDialog dialog = new AddEntityDialog(project, existingClasses); 769 for (String entityClass : dialog.open()) { 770 if (dObj.addClass(persistenceUnit, entityClass)){ 771 ((DefaultListModel )entityList.getModel()).addElement(entityClass); 772 } 773 } 774 } 776 private void libraryComboBoxActionPerformed(java.awt.event.ActionEvent evt) { } 782 private javax.swing.JButton addClassButton; 784 private javax.swing.ButtonGroup buttonGroup2; 785 private javax.swing.JLabel datasourceLabel; 786 private javax.swing.JRadioButton ddCreate; 787 private javax.swing.JRadioButton ddDropCreate; 788 private javax.swing.JRadioButton ddUnknown; 789 private javax.swing.JComboBox dsCombo; 790 private javax.swing.JList entityList; 791 private javax.swing.JCheckBox includeAllEntities; 792 private javax.swing.JLabel jLabel1; 793 private javax.swing.JLabel jLabel2; 794 private javax.swing.JLabel jLabel3; 795 private javax.swing.JPanel jPanel1; 796 private javax.swing.JPanel jPanel2; 797 private javax.swing.JPanel jPanel3; 798 private javax.swing.JPanel jPanel4; 799 private javax.swing.JPanel jPanel5; 800 private javax.swing.JPanel jPanel6; 801 private javax.swing.JPanel jPanel7; 802 private javax.swing.JScrollPane jScrollPane2; 803 private javax.swing.JComboBox jdbcComboBox; 804 private javax.swing.JLabel jdbcLabel; 805 private javax.swing.JCheckBox jtaCheckBox; 806 private javax.swing.JComboBox libraryComboBox; 807 private javax.swing.JLabel libraryLabel; 808 private javax.swing.JTextField nameTextField; 809 private javax.swing.JComboBox providerCombo; 810 private javax.swing.JButton removeClassButton; 811 private javax.swing.JLabel tableGenerationLabel; 812 814 } 815 816 | Popular Tags |