View Javadoc

1   /*   Copyright (C) 2003 Finalist IT Group
2    *
3    *   This file is part of JAG - the Java J2EE Application Generator
4    *
5    *   JAG is free software; you can redistribute it and/or modify
6    *   it under the terms of the GNU General Public License as published by
7    *   the Free Software Foundation; either version 2 of the License, or
8    *   (at your option) any later version.
9    *   JAG is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   *   GNU General Public License for more details.
13   *   You should have received a copy of the GNU General Public License
14   *   along with JAG; if not, write to the Free Software
15   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16   */
17  
18  package com.finalist.jaggenerator.modules;
19  
20  import com.finalist.jaggenerator.*;
21  import com.finalist.jag.util.TemplateString;
22  
23  import java.util.*;
24  import java.awt.event.ActionListener;
25  import java.awt.event.ActionEvent;
26  import javax.swing.*;
27  import javax.swing.tree.*;
28  import javax.xml.parsers.*;
29  
30  import org.w3c.dom.*;
31  import org.apache.commons.logging.Log;
32  import org.apache.commons.logging.LogFactory;
33  
34  /***
35   *
36   * @author  hillie
37   */
38  public class Entity extends DefaultMutableTreeNode implements JagBean, ActionListener {
39     private boolean relationsEnabled;
40     static Log log = LogFactory.getLog(JagGenerator.class);
41  
42     /*** Creates new form BeanForm */
43     public Entity(String rootPackage, String tableName, String pKey) {
44        initComponents();
45        String tableClassName = Utils.toClassName(tableName);
46        rootPackageText.setText(rootPackage + ".entity." + tableClassName.toLowerCase());
47        tableNameText.setText(tableName);
48        nameText.setText(tableClassName);
49        descriptionText.setText(tableClassName);
50        refNameText.setText(tableClassName);
51        pKeyText.setText(pKey);
52        JagGenerator.addEntity(getRefName(), this);
53        //a little sequencing hack.. the last-created relation can still be initialising itself when
54        //this point is reached - so we pause here a little while: otherwise we'll notify before it begins waiting!
55        synchronized(this) {
56           try {
57              wait(100);
58           } catch (InterruptedException e) {}
59        }
60        notifyRelationsThatConstructionIsFinished();
61        SelectTablesDialog.getAlreadyselected().add(tableName);
62     }
63  
64     public Entity(Element el) {
65        relationsEnabled = !JagGenerator.isRelationsEnabled();
66        initComponents();
67        NodeList nl = el.getChildNodes();
68        for (int i = 0; i < nl.getLength(); i++) {
69           Node n = nl.item(i);
70           if (n.getNodeType() == n.ELEMENT_NODE) {
71              Element child = (Element) n;
72              String attName = child.getAttribute("name");
73              try {
74                 Node first = child.getFirstChild();
75                 if (first == null) continue;
76                 String value = first.getNodeValue();
77                 if (value != null) {
78                    if (attName.equalsIgnoreCase("name")) {
79                       nameText.setText(value);
80                       continue;
81                    }
82                    if (attName.equalsIgnoreCase("description")) {
83                       descriptionText.setText(value);
84                       continue;
85                    }
86                    if (attName.equalsIgnoreCase("root-package")) {
87                       rootPackageText.setText(value);
88                       continue;
89                    }
90                    if (attName.equalsIgnoreCase("table-name")) {
91                       tableNameText.setText(value);
92                       SelectTablesDialog.getAlreadyselected().add(value);
93                       continue;
94                    }
95                    if (attName.equalsIgnoreCase("primary-key")) {
96                       pKeyText.setText(value);
97                       continue;
98                    }
99                    if (attName.equalsIgnoreCase("primary-key-type")) {
100                      pKeyTypeText.setText(value);
101                      continue;
102                   }
103                   if (attName.equalsIgnoreCase("is-composite")) {
104                      isCompositeCombo.setSelectedItem(value);
105                      continue;
106                   }
107                   if (attName.equalsIgnoreCase("field")) {
108                      add(new Field(this, child));
109                      continue;
110                   }
111                   if (attName.equalsIgnoreCase("relation")) {
112                      if (warningNeeded()) {
113                         JOptionPane.showMessageDialog(getPanel(),
114                               "The application file you have opened contains relations, but you have disabled relations support. \n" +
115                               "If you later save this file or generate an application from this file, the original relations information will be lost.\n" +
116                               "\n" +
117                               "To avoid this, either enable relations support (Options->Enable relations) and re-open the file, or save the file under a different name.",
118                               "Container-managed relations disabled!",
119                               JOptionPane.INFORMATION_MESSAGE);
120                      } else if (relationsEnabled) {
121                         add(new Relation(this, child));
122                         continue;
123                      }
124                   }
125                }
126             } catch (Exception e) {
127                e.printStackTrace();
128                JagGenerator.logToConsole("Error constructing " + this.toString() + ": " + e);
129             }
130          }
131       }
132       nl = el.getElementsByTagName("ref-name");
133       if (nl.getLength() > 0) {
134          Node node = nl.item(0).getFirstChild();
135          if (node != null) {
136             refNameText.setText(node.getNodeValue());
137          }
138       }
139 
140       JagGenerator.addEntity(getRefName(), this);
141 
142       //a little sequencing hack.. the last-created relation can still be initialising itself when
143       //this point is reached - so we pause here a little while: otherwise we'll notify before it begins waiting!
144       synchronized(this) {
145          try {
146             wait(100);
147          } catch (InterruptedException e) {}
148       }
149       notifyRelationsThatConstructionIsFinished();
150    }
151 
152 
153    public JPanel getPanel() {
154       return panel;
155    }
156 
157    public String getRefName() {
158       return refNameText.getText();
159    }
160 
161    public void setRefName(String text) {
162       refNameText.setText(text);
163    }
164 
165 
166    public void setPKeyType(String pKeyType) {
167       pKeyTypeText.setText(pKeyType);
168    }
169 
170    public void getXML(Element el) throws ParserConfigurationException {
171       Document doc = el.getOwnerDocument();
172       Element module = doc.createElement("module");
173       module.setAttribute("name", "entity");
174 
175       Element name = doc.createElement("module-data");
176       name.setAttribute("name", "name");
177       if (nameText.getText() != null) {
178         name.appendChild(doc.createTextNode(nameText.getText()));
179       }
180       module.appendChild(name);
181 
182       Element description = doc.createElement("module-data");
183       description.setAttribute("name", "description");
184       if (descriptionText.getText() != null) {
185         description.appendChild(doc.createTextNode(descriptionText.getText()));
186       }
187       module.appendChild(description);
188 
189       Element rootPackage = doc.createElement("module-data");
190       rootPackage.setAttribute("name", "root-package");
191       if (rootPackageText.getText() != null) {
192         rootPackage.appendChild(doc.createTextNode(rootPackageText.getText()));
193       }
194       module.appendChild(rootPackage);
195 
196       Element tableName = doc.createElement("module-data");
197       tableName.setAttribute("name", "table-name");
198       if (tableNameText.getText() != null) {
199           tableName.appendChild(doc.createTextNode(tableNameText.getText()));
200       }
201       module.appendChild(tableName);
202 
203       Element pKey = doc.createElement("module-data");
204       pKey.setAttribute("name", "primary-key");
205       pKey.appendChild(doc.createTextNode((isCompositeKey() ? "" : pKeyText.getText())));
206       module.appendChild(pKey);
207 
208       Element pKeyType = doc.createElement("module-data");
209       pKeyType.setAttribute("name", "primary-key-type");
210       if (pKeyTypeText.getText() != null) {
211         pKeyType.appendChild(doc.createTextNode(pKeyTypeText.getText()));
212       }
213       module.appendChild(pKeyType);
214       Element isComposite = doc.createElement("module-data");
215       isComposite.setAttribute("name", "is-composite");
216       isComposite.appendChild(doc.createTextNode((String) isCompositeCombo.getSelectedItem()));
217       module.appendChild(isComposite);
218 
219       Element refName = doc.createElement("ref-name");
220       if (refNameText.getText() != null) {
221         refName.appendChild(doc.createTextNode(refNameText.getText()));
222       }
223       module.appendChild(refName);
224 
225       //..and finally getXML() from the children: fields and relations
226       Enumeration children = children();
227       while (children.hasMoreElements()) {
228          JagBean child = (JagBean) children.nextElement();
229          child.getXML(module);
230       }
231 
232       el.appendChild(module);
233    }
234 
235    public TemplateString getName() {
236       return new TemplateString(nameText.getText());
237    }
238 
239    public void setName(String text) {
240       nameText.setText(text);
241    }
242 
243    public TemplateString getDescription() {
244       return new TemplateString(descriptionText.getText());
245    }
246 
247    public void setDescription(String text) {
248       descriptionText.setText(text);
249    }
250 
251    public TemplateString getRootPackage() {
252       return new TemplateString(rootPackageText.getText());
253    }
254 
255    public void setRootPackage(String text) {
256       rootPackageText.setText(text);
257    }
258 
259 
260    public Field getPrimaryKey() {
261       return isCompositeKey() ? null : (Field) getPkFields().get(0);
262    }
263 
264    /***
265     * Called by a field when it has been selected as primary key in the GUI.
266     *
267     * @param field
268     */
269    public void setPrimaryKey(Field field) {
270       if ("false".equals(isCompositeCombo.getSelectedItem())) {
271          if ("".equals(pKeyText.getText())) {
272             pKeyText.setText(field.getName().toString());
273             pKeyTypeText.setText(field.getType().toString());
274 
275          } else {
276             isCompositeCombo.setSelectedItem("true");
277             pKeyText.setText("");
278             pKeyTypeText.setText(rootPackageText.getText() + '.' + getName() + "PK");
279          }
280       }
281    }
282 
283    /***
284     * Called by a field when it has been de-selected as primary key in the GUI.
285     *
286     * @param field
287     */
288    public void unsetPrimaryKey(Field field) {
289       if ("false".equals(isCompositeCombo.getSelectedItem())) {
290          pKeyText.setText("");
291          pKeyTypeText.setText("");
292 
293       } else {
294          List pkFields = getPkFields();
295          if (pkFields.size() == 1) {
296             isCompositeCombo.setSelectedItem("false");
297             pKeyText.setText(((Field) pkFields.get(0)).getName().toString());
298             pKeyTypeText.setText(((Field) pkFields.get(0)).getType().toString());
299          }
300       }
301    }
302 
303   public TemplateString getPrimaryKeyType() {
304      return new TemplateString(pKeyTypeText.getText());
305   }
306 
307   public TemplateString getPrimaryKeyName() {
308       return new TemplateString(pKeyText.getText());
309   }
310 
311    public String getIsComposite() {
312       return (String) isCompositeCombo.getSelectedItem();
313    }
314 
315    public void setIsComposite(String composite) {
316       isCompositeCombo.setSelectedItem(composite);
317    }
318 
319    public String getRootPath() {
320       return getRootPackage().toString().replace('.', '/');
321    }
322 
323    public List getRelations() {
324       ArrayList relations = new ArrayList();
325       Enumeration children = children();
326       while (children.hasMoreElements()) {
327          JagBean child = (JagBean) children.nextElement();
328          if (child instanceof Relation) {
329             relations.add(child);
330          }
331       }
332       return relations;
333    }
334 
335    /*** Get a list of all Relations to this entity.
336     *
337     * @return list with relations.
338     */
339    public List getEntitiesRelations() {
340       ArrayList result = new ArrayList();
341       List entities = JagGenerator.getObjectsFromTree(Entity.class);
342       for (int i = 0; i < entities.size(); i++) {
343          Entity relatedEntity = (Entity) entities.get(i);
344          List relations = relatedEntity.getRelations();
345          for (int j=0; j < relations.size(); j++) {
346             Relation rel = (Relation) relations.get(j);
347             Entity en = rel.getRelatedEntity();
348             if (en.getName().equals(this.getName())) {
349                result.add(rel);
350             }
351          }
352       }
353       return result;
354    }
355 
356    public List getRelatedEntities() {
357       ArrayList relatedEntities = new ArrayList();
358       Enumeration children = children();
359       while (children.hasMoreElements()) {
360          JagBean child = (JagBean) children.nextElement();
361          if (child instanceof Relation) {
362             relatedEntities.add(((Relation) child).getRelatedEntity());
363          }
364       }
365       return relatedEntities;
366    }
367 
368    /***
369     * Gets the set of field names within this entity, which are used as relations to other CMR-related entity beans.
370     * @return a Set of TemplateString objects.
371     */
372    public List getRelationFieldNames() {
373       ArrayList relationFieldNames = new ArrayList();
374       Enumeration children = children();
375       while (children.hasMoreElements()) {
376          JagBean child = (JagBean) children.nextElement();
377          if (child instanceof Relation) {
378             relationFieldNames.add(((Relation) child).getFieldName());
379          }
380       }
381       return relationFieldNames;
382    }
383 
384    public boolean getHasRelations() {
385       return !getRelations().isEmpty();
386    }
387 
388    public List getFields() {
389       ArrayList fields = new ArrayList();
390       Enumeration children = children();
391       while (children.hasMoreElements()) {
392          JagBean child = (JagBean) children.nextElement();
393          if (child instanceof Field) {
394             fields.add(child);
395          }
396       }
397       return fields;
398    }
399 
400    public List getNonFkFields() {
401       ArrayList fields = new ArrayList();
402       Enumeration children = children();
403       while (children.hasMoreElements()) {
404          JagBean child = (JagBean) children.nextElement();
405          if (child instanceof Field &&
406                !((Field) child).isForeignKey()) {
407             fields.add(child);
408          }
409       }
410       return fields;
411    }
412 
413    public List getFkFields() {
414        ArrayList fields = new ArrayList();
415        Enumeration children = children();
416        while (children.hasMoreElements()) {
417           JagBean child = (JagBean) children.nextElement();
418           if (child instanceof Field &&
419                 ((Field) child).isForeignKey()) {
420              fields.add(child);
421           }
422        }
423        return fields;
424     }
425 
426 
427    public List getNonRelationFields() {
428       ArrayList fields = new ArrayList();
429       Enumeration children = children();
430       while (children.hasMoreElements()) {
431          JagBean child = (JagBean) children.nextElement();
432          if (child instanceof Field &&
433                (((Field) child).getRelation() == null)) {
434             fields.add(child);
435          }
436       }
437       return fields;
438    }
439 
440    public List getPkFields() {
441       ArrayList fields = new ArrayList();
442       Enumeration children = children();
443       while (children.hasMoreElements()) {
444          JagBean child = (JagBean) children.nextElement();
445          if (child instanceof Field &&
446                ((Field) child).isPrimaryKey()) {
447             fields.add(child);
448          }
449       }
450       return fields;
451    }
452 
453    public List getNonPkFields() {
454       List nonPkFields = getFields();
455       nonPkFields.removeAll(getPkFields());
456       return nonPkFields;
457    }
458 
459    /***
460     * Gets the fields that are neither primary keys, nor a foreign key involved in a container-managed relation.
461     * @return
462     */
463    public List getNonPkRelationFields() {
464       List nonPkRelationFields = getNonRelationFields();
465       nonPkRelationFields.removeAll(getPkFields());
466       return nonPkRelationFields;
467    }
468 
469    /***
470     * Iterates over all the table columns and determines whether the table has a single key or a composite key. The
471     * key is said to be composite when more than one column is part of the key.
472     *
473     * @return <code>true</code> only when more the table has a composite key else <code>false</code>
474     */
475    public boolean isCompositeKey() {
476       int countPrimaryKeys = countPrimaryKeyFields();
477       return countPrimaryKeys > 1;
478    }
479 
480    /***
481     * Count the number of primary key fields.
482     *
483     * @return <code>int</code> with the number of primary keys
484     */
485    public int countPrimaryKeyFields() {
486       Enumeration children = children();
487       JagBean bean = null;
488       Field field = null;
489       int countPrimaryKeys = 0;
490       while (children.hasMoreElements()) {
491          bean = (JagBean) children.nextElement();
492          if (bean instanceof Field) {
493             field = (Field) bean;
494             if (field.isPrimaryKey()) countPrimaryKeys++;
495          }
496       }
497       return countPrimaryKeys;
498    }
499 
500    /***
501     * Returns the class that represents the primary key type
502     *
503     * @return the class that represents the primary key type
504     */
505    public String getPrimaryKeyClass() {
506       Enumeration children = children();
507       JagBean bean = null;
508       Field field = null;
509       String getPrimaryKeyClass = null;
510       while (children.hasMoreElements()) {
511          bean = (JagBean) children.nextElement();
512          if (bean instanceof Field) {
513             field = (Field) bean;
514             if (field.isPrimaryKey()) getPrimaryKeyClass = field.getType();
515          }
516       }
517       return getPrimaryKeyClass;
518    }
519 
520    /***
521     * Returns the First primary key field
522     *
523     * @return the field name of the first primary key field or an empty string if nothing was found.
524     */
525    public String getFirstPrimaryKeyFieldName() {
526       Enumeration children = children();
527       JagBean bean = null;
528       Field field = null;
529       String getPrimaryKeyFieldName = "";
530       while (children.hasMoreElements()) {
531          bean = (JagBean) children.nextElement();
532          if (bean instanceof Field) {
533             field = (Field) bean;
534             if (field.isPrimaryKey()) getPrimaryKeyFieldName = field.getName().toString();
535          }
536       }
537       return getPrimaryKeyFieldName;
538    }
539 
540    public void actionPerformed(ActionEvent e) {
541       if (e.getActionCommand().equals("GET_PRIMARY_KEY")) {
542          String key = null;
543          if (isCompositeKey())
544             key = rootPackageText.getText() + "." + nameText.getText() + "PK";
545          else
546             key = getPrimaryKeyClass();
547          pKeyTypeText.setText(key);
548       }
549    }
550 
551    /***
552     * Gets the name of the table represented by this Entity.
553     * @return the table name.
554     */
555    public TemplateString getLocalTableName() {
556       return new TemplateString(tableNameText.getText());
557    }
558 
559    public void setTableName(String table) {
560       tableNameText.setText(table);
561    }
562 
563    public String getTableName() {
564       return tableNameText.getText();
565    }
566 
567    /***
568     * While an entity is being created, its constituent relations have to wait for the entity to finish being
569     * constructed before they can finish initialising themselves.  Call this method when the Entity is ready.
570     */
571    public void notifyRelationsThatConstructionIsFinished() {
572       Iterator relations = getRelations().iterator();
573       while (relations.hasNext()) {
574          Relation relation = (Relation) relations.next();
575          relation.notifyLocalEntityIsComplete();
576       }
577    }
578 
579    /***
580     * When a field name is changed, call this to tell all relations to update their lists.
581     * @param oldName
582     * @param text
583     */
584    public void notifyRelationsThatFieldNameChanged(String oldName, String text) {
585       Iterator relations = getRelations().iterator();
586       while (relations.hasNext()) {
587          Relation relation = (Relation) relations.next();
588          relation.notifyFieldNameChanged(oldName, text);
589       }
590 
591    }
592    public String toString() {
593       return "Entity - " + getRefName();
594    }
595 
596    /***
597     * Inserts a relation in the correct position (relations are always positioned first
598     * amongst an Entity's children, because it looks nicer!).
599     * @param relation
600     */
601    public void addRelation(Relation relation) {
602       TreeNode lastRelly = null;
603       Enumeration kids = children();
604       while (kids.hasMoreElements()) {
605          TreeNode kid = (TreeNode) kids.nextElement();
606          if (kid instanceof Relation) {
607             lastRelly = kid;
608          }
609       }
610       int insertPos = 0;
611       if (lastRelly == null) {
612          insertPos = getIndex(getFirstChild());
613       } else {
614          insertPos = getIndex(lastRelly) + 1;
615       }
616       insert(relation, insertPos);
617    }
618 
619    private boolean warningNeeded() {
620       if (relationsEnabled != JagGenerator.isRelationsEnabled()) {
621          relationsEnabled = JagGenerator.isRelationsEnabled();
622          return !relationsEnabled;
623       }
624       return false;
625    }
626 
627    /*** This method is called from within the constructor to
628     * initialize the form.
629     * WARNING: Do NOT modify this code. The content of this method is
630     * always regenerated by the Form Editor.
631     */
632     private void initComponents() {//GEN-BEGIN:initComponents
633         panel = new javax.swing.JPanel();
634         nameLabel = new javax.swing.JLabel();
635         tableNameLabel = new javax.swing.JLabel();
636         pKeyLabel = new javax.swing.JLabel();
637         pKeyTypeLabel = new javax.swing.JLabel();
638         desciptionLabel = new javax.swing.JLabel();
639         rootPackageLabel = new javax.swing.JLabel();
640         refNameLabel = new javax.swing.JLabel();
641         nameText = new javax.swing.JTextField();
642         tableNameText = new javax.swing.JTextField();
643         pKeyText = new javax.swing.JTextField();
644         pKeyTypeText = new javax.swing.JTextField();
645         descriptionText = new javax.swing.JTextField();
646         rootPackageText = new javax.swing.JTextField();
647         refNameText = new javax.swing.JTextField();
648         isCompositeLabel = new javax.swing.JLabel();
649         isCompositeCombo = new javax.swing.JComboBox();
650 
651         panel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
652 
653         nameLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
654         nameLabel.setText("Name: ");
655         panel.add(nameLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, 90, -1));
656 
657         tableNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
658         tableNameLabel.setText("Table name: ");
659         panel.add(tableNameLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 40, 90, -1));
660 
661         pKeyLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
662         pKeyLabel.setText("Primary key: ");
663         panel.add(pKeyLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 70, 90, -1));
664 
665         pKeyTypeLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
666         pKeyTypeLabel.setText("Primary key class: ");
667         panel.add(pKeyTypeLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 100, 110, -1));
668 
669         desciptionLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
670         desciptionLabel.setText("Description: ");
671         panel.add(desciptionLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 160, 90, -1));
672 
673         rootPackageLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
674         rootPackageLabel.setText("Root-package: ");
675         panel.add(rootPackageLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 190, 90, -1));
676 
677         refNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
678         refNameLabel.setText("Ref-name: ");
679         panel.add(refNameLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 220, 90, -1));
680 
681         nameText.addFocusListener(new java.awt.event.FocusAdapter() {
682             public void focusLost(java.awt.event.FocusEvent evt) {
683                 nameTextFocusLost(evt);
684             }
685         });
686 
687         panel.add(nameText, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 10, 260, -1));
688 
689         tableNameText.addFocusListener(new java.awt.event.FocusAdapter() {
690             public void focusLost(java.awt.event.FocusEvent evt) {
691                 tableNameTextFocusLost(evt);
692             }
693         });
694 
695         panel.add(tableNameText, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 40, 260, -1));
696 
697         pKeyText.addFocusListener(new java.awt.event.FocusAdapter() {
698             public void focusLost(java.awt.event.FocusEvent evt) {
699                 pKeyTextFocusLost(evt);
700             }
701         });
702 
703         panel.add(pKeyText, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 70, 260, -1));
704 
705         pKeyTypeText.addFocusListener(new java.awt.event.FocusAdapter() {
706             public void focusLost(java.awt.event.FocusEvent evt) {
707                 pKeyTypeTextFocusLost(evt);
708             }
709         });
710 
711         panel.add(pKeyTypeText, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 100, 260, -1));
712 
713         descriptionText.addFocusListener(new java.awt.event.FocusAdapter() {
714             public void focusLost(java.awt.event.FocusEvent evt) {
715                 descriptionTextFocusLost(evt);
716             }
717         });
718 
719         panel.add(descriptionText, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 160, 260, -1));
720 
721         rootPackageText.addFocusListener(new java.awt.event.FocusAdapter() {
722             public void focusLost(java.awt.event.FocusEvent evt) {
723                 rootPackageTextFocusLost(evt);
724             }
725         });
726 
727         panel.add(rootPackageText, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 190, 260, -1));
728 
729         refNameText.addFocusListener(new java.awt.event.FocusAdapter() {
730             public void focusLost(java.awt.event.FocusEvent evt) {
731                 refNameTextFocusLost(evt);
732             }
733         });
734         refNameText.addMouseListener(new java.awt.event.MouseAdapter() {
735             public void mouseReleased(java.awt.event.MouseEvent evt) {
736                 refNameTextMouseReleased(evt);
737             }
738         });
739         refNameText.addHierarchyListener(new java.awt.event.HierarchyListener() {
740             public void hierarchyChanged(java.awt.event.HierarchyEvent evt) {
741                 refNameTextHierarchyChanged(evt);
742             }
743         });
744 
745         panel.add(refNameText, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 220, 260, -1));
746 
747         isCompositeLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
748         isCompositeLabel.setText("Composite key:");
749         panel.add(isCompositeLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 130, 110, -1));
750 
751         isCompositeCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "false", "true" }));
752         isCompositeCombo.addActionListener(new java.awt.event.ActionListener() {
753             public void actionPerformed(java.awt.event.ActionEvent evt) {
754                 isCompositeComboActionPerformed(evt);
755             }
756         });
757 
758         panel.add(isCompositeCombo, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 130, 260, -1));
759 
760     }//GEN-END:initComponents
761 
762     private void refNameTextHierarchyChanged(java.awt.event.HierarchyEvent evt) {//GEN-FIRST:event_refNameTextHierarchyChanged
763         // TODO add your handling code here:
764     }//GEN-LAST:event_refNameTextHierarchyChanged
765 
766     private void refNameTextMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_refNameTextMouseReleased
767         // TODO add your handling code here:
768     }//GEN-LAST:event_refNameTextMouseReleased
769 
770    private void refNameTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_refNameTextFocusLost
771       System.out.println("Focus was lost for refname" );
772        JagGenerator.stateChanged(true);
773    }//GEN-LAST:event_refNameTextFocusLost
774 
775    private void rootPackageTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_rootPackageTextFocusLost
776       JagGenerator.stateChanged(false);
777    }//GEN-LAST:event_rootPackageTextFocusLost
778 
779    private void descriptionTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_descriptionTextFocusLost
780       JagGenerator.stateChanged(false);
781    }//GEN-LAST:event_descriptionTextFocusLost
782 
783    private void isCompositeComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_isCompositeComboActionPerformed
784       JagGenerator.stateChanged(false);
785    }//GEN-LAST:event_isCompositeComboActionPerformed
786 
787    private void pKeyTypeTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_pKeyTypeTextFocusLost
788       JagGenerator.stateChanged(false);
789    }//GEN-LAST:event_pKeyTypeTextFocusLost
790 
791    private void pKeyTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_pKeyTextFocusLost
792       JagGenerator.stateChanged(false);
793    }//GEN-LAST:event_pKeyTextFocusLost
794 
795    private void tableNameTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tableNameTextFocusLost
796       JagGenerator.stateChanged(false);
797       JagGenerator.entityHasupdatedTableName(nameText.getText(), tableNameText.getText());
798    }//GEN-LAST:event_tableNameTextFocusLost
799 
800    private void nameTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_nameTextFocusLost
801       // Add your handling code here:
802       evt = null;
803       if ((nameText.getText() != null) && (nameText.getText().length() > 0)) {
804          nameText.setText(Utils.initCap(nameText.getText()));
805          if ((refNameText.getText() == null) || (refNameText.getText().length() == 0)) {         
806              // Only change the refname, if it hasn't been set before.
807             refNameText.setText(nameText.getText());
808          }
809       }
810       JagGenerator.stateChanged(true);
811    }//GEN-LAST:event_nameTextFocusLost
812 
813     // Variables declaration - do not modify//GEN-BEGIN:variables
814     private javax.swing.JLabel desciptionLabel;
815     private javax.swing.JTextField descriptionText;
816     public javax.swing.JComboBox isCompositeCombo;
817     private javax.swing.JLabel isCompositeLabel;
818     private javax.swing.JLabel nameLabel;
819     public javax.swing.JTextField nameText;
820     private javax.swing.JLabel pKeyLabel;
821     public javax.swing.JTextField pKeyText;
822     private javax.swing.JLabel pKeyTypeLabel;
823     public javax.swing.JTextField pKeyTypeText;
824     private javax.swing.JPanel panel;
825     private javax.swing.JLabel refNameLabel;
826     private javax.swing.JTextField refNameText;
827     private javax.swing.JLabel rootPackageLabel;
828     public javax.swing.JTextField rootPackageText;
829     private javax.swing.JLabel tableNameLabel;
830     private javax.swing.JTextField tableNameText;
831     // End of variables declaration//GEN-END:variables
832 }
833