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;
19  
20  import com.finalist.jag.JApplicationGen;
21  import com.finalist.jag.uml.Jag2UMLGenerator;
22  import com.finalist.jag.uml.UML2JagGenerator;
23  import com.finalist.jag.util.TemplateString;
24  import com.finalist.jaggenerator.modules.*;
25  import com.finalist.jaggenerator.template.Template;
26  import org.w3c.dom.Document;
27  import org.w3c.dom.Element;
28  import org.apache.commons.logging.Log;
29  import org.apache.commons.logging.LogFactory;
30  
31  import javax.swing.*;
32  import javax.swing.event.TreeSelectionEvent;
33  import javax.swing.tree.*;
34  import javax.xml.parsers.DocumentBuilder;
35  import javax.xml.parsers.DocumentBuilderFactory;
36  import javax.xml.parsers.ParserConfigurationException;
37  import javax.xml.transform.dom.DOMSource;
38  import javax.xml.transform.stream.StreamResult;
39  import javax.xml.transform.TransformerFactory;
40  import javax.xml.transform.Transformer;
41  import javax.xml.transform.OutputKeys;
42  import java.awt.*;
43  import java.awt.event.KeyEvent;
44  import java.io.File;
45  import java.io.FileWriter;
46  import java.io.IOException;
47  import java.io.StringWriter;
48  import java.net.URL;
49  import java.util.*;
50  import java.util.List;
51  
52  /***
53   * Main class for the JAG GUI.
54   *
55   * @author Hillebrand Gelderblom, Rudie Ekkelenkamp, Michael O'Connor - Finalist IT Group
56   * @version $Revision: 1.55 $, $Date: 2005/06/10 06:57:21 $
57   */
58  public class JagGenerator extends JFrame {
59  
60     static Log log = LogFactory.getLog(JagGenerator.class);
61     private ConsoleLogger logger;
62  
63     private DefaultTreeModel treeModel = null;
64     public Root root = null;
65     private File file = null;
66     private File outputDir = null;
67     private static File applicationFileDir = new File(".");
68     public static JagGenerator jagGenerator;
69     private static GenericJdbcManager conManager;
70     private static final int SPLIT_PANE_WIDTH = 400;
71     private static boolean relationsEnabled = true;
72     private static Thread runningThread;
73     private static final Icon CANCEL_ICON = new ImageIcon("../images/cancel.png");
74     private static final Icon RUN_ICON = new ImageIcon("../images/execute.png");
75     private static final String RUN_ACTION = "run";
76     private static final String STOP_ACTION = "stop";
77     private static final HashMap entities = new HashMap();
78     private static final HashMap entitiesByTableName = new HashMap();
79     private static final String XMI_SUFFIX = ".xmi";
80  
81     private static final HashMap FILECHOOSER_START_DIR = new HashMap();
82     private static final String FILECHOOSER_UMLEXPORT = "UML export";
83     private static final String FILECHOOSER_UMLIMPORT = "UML import";
84     private static final String FILECHOOSER_APPFILE_OPEN = "AppFile open";
85     private static final String FILECHOOSER_APPFILE_SAVE = "AppFile save";
86  
87     public final static String TEMPLATE_USE_RELATIONS = "useRelations";
88     public final static String TEMPLATE_USE_MOCK = "useMock";
89     public final static String TEMPLATE_USE_JAVA5 = "useJava5";
90     public final static String TEMPLATE_USE_WEB_SERVICE = "useWebService";
91  
92     public final static String TEMPLATE_WEB_TIER = "webTier";
93     public final static String TEMPLATE_WEB_TIER_STRUTS1_2 = "Struts 1.2";
94     public final static String TEMPLATE_WEB_TIER_SWING = "Swing";
95  
96     public final static String TEMPLATE_BUSINESS_TIER = "businessTier";
97     public final static String TEMPLATE_BUSINESS_TIER_EJB2 = "EJB 2.0";
98     public final static String TEMPLATE_BUSINESS_TIER_EJB3 = "EJB 3.0";
99     public final static String TEMPLATE_BUSINESS_TIER_HIBERNATE2 = "Hibernate 2";
100    public final static String TEMPLATE_BUSINESS_TIER_HIBERNATE3 = "Hibernate 3";
101    public final static String TEMPLATE_BUSINESS_TIER_MOCK = "Mock";
102 
103    public final static String TEMPLATE_SERVICE_TIER = "serviceTier";
104    public final static String TEMPLATE_SERVICE_TIER_SERVICE_LOCATOR = "ServiceLocator";
105    public final static String TEMPLATE_SERVICE_TIER_SPRING = "Spring";
106 
107    public final static String TEMPLATE_APPLICATION_SERVER = "appserver";
108    public final static String TEMPLATE_APPLICATION_SERVER_JBOSS_4_X = "JBoss 4.x";
109    public final static String TEMPLATE_APPLICATION_SERVER_JBOSS_3_2_2_7 = "JBoss 3.2.2-7";
110    public final static String TEMPLATE_APPLICATION_SERVER_JBOSS_3_2_0_1 = "JBoss 3.2.0-1";
111    public final static String TEMPLATE_APPLICATION_SERVER_JBOSS_3_0 = "JBoss 3.0";
112    public final static String TEMPLATE_APPLICATION_SERVER_TOMCAT_5 = "Tomcat 5";
113    public final static String TEMPLATE_APPLICATION_SERVER_SUN_ONE_7 = "Sun ONE Application Server 7";
114    public final static String TEMPLATE_APPLICATION_SERVER_WEBLOGIC_8_1 = "BEA WebLogic 8.1";
115    public final static String TEMPLATE_APPLICATION_SERVER_WEBLOGIC_EJBGEN_8_1 = "BEA WebLogic 8.1 (Workshop EJBGen)";
116    public final static String TEMPLATE_APPLICATION_SERVER_IBM_WEBSPERE = "IBM WebSphere";
117    public final static String TEMPLATE_APPLICATION_SERVER_ORACLE = "Oracle Application Server";
118 
119 
120    /***
121     * Runs the JaGGenerator.
122     *
123     * @param args the command line arguments
124     */
125    public static void main(String args[]) {
126       // Initialize commons logging..
127       log.info("Starting jag...");
128       jagGenerator = new JagGenerator();
129       jagGenerator.show();
130    }
131 
132    /***
133     * Creates new form jagGenerator
134     */
135    public JagGenerator() {
136       // Read user-prefs
137       Settings.read();
138 
139       // Setup main Window
140       try {
141          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
142       } catch (Exception e) { }
143       initComponents();
144       logger = new ConsoleLogger(console);
145       logger.log("Java Application Generator - console output:\n");
146       initDesktop();
147       fileNameLabel.setToolTipText("No application file selected.");
148       root = new Root();
149       treeModel = new DefaultTreeModel(root);
150       treeModel.addTreeModelListener(new JagTreeModelListener());
151       tree.setCellRenderer(new JagTreeCellRenderer());
152       tree.setModel(treeModel);
153       tree.setSelectionPath(new TreePath(((DefaultMutableTreeNode) root.getFirstChild()).getPath()));
154 
155       // Set divider-locations to the place they were when user closed program
156       splitPane.setDividerLocation(Settings.getVerticalDividerPosition());
157       desktopConsoleSplitPane.setDividerLocation(Settings.getHorizontalDividerPosition());
158       // Give the Window the last known position and size again.
159       setBounds(Settings.getUserWindowBounds(this));
160       // If user was previously working in a maximized Window, return to maximized state
161       if(Settings.isMaximized()) {
162          setExtendedState(MAXIMIZED_BOTH);
163       }
164    }
165 
166 
167    /***
168     * Gets the connection manager, the means by which the database is accessed.  If no connection has
169     * yet been set up, a dialogue will be displayed to the user with the DB settings and following this,
170     * a connection is attempted.
171     *
172     * @return Value of property conManager.
173     */
174    public static GenericJdbcManager getConManager() {
175       if (conManager == null) {
176          JDialog dialog = new ConnectDialog(jagGenerator);
177          dialog.setVisible(true); //necessary as of kestrel
178       }
179       if (conManager != null) {
180          jagGenerator.disconnectMenuItem.setEnabled(true);
181       }
182       return conManager;
183    }
184 
185    /***
186     * Checks whether the database has been connected yet.
187     *
188     * @return <code>true</code> if connected.
189     */
190    public static boolean isDatabaseConnected() {
191       return conManager != null;
192    }
193 
194    /***
195     * Enables the presentation layer to specify that a given field within a given entity is a foreign key field.
196     *
197     * @param tableName the name of the table whose entity contains the field we're interested in.
198     * @param fieldName the foreign key field.
199     */
200    public static void setForeignKeyInField(String tableName, String fieldName) {
201       TreeModel model = jagGenerator.tree.getModel();
202       for (int i = 0; i < model.getChildCount(model.getRoot()); i++) {
203          Object kid = model.getChild(model.getRoot(), i);
204          if (kid instanceof Entity) {
205             Entity entity = (Entity) kid;
206             if (entity.getLocalTableName().equals(tableName)) {
207                for (int j = 0; j < entity.getChildCount(); j++) {
208                   Object kid2 = entity.getChildAt(j);
209                   if (kid2 instanceof Field) {
210                      Field field = (Field) kid2;
211                      if (field.getName().toString().equals(fieldName)) {
212                         field.setForeignKey(true);
213                      }
214                   }
215                }
216             }
217          }
218       }
219    }
220 
221    public static boolean isRelationsEnabled() {
222       return relationsEnabled;
223    }
224 
225    public static void logToConsole(Object o) {
226       if (jagGenerator == null) {
227          System.out.println(o);
228       } else {
229          jagGenerator.logger.log(o.toString());
230       }
231    }
232 
233    public static void stateChanged(boolean updateTree) {
234       setFileNeedsSavingIndicator(true);
235       if (updateTree) {
236          jagGenerator.tree.updateUI();
237       }
238    }
239 
240    public static void finishedGeneration() {
241       jagGenerator.executeButton.setIcon(RUN_ICON);
242       jagGenerator.executeButton.setActionCommand(RUN_ACTION);
243    }
244 
245    public static Template getTemplate() {
246       Enumeration children = jagGenerator.root.children();
247       while (children.hasMoreElements()) {
248          DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
249          if (child instanceof Config) {
250             return ((Config) child).getTemplate();
251          }
252       }
253       return null;
254    }
255 
256    public static List getObjectsFromTree(Class clazz) {
257       ArrayList list = new ArrayList();
258       Enumeration children = jagGenerator.root.children();
259       while (children.hasMoreElements()) {
260          DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
261          if (child != null && child.getClass().equals(clazz)) {
262             list.add(child);
263          }
264       }
265       return list;
266    }
267 
268    public static void addEntity(String refName, Entity entity) {
269       entities.put(refName, entity);
270       entitiesByTableName.put(entity.getTableName(), entity);
271    }
272 
273    public static Entity getEntityByRefName(String refName) {
274       return (Entity) entities.get(refName);
275    }
276 
277    public static Entity getEntityByTableName(String tableName) {
278       return (Entity) entitiesByTableName.get(tableName);
279    }
280 
281    /***
282     * When the table name associated with an entity has been updated, calling this method
283     * updates the cache.
284     *
285     * @param entityName
286     * @param newTableName
287     */
288    public static void entityHasupdatedTableName(String entityName, String newTableName) {
289       synchronized (entitiesByTableName) {
290          Iterator i = entitiesByTableName.entrySet().iterator();
291          while (i.hasNext()) {
292             Map.Entry entry = (Map.Entry) i.next();
293             Entity entity = (Entity) entry.getValue();
294             if (entity.getName().equals(entityName)) {
295                entitiesByTableName.remove(entry.getKey());
296                entitiesByTableName.put(newTableName, entity);
297             }
298          }
299       }
300    }
301 
302    /***
303     * Makes sure that the SQL types of the fields within this application are compatible with the chosen DB.
304     */
305    public static void normaliseSQLTypesWithChosenDatabase() {
306       //I don't think this functionality is really necessary.
307 
308 //      if (jagGenerator.root.datasource.getMapping().toString().equals(Datasource.MYSQL)) {
309 //         replaceSQLTypeInAllFields("NUMBER(//([0-9//s]+,[0-9//s]+//))", "FLOAT$1"); //NUMBER with TWO comma-seperated args
310 //         replaceSQLTypeInAllFields("NUMBER", "INT"); //all other NUMBER
311 //         replaceSQLTypeInAllFields("VARCHAR2", "VARCHAR");
312 //      }
313 //
314 //      if (jagGenerator.root.datasource.getMapping().toString().equals(Datasource.ORACLE8)) {
315 //         replaceSQLTypeInAllFields("INT", "NUMBER");
316 //      }
317    }
318 
319    /***
320     * A record is kept of the last-accessed directory for every FileChooser, this method gets that record.
321     *
322     * @param filechooserKey A unique key.
323     * @return
324     */
325    public static File getFileChooserStartDir(String filechooserKey) {
326       File dir = (File) FILECHOOSER_START_DIR.get(filechooserKey);
327       return dir == null ? applicationFileDir : dir;
328    }
329 
330    /***
331     * A record is kept of the last-accessed directory for every FileChooser, this method sets that record.
332     *
333     * @param filechooserKey A unique key.
334     * @param dir            The new directory.
335     */
336    public static void setFileChooserStartDir(String filechooserKey, File dir) {
337       FILECHOOSER_START_DIR.put(filechooserKey, dir);
338    }
339 
340    private static void saveGuiSettings() {
341       // Store divier locations
342       Settings.setVerticalDividerPosition(jagGenerator.splitPane.getDividerLocation());
343       Settings.setHorizontalDividerPosition(jagGenerator.desktopConsoleSplitPane.getDividerLocation());
344       // Store window's maximized state and/or it's size and location
345       int extendedState = jagGenerator.getExtendedState();
346       boolean isMaximized = ((extendedState & MAXIMIZED_BOTH) == MAXIMIZED_BOTH);
347       if(!isMaximized) {
348          // The current Window-dimensions are only valid if not maximized
349          Settings.setUserWindowBounds(jagGenerator.getBounds());
350       }
351       Settings.setMaximized(isMaximized);
352    }
353 
354    /***
355     * Causes JAG to die.
356     *
357     * @param error if not <code>null</code>, forces an error dialogue before death.
358     */
359    public static void kickTheBucket(String error) {
360       if (error == null) {
361          // Store GUI-settings in user-preferences
362          saveGuiSettings();
363          Settings.write();
364          // Make sure the current database-settings are stored as well
365          ConfigManager.getInstance().save();
366          //todo: prompt to save application file!
367          //todo: Make sure prompt allows you to check "don't show this again"
368          System.exit(0);
369       } else {
370          //something went horribly wrong..
371          JOptionPane.showMessageDialog(jagGenerator,
372                error, "JAG - Fatal error!", JOptionPane.ERROR_MESSAGE);
373          System.exit(1);
374       }
375    }
376 
377    /***
378     * Setter for property conManager.
379     *
380     * @param conManager New value of property conManager.
381     */
382    public void setConManager(GenericJdbcManager conManager) {
383       JagGenerator.conManager = conManager;
384    }
385 
386 
387    private void initDesktop() {
388       desktopPane.setLayout(new GridBagLayout());
389       this.setTitle("Java Application Generator - Finalist IT Group");
390       GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
391       gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
392       gridBagConstraints.gridheight = java.awt.GridBagConstraints.RELATIVE;
393       gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
394       gridBagConstraints.ipadx = 1;
395       gridBagConstraints.ipady = 1;
396       gridBagConstraints.weightx = 1.0;
397       gridBagConstraints.weighty = 1.0;
398       desktopPane.add(splitPane, gridBagConstraints);
399       pack();
400    }
401 
402    private void newRelationMenuItemActionPerformed() {
403       DefaultMutableTreeNode selected = (DefaultMutableTreeNode)
404             tree.getLastSelectedPathComponent();
405       if (!(selected instanceof Entity)) {
406          //see if the parent is an Entity..
407          TreePath selectedPath = tree.getSelectionPath();
408          selected = (DefaultMutableTreeNode) selectedPath.getParentPath().getLastPathComponent();
409          if (!(selected instanceof Entity)) {
410             JOptionPane.showMessageDialog(this,
411                   "A relation can only be added to an entity bean.  Please first select an entity in the application tree.", "Can't add relation!", JOptionPane.ERROR_MESSAGE);
412             return;
413          }
414       }
415       Entity selectedEntity = (Entity) selected;
416 
417       DefaultMutableTreeNode newNode = new Relation(selectedEntity);
418       selectedEntity.addRelation((Relation) newNode);
419       tree.setSelectionPath(new TreePath(newNode.getPath()));
420       tree.updateUI();
421    }
422 
423 
424    /***
425     * Updates objects concerned with 'local' side CMR relations, namely:
426     * 1: for every foreign key Field object within an entity that takes part in a relation, set its Relation object.
427     * 2: for every Relation object, set the Relation's local-side foreign key Field object.
428     */
429    private void updateLocalSideRelations() {
430       Iterator entities = root.getEntityEjbs().iterator();
431       while (entities.hasNext()) {
432          Entity entity = (Entity) entities.next();
433          //for every entity..
434          for (int i = 0; i < entity.getChildCount(); i++) {
435             TreeNode child = entity.getChildAt(i);
436             //for every relation in that entity..
437             if (child instanceof Relation) {
438                Relation relation = (Relation) child;
439                String fkFieldName = relation.getFieldName().toString();
440                for (int j = 0; j < entity.getChildCount(); j++) {
441                   TreeNode child2 = entity.getChildAt(j);
442                   //iterate through all this entity's Fields..
443                   if (child2 instanceof Field) {
444                      Field field = (Field) child2;
445                      //until we find the Field that matches the relation's fkFieldName
446                      if (field.getName().equals(fkFieldName)) {
447                         field.setRelation(relation);
448                         field.setForeignKey(true);
449                         relation.setFieldName(field.getName().toString());
450                         relation.setFkField(field);
451                         if (relation.getLocalColumn() == null) {
452                             relation.setLocalColumn(relation.getFkField().getColumnName());
453                         }
454                         logToConsole("relation " + relation + ": local-side fk field is " + entity.getName() + ":" + field);
455                      }
456                   }
457                }
458             }
459          }
460       }
461    }
462 
463    /***
464     * Updates objects concerned with the 'foreign' side of CMR relations, namely:
465     * 1: for every Relation, set the foreign-side primary key Field object (the primary key of the entity on the
466     * foreign side of the relation).
467     */
468    private void updateForeignSideRelations() {
469       Iterator entities = root.getEntityEjbs().iterator();
470       while (entities.hasNext()) {
471          Entity entity = (Entity) entities.next();
472          for (int i = 0; i < entity.getChildCount(); i++) {
473             TreeNode child = entity.getChildAt(i);
474             if (child instanceof Relation) {
475                Relation relation = (Relation) child;
476                Entity relatedEntity = relation.getRelatedEntity();
477                String column = relation.getForeignColumn();
478                for (int j = 0; j < relatedEntity.getChildCount(); j++) {
479                   TreeNode child2 = relatedEntity.getChildAt(j);
480                   if (child2 instanceof Field) {
481                      Field field = (Field) child2;
482                      if (field.getColumnName().equals(column)) {
483                         relation.setForeignPkField(field);
484                         logToConsole("relation " + relation + ": foreign-side pk is " + relatedEntity + ":" + field);
485                      }
486                   }
487                }
488             }
489          }
490       }
491    }
492 
493 
494    /***
495     * Sometimes a relation specifies an entity that hasn't been added to a session bean (all related entities
496     * must be represented in the session fa?ade).  This method adds those entities automatically.
497     *
498     * @return <code>false</code> if a related entity couldn't be imported into the application.
499     */
500    private boolean addRelatedEntitiesToSessionBeans() {
501       boolean somethingAdded = false;
502       //1: create a map of entity name --> set of related foreign tables, and
503       //            map of local table --> entity bean name, and
504       //            map of entity bean name --> local table
505       HashMap relatedTablesPerEB = new HashMap();
506       HashMap entityPerTable = new HashMap();
507       HashMap tablePerEntity = new HashMap();
508       Iterator entities = root.getEntityEjbs().iterator();
509       while (entities.hasNext()) {
510          Entity entity = (Entity) entities.next();
511          entityPerTable.put(entity.getLocalTableName().toString(), entity.getRefName());
512          tablePerEntity.put(entity.getRefName(), entity.getLocalTableName().toString());
513          for (int i = 0; i < entity.getChildCount(); i++) {
514             TreeNode child = entity.getChildAt(i);
515             if (child instanceof Relation) {
516                Relation relation = (Relation) child;
517                String relatedTableName = relation.getForeignTable();
518                Set existing = (Set) relatedTablesPerEB.get(entity.getRefName());
519                if (existing == null) {
520                   existing = new HashSet();
521                }
522                existing.add(relatedTableName);
523                relatedTablesPerEB.put(entity.getRefName(), existing);
524 
525             }
526          }
527       }
528 
529       //2: remove all related foreign tables from the map, where the table is the local table of an entity that already
530       //   appears within a session bean.
531       Iterator sessions = root.getSessionEjbs().iterator();
532       while (sessions.hasNext()) {
533          Session session = (Session) sessions.next();
534          Iterator entitiesWithinSession = session.getEntityRefs().iterator();
535          while (entitiesWithinSession.hasNext()) {
536             String localTable = (String) tablePerEntity.get(entitiesWithinSession.next());
537             Iterator relatedEntitySets = relatedTablesPerEB.values().iterator();
538             while (relatedEntitySets.hasNext()) {
539                Set set = (Set) relatedEntitySets.next();
540                set.remove(localTable);
541             }
542          }
543       }
544 
545       //3: for each session bean, add any related entities not already contained within a session bean.
546       HashSet addedTables = new HashSet();
547       sessions = root.getSessionEjbs().iterator();
548       while (sessions.hasNext()) {
549          Session session = (Session) sessions.next();
550          Iterator entitiesWithinSession = session.getEntityRefs().iterator();
551          while (entitiesWithinSession.hasNext()) {
552             String entityName = (String) entitiesWithinSession.next();
553             Set tablesToBeAdded = (Set) relatedTablesPerEB.get(entityName);
554             if (tablesToBeAdded != null) {
555                Iterator i = tablesToBeAdded.iterator();
556                while (i.hasNext()) {
557                   String table = (String) i.next();
558                   if (!addedTables.contains(table)) {
559                      String entity = (String) entityPerTable.get(table);
560                      if (entity == null) {
561                         JOptionPane.showMessageDialog(this,
562                               "Entity '" + entityName + "' contains a relation to a table '" + table + "'\n" +
563                               "for which no entity bean exists in the current application.\n" +
564                               "Please either create a new entity bean for this table, or delete the relation.",
565                               "Invalid Container-managed relation!",
566                               JOptionPane.ERROR_MESSAGE);
567                         return false;
568                      } else {
569                         session.addRelationRef(entity);
570                         addedTables.add(table);
571                         somethingAdded = true;
572                         JOptionPane.showMessageDialog(this,
573                               "Entity '" + entityName + "' added to the service bean '" + session.getRefName() +
574                               "' contains a relation to the entity '" + entity + "', which doesn't appear in any service beans.\n" +
575                               "The relation requires accessor methods to '" + entity + "', so these were automatically added to the service bean.",
576                               "Service bean modified",
577                               JOptionPane.INFORMATION_MESSAGE);
578                      }
579                   }
580                }
581             }
582          }
583       }
584 
585       //recursively call this method if an entity had to be added, because possible that entity also contains
586       //relation references to other entities that need to be imported into a session bean...
587       if (somethingAdded) {
588          addRelatedEntitiesToSessionBeans();
589       }
590       return true;
591    }
592 
593 
594    private File selectJagOutDirectory(String startDir) {
595       File directory = null;
596       int fileChooserStatus;
597       JFileChooser fileChooser = new JFileChooser();
598       fileChooser.setDialogTitle("Select an ouput directory for the generated application..");
599       fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
600       fileChooser.setCurrentDirectory(new File(startDir));
601       fileChooserStatus = fileChooser.showOpenDialog(this);
602       if (fileChooserStatus == JFileChooser.APPROVE_OPTION) {
603          directory = fileChooser.getSelectedFile();
604          String projectName = root.app.nameText.getText();
605          directory = new File(directory.getAbsoluteFile(), projectName);
606       }
607       return directory;
608 
609    }
610 
611    /***
612     * Generates relations for a specified entity by reading foreign key info from the database.
613     *
614     * @param entity the Entity whose relations will be generated.
615     */
616    private boolean generateRelationsFromDB(Entity entity) {
617       if (getConManager() == null) {
618          logger.log("Can't regenerate relations - no database!");
619          return false;
620       }
621       log.debug("Get the foreign keys for table: " + entity.getTableName());
622       List fkeys = DatabaseUtils.getForeignKeys(entity.getTableName());
623       HashMap foreignTablesTally = new HashMap();
624       Set foreignKeyFieldNames = new HashSet(fkeys.size());
625       Iterator i = fkeys.iterator();
626       while (i.hasNext()) {
627          ForeignKey fk = (ForeignKey) i.next();
628          foreignKeyFieldNames.add(Utils.format(fk.getFkColumnName()));
629          Relation relation = new Relation(entity, fk);
630          String foreignTable = fk.getPkTableName();
631 
632          // Default to unidirectional:
633          relation.setBidirectional(false);
634          // No support for one-to-one relations yet. So default to many-to-one
635          relation.setTargetMultiple(true);
636          /*
637          if (relation.getFkField() != null && relation.getFkField().isPrimaryKey()) {
638             // In case the local side is a primary key, we have a one to one relation
639             relation.setTargetMultiple(false);
640          } else {
641             // In case the local side isn't a primary key, we asume to have a many to one relation.
642             relation.setTargetMultiple(true);
643          }
644          */
645 
646          if (foreignTablesTally.keySet().contains(foreignTable)) {
647             int tally = ((Integer) foreignTablesTally.get(foreignTable)).intValue() + 1;
648             relation.setName(relation.getName() + tally);
649             foreignTablesTally.put(foreignTable, new Integer(tally));
650          } else {
651             foreignTablesTally.put(foreignTable, new Integer(1));
652          }
653          addObject(entity, relation, false, true);
654       }
655       return true;
656    }
657 
658    private ArrayList sortColumns(ArrayList columns, ArrayList pKeys, Entity entity, String pKey) {
659       ArrayList sortedColumns = new ArrayList();
660       // Make sure the primary key will be the first field!
661       ArrayList primaryKeyColumns = new ArrayList();
662       Column primaryKeyColumn = null;
663       for (Iterator colIt = columns.iterator(); colIt.hasNext();) {
664          Column column = (Column) colIt.next();
665          if (pKeys.contains(column.getName())) {
666             // We found the primary key column!
667             primaryKeyColumn = column;
668             primaryKeyColumn.setPrimaryKey(true);
669             primaryKeyColumns.add(primaryKeyColumn);
670          } else {
671             column.setPrimaryKey(false);
672             sortedColumns.add(column);
673          }
674       }
675       if (pKeys.size() > 1) {
676          // We have a composite primary key!
677          entity.isCompositeCombo.setSelectedItem("true");
678          String compositePK = entity.rootPackageText.getText() + "." + entity.nameText.getText() + "PK";
679          entity.pKeyTypeText.setText(compositePK);
680          entity.pKeyText.setText("");// name is irrelevant now.
681       } else {
682          entity.isCompositeCombo.setSelectedItem("false");
683          if (pKeys.size() == 1) {
684             entity.pKeyText.setText(Utils.format(pKey));// name is irrelevant now.
685 
686          }
687       }
688       // If a primary key column was found, we put it in front of the list.
689       columns = new ArrayList();
690       if (primaryKeyColumn != null)
691          columns.addAll(primaryKeyColumns);
692       columns.addAll(sortedColumns);
693       return columns;
694    }
695 
696    private void addObject(DefaultMutableTreeNode parent, DefaultMutableTreeNode child, boolean forceUpdate, boolean topOfQueue) {
697       if (parent == null) {
698          parent = root;
699       }
700       treeModel.insertNodeInto(child, parent, topOfQueue ? 0 : parent.getChildCount());
701       if (forceUpdate) {
702          tree.setSelectionPath(new TreePath(child.getPath()));
703       }
704    }
705 
706    public boolean save() {
707       //the object graph is incomplete at this stage, so finalise it now:
708       updateLocalSideRelations();
709       updateForeignSideRelations();
710 
711       if (!addRelatedEntitiesToSessionBeans()) {
712          return false;
713       }
714 
715       try {
716          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
717          DocumentBuilder builder = dbf.newDocumentBuilder();
718          Document doc = builder.newDocument();
719          Element skelet = doc.createElement("skelet");
720          doc.appendChild(skelet);
721          root.getXML(skelet);
722          String XMLDoc = outXML(doc);
723          String fileName = file.getName();
724          if (fileName != null) {
725             if (fileName.indexOf(".xml") == -1) {
726                file = new File(file.getAbsolutePath() + ".xml");
727             }
728          }
729          FileWriter fw = new FileWriter(file);
730          fw.write(XMLDoc);
731          fw.close();
732          fileNameLabel.setText("Application file: " + file.getName());
733          fileNameLabel.setToolTipText(file.getAbsolutePath());
734 
735       } catch (ParserConfigurationException e) {
736          e.printStackTrace();
737       } catch (IOException e) {
738          e.printStackTrace();
739       }
740 
741       setFileNeedsSavingIndicator(false);
742       return true;
743    }
744 
745    /* Use the JAXB JDK1.4 parser to serialize to XML. */
746    public static String outXML(Document doc) {
747       try {
748          DOMSource domSource = new DOMSource(doc);
749          StringWriter sw = new StringWriter();
750          StreamResult streamResult = new StreamResult(sw);
751          TransformerFactory tf = TransformerFactory.newInstance();
752          Transformer serializer = tf.newTransformer();
753          serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
754          serializer.setOutputProperty(OutputKeys.INDENT, "yes");
755          serializer.transform(domSource, streamResult);
756          return sw.toString();
757       } catch (Exception e) {
758          e.printStackTrace();
759       }
760       return null;
761    }
762 
763    private static void setFileNeedsSavingIndicator(boolean sterretje) {
764       if (jagGenerator != null && jagGenerator.file != null) {
765          String filename = jagGenerator.fileNameLabel.getText();
766          if (sterretje && filename.charAt(filename.length() - 1) != '*') {
767             jagGenerator.fileNameLabel.setText(filename + '*');
768          } else if (!sterretje && filename.charAt(filename.length() - 1) == '*') {
769             jagGenerator.fileNameLabel.setText(filename.substring(0, filename.length() - 1));
770          }
771       }
772    }
773 
774 
775 //###########################################################################################
776 // All method signatures and "// doc" below here are automatically created
777 // by NetBeans (we used version 4.0).  Only change the method BODIES please,
778 // as this will enable later re-use the NetBeans form editor to make changes in the GUI!
779 //###########################################################################################
780 
781 
782    /***
783     * This method is called from within the constructor to
784     * initialize the form.
785     * WARNING: Do NOT modify this code. The content of this method is
786     * always regenerated by the Form Editor.
787     */
788     private void initComponents() {//GEN-BEGIN:initComponents
789         splitPane = new javax.swing.JSplitPane();
790         treeScrollPane = new javax.swing.JScrollPane();
791         tree = new javax.swing.JTree();
792         toolBar = new javax.swing.JToolBar();
793         newButton = new javax.swing.JButton();
794         openButton = new javax.swing.JButton();
795         saveButton = new javax.swing.JButton();
796         entityButton = new javax.swing.JButton();
797         sessionButton = new javax.swing.JButton();
798         relationButton = new javax.swing.JButton();
799         businessMethodButton = new javax.swing.JButton();
800         deleteButton = new javax.swing.JButton();
801         executeButton = new javax.swing.JButton();
802         helpButton = new javax.swing.JButton();
803         spacer = new javax.swing.JPanel();
804         applicationFileInfoPanel = new javax.swing.JPanel();
805         fileNameLabel = new javax.swing.JLabel();
806         databaseConnectionInfoPanel = new javax.swing.JPanel();
807         databaseConnectionLabel = new javax.swing.JLabel();
808         desktopConsoleSplitPane = new javax.swing.JSplitPane();
809         desktopPane = new javax.swing.JDesktopPane();
810         consoleScrollPane = new javax.swing.JScrollPane();
811         console = new javax.swing.JTextArea();
812         menuBar = new javax.swing.JMenuBar();
813         fileMenu = new javax.swing.JMenu();
814         newMenuItem = new javax.swing.JMenuItem();
815         openMenuItem = new javax.swing.JMenuItem();
816         importMenuItem = new javax.swing.JMenuItem();
817         jSeparator1 = new javax.swing.JSeparator();
818         saveMenuItem = new javax.swing.JMenuItem();
819         saveAsMenuItem = new javax.swing.JMenuItem();
820         exportMenuItem = new javax.swing.JMenuItem();
821         jSeparator2 = new javax.swing.JSeparator();
822         generateJavaApplicationAsMenuItem = new javax.swing.JMenuItem();
823         jSeparator3 = new javax.swing.JSeparator();
824         exitMenuItem = new javax.swing.JMenuItem();
825         editMenu = new javax.swing.JMenu();
826         addSubMenu = new javax.swing.JMenu();
827         addEntityMenuItem = new javax.swing.JMenuItem();
828         addSessionMenuItem = new javax.swing.JMenuItem();
829         addRelationMenuItem = new javax.swing.JMenuItem();
830         addBusinessMenuItem = new javax.swing.JMenuItem();
831         deleteMenuItem = new javax.swing.JMenuItem();
832         connectionMenu = new javax.swing.JMenu();
833         driverManagerMenuItem = new javax.swing.JMenuItem();
834         jSeparator4 = new javax.swing.JSeparator();
835         connectMenuItem = new javax.swing.JMenuItem();
836         disconnectMenuItem = new javax.swing.JMenuItem();
837         helpMenu = new javax.swing.JMenu();
838         aboutMenuItem = new javax.swing.JMenuItem();
839         contentMenuItem = new javax.swing.JMenuItem();
840 
841         splitPane.setBorder(null);
842         splitPane.setDividerLocation(400);
843         splitPane.setDividerSize(3);
844         splitPane.setContinuousLayout(true);
845         splitPane.setOpaque(false);
846         splitPane.setVerifyInputWhenFocusTarget(false);
847         tree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
848             public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
849                 treeValueChanged(evt);
850             }
851         });
852 
853         treeScrollPane.setViewportView(tree);
854 
855         splitPane.setLeftComponent(treeScrollPane);
856 
857         addWindowListener(new java.awt.event.WindowAdapter() {
858             public void windowClosing(java.awt.event.WindowEvent evt) {
859                 exitForm(evt);
860             }
861         });
862 
863         toolBar.setBorder(menuBar.getBorder());
864         toolBar.setFloatable(false);
865         toolBar.setName("toolBar");
866         newButton.setIcon(new javax.swing.ImageIcon("../images/new.png"));
867         newButton.setText(" ");
868         newButton.setToolTipText("New JAG application");
869         newButton.setBorder(null);
870         newButton.addActionListener(new java.awt.event.ActionListener() {
871             public void actionPerformed(java.awt.event.ActionEvent evt) {
872                 newMenuItemActionPerformed(evt);
873             }
874         });
875 
876         toolBar.add(newButton);
877 
878         openButton.setIcon(new javax.swing.ImageIcon("../images/open.png"));
879         openButton.setText(" ");
880         openButton.setToolTipText("Open a JAG application file");
881         openButton.setBorder(null);
882         openButton.addActionListener(new java.awt.event.ActionListener() {
883             public void actionPerformed(java.awt.event.ActionEvent evt) {
884                 openMenuItemActionPerformed(evt);
885             }
886         });
887 
888         toolBar.add(openButton);
889 
890         saveButton.setIcon(new javax.swing.ImageIcon("../images/save.png"));
891         saveButton.setText(" ");
892         saveButton.setToolTipText("Save");
893         saveButton.setBorder(null);
894         saveButton.addActionListener(new java.awt.event.ActionListener() {
895             public void actionPerformed(java.awt.event.ActionEvent evt) {
896                 saveButtonActionPerformed(evt);
897             }
898         });
899 
900         toolBar.add(saveButton);
901 
902         toolBar.addSeparator();
903         entityButton.setIcon(new javax.swing.ImageIcon("../images/entity.png"));
904         entityButton.setText(" ");
905         entityButton.setToolTipText("New entity bean");
906         entityButton.setBorder(null);
907         entityButton.addActionListener(new java.awt.event.ActionListener() {
908             public void actionPerformed(java.awt.event.ActionEvent evt) {
909                 addEntityMenuItemActionPerformed(evt);
910             }
911         });
912 
913         toolBar.add(entityButton);
914 
915         sessionButton.setIcon(new javax.swing.ImageIcon("../images/session.png"));
916         sessionButton.setText(" ");
917         sessionButton.setToolTipText("New service bean");
918         sessionButton.setBorder(null);
919         sessionButton.addActionListener(new java.awt.event.ActionListener() {
920             public void actionPerformed(java.awt.event.ActionEvent evt) {
921                 addSessionMenuItemActionPerformed(evt);
922             }
923         });
924 
925         toolBar.add(sessionButton);
926 
927         relationButton.setIcon(new javax.swing.ImageIcon("../images/relation.png"));
928         relationButton.setText(" ");
929         relationButton.setToolTipText("New relation");
930         relationButton.setBorder(null);
931         relationButton.addActionListener(new java.awt.event.ActionListener() {
932             public void actionPerformed(java.awt.event.ActionEvent evt) {
933                 addRelationPopupMenuItemActionPerformed(evt);
934             }
935         });
936 
937         toolBar.add(relationButton);
938 
939         businessMethodButton.setIcon(new javax.swing.ImageIcon("../images/business.png"));
940         businessMethodButton.setText(" ");
941         businessMethodButton.setToolTipText("New business method");
942         businessMethodButton.setBorder(null);
943         businessMethodButton.addActionListener(new java.awt.event.ActionListener() {
944             public void actionPerformed(java.awt.event.ActionEvent evt) {
945                 businessMethodButtonActionPerformed(evt);
946             }
947         });
948 
949         toolBar.add(businessMethodButton);
950 
951         deleteButton.setIcon(new javax.swing.ImageIcon("../images/delete.png"));
952         deleteButton.setText(" ");
953         deleteButton.setToolTipText("Delete");
954         deleteButton.setBorder(null);
955         deleteButton.addActionListener(new java.awt.event.ActionListener() {
956             public void actionPerformed(java.awt.event.ActionEvent evt) {
957                 deleteMenuItemActionPerformed(evt);
958             }
959         });
960 
961         toolBar.add(deleteButton);
962 
963         toolBar.addSeparator();
964         executeButton.setIcon(new javax.swing.ImageIcon("../images/execute.png"));
965         executeButton.setText(" ");
966         executeButton.setToolTipText("Generate the application");
967         executeButton.setBorder(null);
968         executeButton.addActionListener(new java.awt.event.ActionListener() {
969             public void actionPerformed(java.awt.event.ActionEvent evt) {
970                 generateJavaApplicationAsMenuItemActionPerformed(evt);
971             }
972         });
973 
974         toolBar.add(executeButton);
975 
976         toolBar.addSeparator();
977         helpButton.setIcon(new javax.swing.ImageIcon("../images/help.png"));
978         helpButton.setText(" ");
979         helpButton.setToolTipText("Help");
980         helpButton.setBorder(null);
981         helpButton.addActionListener(new java.awt.event.ActionListener() {
982             public void actionPerformed(java.awt.event.ActionEvent evt) {
983                 contentMenuItemActionPerformed(evt);
984             }
985         });
986 
987         toolBar.add(helpButton);
988 
989         spacer.setLayout(null);
990 
991         toolBar.add(spacer);
992 
993         applicationFileInfoPanel.setName("fileStatusComponent");
994         fileNameLabel.setText("Application file:");
995         fileNameLabel.setToolTipText("File name of the XML skelet");
996         fileNameLabel.setName("fileNameLabel");
997         applicationFileInfoPanel.add(fileNameLabel);
998 
999         toolBar.add(applicationFileInfoPanel);
1000 
1001         databaseConnectionInfoPanel.setName("databaseConnectionComponent");
1002         databaseConnectionLabel.setText("Database Connection:");
1003         databaseConnectionLabel.setName("databaseConnectionLabel");
1004         databaseConnectionInfoPanel.add(databaseConnectionLabel);
1005 
1006         toolBar.add(databaseConnectionInfoPanel);
1007 
1008         getContentPane().add(toolBar, java.awt.BorderLayout.NORTH);
1009 
1010         desktopConsoleSplitPane.setDividerLocation(590);
1011         desktopConsoleSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
1012         desktopConsoleSplitPane.setTopComponent(desktopPane);
1013 
1014         console.setBackground(new java.awt.Color(204, 204, 204));
1015         console.setEditable(false);
1016         console.setFont(new java.awt.Font("Lucida Console", 0, 10));
1017         console.setForeground(new java.awt.Color(0, 0, 1));
1018         console.setRows(5);
1019         consoleScrollPane.setViewportView(console);
1020 
1021         desktopConsoleSplitPane.setBottomComponent(consoleScrollPane);
1022 
1023         getContentPane().add(desktopConsoleSplitPane, java.awt.BorderLayout.CENTER);
1024 
1025         fileMenu.setMnemonic(KeyEvent.VK_F);
1026         fileMenu.setText("File");
1027         newMenuItem.setMnemonic(KeyEvent.VK_N);
1028         newMenuItem.setAccelerator(
1029             KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK));
1030         newMenuItem.setText("New");
1031         newMenuItem.addActionListener(new java.awt.event.ActionListener() {
1032             public void actionPerformed(java.awt.event.ActionEvent evt) {
1033                 newMenuItemActionPerformed(evt);
1034             }
1035         });
1036 
1037         fileMenu.add(newMenuItem);
1038 
1039         openMenuItem.setMnemonic(KeyEvent.VK_O);
1040         openMenuItem.setAccelerator(
1041             KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK));
1042         openMenuItem.setText("Open");
1043         openMenuItem.addActionListener(new java.awt.event.ActionListener() {
1044             public void actionPerformed(java.awt.event.ActionEvent evt) {
1045                 openMenuItemActionPerformed(evt);
1046             }
1047         });
1048 
1049         fileMenu.add(openMenuItem);
1050 
1051         importMenuItem.setMnemonic(KeyEvent.VK_I);
1052         importMenuItem.setAccelerator(
1053             KeyStroke.getKeyStroke(KeyEvent.VK_I, KeyEvent.CTRL_MASK));
1054         importMenuItem.setText("Import UML model..");
1055         importMenuItem.addActionListener(new java.awt.event.ActionListener() {
1056             public void actionPerformed(java.awt.event.ActionEvent evt) {
1057                 importMenuItemActionPerformed(evt);
1058             }
1059         });
1060 
1061         fileMenu.add(importMenuItem);
1062 
1063         fileMenu.add(jSeparator1);
1064 
1065         saveMenuItem.setMnemonic(KeyEvent.VK_S);
1066         saveMenuItem.setAccelerator(
1067             KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));
1068         saveMenuItem.setText("Save");
1069         saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
1070             public void actionPerformed(java.awt.event.ActionEvent evt) {
1071                 saveMenuItemActionPerformed(evt);
1072             }
1073         });
1074 
1075         fileMenu.add(saveMenuItem);
1076 
1077         saveAsMenuItem.setMnemonic(KeyEvent.VK_A);
1078         saveAsMenuItem.setAccelerator(
1079             KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0));
1080         saveAsMenuItem.setText("Save As ...");
1081         saveAsMenuItem.addActionListener(new java.awt.event.ActionListener() {
1082             public void actionPerformed(java.awt.event.ActionEvent evt) {
1083                 saveAsMenuItemActionPerformed(evt);
1084             }
1085         });
1086 
1087         fileMenu.add(saveAsMenuItem);
1088 
1089         exportMenuItem.setMnemonic(KeyEvent.VK_E);
1090         exportMenuItem.setAccelerator(
1091             KeyStroke.getKeyStroke(KeyEvent.VK_E, KeyEvent.CTRL_MASK));
1092         exportMenuItem.setText("Export UML model..");
1093         exportMenuItem.addActionListener(new java.awt.event.ActionListener() {
1094             public void actionPerformed(java.awt.event.ActionEvent evt) {
1095                 exportMenuItemActionPerformed(evt);
1096             }
1097         });
1098 
1099         fileMenu.add(exportMenuItem);
1100 
1101         fileMenu.add(jSeparator2);
1102 
1103         generateJavaApplicationAsMenuItem.setMnemonic(KeyEvent.VK_G);
1104         generateJavaApplicationAsMenuItem.setAccelerator(
1105             KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
1106         generateJavaApplicationAsMenuItem.setText("Generate application...");
1107         generateJavaApplicationAsMenuItem.setToolTipText("Generate a J2EE Applicatin");
1108         generateJavaApplicationAsMenuItem.addActionListener(new java.awt.event.ActionListener() {
1109             public void actionPerformed(java.awt.event.ActionEvent evt) {
1110                 generateJavaApplicationAsMenuItemActionPerformed(evt);
1111             }
1112         });
1113 
1114         fileMenu.add(generateJavaApplicationAsMenuItem);
1115 
1116         fileMenu.add(jSeparator3);
1117 
1118         exitMenuItem.setMnemonic(KeyEvent.VK_X);
1119         exitMenuItem.setText("Exit");
1120         exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
1121             public void actionPerformed(java.awt.event.ActionEvent evt) {
1122                 exitMenuItemActionPerformed(evt);
1123             }
1124         });
1125 
1126         fileMenu.add(exitMenuItem);
1127 
1128         menuBar.add(fileMenu);
1129 
1130         editMenu.setMnemonic(KeyEvent.VK_E);
1131         editMenu.setText("Edit");
1132         editMenu.addActionListener(new java.awt.event.ActionListener() {
1133             public void actionPerformed(java.awt.event.ActionEvent evt) {
1134                 editMenuActionPerformed(evt);
1135             }
1136         });
1137 
1138         addSubMenu.setText("Add");
1139         addEntityMenuItem.setMnemonic(KeyEvent.VK_E);
1140         addEntityMenuItem.setAccelerator(
1141             KeyStroke.getKeyStroke(KeyEvent.VK_1, KeyEvent.CTRL_MASK));
1142         addEntityMenuItem.setText("entity bean");
1143         addEntityMenuItem.addActionListener(new java.awt.event.ActionListener() {
1144             public void actionPerformed(java.awt.event.ActionEvent evt) {
1145                 addEntityMenuItemActionPerformed(evt);
1146             }
1147         });
1148 
1149         addSubMenu.add(addEntityMenuItem);
1150 
1151         addSessionMenuItem.setMnemonic(KeyEvent.VK_S);
1152         addSessionMenuItem.setAccelerator(
1153             KeyStroke.getKeyStroke(KeyEvent.VK_2, KeyEvent.CTRL_MASK));
1154         addSessionMenuItem.setText("service bean");
1155         addSessionMenuItem.addActionListener(new java.awt.event.ActionListener() {
1156             public void actionPerformed(java.awt.event.ActionEvent evt) {
1157                 addSessionMenuItemActionPerformed(evt);
1158             }
1159         });
1160 
1161         addSubMenu.add(addSessionMenuItem);
1162 
1163         addRelationMenuItem.setMnemonic(KeyEvent.VK_R);
1164         addRelationMenuItem.setAccelerator(
1165             KeyStroke.getKeyStroke(KeyEvent.VK_R, KeyEvent.CTRL_MASK));
1166         addRelationMenuItem.setText("relation");
1167         addRelationMenuItem.addActionListener(new java.awt.event.ActionListener() {
1168             public void actionPerformed(java.awt.event.ActionEvent evt) {
1169                 addRelationPopupMenuItemActionPerformed(evt);
1170             }
1171         });
1172 
1173         addSubMenu.add(addRelationMenuItem);
1174 
1175         addBusinessMenuItem.setMnemonic(KeyEvent.VK_B);
1176         addBusinessMenuItem.setAccelerator(
1177             KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK));
1178         addBusinessMenuItem.setText("business");
1179         addBusinessMenuItem.addActionListener(new java.awt.event.ActionListener() {
1180             public void actionPerformed(java.awt.event.ActionEvent evt) {
1181                 addBusinessMenuItemActionPerformed(evt);
1182             }
1183         });
1184 
1185         addSubMenu.add(addBusinessMenuItem);
1186 
1187         editMenu.add(addSubMenu);
1188 
1189         deleteMenuItem.setMnemonic(KeyEvent.VK_D);
1190         deleteMenuItem.setAccelerator(
1191             KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, KeyEvent.CTRL_MASK));
1192         deleteMenuItem.setText(" Delete");
1193         deleteMenuItem.addActionListener(new java.awt.event.ActionListener() {
1194             public void actionPerformed(java.awt.event.ActionEvent evt) {
1195                 deleteMenuItemActionPerformed(evt);
1196             }
1197         });
1198 
1199         editMenu.add(deleteMenuItem);
1200 
1201         menuBar.add(editMenu);
1202 
1203         connectionMenu.setMnemonic(KeyEvent.VK_D);
1204         connectionMenu.setText("Database");
1205         driverManagerMenuItem.setText("Driver Manager..");
1206         driverManagerMenuItem.addActionListener(new java.awt.event.ActionListener() {
1207             public void actionPerformed(java.awt.event.ActionEvent evt) {
1208                 driverManagerMenuItemActionPerformed(evt);
1209             }
1210         });
1211 
1212         connectionMenu.add(driverManagerMenuItem);
1213 
1214         connectionMenu.add(jSeparator4);
1215 
1216         connectMenuItem.setText("Create connection...");
1217         connectMenuItem.addActionListener(new java.awt.event.ActionListener() {
1218             public void actionPerformed(java.awt.event.ActionEvent evt) {
1219                 connectMenuItemActionPerformed(evt);
1220             }
1221         });
1222 
1223         connectionMenu.add(connectMenuItem);
1224 
1225         disconnectMenuItem.setText("Disconnect");
1226         disconnectMenuItem.setEnabled(false);
1227         disconnectMenuItem.addActionListener(new java.awt.event.ActionListener() {
1228             public void actionPerformed(java.awt.event.ActionEvent evt) {
1229                 disconnectMenuItemActionPerformed(evt);
1230             }
1231         });
1232 
1233         connectionMenu.add(disconnectMenuItem);
1234 
1235         menuBar.add(connectionMenu);
1236 
1237         helpMenu.setMnemonic(KeyEvent.VK_H);
1238         helpMenu.setText("Help");
1239         aboutMenuItem.setText("About");
1240         aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
1241             public void actionPerformed(java.awt.event.ActionEvent evt) {
1242                 aboutMenuItemActionPerformed(evt);
1243             }
1244         });
1245 
1246         helpMenu.add(aboutMenuItem);
1247 
1248         contentMenuItem.setMnemonic(KeyEvent.VK_C);
1249         contentMenuItem.setAccelerator(
1250             KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
1251         contentMenuItem.setText("Content");
1252         contentMenuItem.addActionListener(new java.awt.event.ActionListener() {
1253             public void actionPerformed(java.awt.event.ActionEvent evt) {
1254                 contentMenuItemActionPerformed(evt);
1255             }
1256         });
1257 
1258         helpMenu.add(contentMenuItem);
1259 
1260         menuBar.add(helpMenu);
1261 
1262         setJMenuBar(menuBar);
1263 
1264         pack();
1265     }//GEN-END:initComponents
1266 
1267     private void addBusinessMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addBusinessMenuItemActionPerformed
1268         // TODO add your handling code here:
1269         businessMethodButtonActionPerformed(evt);
1270     }//GEN-LAST:event_addBusinessMenuItemActionPerformed
1271 
1272     private void editMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editMenuActionPerformed
1273         // TODO add your handling code here:
1274     }//GEN-LAST:event_editMenuActionPerformed
1275 
1276     private void businessMethodButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_businessMethodButtonActionPerformed
1277       DefaultMutableTreeNode selected = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
1278       if (!(selected instanceof Session)) {
1279          //see if the parent is an Entity..
1280          TreePath selectedPath = tree.getSelectionPath();
1281          selected = (DefaultMutableTreeNode) selectedPath.getParentPath().getLastPathComponent();
1282          if (!(selected instanceof Session)) {
1283             JOptionPane.showMessageDialog(this,
1284                   "A business method can only be added to a service bean.  Please first select a session in the application tree.", "Can't add business method!", JOptionPane.ERROR_MESSAGE);
1285             return;
1286          }
1287       }
1288       Session selectedSession = (Session) selected;
1289 
1290       BusinessMethod newBusinessMethod = new BusinessMethod(selectedSession);
1291       selectedSession.add(newBusinessMethod);
1292       tree.setSelectionPath(new TreePath(newBusinessMethod.getPath()));
1293       tree.updateUI();
1294     }//GEN-LAST:event_businessMethodButtonActionPerformed
1295 
1296    private void driverManagerMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_driverManagerMenuItemActionPerformed
1297       DatabaseManagerFrame.getInstance().show();
1298    }//GEN-LAST:event_driverManagerMenuItemActionPerformed
1299 
1300    private void exportMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportMenuItemActionPerformed
1301       if (file == null) {
1302          logger.log("UML Export: save application file first!");
1303          String message = "Before exporting the current application to UML, please save it to an application file.";
1304          JOptionPane.showMessageDialog(this, message, "No application file!", JOptionPane.ERROR_MESSAGE);
1305          saveButtonActionPerformed(null);
1306          if (file == null) {
1307             logger.log("Aborted UML Export!");
1308             return;
1309          }
1310       } else {
1311          saveButtonActionPerformed(null);
1312       }
1313 
1314       int fileChooserStatus;
1315       logToConsole("Exporting application to an XMI file.  Please wait...");
1316       final JFileChooser fileChooser = new JFileChooser(getFileChooserStartDir(FILECHOOSER_UMLEXPORT));
1317       fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
1318       String[] extenstions = {"xmi","xml"};
1319       ExtensionsFileFilter filter = new ExtensionsFileFilter(extenstions);
1320       fileChooser.setFileFilter(filter);
1321 
1322       fileChooser.setDialogTitle("UML Export: Choose a destination XMI file..");
1323       fileChooserStatus = fileChooser.showSaveDialog(this);
1324       if (fileChooserStatus == JFileChooser.APPROVE_OPTION) {
1325          File xmiFile = fileChooser.getSelectedFile();
1326          if (!xmiFile.getAbsolutePath().endsWith(XMI_SUFFIX)) {
1327             xmiFile = new File(xmiFile.getAbsolutePath() + XMI_SUFFIX);
1328          }
1329          //run the export tool
1330          new Jag2UMLGenerator(logger).generateXMI(file.getAbsolutePath(), xmiFile);
1331          logToConsole("...UML export complete.");
1332          setFileChooserStartDir(FILECHOOSER_UMLEXPORT, xmiFile);
1333 
1334       } else {
1335          logToConsole("...aborted!");
1336       }
1337    }//GEN-LAST:event_exportMenuItemActionPerformed
1338 
1339    private void importMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importMenuItemActionPerformed
1340       int fileChooserStatus;
1341       logToConsole("Importing UML model from XMI file.  Please wait...");
1342       final JFileChooser fileChooser = new JFileChooser(getFileChooserStartDir(FILECHOOSER_UMLIMPORT));
1343       String[] extenstions = {"xmi","xml"};
1344       ExtensionsFileFilter filter = new ExtensionsFileFilter(extenstions);
1345       fileChooser.setDialogTitle("UML Import: Choose an XMI file..");
1346       fileChooser.setFileFilter(filter);
1347       fileChooserStatus = fileChooser.showOpenDialog(this);
1348       if (fileChooserStatus == JFileChooser.APPROVE_OPTION) {
1349          String xmiFile = fileChooser.getSelectedFile().getAbsolutePath();
1350          String outputDir = ".";
1351          //run the import tool - creates an XML application file in the output directory
1352          File xmi = new UML2JagGenerator(logger).generateXML(xmiFile, outputDir);
1353          log.info("Generated the jag project file from the UML Model. Now load the file to JAG.");
1354          loadApplicationFile(xmi);
1355          log.info("JAG project file was loaded.");
1356          xmi.delete(); // delete the generated XML file: give the user the choice of where to store it later.
1357          logToConsole("...UML import complete.");
1358          setFileChooserStartDir(FILECHOOSER_UMLIMPORT, fileChooser.getSelectedFile());
1359 
1360 
1361       } else {
1362          logToConsole("...aborted!");
1363       }
1364 
1365    }//GEN-LAST:event_importMenuItemActionPerformed
1366 
1367    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
1368       if (file == null) {
1369          saveAsMenuItemActionPerformed(evt);
1370       } else {
1371          save();
1372       }
1373    }//GEN-LAST:event_saveButtonActionPerformed
1374 
1375    private void disconnectMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_disconnectMenuItemActionPerformed
1376       conManager = null;
1377       databaseConnectionLabel.setText("Database Connection: not connected");
1378       disconnectMenuItem.setEnabled(false);
1379       DatabaseUtils.clearCache();
1380    }//GEN-LAST:event_disconnectMenuItemActionPerformed
1381 
1382    private void addEntityMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addEntityMenuItemActionPerformed
1383       getConManager();
1384       if (conManager == null) {
1385          logger.log("Can't add entity - no database connection!");
1386          return;
1387       }
1388       new SelectTablesDialog(this).show();
1389 
1390       new Thread(new Runnable() {
1391          public void run() {
1392             DefaultMutableTreeNode parent = (DefaultMutableTreeNode) treeModel.getRoot();
1393             Object referencingModule = tree.getLastSelectedPathComponent();
1394             String templateValue = (String) root.config.getTemplateSettings().get(JagGenerator.TEMPLATE_USE_RELATIONS);
1395             if ("true".equalsIgnoreCase(templateValue)) {
1396                relationsEnabled = true;
1397             } else if ("false".equalsIgnoreCase(templateValue)) {
1398                relationsEnabled = false;
1399             } else {
1400                relationsEnabled = false;
1401             }
1402             ArrayList createdEntities = new ArrayList();
1403             for (Iterator tabIt = SelectTablesDialog.getTablelist().iterator(); tabIt.hasNext();) {
1404                String table = (String) tabIt.next();
1405                logger.log("Creating entity for table '" + table + "'...");
1406                ArrayList pKeys = DatabaseUtils.getPrimaryKeys(table);
1407                String pKey = "";
1408                if (pKeys.size() == 1) {
1409                   pKey = (String) pKeys.get(0);
1410                } else if (pKeys.size() > 1) {
1411                   String tableClassName = Utils.toClassName(table);
1412                   pKey = root.getRootPackage() + ".entity" + tableClassName + "PK";
1413                }
1414 
1415                Entity entity = new Entity(root.getRootPackage(), table, pKey);
1416                entity.setTableName(table);
1417                addObject(parent, entity, true, false);
1418                if (referencingModule instanceof Session) {
1419                   Session session = (Session) referencingModule;
1420                   session.addRef(entity.getRefName());
1421                }
1422 
1423                ArrayList columns = sortColumns(DatabaseUtils.getColumns(table), pKeys, entity, pKey);
1424                if (relationsEnabled) {
1425                   generateRelationsFromDB(entity);
1426                }
1427 
1428                // Now build the fields.
1429                for (Iterator colIt = columns.iterator(); colIt.hasNext();) {
1430                   Column column = (Column) colIt.next();
1431                   Field field = new Field(entity, column);
1432                   addObject(entity, field, false, false);
1433                   if (column.getName().equalsIgnoreCase(pKey)) {
1434                      entity.setPKeyType(field.getType(column));
1435                   }
1436                }
1437                createdEntities.add(entity);
1438             }
1439 
1440             // This will make sure the relations are updated correctly in the gui.
1441             for (Iterator iterator = createdEntities.iterator(); iterator.hasNext();) {
1442                Entity entity = (Entity) iterator.next();
1443                entity.notifyRelationsThatConstructionIsFinished();
1444             }
1445             logger.log("...finished!");
1446             tree.updateUI();
1447          }
1448 
1449       }).start();
1450    }//GEN-LAST:event_addEntityMenuItemActionPerformed
1451 
1452    private void addRelationPopupMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addRelationPopupMenuItemActionPerformed
1453       newRelationMenuItemActionPerformed();
1454    }//GEN-LAST:event_addRelationPopupMenuItemActionPerformed
1455 
1456    private void contentMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_contentMenuItemActionPerformed
1457       URL helpURL = null;
1458       String s = null;
1459       try {
1460          s = "file:"
1461                + System.getProperty("user.dir")
1462                + System.getProperty("file.separator")
1463                + "../doc/help/help.html";
1464          helpURL = new URL(s);
1465       } catch (IOException e) {
1466          JagGenerator.logToConsole("Missing help file: " + s);
1467       }
1468       new HtmlContentPopUp(null, "JAG Help", false, helpURL).show();
1469    }//GEN-LAST:event_contentMenuItemActionPerformed
1470 
1471    private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
1472       URL helpURL = null;
1473       String s = null;
1474       try {
1475          s = "file:"
1476                + System.getProperty("user.dir")
1477                + System.getProperty("file.separator")
1478                + "../doc/help/about.html";
1479          helpURL = new URL(s);
1480       } catch (IOException e) {
1481          JagGenerator.logToConsole("Missing help file: " + s);
1482       }
1483       new HtmlContentPopUp(null, "JAG About", false, helpURL).show();
1484    }//GEN-LAST:event_aboutMenuItemActionPerformed
1485 
1486    private void generateJavaApplicationAsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generateJavaApplicationAsMenuItemActionPerformed
1487       if (evt.getActionCommand() == STOP_ACTION) {
1488          runningThread.interrupt();
1489          return;
1490       }
1491 
1492       if (file == null) {
1493          logger.log("No file specified! Save file first.");
1494          String message = "No application file (XML skelet) has been selected.\n" +
1495                "Please save the current application to a file or open an existing application file.";
1496          JOptionPane.showMessageDialog(this, message, "No application file!", JOptionPane.ERROR_MESSAGE);
1497       } else {
1498          SkeletValidator validator = new SkeletValidator(root, tree, entitiesByTableName, logger);
1499          String message = validator.validateSkelet();
1500          if (message != null) {
1501             logger.log("Not a valid application file!");
1502             JOptionPane.showMessageDialog(this, message, "Invalid configuration", JOptionPane.ERROR_MESSAGE);
1503             return;
1504          }
1505          // Make sure the lates skelet has been saved:
1506          if (!save()) {
1507             logger.log("Can't generate application - Invalid relation(s).");
1508             return;
1509          }
1510 
1511          // Now select an output directory for the generated java application.
1512          String outDir = ".";
1513          if (outputDir != null) {
1514             outDir = outputDir.getParentFile().getAbsolutePath();
1515          }
1516          outputDir = selectJagOutDirectory(outDir);
1517          if (outputDir == null) {
1518             return;
1519          }
1520          final String[] args = new String[3];
1521          args[0] = outputDir.getAbsolutePath();
1522          args[1] = file.getAbsolutePath();
1523          runningThread = new Thread() {
1524             public void run() {
1525 
1526                logger.log("Running jag in the " + args[0] + " directory for application file: " + args[1]);
1527                JApplicationGen.setLogger(logger);
1528                JApplicationGen.main(args);
1529             }
1530          };
1531          runningThread.start();
1532          executeButton.setIcon(CANCEL_ICON);
1533          executeButton.setActionCommand(STOP_ACTION);
1534       }
1535       setFileNeedsSavingIndicator(false);
1536    }//GEN-LAST:event_generateJavaApplicationAsMenuItemActionPerformed
1537 
1538    private void deleteMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteMenuItemActionPerformed
1539       TreePath[] sel = tree.getSelectionPaths();
1540       for (int i = 0; i < sel.length; i++) {
1541          Object selectedObject = sel[i].getLastPathComponent();
1542          if (!(selectedObject instanceof Config ||
1543                selectedObject instanceof App ||
1544                selectedObject instanceof Paths ||
1545                selectedObject instanceof Datasource)) {
1546 
1547             treeModel.removeNodeFromParent((DefaultMutableTreeNode) selectedObject);
1548          }
1549          if (selectedObject instanceof Entity) {
1550             TemplateString table = ((Entity) selectedObject).getLocalTableName();
1551             SelectTablesDialog.getAlreadyselected().remove(table);
1552             DatabaseUtils.clearColumnsCacheForTable(table.toString());
1553          }
1554       }
1555       setFileNeedsSavingIndicator(true);
1556    }//GEN-LAST:event_deleteMenuItemActionPerformed
1557 
1558    private void newMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newMenuItemActionPerformed
1559       root = new Root();
1560       file = null;
1561       fileNameLabel.setText("Application file:");
1562       fileNameLabel.setToolTipText("No application file selected");
1563       disconnectMenuItemActionPerformed(null);
1564 
1565       treeModel.setRoot(root);
1566    }//GEN-LAST:event_newMenuItemActionPerformed
1567 
1568    private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
1569       int fileChooserStatus;
1570       JFileChooser fileChooser = new JFileChooser(getFileChooserStartDir(FILECHOOSER_APPFILE_OPEN));
1571       ExtensionsFileFilter filter = new ExtensionsFileFilter("xml");
1572       logToConsole("Opening application file..");
1573 
1574       fileChooser.setDialogTitle("Open an existing application file..");
1575       fileChooser.setFileFilter(filter);
1576       fileChooserStatus = fileChooser.showOpenDialog(this);
1577       if (fileChooserStatus == JFileChooser.APPROVE_OPTION) {
1578          file = fileChooser.getSelectedFile();
1579          loadApplicationFile(file);
1580 
1581       } else {
1582          logToConsole("..aborted application file load!");
1583       }
1584 
1585       if (file != null) {
1586          fileNameLabel.setText("Application file: " + file.getName());
1587          fileNameLabel.setToolTipText(file.getAbsolutePath());
1588          setFileChooserStartDir(FILECHOOSER_APPFILE_OPEN, file);
1589       }
1590    }//GEN-LAST:event_openMenuItemActionPerformed
1591 
1592    public void loadApplicationFile(File file) {
1593       this.file = file;
1594       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
1595       DocumentBuilder builder = null;
1596       Document doc = null;
1597       try {
1598          builder = dbf.newDocumentBuilder();
1599          doc = builder.parse(file);
1600          root = new Root(doc);
1601          logToConsole("..application file " + file + " loaded!");
1602          treeModel.setRoot(root);
1603          tree.setSelectionPath(new TreePath(((DefaultMutableTreeNode) root.getFirstChild()).getPath()));
1604          setFileNeedsSavingIndicator(false);
1605          SelectTablesDialog.clear();
1606          disconnectMenuItemActionPerformed(null);
1607 
1608       } catch (Exception e) {
1609          e.printStackTrace();
1610          logToConsole("Failed to load application file! (" + e + ")");
1611       }
1612    }
1613 
1614    private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuItemActionPerformed
1615       saveButtonActionPerformed(evt);
1616    }//GEN-LAST:event_saveMenuItemActionPerformed
1617 
1618    private void saveAsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsMenuItemActionPerformed
1619       int fileChooserStatus;
1620       JFileChooser fileChooser = new JFileChooser(getFileChooserStartDir(FILECHOOSER_APPFILE_SAVE));
1621       fileChooser.setDialogTitle("Save application file..");
1622       ExtensionsFileFilter filter = new ExtensionsFileFilter("xml");
1623       fileChooser.setFileFilter(filter);
1624       fileChooserStatus = fileChooser.showSaveDialog(this);
1625       if (fileChooserStatus == JFileChooser.APPROVE_OPTION) {
1626          file = fileChooser.getSelectedFile();
1627          setFileChooserStartDir(FILECHOOSER_APPFILE_SAVE, file);
1628          save();
1629       }
1630    }//GEN-LAST:event_saveAsMenuItemActionPerformed
1631 
1632    private void connectMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectMenuItemActionPerformed
1633       GenericJdbcManager previous = conManager;
1634       conManager = null;
1635       getConManager();
1636       if (conManager == null) {
1637          conManager = previous;
1638 
1639       } else {
1640          //we're connected!
1641          DatabaseUtils.clearCache();
1642 
1643          Iterator entities = root.getEntityEjbs().iterator();
1644          while (entities.hasNext()) {
1645             Entity entity = (Entity) entities.next();
1646             for (int i = 0; i < entity.getChildCount(); i++) {
1647                TreeNode child = entity.getChildAt(i);
1648                if (child instanceof Relation) {
1649                   ((RelationPanel) ((Relation) child).getPanel()).initValues(false);
1650                }
1651             }
1652          }
1653       }
1654    }//GEN-LAST:event_connectMenuItemActionPerformed
1655 
1656    private void addSessionMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addSessionMenuItemActionPerformed
1657       addObject(root, new Session(root.getRootPackage()), true, false);
1658       setFileNeedsSavingIndicator(true);
1659    }//GEN-LAST:event_addSessionMenuItemActionPerformed
1660 
1661    private void treeValueChanged(TreeSelectionEvent evt) {//GEN-FIRST:event_treeValueChanged
1662       TreePath path = evt.getNewLeadSelectionPath();
1663       JagBean jagBean;
1664       if (path != null) {
1665          jagBean = (JagBean) path.getLastPathComponent();
1666       } else {
1667          jagBean = (JagBean) treeModel.getRoot();
1668       }
1669       splitPane.setRightComponent(jagBean.getPanel());
1670       splitPane.setDividerLocation(SPLIT_PANE_WIDTH);
1671    }//GEN-LAST:event_treeValueChanged
1672 
1673    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
1674       exitForm(null);
1675    }//GEN-LAST:event_exitMenuItemActionPerformed
1676 
1677    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
1678       kickTheBucket(null);
1679    }//GEN-LAST:event_exitForm
1680 
1681     // Variables declaration - do not modify//GEN-BEGIN:variables
1682     private javax.swing.JMenuItem aboutMenuItem;
1683     private javax.swing.JMenuItem addBusinessMenuItem;
1684     private javax.swing.JMenuItem addEntityMenuItem;
1685     private javax.swing.JMenuItem addRelationMenuItem;
1686     private javax.swing.JMenuItem addSessionMenuItem;
1687     private javax.swing.JMenu addSubMenu;
1688     public javax.swing.JPanel applicationFileInfoPanel;
1689     private javax.swing.JButton businessMethodButton;
1690     private javax.swing.JMenuItem connectMenuItem;
1691     private javax.swing.JMenu connectionMenu;
1692     private javax.swing.JTextArea console;
1693     private javax.swing.JScrollPane consoleScrollPane;
1694     private javax.swing.JMenuItem contentMenuItem;
1695     public javax.swing.JPanel databaseConnectionInfoPanel;
1696     public javax.swing.JLabel databaseConnectionLabel;
1697     private javax.swing.JButton deleteButton;
1698     private javax.swing.JMenuItem deleteMenuItem;
1699     private javax.swing.JSplitPane desktopConsoleSplitPane;
1700     private javax.swing.JDesktopPane desktopPane;
1701     private javax.swing.JMenuItem disconnectMenuItem;
1702     private javax.swing.JMenuItem driverManagerMenuItem;
1703     private javax.swing.JMenu editMenu;
1704     private javax.swing.JButton entityButton;
1705     private javax.swing.JButton executeButton;
1706     private javax.swing.JMenuItem exitMenuItem;
1707     private javax.swing.JMenuItem exportMenuItem;
1708     private javax.swing.JMenu fileMenu;
1709     public javax.swing.JLabel fileNameLabel;
1710     private javax.swing.JMenuItem generateJavaApplicationAsMenuItem;
1711     private javax.swing.JButton helpButton;
1712     private javax.swing.JMenu helpMenu;
1713     private javax.swing.JMenuItem importMenuItem;
1714     private javax.swing.JSeparator jSeparator1;
1715     private javax.swing.JSeparator jSeparator2;
1716     private javax.swing.JSeparator jSeparator3;
1717     private javax.swing.JSeparator jSeparator4;
1718     private javax.swing.JMenuBar menuBar;
1719     private javax.swing.JButton newButton;
1720     private javax.swing.JMenuItem newMenuItem;
1721     private javax.swing.JButton openButton;
1722     private javax.swing.JMenuItem openMenuItem;
1723     private javax.swing.JButton relationButton;
1724     private javax.swing.JMenuItem saveAsMenuItem;
1725     private javax.swing.JButton saveButton;
1726     private javax.swing.JMenuItem saveMenuItem;
1727     private javax.swing.JButton sessionButton;
1728     private javax.swing.JPanel spacer;
1729     private javax.swing.JSplitPane splitPane;
1730     public javax.swing.JToolBar toolBar;
1731     private javax.swing.JTree tree;
1732     private javax.swing.JScrollPane treeScrollPane;
1733     // End of variables declaration//GEN-END:variables
1734 
1735 }