View Javadoc

1   /*
2    *  nextobjects Copyright (C) 2001-2005 Emmanuel Florent
3    *  This program is free software; you can redistribute it and/or modify
4    *  it under the terms of the GNU General Public License as published by the
5    *  Free Software Foundation; either version 2 of the License, or (at your
6    *  option) any later version.
7    *  This program is distributed in the hope that it will
8    *  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9    *  of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10   *  PURPOSE. See the GNU General Public License for more details.
11   *  You should have received a copy of the GNU General Public License along
12   *  with this program; if not, write to the Free Software Foundation, Inc., 59
13   *  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14   */
15  package org.devaki.nextobjects.util;
16  import java.util.Vector;
17  import java.util.StringTokenizer;
18  import java.util.Iterator;
19  import java.util.List;
20  import java.awt.Point;
21  import java.awt.Dimension;
22  import javax.swing.JPanel;
23  import org.devaki.nextobjects.NextObjects;
24  import org.devaki.nextobjects.ui.main.NOLog;
25  import org.devaki.nextobjects.ui.components.CustomTreeNode;
26  import org.devaki.nextobjects.ui.main.NOTreeView;
27  import org.devaki.nextobjects.ui.menus.NOMenuBar;
28  import org.devaki.nextobjects.ui.toolbars.NOToolBar1;
29  import org.devaki.nextobjects.ui.toolbars.NOToolBar2;
30  import org.devaki.nextobjects.workspace.models.BaseModel;
31  import org.devaki.nextobjects.workspace.models.ConceptualModel;
32  import org.devaki.nextobjects.workspace.models.PhysicalModel;
33  import org.devaki.nextobjects.workspace.models.graphics.ConceptualView;
34  import org.devaki.nextobjects.workspace.models.graphics.AssociationView;
35  import org.devaki.nextobjects.workspace.models.graphics.LineView;
36  import org.devaki.nextobjects.workspace.models.graphics.PhysicalView;
37  import org.devaki.nextobjects.workspace.models.graphics.ClassView;
38  import org.devaki.nextobjects.workspace.models.objects.Association;
39  import org.devaki.nextobjects.workspace.models.columns.Column;
40  import org.devaki.nextobjects.workspace.models.objects.AssociationLink;
41  import org.devaki.nextobjects.workspace.models.objects.BaseObject;
42  import org.devaki.nextobjects.workspace.models.objects.BaseClass;
43  import org.devaki.nextobjects.workspace.models.objects.BaseLine;
44  import org.devaki.nextobjects.workspace.models.objects.Constraint;
45  import org.devaki.nextobjects.workspace.models.objects.Entity;
46  import org.devaki.nextobjects.workspace.models.objects.InheritanceLink;
47  import org.devaki.nextobjects.workspace.models.objects.Table;
48  import org.devaki.nextobjects.workspace.models.objects.Label;
49  /***
50   *  the model manager this class manage all the objects,UIs around models
51   *
52   * @author     <a href="mailto:eflorent@devaki.org">Emmanuel Florent</a>
53   * @created    December 27, 2003
54   * @todo       make auto increment works
55   * @todo       id-table-parameters
56   * @todo       complete redo log for remove*Link
57   */
58  public final class ModelMan
59  {
60      /***  Reference to the current ModelMan object */
61      private static ModelMan modelMan;
62      /***  / All existings models (asFrames) */
63      private static Vector models = new Vector();
64      /***  The current model */
65      private static BaseModel currentModel;
66      /***  The dragged objects */
67      private static BaseObject draggedObject;
68      /***  The drop Target Object */
69      private static BaseObject dropTargetObject;
70      /***  The selected objects */
71      private static Vector currentObjects = new Vector();
72      /***  The object currently being resized */
73      private static BaseClass objectToResize;
74      /***  Construct a new 'ModelMan' object */
75      private ModelMan()
76      {
77          // Initializes the local reference of ModelMan
78          //modelMan = this;
79      }
80      /***
81       *  Create a new Conceptual Data Model
82       *
83       * @param  pMerise  the Conceptual Data Model
84       */
85      public static void newConceptualDatamodel(final ConceptualModel pMerise)
86      {
87          resetCurrentObjects();
88          addModel(pMerise);
89          for (int i = 0; i < pMerise.countAssociation(); i++)
90          {
91              addAssociation(pMerise, pMerise.getAssociationAt(i));
92          }
93          for (int i = 0; i < pMerise.countEntities(); i++)
94          {
95              addEntity(pMerise, pMerise.getEntityAt(i));
96          }
97          createFrame(pMerise, (ConceptualView) pMerise.getModelView());
98          pMerise.getModelView().center(true);
99          setCurrentModel(pMerise);
100     }
101     /***
102      *  Conveniency method for the ConceptualView.java to add an entity.
103      *
104      * @param  pMerise  the CM
105      * @param  p        point
106      * @return          the entity
107      */
108     public static Entity addEntity(
109         final ConceptualModel pMerise,
110         final Point p)
111     {
112         pMerise.setVerified(false);
113         pMerise.setSaved(false);
114         Entity newEntity = new Entity(pMerise);
115         p.move(
116             (int) ((p.getX()
117                 - (newEntity.getObjectView().getSize().getWidth() / 2))),
118             (int) ((p.getY()
119                 - newEntity.getObjectView().getSize().getHeight() / 2)));
120         newEntity.getObjectView().setLocation(p);
121         addEntity(pMerise, newEntity);
122         setCurrentObject(newEntity);
123         NOToolBar2.setCurrentTool(NOToolBar2.TOOL_SELECTION);
124         return newEntity;
125     }
126     /***
127      *  Function used to paste an entity when using the clipboard
128      *
129      * @param  pMerise  the model
130      * @param  pEntity  the entity
131      */
132     public static void addEntity(
133         final ConceptualModel pMerise,
134         final Entity pEntity)
135     {
136         pMerise.setVerified(false);
137         pMerise.setSaved(false);
138         CustomTreeNode newNode = new CustomTreeNode(pEntity);
139         pEntity.setDynamicTreeNode(newNode);
140         NOTreeView.addNode(
141             pEntity.getDynamicTreeNode(),
142             pMerise.getDynamicTreeNode(),
143             pMerise.getDynamicTreeNode().getChildCount());
144         // If there is data in the entity, load childrens (columns) in the tree
145         // It only happens when opening a model (so verify the data size)
146         if (pEntity.getData().size() != 0)
147         {
148             NOTreeView.reloadBaseClassChildrens(pEntity.getDynamicTreeNode());
149         }
150         pEntity.setMyModel(pMerise);
151         pMerise.getEntities().addElement(pEntity);
152         currentModel.getRedoLog().log(
153             NORedoLog.ACTION_CREATE,
154             pEntity,
155             (int) pEntity.getObjectView().getLocation().getX(),
156             (int) pEntity.getObjectView().getLocation().getY());
157     }
158     /***
159      *  Function used to paste an association when using the clipboard
160      *
161      * @param  pMerise  the model
162      * @param  pAssoc   the association
163      */
164     public static void addAssociation(
165         final ConceptualModel pMerise,
166         final Association pAssoc)
167     {
168         pMerise.setVerified(false);
169         pMerise.setSaved(false);
170         pAssoc.setMyModel(pMerise);
171         CustomTreeNode newNode = new CustomTreeNode(pAssoc);
172         pAssoc.setDynamicTreeNode(newNode);
173         NOTreeView.addNode(
174             pAssoc.getDynamicTreeNode(),
175             pMerise.getDynamicTreeNode(),
176             pMerise.getDynamicTreeNode().getChildCount());
177         // If there is data in the association, load childrens in the tree
178         // It only happens when opening a model (so verify the data size)
179         if (pAssoc.getData().size() != 0)
180         {
181             NOTreeView.reloadBaseClassChildrens(pAssoc.getDynamicTreeNode());
182         }
183         //pAssoc.getObjectView().resetSelectionPoint();
184         pMerise.getAssociations().addElement(pAssoc);
185     }
186     /***
187      *  Add an association
188      *
189      * @param  pMerise  the model
190      * @param  p        the point
191      * @return          the association
192      */
193     public static Association addAssociation(
194         final ConceptualModel pMerise,
195         final Point p)
196     {
197         Association newAssociation = new Association(pMerise);
198         p.move(
199             (int) (p.getX()
200                 - newAssociation.getObjectView().getSize().getWidth() / 2),
201             (int) (p.getY()
202                 - newAssociation.getObjectView().getSize().getHeight() / 2));
203         newAssociation.getObjectView().setLocation(p);
204         ((AssociationView) newAssociation.getObjectView()).setOldLocation(p);
205         addAssociation(pMerise, newAssociation);
206         resetCurrentObjects();
207         currentObjects.addElement(newAssociation);
208         currentModel.getRedoLog().log(
209             NORedoLog.ACTION_CREATE,
210             newAssociation,
211             (int) newAssociation.getObjectView().getLocation().getX(),
212             (int) newAssociation.getObjectView().getLocation().getY());
213         NOToolBar2.setCurrentTool(NOToolBar2.TOOL_SELECTION);
214         return newAssociation;
215     }
216     /***
217      *  Add an associationLink
218      *
219      * @param  pMerise     the model
220      * @param  pAssocLink  the association
221      * @return             the association link
222      */
223     public static AssociationLink addAssociationLink(
224         final ConceptualModel pMerise,
225         final AssociationLink pAssocLink)
226     {
227         pMerise.setVerified(false);
228         pMerise.setSaved(false);
229         ((Association) pAssocLink.getParentClass()).addAssociationLink(
230             ((Entity) pAssocLink.getChildClass()));
231         ((LineView) pAssocLink.getObjectView()).computeBestPoints();
232         currentModel.getRedoLog().log(
233             NORedoLog.ACTION_CREATE,
234             pAssocLink,
235             0,
236             0);
237         return pAssocLink;
238     }
239     /***
240      *  Remove an entity from a model
241      *
242      * @param  pMerise  the model
243      * @param  pEntity  the entity
244      */
245     private static void removeEntity(
246         final ConceptualModel pMerise,
247         final Entity pEntity)
248     {
249         pMerise.setVerified(false);
250         pMerise.setSaved(false);
251         pMerise.getEntities().removeElement(pEntity);
252         NOTreeView.removeNode(pEntity.getDynamicTreeNode());
253         Iterator itInhrLinks = pMerise.getInheritanceLinks().iterator();
254         Vector vctRemove = new Vector();
255         //cascade delete inheritance links.
256         while (itInhrLinks.hasNext())
257         {
258             InheritanceLink tmpLink = (InheritanceLink) itInhrLinks.next();
259             if (tmpLink.getChildClass().equals(pEntity)
260                 || tmpLink.getParentClass().equals(pEntity))
261             {
262                 vctRemove.addElement(tmpLink);
263             }
264         }
265         Iterator itRemove = vctRemove.iterator();
266         while (itRemove.hasNext())
267         {
268             removeInheritanceLink(pMerise, (InheritanceLink) itRemove.next());
269         }
270         //cascade delete association links.
271         Iterator itAssoLinks = pMerise.getAssociationLinks().iterator();
272         vctRemove = new Vector();
273         while (itAssoLinks.hasNext())
274         {
275             AssociationLink tmpLink = (AssociationLink) itAssoLinks.next();
276             if (tmpLink.getChildClass().equals(pEntity))
277             {
278                 vctRemove.addElement(tmpLink);
279             }
280         }
281         itRemove = vctRemove.iterator();
282         while (itRemove.hasNext())
283         {
284             removeAssociationLink(pMerise, (AssociationLink) itRemove.next());
285         }
286     }
287     /***
288      *  Remove an association from a model
289      *
290      * @param  pMerise  the model
291      * @param  pAssoc   the association
292      */
293     private static void removeAssociation(
294         final ConceptualModel pMerise,
295         final Association pAssoc)
296     {
297         pMerise.setVerified(false);
298         pMerise.setSaved(false);
299         Iterator itAssoLink = pAssoc.getAssociationLinks().iterator();
300         while (itAssoLink.hasNext())
301         {
302             removeAssociationLink(pMerise, (AssociationLink) itAssoLink.next());
303         }
304         pMerise.getAssociations().removeElement(pAssoc);
305         NOTreeView.removeNode(pAssoc.getDynamicTreeNode());
306     }
307     /***
308      *  Remove an AssociacionLink from a model
309      *
310      * @param  pModel      the model
311      * @param  pAssocLink  the association
312      */
313     private static void removeAssociationLink(
314         final ConceptualModel pModel,
315         final AssociationLink pAssocLink)
316     {
317         pModel.setVerified(false);
318         pModel.setSaved(false);
319         pModel.getAssociationLinks().removeElement(pAssocLink);
320         ((Association) pAssocLink.getParentClass())
321             .getAssociationLinks()
322             .removeElement(
323             pAssocLink);
324     }
325     /***
326      *  Remove an InheritanceLink from a model
327      *
328      * @param  pModel        the model
329      * @param  pInheritLink  the inheritance link
330      */
331     private static void removeInheritanceLink(
332         final BaseModel pModel,
333         final InheritanceLink pInheritLink)
334     {
335         pModel.setVerified(false);
336         pModel.setSaved(false);
337         pModel.getInheritanceLinks().removeElement(pInheritLink);
338     }
339     /***
340      *  Create a new Physical Data Model
341      *
342      * @param  pDatabase  the database
343      */
344     public static void newPhysicalDatamodel(final PhysicalModel pDatabase)
345     {
346         resetCurrentObjects();
347         addModel(pDatabase);
348         for (int i = 0; i < pDatabase.countTable(); i++)
349         {
350             ModelMan.addTable(pDatabase, pDatabase.getTableAt(i));
351         }
352         createFrame(pDatabase, (PhysicalView) pDatabase.getModelView());
353         pDatabase.getModelView().center(true);
354         setCurrentModel(pDatabase);
355         NOToolBar2.setCurrentTool(NOToolBar2.TOOL_SELECTION);
356     }
357     /***
358      *  Add a new table
359      *
360      * @param  pDatabase  the database
361      * @param  p          the point
362      * @return            the table
363      */
364     public static Table addTable(final PhysicalModel pDatabase, final Point p)
365     {
366         pDatabase.setVerified(false);
367         pDatabase.setSaved(false);
368         Table pTable = new Table(pDatabase);
369         p.move(
370             (int) ((p.getX()
371                 - (pTable.getObjectView().getSize().getWidth() / 2))),
372             (int) ((p.getY()
373                 - pTable.getObjectView().getSize().getHeight() / 2)));
374         pTable.getObjectView().setLocation(p);
375         addTable(pDatabase, pTable);
376         NOToolBar2.setCurrentTool(NOToolBar2.TOOL_SELECTION);
377         return pTable;
378     }
379     /***
380      *  Function used by to create (using the popup menu) or paste a new table
381      *
382      * @param  pDatabase  the database
383      * @param  pTable     the table
384      */
385     public static void addTable(
386         final PhysicalModel pDatabase,
387         final Table pTable)
388     {
389         pDatabase.setVerified(false);
390         pDatabase.setSaved(false);
391         resetCurrentObjects();
392         currentObjects.addElement(pTable);
393         CustomTreeNode newNode = new CustomTreeNode(pTable);
394         pTable.setDynamicTreeNode(newNode);
395         pTable.setMyModel(pDatabase);
396         NOTreeView.addNode(
397             pTable.getDynamicTreeNode(),
398             pDatabase.getDynamicTreeNode(),
399             pDatabase.getDynamicTreeNode().getChildCount());
400         // If there is data in the table, load childrens (columns) in the tree
401         // It only happens when opening a model (so verify the data size)
402         if (pTable.getData().size() != 0)
403         {
404             NOTreeView.reloadBaseClassChildrens(pTable.getDynamicTreeNode());
405         }
406         currentModel.getRedoLog().log(
407             NORedoLog.ACTION_CREATE,
408             pTable,
409             (int) pTable.getObjectView().getLocation().getX(),
410             (int) pTable.getObjectView().getLocation().getY());
411         pDatabase.getTables().addElement(pTable);
412         ((ClassView) pTable.getObjectView()).setOldLocation(
413             pTable.getObjectView().getLocation());
414         pTable.getObjectView().resetSelectionPoint();
415         //pDatabase.getPanel().repaint();
416     }
417     /***
418      *  Add a constraint
419      *
420      * @param  pDatabase    the databse
421      * @param  pConstraint  the contraint
422      * @return              the constraint
423      */
424     public static Constraint addConstraint(
425         final PhysicalModel pDatabase,
426         final Constraint pConstraint)
427     {
428         pDatabase.setVerified(false);
429         pDatabase.setSaved(false);
430         if (pConstraint != null)
431         {
432             pConstraint.setMyModel(pDatabase);
433             pDatabase.getConstraints().addElement(pConstraint);
434             CustomTreeNode newNode = new CustomTreeNode(pConstraint);
435             pConstraint.setDynamicTreeNode(newNode);
436             NOTreeView.addNode(
437                 pConstraint.getDynamicTreeNode(),
438                 pDatabase.getDynamicTreeNode(),
439                 pDatabase.getDynamicTreeNode().getChildCount());
440             currentModel.getRedoLog().log(
441                 NORedoLog.ACTION_CREATE,
442                 pConstraint,
443                 0,
444                 0);
445         }
446         return pConstraint;
447     }
448     /***
449      *  Conveniency method for the ConceptualView.java to add an
450      *  InheritanceLink.
451      *
452      * @param  pModel            the model
453      * @param  pInheritanceLink  the link
454      */
455     public static void addInheritanceLink(
456         final BaseModel pModel,
457         final InheritanceLink pInheritanceLink)
458     {
459         pModel.setVerified(false);
460         pModel.setSaved(false);
461         pInheritanceLink.setMyModel(pModel);
462         pModel.getInheritanceLinks().addElement(pInheritanceLink);
463         ((LineView) pInheritanceLink.getObjectView()).computeBestPoints();
464         CustomTreeNode newNode = new CustomTreeNode(pInheritanceLink);
465         pInheritanceLink.setDynamicTreeNode(newNode);
466         NOTreeView.addNode(
467             pInheritanceLink.getDynamicTreeNode(),
468             pModel.getDynamicTreeNode(),
469             pModel.getDynamicTreeNode().getChildCount());
470         currentModel.getRedoLog().log(
471             NORedoLog.ACTION_CREATE,
472             pInheritanceLink,
473             (int) pInheritanceLink.getObjectView().getLocation().getX(),
474             (int) pInheritanceLink.getObjectView().getLocation().getY());
475         resetCurrentObjects();
476         currentObjects.addElement(pInheritanceLink);
477     }
478     /***
479      *  method for the <code>ModelView</code> to add a label
480      *
481      * @param  pModel  the model
482      * @param  p       the point
483      */
484     public static void addLabel(final BaseModel pModel, final Point p)
485     {
486         Label lbl = new Label(pModel);
487         lbl.getObjectView().setLocation(p);
488         addLabel(pModel, lbl);
489     }
490     /***
491      *  Method to add a label
492      *
493      * @param  pModel  the model
494      * @param  lbl     the label
495      */
496     public static void addLabel(final BaseModel pModel, final Label lbl)
497     {
498         pModel.getLabels().addElement(lbl.getObjectView());
499         addCurrentObject(lbl);
500         NOToolBar2.setCurrentTool(NOToolBar2.TOOL_SELECTION);
501         lbl.setMyModel(pModel);
502         currentModel.getRedoLog().log(
503             NORedoLog.ACTION_CREATE,
504             lbl,
505             (int) lbl.getObjectView().getLocation().getX(),
506             (int) lbl.getObjectView().getLocation().getY());
507     }
508     /***
509      *  Remove a table from a database
510      *
511      * @param  pDatabase  the database
512      * @param  t          the table
513      */
514     public static void removeTable(
515         final PhysicalModel pDatabase,
516         final Table t)
517     {
518         pDatabase.setVerified(false);
519         pDatabase.setSaved(false);
520         pDatabase.getTables().removeElement(t);
521         NOTreeView.removeNode(t.getDynamicTreeNode());
522         //cascade delete inheritance links.
523         Iterator itInhrLinks = pDatabase.getInheritanceLinks().iterator();
524         Vector vctRemove = new Vector();
525         while (itInhrLinks.hasNext())
526         {
527             InheritanceLink tmpLink = (InheritanceLink) itInhrLinks.next();
528             if (tmpLink.getChildClass().equals(pDatabase)
529                 || tmpLink.getParentClass().equals(pDatabase))
530             {
531                 vctRemove.addElement(tmpLink);
532             }
533         }
534         Iterator itRemove = vctRemove.iterator();
535         while (itRemove.hasNext())
536         {
537             removeInheritanceLink(pDatabase, (InheritanceLink) itRemove.next());
538         }
539         //cascade delete constraints
540         Iterator itCst = pDatabase.getConstraints().iterator();
541         vctRemove = new Vector();
542         while (itCst.hasNext())
543         {
544             Constraint tmpLink = (Constraint) itCst.next();
545             if (tmpLink.getChildClass().equals(t)
546                 || tmpLink.getParentClass().equals(t))
547             {
548                 vctRemove.addElement(tmpLink);
549             }
550         }
551         itRemove = vctRemove.iterator();
552         while (itRemove.hasNext())
553         {
554             removeConstraint(pDatabase, (Constraint) itRemove.next());
555         }
556     }
557     /***
558      *  Remove a label from a model
559      *
560      * @param  pModel  the model
561      * @param  pLabel  the label
562      */
563     public static void removeLabel(final BaseModel pModel, final Label pLabel)
564     {
565         pModel.setVerified(false);
566         pModel.setSaved(false);
567         resetCurrentObjects();
568         pModel.getLabels().removeElement(pLabel.getObjectView());
569     }
570     /***
571      *  Remove a constraint from a table
572      *
573      * @param  pDatabase  the database
574      * @param  c          the constraint
575      */
576     private static void removeConstraint(
577         final PhysicalModel pDatabase,
578         final Constraint c)
579     {
580         pDatabase.setVerified(false);
581         pDatabase.setSaved(false);
582         List pFK=c.getReferences();
583         for (int i=0;i<pFK.size();i++) {
584             ((Column)pFK.get(i)).setForeignKey(true);
585         }
586         pDatabase.getConstraints().removeElement(c);
587         NOTreeView.removeNode(c.getDynamicTreeNode());
588     }
589     /***
590      *  Return the list of models
591      *
592      * @return    the models
593      */
594     public static Vector getModels()
595     {
596         return models;
597     }
598     /***
599      *  Complete the list of models
600      *
601      * @param  pModel  the model
602      */
603     private static void addModel(final BaseModel pModel)
604     {
605         models.addElement(pModel);
606         CustomTreeNode newNode = new CustomTreeNode(pModel);
607         pModel.setDynamicTreeNode(newNode);
608         NOTreeView.addNode(pModel.getDynamicTreeNode());
609     }
610     /***
611      *  Add an object when using the action 'New' on the popup menu
612      *
613      * @param  p  the point
614      */
615     public static void newObject(final Point p)
616     {
617         if (currentModel instanceof ConceptualModel)
618         {
619             addEntity((ConceptualModel) currentModel, p);
620         }
621         else
622             if (currentModel instanceof PhysicalModel)
623             {
624                 addTable((PhysicalModel) currentModel, p);
625             }
626     }
627     /***
628      *  Get the current model
629      *
630      * @return    the model
631      */
632     public static BaseModel getCurrentModel()
633     {
634         return currentModel;
635     }
636     /***
637      *  Define the current model
638      *
639      * @param  pNOModel  the modell
640      */
641     public static void setCurrentModel(final BaseModel pNOModel)
642     {
643         if (pNOModel != null)
644         {
645             currentModel = pNOModel;
646             resetCurrentObjects();
647             NextObjects.getReference().getNOWorkspace().setSelectedComponent(
648                 pNOModel.getPanel());
649         }
650         NOMenuBar.fixModelMenu();
651         NOToolBar2.fixIcons();
652     }
653     /***
654      *  Return the current selected object
655      *
656      * @return    all the selected objects
657      */
658     public static Vector getCurrentObjects()
659     {
660         return currentObjects;
661     }
662     /***
663      *  Return the first selected object
664      *
665      * @return    the last selected object
666      */
667     public static BaseObject getCurrentObject()
668     {
669         if (currentObjects != null && !currentObjects.isEmpty())
670         {
671             return (BaseObject) currentObjects.lastElement();
672         }
673         else
674         {
675             return null;
676         }
677     }
678     /***
679      *  Define the current selected object
680      *
681      * @param  pCurrentObject  the objects
682      */
683     public static void addCurrentObject(final BaseObject pCurrentObject)
684     {
685         if (pCurrentObject == null)
686         {
687             resetCurrentObjects();
688         }
689         else
690         {
691             if (!currentObjects.contains(pCurrentObject))
692             {
693                 currentObjects.addElement(pCurrentObject);
694             }
695             else
696             {
697                 currentObjects.removeElement(pCurrentObject);
698             }
699             // Update selection the tree
700             if (pCurrentObject.getDynamicTreeNode() != null)
701             {
702                 NOTreeView.addSelectedNode(pCurrentObject.getDynamicTreeNode());
703             }
704             // Fix GUI
705             pCurrentObject.getObjectView().resetSelectionPoint();
706             currentModel.getPanel().repaint();
707             NOMenuBar.fixEditMenu();
708             NOToolBar1.fixIcons();
709         }
710     }
711     /***
712      *  Define the current selected object
713      *
714      * @param  pCurrentObject  the" object
715      */
716     public static void setCurrentObject(final BaseObject pCurrentObject)
717     {
718         resetCurrentObjects();
719         addCurrentObject(pCurrentObject);
720     }
721     /***  Return the current selected object */
722     public static void resetCurrentObjects()
723     {
724         currentObjects.removeAllElements();
725         NOTreeView.resetSelectedNode();
726     }
727     /***
728      *  Define the current dragged object
729      *
730      * @param  pDraggedObject  the object
731      */
732     public static void setDraggedObject(final BaseObject pDraggedObject)
733     {
734         draggedObject = pDraggedObject;
735     }
736     /***
737      *  get the dragged object
738      *
739      * @return    the object
740      */
741     public static BaseObject getDraggedObject()
742     {
743         return draggedObject;
744     }
745     /***
746      *  Define the current Drop Target Object
747      *
748      * @param  pDropTargetObject  the object
749      */
750     public static void setDropTargetObject(final BaseObject pDropTargetObject)
751     {
752         dropTargetObject = pDropTargetObject;
753     }
754     /***
755      *  get the drop target object
756      *
757      * @return    the object
758      */
759     public static BaseObject getDropTargetObject()
760     {
761         return dropTargetObject;
762     }
763     /***
764      *  Define the object currently being resized
765      *
766      * @param  pObjectToResize  the object
767      */
768     public static void setObjectToResize(final BaseClass pObjectToResize)
769     {
770         objectToResize = pObjectToResize;
771     }
772     /***
773      *  Get the object currently being resized
774      *
775      * @return    the object
776      */
777     public static BaseClass getObjectToResize()
778     {
779         return objectToResize;
780     }
781     /***
782      *  Resize all currents objects and log it.
783      *
784      * @param  xi  x width
785      * @param  yi  height
786      */
787     public static void resizeCurrentObject(final int xi, final int yi)
788     {
789         for (int i = 0; i < currentObjects.size(); i++)
790         {
791             BaseObject currentObject =
792                 ((BaseObject) currentObjects.elementAt(i));
793             Dimension d = currentObject.getObjectView().getSize();
794             currentModel.getRedoLog().log(
795                 NORedoLog.ACTION_RESIZE,
796                 currentObject,
797                 d.width,
798                 d.height);
799             d.setSize(new Dimension(xi, yi));
800             currentObject.getObjectView().setSize(d);
801             //currentObject.getObjectView().resetSelectionPoint();
802         }
803     }
804     /***
805      *  Move all selected objects and log it
806      *
807      * @param  xi  the delta x
808      * @param  yi  the delta y
809      */
810     public static void moveCurrentObjects(final int xi, final int yi)
811     {
812         Iterator itCurrents = currentObjects.iterator();
813         while (itCurrents.hasNext())
814         {
815             BaseObject tmpObject = ((BaseObject) itCurrents.next());
816             if (tmpObject.getObjectView() instanceof ClassView)
817             {
818                 Point oldPoint =
819                     ((ClassView) tmpObject.getObjectView()).getLocation();
820                 ((ClassView) tmpObject.getObjectView()).setOldLocation(
821                     oldPoint);
822                 Point newPoint = new Point(oldPoint.x + xi, oldPoint.y + yi);
823                 ((ClassView) tmpObject.getObjectView()).setLocation(newPoint);
824                 tmpObject.getObjectView().resetSelectionPoint();
825                 if (!(xi == 0 && yi == 0))
826                 {
827                     currentModel.getRedoLog().log(
828                         NORedoLog.ACTION_MOVE,
829                         tmpObject,
830                         xi,
831                         yi);
832                 }
833             }
834             else
835                 if (tmpObject.getObjectView() instanceof LineView)
836                 {
837                     if (xi != 0)
838                     {
839                         (
840                             (LineView) tmpObject
841                                 .getObjectView())
842                                 .computeBestPoints(
843                             new Point(xi, yi));
844                         currentModel.getRedoLog().log(
845                             NORedoLog.ACTION_MOVE,
846                             tmpObject,
847                             xi,
848                             yi);
849                     }
850                 }
851         }
852     }
853     /***  Description of the Method */
854     public static void resetActionLocations()
855     {
856         Iterator itCurrents = currentObjects.iterator();
857         while (itCurrents.hasNext())
858         {
859             ((BaseObject) itCurrents.next())
860                 .getObjectView()
861                 .resetActionLocation();
862         }
863     }
864     /***
865      *  Delete an object when using the action 'Delete' on the popup menu
866      */
867     public static void delete()
868     {
869         for (int i = 0; i < currentObjects.size(); i++)
870         {
871             BaseObject currentObject = (BaseObject) currentObjects.elementAt(i);
872             currentModel.getRedoLog().log(
873                 NORedoLog.ACTION_DELETE,
874                 currentObject,
875                 (int) currentObject.getObjectView().getLocation().getX(),
876                 (int) currentObject.getObjectView().getLocation().getY());
877             if (currentModel instanceof ConceptualModel)
878             {
879                 if (currentObject instanceof Entity)
880                 {
881                     removeEntity(
882                         ((ConceptualModel) currentModel),
883                         (Entity) currentObject);
884                 }
885                 else
886                     if (currentObject instanceof Association)
887                     {
888                         removeAssociation(
889                             ((ConceptualModel) currentModel),
890                             (Association) currentObject);
891                     }
892                     else
893                         if (currentObject instanceof AssociationLink)
894                         {
895                             removeAssociationLink(
896                                 ((ConceptualModel) currentModel),
897                                 (AssociationLink) currentObject);
898                         }
899                         else
900                             if (currentObject instanceof InheritanceLink)
901                             {
902                                 removeInheritanceLink(
903                                     ((ConceptualModel) currentModel),
904                                     (InheritanceLink) currentObject);
905                             }
906                             else
907                                 if (currentObject instanceof Label)
908                                 {
909                                     removeLabel(
910                                         currentModel,
911                                         (Label) currentObject);
912                                 }
913             }
914             else
915                 if (currentModel instanceof PhysicalModel)
916                 {
917                     if (currentObject instanceof Table)
918                     {
919                         removeTable(
920                             ((PhysicalModel) currentModel),
921                             (Table) currentObject);
922                     }
923                     else
924                         if (currentObject instanceof Constraint)
925                         {
926                             removeConstraint(
927                                 ((PhysicalModel) currentModel),
928                                 (Constraint) currentObject);
929                         }
930                         else
931                             if (currentObject instanceof InheritanceLink)
932                             {
933                                 removeInheritanceLink(
934                                     currentModel,
935                                     (InheritanceLink) currentObject);
936                             }
937                             else
938                                 if (currentObject instanceof Label)
939                                 {
940                                     removeLabel(
941                                         currentModel,
942                                         (Label) currentObject);
943                                 }
944                 }
945         }
946         resetCurrentObjects();
947         currentModel.getModelView().setFullRefresh(true);
948         currentModel.getModelView().repaint();
949     }
950     /***
951      *  Create a new internal frame
952      *
953      * @param  pNOModel  the model
954      * @param  view      the drawin g area
955      */
956     private static void createFrame(
957         final BaseModel pNOModel,
958         final JPanel view)
959     {
960         //BaseModel model=pNOModel;
961         pNOModel.setPanel(view);
962         String type = "";
963         if (pNOModel instanceof ConceptualModel)
964         {
965             type = "cdm::";
966         }
967         else
968         {
969             type = "pdm::";
970         }
971         NextObjects.getReference().getNOWorkspace().addPanel(
972             view,
973             type + pNOModel.getName());
974         setCurrentModel(pNOModel);
975         NOMenuBar.fixFileMenu();
976         NOMenuBar.fixEditMenu();
977         NOToolBar1.fixIcons();
978         NOToolBar2.fixIcons();
979     }
980     /***
981      *  get rid of a model
982      *
983      * @param  pNOModel  the model
984      */
985     public static void removeModel(final BaseModel pNOModel)
986     {
987         NextObjects.getReference().getNOWorkspace().removeTabAt(
988             models.indexOf(pNOModel));
989         models.removeElement(pNOModel);
990         models.trimToSize();
991         NOTreeView.removeNode(pNOModel.getDynamicTreeNode());
992         setCurrentModel(null);
993         NOMenuBar.fixFileMenu();
994         NOMenuBar.fixEditMenu();
995         NOToolBar1.fixIcons();
996         NOToolBar2.fixIcons();
997     }
998     /***
999      * @param  pModel  Description of the Parameter
1000      */
1001     /***
1002      *  Others functions *
1003      *
1004      * @param  pModel  Description of the Parameter
1005      */
1006     /***
1007      * @param  pModel  Description of the Parameter
1008      */
1009     /***
1010      *  Call the right verifier according to the model type.
1011      *
1012      * @param  pModel  the model
1013      */
1014     public static void verify(final BaseModel pModel)
1015     {
1016         if (pModel instanceof ConceptualModel)
1017         {
1018             CDMVerifier.verify((ConceptualModel) pModel);
1019         }
1020         else
1021             if (pModel instanceof PhysicalModel)
1022             {
1023                 PDMVerifier.verify((PhysicalModel) pModel);
1024             }
1025         NOLog.showPane(0);
1026     }
1027     /***
1028      *  Compute best size for classes and best positions for links
1029      *
1030      * @param  pModel  the model
1031      */
1032     public static void resizeModelObjects(final BaseModel pModel)
1033     {
1034         if (pModel != null)
1035         {
1036             Vector classes = pModel.getClasses();
1037             Iterator iterator1 = classes.iterator();
1038             while (iterator1.hasNext())
1039             {
1040                 BaseClass baseClass = (BaseClass) iterator1.next();
1041                 ((ClassView) baseClass.getObjectView()).autoResize(true);
1042             }
1043             Vector links = pModel.getLinks();
1044             Iterator iterator2 = links.iterator();
1045             while (iterator2.hasNext())
1046             {
1047                 BaseLine baseLine = (BaseLine) iterator2.next();
1048                 ((LineView) baseLine.getObjectView()).computeBestPoints();
1049             }
1050             currentModel.getModelView().setFullRefresh(true);
1051             currentModel.getModelView().repaint();
1052         }
1053     }
1054     /***
1055      *  Converts a database schema name to java object name. Operates same as
1056      *  underscoreMethod but does not convert anything to lowercase.
1057      *
1058      * @param  schemaName  name to be converted.
1059      * @return             converted name.
1060      * @see                org.apache.torque.engine.database.model.NameGenerator
1061      * @see                #underscoreMethod(String)
1062      */
1063     public static String getJavaName(final String schemaName)
1064     {
1065         StringBuffer name = new StringBuffer();
1066         StringTokenizer tok =
1067             new StringTokenizer(schemaName, String.valueOf("_"));
1068         while (tok.hasMoreTokens())
1069         {
1070             String namePart = (String) tok.nextElement();
1071             name.append(
1072                 new StringBuffer(namePart.length())
1073                     .append(Character.toTitleCase(namePart.charAt(0)))
1074                     .append(namePart.substring(1))
1075                     .toString());
1076         }
1077         return name.toString();
1078     }
1079 }