1 17 18 package com.finalist.jaggenerator.modules; 19 20 import com.finalist.jag.util.TemplateString; 21 import com.finalist.jaggenerator.JagGenerator; 22 import com.finalist.jaggenerator.SelectTablesDialog; 23 import com.finalist.jaggenerator.Utils; 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.w3c.dom.Document ; 27 import org.w3c.dom.Element ; 28 import org.w3c.dom.Node ; 29 import org.w3c.dom.NodeList ; 30 31 import javax.swing.*; 32 import javax.swing.tree.DefaultMutableTreeNode ; 33 import javax.swing.tree.TreeNode ; 34 import javax.xml.parsers.ParserConfigurationException ; 35 import java.awt.event.ActionEvent ; 36 import java.awt.event.ActionListener ; 37 import java.util.ArrayList ; 38 import java.util.Enumeration ; 39 import java.util.Iterator ; 40 import java.util.List ; 41 42 45 public class Entity extends DefaultMutableTreeNode implements JagBean, ActionListener { 46 private boolean relationsEnabled; 47 static Log log = LogFactory.getLog(JagGenerator.class); 48 49 52 public Entity(String rootPackage, String tableName, String pKey) { 53 initComponents(); 54 String tableClassName = Utils.toClassName(tableName); 55 rootPackageText.setText(rootPackage + ".entity." + tableClassName.toLowerCase()); 56 tableNameText.setText(tableName); 57 nameText.setText(tableClassName); 58 descriptionText.setText(tableClassName); 59 refNameText.setText(tableClassName); 60 pKeyText.setText(pKey); 61 JagGenerator.addEntity(getRefName(), this); 62 synchronized (this) { 65 try { 66 wait(100); 67 } catch (InterruptedException e) { 68 } 69 } 70 notifyRelationsThatConstructionIsFinished(); 71 SelectTablesDialog.getAlreadyselected().add(tableName); 72 } 73 74 public Entity(Element el) { 75 relationsEnabled = !JagGenerator.isRelationsEnabled(); 76 initComponents(); 77 NodeList nl = el.getChildNodes(); 78 for (int i = 0; i < nl.getLength(); i++) { 79 Node n = nl.item(i); 80 if (n.getNodeType() == n.ELEMENT_NODE) { 81 Element child = (Element ) n; 82 String attName = child.getAttribute("name"); 83 try { 84 Node first = child.getFirstChild(); 85 if (first == null) continue; 86 String value = first.getNodeValue(); 87 if (value != null) { 88 if (attName.equalsIgnoreCase("name")) { 89 nameText.setText(value); 90 continue; 91 } 92 if (attName.equalsIgnoreCase("display-name")) { 93 displayNameText.setText(value); 94 continue; 95 } 96 if (attName.equalsIgnoreCase("description")) { 97 descriptionText.setText(value); 98 continue; 99 } 100 if (attName.equalsIgnoreCase("root-package")) { 101 rootPackageText.setText(value); 102 continue; 103 } 104 if (attName.equalsIgnoreCase("table-name")) { 105 tableNameText.setText(value); 106 SelectTablesDialog.getAlreadyselected().add(value); 107 continue; 108 } 109 if (attName.equalsIgnoreCase("primary-key")) { 110 pKeyText.setText(value); 111 continue; 112 } 113 if (attName.equalsIgnoreCase("primary-key-type")) { 114 pKeyTypeText.setText(value); 115 continue; 116 } 117 if (attName.equalsIgnoreCase("is-composite")) { 118 isCompositeCombo.setSelectedItem(value); 119 continue; 120 } 121 if (attName.equalsIgnoreCase("is-association")) { 122 isAssociationEntity.setSelectedItem(value); 123 continue; 124 } 125 if (attName.equalsIgnoreCase("field")) { 126 add(new Field(this, child)); 127 continue; 128 } 129 if (attName.equalsIgnoreCase("relation")) { 130 if (warningNeeded()) { 131 JOptionPane.showMessageDialog(getPanel(), 132 "The application file you have opened contains relations, but you have disabled relations support. \n" + 133 "If you later save this file or generate an application from this file, the original relations information will be lost.\n" + 134 "\n" + 135 "To avoid this, either enable relations support (Options->Enable relations) and re-open the file, or save the file under a different name.", 136 "Container-managed relations disabled!", 137 JOptionPane.INFORMATION_MESSAGE); 138 } else if (relationsEnabled) { 139 add(new Relation(this, child)); 140 continue; 141 } 142 } 143 } 144 } catch (Exception e) { 145 e.printStackTrace(); 146 JagGenerator.logToConsole("Error constructing " + this.toString() + ": " + e); 147 } 148 } 149 } 150 nl = el.getElementsByTagName("ref-name"); 151 if (nl.getLength() > 0) { 152 Node node = nl.item(0).getFirstChild(); 153 if (node != null) { 154 refNameText.setText(node.getNodeValue()); 155 } 156 } 157 158 JagGenerator.addEntity(getRefName(), this); 159 160 synchronized (this) { 163 try { 164 wait(100); 165 } catch (InterruptedException e) { 166 } 167 } 168 notifyRelationsThatConstructionIsFinished(); 169 } 170 171 172 public JPanel getPanel() { 173 return panel; 174 } 175 176 public String getRefName() { 177 return refNameText.getText(); 178 } 179 180 public void setRefName(String text) { 181 refNameText.setText(text); 182 } 183 184 185 public void setPKeyType(String pKeyType) { 186 pKeyTypeText.setText(pKeyType); 187 } 188 189 public void getXML(Element el) throws ParserConfigurationException { 190 Document doc = el.getOwnerDocument(); 191 Element module = doc.createElement("module"); 192 module.setAttribute("name", "entity"); 193 194 Element name = doc.createElement("module-data"); 195 name.setAttribute("name", "name"); 196 if (nameText.getText() != null) { 197 name.appendChild(doc.createTextNode(nameText.getText())); 198 } 199 module.appendChild(name); 200 201 Element displayname = doc.createElement("module-data"); 202 displayname.setAttribute("name", "display-name"); 203 if (displayNameText.getText() != null) { 204 displayname.appendChild(doc.createTextNode(displayNameText.getText())); 205 } 206 module.appendChild(displayname); 207 208 209 Element description = doc.createElement("module-data"); 210 description.setAttribute("name", "description"); 211 if (descriptionText.getText() != null) { 212 description.appendChild(doc.createTextNode(descriptionText.getText())); 213 } 214 module.appendChild(description); 215 216 Element rootPackage = doc.createElement("module-data"); 217 rootPackage.setAttribute("name", "root-package"); 218 if (rootPackageText.getText() != null) { 219 rootPackage.appendChild(doc.createTextNode(rootPackageText.getText())); 220 } 221 module.appendChild(rootPackage); 222 223 Element tableName = doc.createElement("module-data"); 224 tableName.setAttribute("name", "table-name"); 225 if (tableNameText.getText() != null) { 226 tableName.appendChild(doc.createTextNode(tableNameText.getText())); 227 } 228 module.appendChild(tableName); 229 230 Element pKey = doc.createElement("module-data"); 231 pKey.setAttribute("name", "primary-key"); 232 pKey.appendChild(doc.createTextNode((isCompositeKey() ? "" : pKeyText.getText()))); 233 module.appendChild(pKey); 234 235 Element pKeyType = doc.createElement("module-data"); 236 pKeyType.setAttribute("name", "primary-key-type"); 237 if (pKeyTypeText.getText() != null) { 238 pKeyType.appendChild(doc.createTextNode(pKeyTypeText.getText())); 239 } 240 241 module.appendChild(pKeyType); 242 Element isComposite = doc.createElement("module-data"); 243 isComposite.setAttribute("name", "is-composite"); 244 isComposite.appendChild(doc.createTextNode((String ) isCompositeCombo.getSelectedItem())); 245 module.appendChild(isComposite); 246 247 248 Element isAssociation = doc.createElement("module-data"); 249 isAssociation.setAttribute("name", "is-association"); 250 isAssociation.appendChild(doc.createTextNode((String ) isAssociationEntity.getSelectedItem())); 251 module.appendChild(isAssociation); 252 253 Element refName = doc.createElement("ref-name"); 254 if (refNameText.getText() != null) { 255 refName.appendChild(doc.createTextNode(refNameText.getText())); 256 } 257 module.appendChild(refName); 258 259 Enumeration children = children(); 261 while (children.hasMoreElements()) { 262 JagBean child = (JagBean) children.nextElement(); 263 child.getXML(module); 264 } 265 266 el.appendChild(module); 267 } 268 269 public TemplateString getName() { 270 return new TemplateString(nameText.getText()); 271 } 272 273 public void setName(String text) { 274 nameText.setText(text); 275 } 276 277 282 public TemplateString getDisplayName() { 283 if (displayNameText.getText() == null || "".equals(displayNameText.getText())) { 284 if (getPrimaryKey() == null) { 285 return new TemplateString(""); 286 } else { 287 return new TemplateString(getPrimaryKey().toString()); 288 } 289 } 290 return new TemplateString(displayNameText.getText()); 291 } 292 293 public void setDisplayName(String text) { 294 displayNameText.setText(text); 295 } 296 297 public TemplateString getDescription() { 298 return new TemplateString(descriptionText.getText()); 299 } 300 301 public void setDescription(String text) { 302 descriptionText.setText(text); 303 } 304 305 public TemplateString getRootPackage() { 306 return new TemplateString(rootPackageText.getText()); 307 } 308 309 public void setRootPackage(String text) { 310 rootPackageText.setText(text); 311 } 312 313 314 public Field getPrimaryKey() { 315 return isCompositeKey() ? null : (Field) getPkFields().get(0); 316 } 317 318 323 public void setPrimaryKey(Field field) { 324 if ("false".equals(isCompositeCombo.getSelectedItem())) { 325 if ("".equals(pKeyText.getText())) { 326 pKeyText.setText(field.getName().toString()); 327 pKeyTypeText.setText(field.getType().toString()); 328 329 } else { 330 isCompositeCombo.setSelectedItem("true"); 331 pKeyText.setText(""); 332 pKeyTypeText.setText(rootPackageText.getText() + '.' + getName() + "PK"); 333 } 334 } 335 } 336 337 342 public void unsetPrimaryKey(Field field) { 343 if ("false".equals(isCompositeCombo.getSelectedItem())) { 344 pKeyText.setText(""); 345 pKeyTypeText.setText(""); 346 347 } else { 348 List pkFields = getPkFields(); 349 if (pkFields.size() == 1) { 350 isCompositeCombo.setSelectedItem("false"); 351 pKeyText.setText(((Field) pkFields.get(0)).getName().toString()); 352 pKeyTypeText.setText(((Field) pkFields.get(0)).getType().toString()); 353 } 354 } 355 } 356 357 public TemplateString getPrimaryKeyType() { 358 return new TemplateString(pKeyTypeText.getText()); 359 } 360 361 public TemplateString getPrimaryKeyName() { 362 return new TemplateString(pKeyText.getText()); 363 } 364 365 public String getIsComposite() { 366 return (String ) isCompositeCombo.getSelectedItem(); 367 } 368 369 public void setIsComposite(String composite) { 370 isCompositeCombo.setSelectedItem(composite); 371 } 372 373 public String getIsAssociationEntity() { 374 return (String ) isAssociationEntity.getSelectedItem(); 375 } 376 377 public void setIsAssociationEntity(String associationEntity) { 378 isAssociationEntity.setSelectedItem(associationEntity); 379 } 380 381 public String getRootPath() { 382 return getRootPackage().toString().replace('.', '/'); 383 } 384 385 public List getRelations() { 386 ArrayList relations = new ArrayList (); 387 Enumeration children = children(); 388 while (children.hasMoreElements()) { 389 JagBean child = (JagBean) children.nextElement(); 390 if (child instanceof Relation) { 391 relations.add(child); 392 } 393 } 394 return relations; 395 } 396 397 402 public List getEntitiesRelations() { 403 ArrayList result = new ArrayList (); 404 List entities = JagGenerator.getObjectsFromTree(Entity.class); 405 for (int i = 0; i < entities.size(); i++) { 406 Entity relatedEntity = (Entity) entities.get(i); 407 List relations = relatedEntity.getRelations(); 408 for (int j = 0; j < relations.size(); j++) { 409 Relation rel = (Relation) relations.get(j); 410 Entity en = rel.getRelatedEntity(); 411 if ("false".equals(relatedEntity.getIsAssociationEntity()) && en.getName().equals(this.getName())) { 413 result.add(rel); 414 } 415 } 416 } 417 return result; 418 } 419 420 425 public List getEntitiesAssocationRelations() { 426 ArrayList result = new ArrayList (); 427 List entities = JagGenerator.getObjectsFromTree(Entity.class); 428 for (int i = 0; i < entities.size(); i++) { 429 Entity relatedEntity = (Entity) entities.get(i); 430 List relations = relatedEntity.getRelations(); 431 for (int j = 0; j < relations.size(); j++) { 432 Relation rel = (Relation) relations.get(j); 433 Entity en = rel.getRelatedEntity(); 435 if (en.getName().equals(this.getName())) { 436 if ("true".equals(relatedEntity.getIsAssociationEntity())) { 437 result.add(rel); 438 } 439 } 440 } 441 } 442 return result; 443 } 444 445 451 public Entity getAssocationEntity(String relationName) { 452 return null; 454 } 455 456 public List getRelatedEntities() { 457 ArrayList relatedEntities = new ArrayList (); 458 Enumeration children = children(); 459 while (children.hasMoreElements()) { 460 JagBean child = (JagBean) children.nextElement(); 461 if (child instanceof Relation) { 462 relatedEntities.add(((Relation) child).getRelatedEntity()); 463 } 464 } 465 return relatedEntities; 466 } 467 468 473 public List getRelationFieldNames() { 474 ArrayList relationFieldNames = new ArrayList (); 475 Enumeration children = children(); 476 while (children.hasMoreElements()) { 477 JagBean child = (JagBean) children.nextElement(); 478 if (child instanceof Relation) { 479 relationFieldNames.add(((Relation) child).getFieldName()); 480 } 481 } 482 return relationFieldNames; 483 } 484 485 public boolean getHasRelations() { 486 return !getRelations().isEmpty(); 487 } 488 489 public List getFields() { 490 ArrayList fields = new ArrayList (); 491 Enumeration children = children(); 492 while (children.hasMoreElements()) { 493 JagBean child = (JagBean) children.nextElement(); 494 if (child instanceof Field) { 495 fields.add(child); 496 } 497 } 498 return fields; 499 } 500 501 public List getNonFkFields() { 502 ArrayList fields = new ArrayList (); 503 Enumeration children = children(); 504 while (children.hasMoreElements()) { 505 JagBean child = (JagBean) children.nextElement(); 506 if (child instanceof Field && 507 !((Field) child).isForeignKey()) { 508 fields.add(child); 509 } 510 } 511 return fields; 512 } 513 514 public List getFkFields() { 515 ArrayList fields = new ArrayList (); 516 Enumeration children = children(); 517 while (children.hasMoreElements()) { 518 JagBean child = (JagBean) children.nextElement(); 519 if (child instanceof Field && 520 ((Field) child).isForeignKey()) { 521 fields.add(child); 522 } 523 } 524 return fields; 525 } 526 527 528 public List getNonRelationFields() { 529 ArrayList fields = new ArrayList (); 530 Enumeration children = children(); 531 while (children.hasMoreElements()) { 532 JagBean child = (JagBean) children.nextElement(); 533 if (child instanceof Field && 534 (((Field) child).getRelation() == null)) { 535 fields.add(child); 536 } 537 } 538 return fields; 539 } 540 541 public List getPkFields() { 542 ArrayList fields = new ArrayList (); 543 Enumeration children = children(); 544 while (children.hasMoreElements()) { 545 JagBean child = (JagBean) children.nextElement(); 546 if (child instanceof Field && 547 ((Field) child).isPrimaryKey()) { 548 fields.add(child); 549 } 550 } 551 return fields; 552 } 553 554 public List getNonPkFields() { 555 List nonPkFields = getFields(); 556 nonPkFields.removeAll(getPkFields()); 557 return nonPkFields; 558 } 559 560 565 public List getNonPkRelationFields() { 566 List nonPkRelationFields = getNonRelationFields(); 567 nonPkRelationFields.removeAll(getPkFields()); 568 return nonPkRelationFields; 569 } 570 571 577 public boolean isCompositeKey() { 578 int countPrimaryKeys = countPrimaryKeyFields(); 579 return countPrimaryKeys > 1; 580 } 581 582 587 public int countPrimaryKeyFields() { 588 Enumeration children = children(); 589 JagBean bean = null; 590 Field field = null; 591 int countPrimaryKeys = 0; 592 while (children.hasMoreElements()) { 593 bean = (JagBean) children.nextElement(); 594 if (bean instanceof Field) { 595 field = (Field) bean; 596 if (field.isPrimaryKey()) countPrimaryKeys++; 597 } 598 } 599 return countPrimaryKeys; 600 } 601 602 607 public String getPrimaryKeyClass() { 608 Enumeration children = children(); 609 JagBean bean = null; 610 Field field = null; 611 String getPrimaryKeyClass = null; 612 while (children.hasMoreElements()) { 613 bean = (JagBean) children.nextElement(); 614 if (bean instanceof Field) { 615 field = (Field) bean; 616 if (field.isPrimaryKey()) getPrimaryKeyClass = field.getType(); 617 } 618 } 619 return getPrimaryKeyClass; 620 } 621 622 627 public String getFirstPrimaryKeyFieldName() { 628 Enumeration children = children(); 629 JagBean bean = null; 630 Field field = null; 631 String getPrimaryKeyFieldName = ""; 632 while (children.hasMoreElements()) { 633 bean = (JagBean) children.nextElement(); 634 if (bean instanceof Field) { 635 field = (Field) bean; 636 if (field.isPrimaryKey()) getPrimaryKeyFieldName = field.getName().toString(); 637 } 638 } 639 return getPrimaryKeyFieldName; 640 } 641 642 public void actionPerformed(ActionEvent e) { 643 if (e.getActionCommand().equals("GET_PRIMARY_KEY")) { 644 String key = null; 645 if (isCompositeKey()) 646 key = rootPackageText.getText() + "." + nameText.getText() + "PK"; 647 else 648 key = getPrimaryKeyClass(); 649 pKeyTypeText.setText(key); 650 } 651 } 652 653 658 public TemplateString getLocalTableName() { 659 return new TemplateString(tableNameText.getText()); 660 } 661 662 public void setTableName(String table) { 663 tableNameText.setText(table); 664 } 665 666 public String getTableName() { 667 return tableNameText.getText(); 668 } 669 670 674 public void notifyRelationsThatConstructionIsFinished() { 675 Iterator relations = getRelations().iterator(); 676 while (relations.hasNext()) { 677 Relation relation = (Relation) relations.next(); 678 relation.notifyLocalEntityIsComplete(); 679 } 680 } 681 682 688 public void notifyRelationsThatFieldNameChanged(String oldName, String text) { 689 Iterator relations = getRelations().iterator(); 690 while (relations.hasNext()) { 691 Relation relation = (Relation) relations.next(); 692 relation.notifyFieldNameChanged(oldName, text); 693 } 694 695 } 696 697 public String toString() { 698 return "Entity - " + getRefName(); 699 } 700 701 707 public void addRelation(Relation relation) { 708 TreeNode lastRelly = null; 709 Enumeration kids = children(); 710 while (kids.hasMoreElements()) { 711 TreeNode kid = (TreeNode ) kids.nextElement(); 712 if (kid instanceof Relation) { 713 lastRelly = kid; 714 } 715 } 716 int insertPos = 0; 717 if (lastRelly == null) { 718 insertPos = getIndex(getFirstChild()); 719 } else { 720 insertPos = getIndex(lastRelly) + 1; 721 } 722 insert(relation, insertPos); 723 } 724 725 726 731 public boolean isSequenceEntity() { 732 List fields = getFields(); 733 for (int i=0; i < getFields().size(); i++) { 734 Field field = (Field) fields.get(i); 735 if (field.isSequenceField()) { 736 return true; 737 } 738 } 739 return false; 740 } 741 745 public Session getFirstSession() { 746 List services = JagGenerator.getObjectsFromTree(Session.class); 747 for (int i=0; i<services.size(); i++) { 748 Session s = (Session) services.get(i); 749 if (s.getEntities().contains(this)) { 750 return s; 751 } 752 } 753 System.out.println("No session found for entity:" + getName()); 754 return null; 755 } 756 757 private boolean warningNeeded() { 758 if (relationsEnabled != JagGenerator.isRelationsEnabled()) { 759 relationsEnabled = JagGenerator.isRelationsEnabled(); 760 return !relationsEnabled; 761 } 762 return false; 763 } 764 765 771 private void initComponents() { 773 panel = new javax.swing.JPanel (); 774 nameLabel = new javax.swing.JLabel (); 775 tableNameLabel = new javax.swing.JLabel (); 776 pKeyLabel = new javax.swing.JLabel (); 777 pKeyTypeLabel = new javax.swing.JLabel (); 778 desciptionLabel = new javax.swing.JLabel (); 779 rootPackageLabel = new javax.swing.JLabel (); 780 refNameLabel = new javax.swing.JLabel (); 781 nameText = new javax.swing.JTextField (); 782 tableNameText = new javax.swing.JTextField (); 783 pKeyText = new javax.swing.JTextField (); 784 pKeyTypeText = new javax.swing.JTextField (); 785 descriptionText = new javax.swing.JTextField (); 786 rootPackageText = new javax.swing.JTextField (); 787 refNameText = new javax.swing.JTextField (); 788 isCompositeLabel = new javax.swing.JLabel (); 789 isCompositeCombo = new javax.swing.JComboBox (); 790 nameLabel1 = new javax.swing.JLabel (); 791 displayNameText = new javax.swing.JTextField (); 792 isCompositeLabel1 = new javax.swing.JLabel (); 793 isAssociationEntity = new javax.swing.JComboBox (); 794 795 panel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); 796 797 nameLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); 798 nameLabel.setText("Name: "); 799 nameLabel.setToolTipText("Name of the entity"); 800 panel.add(nameLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, 90, -1)); 801 802 tableNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); 803 tableNameLabel.setText("Table name: "); 804 tableNameLabel.setToolTipText("Physical table name the entity is mapped to"); 805 panel.add(tableNameLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 70, 90, -1)); 806 807 pKeyLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); 808 pKeyLabel.setText("Primary key: "); 809 pKeyLabel.setToolTipText("Primary key field of the entity"); 810 panel.add(pKeyLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 100, 90, -1)); 811 812 pKeyTypeLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); 813 pKeyTypeLabel.setText("Primary key class: "); 814 pKeyTypeLabel.setToolTipText("Primary key class in case of a composite key"); 815 panel.add(pKeyTypeLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 130, 110, -1)); 816 817 desciptionLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); 818 desciptionLabel.setText("Description: "); 819 desciptionLabel.setToolTipText("Description of the entity"); 820 panel.add(desciptionLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 220, 90, -1)); 821 822 rootPackageLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); 823 rootPackageLabel.setText("Root-package: "); 824 rootPackageLabel.setToolTipText("Root package for the entity"); 825 panel.add(rootPackageLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 250, 90, -1)); 826 827 refNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); 828 refNameLabel.setText("Ref-name: "); 829 refNameLabel.setToolTipText("Reference name for the entity"); 830 panel.add(refNameLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 280, 90, -1)); 831 832 nameText.setToolTipText("Name of the entity"); 833 nameText.addActionListener(new java.awt.event.ActionListener () { 834 public void actionPerformed(java.awt.event.ActionEvent evt) { 835 nameTextActionPerformed(evt); 836 } 837 }); 838 nameText.addFocusListener(new java.awt.event.FocusAdapter () { 839 public void focusLost(java.awt.event.FocusEvent evt) { 840 nameTextFocusLost(evt); 841 } 842 }); 843 844 panel.add(nameText, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 10, 260, -1)); 845 846 tableNameText.setToolTipText("Physical table name the entity is mapped to"); 847 tableNameText.addFocusListener(new java.awt.event.FocusAdapter () { 848 public void focusLost(java.awt.event.FocusEvent evt) { 849 tableNameTextFocusLost(evt); 850 } 851 }); 852 853 panel.add(tableNameText, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 70, 260, -1)); 854 855 pKeyText.setToolTipText("Primary key field of the entity"); 856 pKeyText.addFocusListener(new java.awt.event.FocusAdapter () { 857 public void focusLost(java.awt.event.FocusEvent evt) { 858 pKeyTextFocusLost(evt); 859 } 860 }); 861 862 panel.add(pKeyText, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 100, 260, -1)); 863 864 pKeyTypeText.setToolTipText("Primary key class in case of a composite key"); 865 pKeyTypeText.addFocusListener(new java.awt.event.FocusAdapter () { 866 public void focusLost(java.awt.event.FocusEvent evt) { 867 pKeyTypeTextFocusLost(evt); 868 } 869 }); 870 871 panel.add(pKeyTypeText, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 130, 260, -1)); 872 873 descriptionText.setToolTipText("Description of the entity"); 874 descriptionText.addFocusListener(new java.awt.event.FocusAdapter () { 875 public void focusLost(java.awt.event.FocusEvent evt) { 876 descriptionTextFocusLost(evt); 877 } 878 }); 879 880 panel.add(descriptionText, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 220, 260, -1)); 881 882 rootPackageText.setToolTipText("Root package for the entity"); 883 rootPackageText.addFocusListener(new java.awt.event.FocusAdapter () { 884 public void focusLost(java.awt.event.FocusEvent evt) { 885 rootPackageTextFocusLost(evt); 886 } 887 }); 888 889 panel.add(rootPackageText, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 250, 260, -1)); 890 891 refNameText.setToolTipText("Reference name for the entity"); 892 refNameText.addFocusListener(new java.awt.event.FocusAdapter () { 893 public void focusLost(java.awt.event.FocusEvent evt) { 894 refNameTextFocusLost(evt); 895 } 896 }); 897 refNameText.addMouseListener(new java.awt.event.MouseAdapter () { 898 public void mouseReleased(java.awt.event.MouseEvent evt) { 899 refNameTextMouseReleased(evt); 900 } 901 }); 902 refNameText.addHierarchyListener(new java.awt.event.HierarchyListener () { 903 public void hierarchyChanged(java.awt.event.HierarchyEvent evt) { 904 refNameTextHierarchyChanged(evt); 905 } 906 }); 907 908 panel.add(refNameText, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 280, 260, -1)); 909 910 isCompositeLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); 911 isCompositeLabel.setText("Composite key:"); 912 isCompositeLabel.setToolTipText("Set to true in case of a composite key"); 913 panel.add(isCompositeLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 190, 110, -1)); 914 915 isCompositeCombo.setModel(new javax.swing.DefaultComboBoxModel (new String [] { "false", "true" })); 916 isCompositeCombo.setToolTipText("Set to true in case of a composite key"); 917 isCompositeCombo.addActionListener(new java.awt.event.ActionListener () { 918 public void actionPerformed(java.awt.event.ActionEvent evt) { 919 isCompositeComboActionPerformed(evt); 920 } 921 }); 922 923 panel.add(isCompositeCombo, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 190, 260, -1)); 924 925 nameLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); 926 nameLabel1.setText("Display name: "); 927 nameLabel1.setToolTipText("Display name for the entity. Should be one of the entity fields."); 928 panel.add(nameLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 40, 90, -1)); 929 930 displayNameText.setToolTipText("Display name for the entity"); 931 panel.add(displayNameText, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 40, 260, -1)); 932 933 isCompositeLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); 934 isCompositeLabel1.setText("Association entity:"); 935 isCompositeLabel1.setToolTipText("Entity used for many to many relations"); 936 panel.add(isCompositeLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 160, 110, -1)); 937 938 isAssociationEntity.setModel(new javax.swing.DefaultComboBoxModel (new String [] { "false", "true" })); 939 isAssociationEntity.setToolTipText("Entity used for many to many relations"); 940 isAssociationEntity.addActionListener(new java.awt.event.ActionListener () { 941 public void actionPerformed(java.awt.event.ActionEvent evt) { 942 isAssociationEntityActionPerformed(evt); 943 } 944 }); 945 946 panel.add(isAssociationEntity, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 160, 260, -1)); 947 948 } 950 private void isAssociationEntityActionPerformed(java.awt.event.ActionEvent evt) { if ("true".equals(this.isAssociationEntity.getSelectedItem().toString())) { 952 this.pKeyTypeText.setEnabled(false); 953 this.pKeyText.setEnabled(false); 954 this.isCompositeCombo.setEnabled(false); 955 } else { 956 this.pKeyText.setEnabled(true); 957 this.pKeyTypeText.setEnabled(true); 958 this.isCompositeCombo.setEnabled(true); 959 } 960 } 962 private void nameTextActionPerformed(java.awt.event.ActionEvent evt) { } 966 private void refNameTextHierarchyChanged(java.awt.event.HierarchyEvent evt) { } 970 private void refNameTextMouseReleased(java.awt.event.MouseEvent evt) { } 974 private void refNameTextFocusLost(java.awt.event.FocusEvent evt) { System.out.println("Focus was lost for refname"); 976 JagGenerator.stateChanged(true); 977 } 979 private void rootPackageTextFocusLost(java.awt.event.FocusEvent evt) { JagGenerator.stateChanged(false); 981 } 983 private void descriptionTextFocusLost(java.awt.event.FocusEvent evt) { JagGenerator.stateChanged(false); 985 } 987 private void isCompositeComboActionPerformed(java.awt.event.ActionEvent evt) { JagGenerator.stateChanged(false); 989 } 991 private void pKeyTypeTextFocusLost(java.awt.event.FocusEvent evt) { JagGenerator.stateChanged(false); 993 } 995 private void pKeyTextFocusLost(java.awt.event.FocusEvent evt) { JagGenerator.stateChanged(false); 997 } 999 private void tableNameTextFocusLost(java.awt.event.FocusEvent evt) { JagGenerator.stateChanged(false); 1001 JagGenerator.entityHasupdatedTableName(nameText.getText(), tableNameText.getText()); 1002 } 1004 private void nameTextFocusLost(java.awt.event.FocusEvent evt) { evt = null; 1007 if ((nameText.getText() != null) && (nameText.getText().length() > 0)) { 1008 nameText.setText(Utils.initCap(nameText.getText())); 1009 if ((refNameText.getText() == null) || (refNameText.getText().length() == 0)) { 1010 refNameText.setText(nameText.getText()); 1012 } 1013 } 1014 JagGenerator.stateChanged(true); 1015 } 1017 private javax.swing.JLabel desciptionLabel; 1019 private javax.swing.JTextField descriptionText; 1020 public javax.swing.JTextField displayNameText; 1021 public javax.swing.JComboBox isAssociationEntity; 1022 public javax.swing.JComboBox isCompositeCombo; 1023 private javax.swing.JLabel isCompositeLabel; 1024 private javax.swing.JLabel isCompositeLabel1; 1025 private javax.swing.JLabel nameLabel; 1026 private javax.swing.JLabel nameLabel1; 1027 public javax.swing.JTextField nameText; 1028 private javax.swing.JLabel pKeyLabel; 1029 public javax.swing.JTextField pKeyText; 1030 private javax.swing.JLabel pKeyTypeLabel; 1031 public javax.swing.JTextField pKeyTypeText; 1032 private javax.swing.JPanel panel; 1033 private javax.swing.JLabel refNameLabel; 1034 private javax.swing.JTextField refNameText; 1035 private javax.swing.JLabel rootPackageLabel; 1036 public javax.swing.JTextField rootPackageText; 1037 private javax.swing.JLabel tableNameLabel; 1038 private javax.swing.JTextField tableNameText; 1039 } 1041 1042 | Popular Tags |