KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectstyle > cayenne > modeler > ProjectController


1 /* ====================================================================
2  *
3  * The ObjectStyle Group Software License, version 1.1
4  * ObjectStyle Group - http://objectstyle.org/
5  *
6  * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
7  * of the software. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution, if any,
22  * must include the following acknowlegement:
23  * "This product includes software developed by independent contributors
24  * and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
25  * Alternately, this acknowlegement may appear in the software itself,
26  * if and wherever such third-party acknowlegements normally appear.
27  *
28  * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
29  * or promote products derived from this software without prior written
30  * permission. For written permission, email
31  * "andrus at objectstyle dot org".
32  *
33  * 5. Products derived from this software may not be called "ObjectStyle"
34  * or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
35  * names without prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals and hosted on ObjectStyle Group web site. For more
53  * information on the ObjectStyle Group, please see
54  * <http://objectstyle.org/>.
55  */

56 package org.objectstyle.cayenne.modeler;
57
58 import java.awt.Component JavaDoc;
59 import java.util.ArrayList JavaDoc;
60 import java.util.EventListener JavaDoc;
61 import java.util.EventObject JavaDoc;
62 import java.util.Iterator JavaDoc;
63
64 import javax.swing.event.EventListenerList JavaDoc;
65
66 import org.objectstyle.cayenne.CayenneRuntimeException;
67 import org.objectstyle.cayenne.access.DataDomain;
68 import org.objectstyle.cayenne.access.DataNode;
69 import org.objectstyle.cayenne.map.DataMap;
70 import org.objectstyle.cayenne.map.DbAttribute;
71 import org.objectstyle.cayenne.map.DbEntity;
72 import org.objectstyle.cayenne.map.DbRelationship;
73 import org.objectstyle.cayenne.map.ObjAttribute;
74 import org.objectstyle.cayenne.map.ObjEntity;
75 import org.objectstyle.cayenne.map.ObjRelationship;
76 import org.objectstyle.cayenne.map.Procedure;
77 import org.objectstyle.cayenne.map.ProcedureParameter;
78 import org.objectstyle.cayenne.map.event.AttributeEvent;
79 import org.objectstyle.cayenne.map.event.DataMapEvent;
80 import org.objectstyle.cayenne.map.event.DataMapListener;
81 import org.objectstyle.cayenne.map.event.DataNodeEvent;
82 import org.objectstyle.cayenne.map.event.DataNodeListener;
83 import org.objectstyle.cayenne.map.event.DbAttributeListener;
84 import org.objectstyle.cayenne.map.event.DbEntityListener;
85 import org.objectstyle.cayenne.map.event.DbRelationshipListener;
86 import org.objectstyle.cayenne.map.event.DomainEvent;
87 import org.objectstyle.cayenne.map.event.DomainListener;
88 import org.objectstyle.cayenne.map.event.EntityEvent;
89 import org.objectstyle.cayenne.map.event.ObjAttributeListener;
90 import org.objectstyle.cayenne.map.event.ObjEntityListener;
91 import org.objectstyle.cayenne.map.event.ObjRelationshipListener;
92 import org.objectstyle.cayenne.map.event.ProcedureEvent;
93 import org.objectstyle.cayenne.map.event.ProcedureListener;
94 import org.objectstyle.cayenne.map.event.ProcedureParameterEvent;
95 import org.objectstyle.cayenne.map.event.ProcedureParameterListener;
96 import org.objectstyle.cayenne.map.event.QueryEvent;
97 import org.objectstyle.cayenne.map.event.QueryListener;
98 import org.objectstyle.cayenne.map.event.RelationshipEvent;
99 import org.objectstyle.cayenne.modeler.action.NavigateBackwardAction;
100 import org.objectstyle.cayenne.modeler.action.NavigateForwardAction;
101 import org.objectstyle.cayenne.modeler.action.RevertAction;
102 import org.objectstyle.cayenne.modeler.action.SaveAction;
103 import org.objectstyle.cayenne.modeler.event.AttributeDisplayEvent;
104 import org.objectstyle.cayenne.modeler.event.DataMapDisplayEvent;
105 import org.objectstyle.cayenne.modeler.event.DataMapDisplayListener;
106 import org.objectstyle.cayenne.modeler.event.DataNodeDisplayEvent;
107 import org.objectstyle.cayenne.modeler.event.DataNodeDisplayListener;
108 import org.objectstyle.cayenne.modeler.event.DbAttributeDisplayListener;
109 import org.objectstyle.cayenne.modeler.event.DbEntityDisplayListener;
110 import org.objectstyle.cayenne.modeler.event.DbRelationshipDisplayListener;
111 import org.objectstyle.cayenne.modeler.event.DisplayEvent;
112 import org.objectstyle.cayenne.modeler.event.DomainDisplayEvent;
113 import org.objectstyle.cayenne.modeler.event.DomainDisplayListener;
114 import org.objectstyle.cayenne.modeler.event.EntityDisplayEvent;
115 import org.objectstyle.cayenne.modeler.event.ObjAttributeDisplayListener;
116 import org.objectstyle.cayenne.modeler.event.ObjEntityDisplayListener;
117 import org.objectstyle.cayenne.modeler.event.ObjRelationshipDisplayListener;
118 import org.objectstyle.cayenne.modeler.event.ProcedureDisplayEvent;
119 import org.objectstyle.cayenne.modeler.event.ProcedureDisplayListener;
120 import org.objectstyle.cayenne.modeler.event.ProcedureParameterDisplayEvent;
121 import org.objectstyle.cayenne.modeler.event.ProcedureParameterDisplayListener;
122 import org.objectstyle.cayenne.modeler.event.QueryDisplayEvent;
123 import org.objectstyle.cayenne.modeler.event.QueryDisplayListener;
124 import org.objectstyle.cayenne.modeler.event.RelationshipDisplayEvent;
125 import org.objectstyle.cayenne.modeler.pref.DataMapDefaults;
126 import org.objectstyle.cayenne.modeler.pref.DataNodeDefaults;
127 import org.objectstyle.cayenne.modeler.util.CayenneController;
128 import org.objectstyle.cayenne.modeler.util.CircularArray;
129 import org.objectstyle.cayenne.pref.Domain;
130 import org.objectstyle.cayenne.project.Project;
131 import org.objectstyle.cayenne.query.Query;
132 import org.objectstyle.cayenne.util.IDUtil;
133
134 /**
135  * A controller that works with the project tree, tracking selection and dispatching
136  * project events.
137  * <p>
138  * TODO: Refactor the event model, so that events are generic and contain "path" to a
139  * project node in question. After this is done, EventController should no longer maintain
140  * the selection model (currentXYZ ivars), rather it should update internal model.
141  * </p>
142  */

143 public class ProjectController extends CayenneController {
144
145     /*
146      * A snapshot of the current state of the project controller.
147      * This was added so that we could support history of recent objects.
148      */

149     public class ControllerState {
150         private boolean isRefiring;
151         private DisplayEvent event;
152         private DataDomain domain;
153         private DataNode node;
154         private DataMap map;
155         private ObjEntity objEntity;
156         private DbEntity dbEntity;
157         private ObjAttribute objAttr;
158         private DbAttribute dbAttr;
159         private ObjRelationship objRel;
160         private DbRelationship dbRel;
161         private Procedure procedure;
162         private ProcedureParameter procedureParameter;
163         private Query query;
164         
165         public ControllerState(){
166             domain = null;
167             node = null;
168             map = null;
169
170             objEntity = null;
171             objAttr = null;
172             objRel = null;
173
174             dbEntity = null;
175             dbAttr = null;
176             dbRel = null;
177             
178             procedure = null;
179             procedureParameter = null;
180             
181             query = null;
182             
183             event = null;
184             isRefiring = false;
185         }
186         
187         /*
188          * Used to determine if the val ControllerState is equivalent, which
189          * means if the event is refired again, will it end up in the same
190          * place on the screen. This get's a bit messy at the end, because
191          * of inheritance heirarchy issues.
192          */

193         public boolean isEquivalent(ControllerState val){
194             if (val == null) return false;
195             
196             if (event instanceof EntityDisplayEvent && val.event instanceof EntityDisplayEvent){
197                 if (((EntityDisplayEvent)val.event).getEntity() instanceof ObjEntity){
198                     return objEntity == val.objEntity;
199                 }
200                 else {
201                     return dbEntity == val.dbEntity;
202                 }
203             }
204             else if (event instanceof ProcedureDisplayEvent && val.event instanceof ProcedureDisplayEvent){
205                 return procedure == val.procedure;
206             }
207             else if (event instanceof QueryDisplayEvent && val.event instanceof QueryDisplayEvent){
208                 return query == val.query;
209             }
210             else if (event.getClass() == DataMapDisplayEvent.class && event.getClass() == val.event.getClass()){
211                 return map == val.map;
212             }
213             else if (event.getClass() == DataNodeDisplayEvent.class && event.getClass() == val.event.getClass()){
214                 return node == val.node;
215             }
216             else if (event.getClass() == DomainDisplayEvent.class && event.getClass() == val.event.getClass()){
217                 return domain == val.domain;
218             }
219             return false;
220         }
221     }
222     
223     protected EventListenerList JavaDoc listenerList;
224     protected boolean dirty;
225
226     protected Project project;
227     protected Domain projectPreferences;
228
229     protected ControllerState currentState;
230     protected CircularArray controllerStateHistory;
231     protected int maxHistorySize = 20;
232
233     public ProjectController(CayenneModelerController parent) {
234         super(parent);
235         this.listenerList = new EventListenerList JavaDoc();
236         controllerStateHistory = new CircularArray(maxHistorySize);
237         currentState = new ControllerState();
238     }
239
240     public Component JavaDoc getView() {
241         return parent.getView();
242     }
243
244     public Project getProject() {
245         return project;
246     }
247
248     public void setProject(Project currentProject) {
249         this.project = currentProject;
250         this.projectPreferences = null;
251     }
252
253     /**
254      * Returns top preferences Domain for the application.
255      */

256     public Domain getApplicationPreferenceDomain() {
257         return getApplication().getPreferenceDomain();
258     }
259
260     /**
261      * Returns top preferences Domain for the current project, throwing an exception if no
262      * project is selected.
263      */

264     public Domain getPreferenceDomainForProject() {
265         Project project = getProject();
266         if (project == null) {
267             throw new CayenneRuntimeException("No Project selected");
268         }
269
270         if (projectPreferences == null) {
271             String JavaDoc key = project.isLocationUndefined() ? new String JavaDoc(IDUtil
272                     .pseudoUniqueByteSequence16()) : project
273                     .getMainFile()
274                     .getAbsolutePath();
275
276             projectPreferences = getApplicationPreferenceDomain().getSubdomain(
277                     Project.class).getSubdomain(key);
278         }
279
280         return projectPreferences;
281     }
282
283     /**
284      * Returns top preferences Domain for the current project, throwing an exception if no
285      * project is selected.
286      */

287     public Domain getPreferenceDomainForDataDomain() {
288         DataDomain dataDomain = getCurrentDataDomain();
289         if (dataDomain == null) {
290             throw new CayenneRuntimeException("No DataDomain selected");
291         }
292
293         return getPreferenceDomainForProject()
294                 .getSubdomain(DataDomain.class)
295                 .getSubdomain(dataDomain.getName());
296     }
297
298     /**
299      * Returns preferences object for the current DataMap. If no preferences exist for the current DataMap,
300      * a new Preferences object is created. If no DataMap is currently selected, an exception is thrown.
301      */

302     public DataMapDefaults getDataMapPreferences() {
303         DataMap map = getCurrentDataMap();
304         if (map == null) {
305             throw new CayenneRuntimeException("No DataMap selectd");
306         }
307
308         return (DataMapDefaults) getPreferenceDomainForDataDomain().getDetail(
309                 map.getName(),
310                 DataMapDefaults.class,
311                 true);
312     }
313
314     /**
315      * Returns preferences object for the current DataMap, throwing an exception if no
316      * DataMap is selected.
317      */

318     public DataNodeDefaults getDataNodePreferences() {
319         DataNode node = getCurrentDataNode();
320         if (node == null) {
321             throw new CayenneRuntimeException("No DataNode selected");
322         }
323
324         return (DataNodeDefaults) getPreferenceDomainForDataDomain().getDetail(
325                 node.getName(),
326                 DataNodeDefaults.class,
327                 true);
328     }
329
330     public void projectOpened() {
331         CayenneModelerFrame frame = (CayenneModelerFrame) getView();
332         addDataNodeDisplayListener(frame);
333         addDataMapDisplayListener(frame);
334         addObjEntityDisplayListener(frame);
335         addDbEntityDisplayListener(frame);
336         addObjAttributeDisplayListener(frame);
337         addDbAttributeDisplayListener(frame);
338         addObjRelationshipDisplayListener(frame);
339         addDbRelationshipDisplayListener(frame);
340         addQueryDisplayListener(frame);
341         addProcedureDisplayListener(frame);
342         addProcedureParameterDisplayListener(frame);
343     }
344
345     public void reset() {
346         clearState();
347         setDirty(false);
348         listenerList = new EventListenerList JavaDoc();
349         controllerStateHistory.clear();
350     }
351
352     /*
353      * Allow the user to change the default history size.
354      *
355      * TODO When a user changes their preferences it should call this method.
356      * I don't know how the preferences work, so I will leave this to someone else to do. Garry
357      */

358     public void setHistorySize(int newSize){
359         controllerStateHistory.resize(newSize);
360     }
361     
362     public boolean isDirty() {
363         return dirty;
364     }
365
366     /** Resets all current models to null. */
367     private void clearState() {
368         // don't clear if we are refiring events for history navigation
369
if (currentState.isRefiring) return;
370         
371         currentState = new ControllerState();
372     }
373     
374     private void saveState(DisplayEvent e){
375         if (!controllerStateHistory.contains(currentState)){
376             currentState.event = e;
377             controllerStateHistory.add(currentState);
378         }
379     }
380     
381     protected void refreshNamespace() {
382         DataDomain domain = getCurrentDataDomain();
383         if (domain != null) {
384             domain.getEntityResolver().clearCache();
385         }
386     }
387
388     private void removeFromHistory(EventObject JavaDoc e) {
389         int count = controllerStateHistory.size();
390         ArrayList JavaDoc removeList = new ArrayList JavaDoc();
391         
392         for (int i = 0; i < count; i++) {
393             ControllerState cs = (ControllerState) controllerStateHistory.get(i);
394
395             EventObject JavaDoc csEvent = cs.event;
396             
397             if (csEvent == null) {
398                 continue;
399             }
400
401             if (e instanceof EntityEvent && csEvent instanceof EntityDisplayEvent) {
402                 if (((EntityEvent) e).getEntity() == ((EntityDisplayEvent) csEvent)
403                         .getEntity()) {
404                     removeList.add(cs);
405                 }
406             }
407             else if (e instanceof ProcedureEvent
408                     && csEvent instanceof ProcedureDisplayEvent) {
409                 if (((ProcedureEvent) e).getProcedure() == ((ProcedureDisplayEvent) csEvent)
410                         .getProcedure()) {
411                     removeList.add(cs);
412                 }
413             }
414             else if (e instanceof QueryEvent && csEvent instanceof QueryDisplayEvent) {
415                 if (((QueryEvent) e).getQuery() == ((QueryDisplayEvent) csEvent)
416                         .getQuery()) {
417                     removeList.add(cs);
418                 }
419             }
420             else if (e instanceof DataMapEvent && csEvent instanceof DataMapDisplayEvent) {
421                 if (((DataMapEvent) e).getDataMap() == ((DataMapDisplayEvent) csEvent)
422                         .getDataMap()) {
423                     removeList.add(cs);
424                 }
425             }
426             else if (e instanceof DataNodeEvent
427                     && csEvent instanceof DataNodeDisplayEvent) {
428                 if (((DataNodeEvent) e).getDataNode() == ((DataNodeDisplayEvent) csEvent)
429                         .getDataNode()) {
430                     removeList.add(cs);
431                 }
432             }
433             else if (e instanceof DomainEvent && csEvent instanceof DomainDisplayEvent) {
434                 if (((DomainEvent) e).getDomain() == ((DomainDisplayEvent) csEvent)
435                         .getDomain()) {
436                     removeList.add(cs);
437                 }
438             }
439         }
440         Iterator JavaDoc it = removeList.iterator();
441         while (it.hasNext()) {
442             controllerStateHistory.remove(it.next());
443         }
444     }
445     
446     public DataNode getCurrentDataNode() {
447         return currentState.node;
448     }
449
450     public DataDomain getCurrentDataDomain() {
451         return currentState.domain;
452     }
453
454     public DataMap getCurrentDataMap() {
455         return currentState.map;
456     }
457
458     public ObjEntity getCurrentObjEntity() {
459         return currentState.objEntity;
460     }
461
462     public DbEntity getCurrentDbEntity() {
463         return currentState.dbEntity;
464     }
465
466     public ObjAttribute getCurrentObjAttribute() {
467         return currentState.objAttr;
468     }
469
470     public DbAttribute getCurrentDbAttribute() {
471         return currentState.dbAttr;
472     }
473
474     public ObjRelationship getCurrentObjRelationship() {
475         return currentState.objRel;
476     }
477
478     public DbRelationship getCurrentDbRelationship() {
479         return currentState.dbRel;
480     }
481
482     public Query getCurrentQuery() {
483         return currentState.query;
484     }
485
486     public Procedure getCurrentProcedure() {
487         return currentState.procedure;
488     }
489
490     public ProcedureParameter getCurrentProcedureParameter() {
491         return currentState.procedureParameter;
492     }
493
494     public void addDomainDisplayListener(DomainDisplayListener listener) {
495         listenerList.add(DomainDisplayListener.class, listener);
496     }
497
498     public void addDomainListener(DomainListener listener) {
499         listenerList.add(DomainListener.class, listener);
500     }
501
502     public void addDataNodeDisplayListener(DataNodeDisplayListener listener) {
503         listenerList.add(DataNodeDisplayListener.class, listener);
504     }
505
506     public void addDataNodeListener(DataNodeListener listener) {
507         listenerList.add(DataNodeListener.class, listener);
508     }
509
510     public void addDataMapDisplayListener(DataMapDisplayListener listener) {
511         listenerList.add(DataMapDisplayListener.class, listener);
512     }
513
514     public void addDataMapListener(DataMapListener listener) {
515         listenerList.add(DataMapListener.class, listener);
516     }
517
518     public void addDbEntityListener(DbEntityListener listener) {
519         listenerList.add(DbEntityListener.class, listener);
520     }
521
522     public void addObjEntityListener(ObjEntityListener listener) {
523         listenerList.add(ObjEntityListener.class, listener);
524     }
525
526     public void addDbEntityDisplayListener(DbEntityDisplayListener listener) {
527         listenerList.add(DbEntityDisplayListener.class, listener);
528     }
529
530     public void addObjEntityDisplayListener(ObjEntityDisplayListener listener) {
531         listenerList.add(ObjEntityDisplayListener.class, listener);
532     }
533
534     public void addDbAttributeListener(DbAttributeListener listener) {
535         listenerList.add(DbAttributeListener.class, listener);
536     }
537
538     public void addDbAttributeDisplayListener(DbAttributeDisplayListener listener) {
539         listenerList.add(DbAttributeDisplayListener.class, listener);
540     }
541
542     public void addObjAttributeListener(ObjAttributeListener listener) {
543         listenerList.add(ObjAttributeListener.class, listener);
544     }
545
546     public void addObjAttributeDisplayListener(ObjAttributeDisplayListener listener) {
547         listenerList.add(ObjAttributeDisplayListener.class, listener);
548     }
549
550     public void addDbRelationshipListener(DbRelationshipListener listener) {
551         listenerList.add(DbRelationshipListener.class, listener);
552     }
553
554     public void addDbRelationshipDisplayListener(DbRelationshipDisplayListener listener) {
555         listenerList.add(DbRelationshipDisplayListener.class, listener);
556     }
557
558     public void addObjRelationshipListener(ObjRelationshipListener listener) {
559         listenerList.add(ObjRelationshipListener.class, listener);
560     }
561
562     public void addObjRelationshipDisplayListener(ObjRelationshipDisplayListener listener) {
563         listenerList.add(ObjRelationshipDisplayListener.class, listener);
564     }
565
566     public void addQueryDisplayListener(QueryDisplayListener listener) {
567         listenerList.add(QueryDisplayListener.class, listener);
568     }
569
570     public void addQueryListener(QueryListener listener) {
571         listenerList.add(QueryListener.class, listener);
572     }
573
574     public void addProcedureDisplayListener(ProcedureDisplayListener listener) {
575         listenerList.add(ProcedureDisplayListener.class, listener);
576     }
577
578     public void addProcedureListener(ProcedureListener listener) {
579         listenerList.add(ProcedureListener.class, listener);
580     }
581
582     public void addProcedureParameterListener(ProcedureParameterListener listener) {
583         listenerList.add(ProcedureParameterListener.class, listener);
584     }
585
586     public void addProcedureParameterDisplayListener(
587             ProcedureParameterDisplayListener listener) {
588         listenerList.add(ProcedureParameterDisplayListener.class, listener);
589     }
590
591     public void fireDomainDisplayEvent(DomainDisplayEvent e) {
592         boolean changed = e.getDomain() != currentState.domain;
593         if (!changed){
594             changed = currentState.node != null
595                 || currentState.map != null
596                 || currentState.dbEntity != null
597                 || currentState.objEntity != null
598                 || currentState.procedure != null
599                 || currentState.query != null;
600         }
601
602         
603         if (!e.isRefired()){
604             e.setDomainChanged(changed);
605             if (changed){
606                 clearState();
607                 currentState.domain = e.getDomain();
608             }
609         }
610         
611         if (changed){
612             saveState(e);
613         }
614
615         EventListener JavaDoc[] list = listenerList.getListeners(DomainDisplayListener.class);
616         for (int i = 0; i < list.length; i++) {
617             DomainDisplayListener temp = (DomainDisplayListener) list[i];
618             temp.currentDomainChanged(e);
619         }
620
621         ((CayenneModelerController) parent).dataDomainSelectedAction(currentState.domain);
622     }
623
624     /**
625      * Informs all listeners of the DomainEvent. Does not send the event to its
626      * originator.
627      */

628     public void fireDomainEvent(DomainEvent e) {
629         setDirty(true);
630
631         if (e.getId() == DomainEvent.REMOVE) {
632             refreshNamespace();
633             removeFromHistory(e);
634         }
635
636         EventListener JavaDoc[] list = listenerList.getListeners(DomainListener.class);
637         for (int i = 0; i < list.length; i++) {
638             DomainListener temp = (DomainListener) list[i];
639             switch (e.getId()) {
640                 case DomainEvent.ADD:
641                     temp.domainAdded(e);
642                     break;
643                 case DomainEvent.CHANGE:
644                     temp.domainChanged(e);
645                     break;
646                 case DomainEvent.REMOVE:
647                     temp.domainRemoved(e);
648                     break;
649                 default:
650                     throw new IllegalArgumentException JavaDoc("Invalid DomainEvent type: "
651                             + e.getId());
652             }
653         }
654     }
655
656     public void fireDataNodeDisplayEvent(DataNodeDisplayEvent e) {
657         boolean changed = e.getDataNode() != currentState.node;
658
659         if (!changed){
660             changed = currentState.map != null
661                 || currentState.dbEntity != null
662                 || currentState.objEntity != null
663                 || currentState.procedure != null
664                 || currentState.query != null;
665         }
666
667         if (!e.isRefired()){
668             e.setDataNodeChanged(changed);
669             
670             if (changed){
671                 clearState();
672                 currentState.domain = e.getDomain();
673                 currentState.node = e.getDataNode();
674             }
675         }
676         
677         if (changed){
678             saveState(e);
679         }
680         
681         EventListener JavaDoc[] list = listenerList.getListeners(DataNodeDisplayListener.class);
682         for (int i = 0; i < list.length; i++) {
683             ((DataNodeDisplayListener) list[i]).currentDataNodeChanged(e);
684         }
685     }
686
687     /**
688      * Informs all listeners of the DataNodeEvent. Does not send the event to its
689      * originator.
690      */

691     public void fireDataNodeEvent(DataNodeEvent e) {
692         setDirty(true);
693         
694         if (e.getId() == DataNodeEvent.REMOVE) {
695             refreshNamespace();
696             removeFromHistory(e);
697         }
698
699         EventListener JavaDoc[] list = listenerList.getListeners(DataNodeListener.class);
700         for (int i = 0; i < list.length; i++) {
701             DataNodeListener temp = (DataNodeListener) list[i];
702             switch (e.getId()) {
703                 case DataNodeEvent.ADD:
704                     temp.dataNodeAdded(e);
705                     break;
706                 case DataNodeEvent.CHANGE:
707                     temp.dataNodeChanged(e);
708                     break;
709                 case DataNodeEvent.REMOVE:
710                     temp.dataNodeRemoved(e);
711                     break;
712                 default:
713                     throw new IllegalArgumentException JavaDoc("Invalid DataNodeEvent type: "
714                             + e.getId());
715             }
716         }
717     }
718
719     public void fireDataMapDisplayEvent(DataMapDisplayEvent e) {
720         boolean changed = e.getDataMap() != currentState.map;
721         if (!changed){
722             changed = currentState.dbEntity != null
723                 || currentState.objEntity != null
724                 || currentState.procedure != null
725                 || currentState.query != null;
726         }
727         
728         if (!e.isRefired()){
729             e.setDataMapChanged(changed);
730
731             if (changed){
732                 clearState();
733                 currentState.domain = e.getDomain();
734                 currentState.node = e.getDataNode();
735                 currentState.map = e.getDataMap();
736             }
737         }
738         
739         if (changed){
740             saveState(e);
741         }
742
743         EventListener JavaDoc[] list = listenerList.getListeners(DataMapDisplayListener.class);
744         for (int i = 0; i < list.length; i++) {
745             DataMapDisplayListener temp = (DataMapDisplayListener) list[i];
746             temp.currentDataMapChanged(e);
747         }
748     }
749
750     /**
751      * Informs all listeners of the DataMapEvent. Does not send the event to its
752      * originator.
753      */

754     public void fireDataMapEvent(DataMapEvent e) {
755         setDirty(true);
756         
757         if (e.getId() == DataMapEvent.REMOVE) {
758             refreshNamespace();
759             removeFromHistory(e);
760         }
761
762         EventListener JavaDoc[] list = listenerList.getListeners(DataMapListener.class);
763         for (int i = 0; i < list.length; i++) {
764             DataMapListener listener = (DataMapListener) list[i];
765             switch (e.getId()) {
766                 case DataMapEvent.ADD:
767                     listener.dataMapAdded(e);
768                     break;
769                 case DataMapEvent.CHANGE:
770                     listener.dataMapChanged(e);
771                     break;
772                 case DataMapEvent.REMOVE:
773                     listener.dataMapRemoved(e);
774                     break;
775                 default:
776                     throw new IllegalArgumentException JavaDoc("Invalid DataMapEvent type: "
777                             + e.getId());
778             }
779         }
780     }
781
782     /**
783      * Informs all listeners of the EntityEvent. Does not send the event to its
784      * originator.
785      */

786     public void fireObjEntityEvent(EntityEvent e) {
787         setDirty(true);
788
789         if (currentState.map != null && e.getId() == EntityEvent.CHANGE){
790             currentState.map.objEntityChanged(e);
791         }
792
793         if (e.getId() == EntityEvent.REMOVE) {
794             refreshNamespace();
795             removeFromHistory(e);
796         }
797
798         EventListener JavaDoc[] list = listenerList.getListeners(ObjEntityListener.class);
799         for (int i = 0; i < list.length; i++) {
800             ObjEntityListener temp = (ObjEntityListener) list[i];
801             switch (e.getId()) {
802                 case EntityEvent.ADD:
803                     temp.objEntityAdded(e);
804                     break;
805                 case EntityEvent.CHANGE:
806                     temp.objEntityChanged(e);
807                     break;
808                 case EntityEvent.REMOVE:
809                     temp.objEntityRemoved(e);
810                     break;
811                 default:
812                     throw new IllegalArgumentException JavaDoc("Invalid EntityEvent type: "
813                             + e.getId());
814             }
815         }
816     }
817
818     /**
819      * Informs all listeners of the EntityEvent. Does not send the event to its
820      * originator.
821      */

822     public void fireDbEntityEvent(EntityEvent e) {
823         setDirty(true);
824         
825         if (currentState.map != null && e.getId() == EntityEvent.CHANGE){
826             currentState.map.dbEntityChanged(e);
827         }
828
829         if (e.getId() == EntityEvent.REMOVE) {
830             refreshNamespace();
831             removeFromHistory(e);
832         }
833
834         EventListener JavaDoc[] list = listenerList.getListeners(DbEntityListener.class);
835         for (int i = 0; i < list.length; i++) {
836             DbEntityListener temp = (DbEntityListener) list[i];
837             switch (e.getId()) {
838                 case EntityEvent.ADD:
839                     temp.dbEntityAdded(e);
840                     break;
841                 case EntityEvent.CHANGE:
842                     temp.dbEntityChanged(e);
843                     break;
844                 case EntityEvent.REMOVE:
845                     temp.dbEntityRemoved(e);
846                     break;
847                 default:
848                     throw new IllegalArgumentException JavaDoc("Invalid EntityEvent type: "
849                             + e.getId());
850             }
851         }
852     }
853
854     /**
855      * Informs all listeners of the ProcedureEvent. Does not send the event to its
856      * originator.
857      */

858     public void fireQueryEvent(QueryEvent e) {
859         setDirty(true);
860         
861         if (e.getId() == QueryEvent.REMOVE) {
862             refreshNamespace();
863             removeFromHistory(e);
864         }
865
866         EventListener JavaDoc[] list = listenerList.getListeners(QueryListener.class);
867         for (int i = 0; i < list.length; i++) {
868             QueryListener listener = (QueryListener) list[i];
869             switch (e.getId()) {
870                 case QueryEvent.ADD:
871                     listener.queryAdded(e);
872                     break;
873                 case QueryEvent.CHANGE:
874                     listener.queryChanged(e);
875                     break;
876                 case QueryEvent.REMOVE:
877                     listener.queryRemoved(e);
878                     break;
879                 default:
880                     throw new IllegalArgumentException JavaDoc("Invalid ProcedureEvent type: "
881                             + e.getId());
882             }
883         }
884     }
885
886     /**
887      * Informs all listeners of the ProcedureEvent. Does not send the event to its
888      * originator.
889      */

890     public void fireProcedureEvent(ProcedureEvent e) {
891         setDirty(true);
892         
893         if (e.getId() == ProcedureEvent.REMOVE) {
894             refreshNamespace();
895             removeFromHistory(e);
896         }
897
898         EventListener JavaDoc[] list = listenerList.getListeners(ProcedureListener.class);
899         for (int i = 0; i < list.length; i++) {
900             ProcedureListener listener = (ProcedureListener) list[i];
901             switch (e.getId()) {
902                 case ProcedureEvent.ADD:
903                     listener.procedureAdded(e);
904                     break;
905                 case ProcedureEvent.CHANGE:
906                     listener.procedureChanged(e);
907                     break;
908                 case ProcedureEvent.REMOVE:
909                     listener.procedureRemoved(e);
910                     break;
911                 default:
912                     throw new IllegalArgumentException JavaDoc("Invalid ProcedureEvent type: "
913                             + e.getId());
914             }
915         }
916     }
917
918     /**
919      * Informs all listeners of the ProcedureEvent. Does not send the event to its
920      * originator.
921      */

922     public void fireProcedureParameterEvent(ProcedureParameterEvent e) {
923         setDirty(true);
924         
925         EventListener JavaDoc[] list = listenerList.getListeners(ProcedureParameterListener.class);
926         for (int i = 0; i < list.length; i++) {
927             ProcedureParameterListener listener = (ProcedureParameterListener) list[i];
928             switch (e.getId()) {
929                 case EntityEvent.ADD:
930                     listener.procedureParameterAdded(e);
931                     break;
932                 case EntityEvent.CHANGE:
933                     listener.procedureParameterChanged(e);
934                     break;
935                 case EntityEvent.REMOVE:
936                     listener.procedureParameterRemoved(e);
937                     break;
938                 default:
939                     throw new IllegalArgumentException JavaDoc(
940                             "Invalid ProcedureParameterEvent type: " + e.getId());
941             }
942         }
943     }
944
945     public void fireNavigationEvent(EventObject JavaDoc e){
946         Object JavaDoc source = e.getSource();
947         if (source == null) return;
948         
949         int size = controllerStateHistory.size();
950         if (size == 0) return;
951         
952         int i = controllerStateHistory.indexOf(currentState);
953         ControllerState cs = null;
954         if (size == 1){
955             cs = (ControllerState)controllerStateHistory.get(0);
956         }
957         else if (source instanceof NavigateForwardAction){
958             int counter = 0;
959             while(true) {
960                 if (i < 0){
961                     // a new state got created without it being saved.
962
// just move to the beginning of the list
963
cs = (ControllerState)controllerStateHistory.get(0);
964                 }
965                 else if (i+1 < size) {
966                     // move forward
967
cs = (ControllerState)controllerStateHistory.get(i+1);
968                 }
969                 else {
970                     // wrap around
971
cs = (ControllerState)controllerStateHistory.get(0);
972                 }
973                 if (!cs.isEquivalent(currentState)){
974                     break;
975                 }
976                 
977                 // if it doesn't find it within 5 tries it is probably stuck in a loop
978
if (++counter > 5){
979                     break;
980                 }
981                 i++;
982             }
983         }
984         else if (source instanceof NavigateBackwardAction){
985             int counter = 0;
986             while(true) {
987                 if (i < 0){
988                     // a new state got created without it being saved.
989
try {
990                         cs = (ControllerState)controllerStateHistory.get(size-2);
991                     }
992                     catch(ArrayIndexOutOfBoundsException JavaDoc ex){
993                         cs = (ControllerState)controllerStateHistory.get(size-1);
994                     }
995                 }
996                 else if (i-1 >= 0) {
997                     // move to the previous one
998
cs = (ControllerState)controllerStateHistory.get(i-1);
999                 }
1000                else {
1001                    // wrap around
1002
cs = (ControllerState)controllerStateHistory.get(size-1);
1003                }
1004                if (!cs.isEquivalent(currentState)){
1005                    break;
1006                }
1007                // if it doesn't find it within 5 tries it is probably stuck in a loop
1008
if (++counter > 5){
1009                    break;
1010                }
1011                i--;
1012            }
1013        }
1014
1015        // reset the current state to the one we just navigated to
1016
currentState = cs;
1017        DisplayEvent de = cs.event;
1018        if (de == null) return;
1019        
1020        // make sure that isRefiring is turned off prior to exiting this routine
1021
// this flag is used to tell the controller to not create new states
1022
// when we are refiring the event that we saved earlier
1023
currentState.isRefiring = true;
1024        
1025        // the order of the following is checked in most specific to generic because
1026
// of the inheritance heirarchy
1027
de.setRefired(true);
1028        if (de instanceof EntityDisplayEvent){
1029            EntityDisplayEvent ede = (EntityDisplayEvent)de;
1030            ede.setEntityChanged(true);
1031            if (ede.getEntity() instanceof ObjEntity){
1032                fireObjEntityDisplayEvent(ede);
1033            }
1034            else if (ede.getEntity() instanceof DbEntity){
1035                fireDbEntityDisplayEvent(ede);
1036            }
1037        }
1038        else if (de instanceof ProcedureDisplayEvent){
1039            ProcedureDisplayEvent pde = (ProcedureDisplayEvent)de;
1040            pde.setProcedureChanged(true);
1041            fireProcedureDisplayEvent(pde);
1042        }
1043        else if (de instanceof QueryDisplayEvent){
1044            QueryDisplayEvent qde = (QueryDisplayEvent)de;
1045            qde.setQueryChanged(true);
1046            fireQueryDisplayEvent(qde);
1047        }
1048        else if (de instanceof DataMapDisplayEvent){
1049            DataMapDisplayEvent dmde = (DataMapDisplayEvent)de;
1050            dmde.setDataMapChanged(true);
1051            fireDataMapDisplayEvent(dmde);
1052        }
1053        else if (de instanceof DataNodeDisplayEvent){
1054            DataNodeDisplayEvent dnde = (DataNodeDisplayEvent)de;
1055            dnde.setDataNodeChanged(true);
1056            fireDataNodeDisplayEvent(dnde);
1057        }
1058        else if (de instanceof DomainDisplayEvent){
1059            DomainDisplayEvent dde = (DomainDisplayEvent)de;
1060            dde.setDomainChanged(true);
1061            fireDomainDisplayEvent(dde);
1062        }
1063 
1064        // turn off refiring
1065
currentState.isRefiring = false;
1066    }
1067    
1068    public void fireObjEntityDisplayEvent(EntityDisplayEvent e) {
1069        boolean changed = e.getEntity() != currentState.objEntity;
1070        
1071        if (!e.isRefired()){
1072            e.setEntityChanged(changed);
1073
1074            if (changed){
1075                clearState();
1076                currentState.domain = e.getDomain();
1077                currentState.node = e.getDataNode();
1078                currentState.map = e.getDataMap();
1079                currentState.objEntity = (ObjEntity) e.getEntity();
1080            }
1081        }
1082        
1083        if (changed){
1084            saveState(e);
1085        }
1086        
1087        EventListener JavaDoc[] list = listenerList.getListeners(ObjEntityDisplayListener.class);
1088        for (int i = 0; i < list.length; i++) {
1089            ObjEntityDisplayListener temp = (ObjEntityDisplayListener) list[i];
1090            temp.currentObjEntityChanged(e);
1091        }
1092    }
1093
1094    public void fireQueryDisplayEvent(QueryDisplayEvent e) {
1095        boolean changed = e.getQuery() != currentState.query;
1096        
1097        if (!e.isRefired()){
1098            e.setQueryChanged(changed);
1099    
1100            if (changed){
1101                clearState();
1102                currentState.domain = e.getDomain();
1103                currentState.map = e.getDataMap();
1104                currentState.query = e.getQuery();
1105            }
1106        }
1107        
1108        if (changed){
1109            saveState(e);
1110        }
1111        
1112        EventListener JavaDoc[] list = listenerList.getListeners(QueryDisplayListener.class);
1113        for (int i = 0; i < list.length; i++) {
1114            QueryDisplayListener listener = (QueryDisplayListener) list[i];
1115            listener.currentQueryChanged(e);
1116        }
1117    }
1118
1119    public void fireProcedureDisplayEvent(ProcedureDisplayEvent e) {
1120        boolean changed = e.getProcedure() != currentState.procedure;
1121
1122        if (!e.isRefired()){
1123            e.setProcedureChanged(changed);
1124
1125            if (changed){
1126                clearState();
1127                currentState.domain = e.getDomain();
1128                currentState.map = e.getDataMap();
1129                currentState.procedure = e.getProcedure();
1130            }
1131        }
1132        
1133        if (changed){
1134            saveState(e);
1135        }
1136
1137        EventListener JavaDoc[] list = listenerList.getListeners(ProcedureDisplayListener.class);
1138        for (int i = 0; i < list.length; i++) {
1139            ProcedureDisplayListener listener = (ProcedureDisplayListener) list[i];
1140            listener.currentProcedureChanged(e);
1141        }
1142    }
1143
1144    public void fireProcedureParameterDisplayEvent(ProcedureParameterDisplayEvent e) {
1145        boolean changed = e.getProcedureParameter() != currentState.procedureParameter;
1146
1147        if (changed){
1148            if (currentState.procedure != e.getProcedure()){
1149                clearState();
1150                currentState.domain = e.getDomain();
1151                currentState.map = e.getDataMap();
1152                currentState.procedure = e.getProcedure();
1153            }
1154            currentState.procedureParameter = e.getProcedureParameter();
1155        }
1156
1157        EventListener JavaDoc[] list = listenerList.getListeners(ProcedureParameterDisplayListener.class);
1158        for (int i = 0; i < list.length; i++) {
1159            ProcedureParameterDisplayListener listener = (ProcedureParameterDisplayListener) list[i];
1160            listener.currentProcedureParameterChanged(e);
1161        }
1162    }
1163
1164    public void fireDbEntityDisplayEvent(EntityDisplayEvent e) {
1165        boolean changed = e.getEntity() != currentState.dbEntity;
1166        if (!e.isRefired()){
1167            e.setEntityChanged(changed);
1168
1169            if (changed) {
1170                clearState();
1171                currentState.domain = e.getDomain();
1172                currentState.node = e.getDataNode();
1173                currentState.map = e.getDataMap();
1174                currentState.dbEntity = (DbEntity) e.getEntity();
1175            }
1176        }
1177
1178        if (changed){
1179            saveState(e);
1180        }
1181
1182        EventListener JavaDoc[] list = listenerList.getListeners(DbEntityDisplayListener.class);
1183        for (int i = 0; i < list.length; i++) {
1184            DbEntityDisplayListener temp = (DbEntityDisplayListener) list[i];
1185            temp.currentDbEntityChanged(e);
1186        }
1187    }
1188
1189    /** Notifies all listeners of the change(add, remove) and does the change. */
1190    public void fireDbAttributeEvent(AttributeEvent e) {
1191        setDirty(true);
1192
1193        if (currentState.map != null && e.getId() == AttributeEvent.CHANGE){
1194            currentState.map.dbAttributeChanged(e);
1195        }
1196
1197        EventListener JavaDoc[] list = listenerList.getListeners(DbAttributeListener.class);
1198        for (int i = 0; i < list.length; i++) {
1199            DbAttributeListener temp = (DbAttributeListener) list[i];
1200            switch (e.getId()) {
1201                case AttributeEvent.ADD:
1202                    temp.dbAttributeAdded(e);
1203                    break;
1204                case AttributeEvent.CHANGE:
1205                    temp.dbAttributeChanged(e);
1206                    break;
1207                case AttributeEvent.REMOVE:
1208                    temp.dbAttributeRemoved(e);
1209                    break;
1210                default:
1211                    throw new IllegalArgumentException JavaDoc("Invalid AttributeEvent type: "
1212                            + e.getId());
1213            }
1214        }
1215    }
1216
1217    public void fireDbAttributeDisplayEvent(AttributeDisplayEvent e) {
1218        boolean changed = e.getAttribute() != currentState.dbAttr;
1219
1220        if (changed){
1221            if (e.getEntity() != currentState.dbEntity){
1222                clearState();
1223                currentState.domain = e.getDomain();
1224                currentState.map = e.getDataMap();
1225                currentState.dbEntity = (DbEntity) e.getEntity();
1226            }
1227            currentState.dbAttr = (DbAttribute) e.getAttribute();
1228        }
1229        
1230        EventListener JavaDoc[] list = listenerList.getListeners(DbAttributeDisplayListener.class);
1231        for (int i = 0; i < list.length; i++) {
1232            DbAttributeDisplayListener temp = (DbAttributeDisplayListener) list[i];
1233            temp.currentDbAttributeChanged(e);
1234        }
1235    }
1236
1237    /** Notifies all listeners of the change (add, remove) and does the change. */
1238    public void fireObjAttributeEvent(AttributeEvent e) {
1239        setDirty(true);
1240        
1241        if (currentState.map != null && e.getId() == AttributeEvent.CHANGE){
1242            currentState.map.objAttributeChanged(e);
1243        }
1244        
1245        EventListener JavaDoc[] list = listenerList.getListeners(ObjAttributeListener.class);
1246        for (int i = 0; i < list.length; i++) {
1247            ObjAttributeListener temp = (ObjAttributeListener) list[i];
1248            switch (e.getId()) {
1249                case AttributeEvent.ADD:
1250                    temp.objAttributeAdded(e);
1251                    break;
1252                case AttributeEvent.CHANGE:
1253                    temp.objAttributeChanged(e);
1254                    break;
1255                case AttributeEvent.REMOVE:
1256                    temp.objAttributeRemoved(e);
1257                    break;
1258                default:
1259                    throw new IllegalArgumentException JavaDoc("Invalid AttributeEvent type: "
1260                            + e.getId());
1261            }
1262        }
1263    }
1264
1265    public void fireObjAttributeDisplayEvent(AttributeDisplayEvent e) {
1266        boolean changed = e.getAttribute() != currentState.objAttr;
1267
1268        if (changed){
1269            if (e.getEntity() != currentState.objEntity){
1270                clearState();
1271                currentState.domain = e.getDomain();
1272                currentState.map = e.getDataMap();
1273                currentState.objEntity = (ObjEntity) e.getEntity();
1274            }
1275            currentState.objAttr = (ObjAttribute) e.getAttribute();
1276        }
1277        
1278        EventListener JavaDoc[] list = listenerList.getListeners(ObjAttributeDisplayListener.class);
1279        for (int i = 0; i < list.length; i++) {
1280            ObjAttributeDisplayListener temp = (ObjAttributeDisplayListener) list[i];
1281            temp.currentObjAttributeChanged(e);
1282        }
1283    }
1284
1285    /** Notifies all listeners of the change(add, remove) and does the change. */
1286    public void fireDbRelationshipEvent(RelationshipEvent e) {
1287        setDirty(true);
1288        
1289        if (currentState.map != null && e.getId() == RelationshipEvent.CHANGE){
1290            currentState.map.dbRelationshipChanged(e);
1291        }
1292
1293        EventListener JavaDoc[] list = listenerList.getListeners(DbRelationshipListener.class);
1294        for (int i = 0; i < list.length; i++) {
1295            DbRelationshipListener temp = (DbRelationshipListener) list[i];
1296            switch (e.getId()) {
1297                case RelationshipEvent.ADD:
1298                    temp.dbRelationshipAdded(e);
1299                    break;
1300                case RelationshipEvent.CHANGE:
1301                    temp.dbRelationshipChanged(e);
1302                    break;
1303                case RelationshipEvent.REMOVE:
1304                    temp.dbRelationshipRemoved(e);
1305                    break;
1306                default:
1307                    throw new IllegalArgumentException JavaDoc("Invalid RelationshipEvent type: "
1308                            + e.getId());
1309            }
1310        }
1311    }
1312
1313    public void fireDbRelationshipDisplayEvent(RelationshipDisplayEvent e) {
1314        boolean changed = e.getRelationship() != currentState.dbRel;
1315        e.setRelationshipChanged(changed);
1316        
1317        if (changed){
1318            if (e.getEntity() != currentState.dbEntity){
1319                clearState();
1320                currentState.domain = e.getDomain();
1321                currentState.map = e.getDataMap();
1322                currentState.dbEntity = (DbEntity) e.getEntity();
1323            }
1324            currentState.dbRel = (DbRelationship) e.getRelationship();
1325        }
1326        
1327        EventListener JavaDoc[] list = listenerList.getListeners(DbRelationshipDisplayListener.class);
1328        for (int i = 0; i < list.length; i++) {
1329            DbRelationshipDisplayListener temp = (DbRelationshipDisplayListener) list[i];
1330            temp.currentDbRelationshipChanged(e);
1331        }
1332    }
1333
1334    /** Notifies all listeners of the change(add, remove) and does the change. */
1335    public void fireObjRelationshipEvent(RelationshipEvent e) {
1336        setDirty(true);
1337        
1338        if (currentState.map != null && e.getId() == RelationshipEvent.CHANGE){
1339            currentState.map.objRelationshipChanged(e);
1340        }
1341
1342        EventListener JavaDoc[] list = listenerList.getListeners(ObjRelationshipListener.class);
1343        for (int i = 0; i < list.length; i++) {
1344            ObjRelationshipListener temp = (ObjRelationshipListener) list[i];
1345            switch (e.getId()) {
1346                case RelationshipEvent.ADD:
1347                    temp.objRelationshipAdded(e);
1348                    break;
1349                case RelationshipEvent.CHANGE:
1350                    temp.objRelationshipChanged(e);
1351                    break;
1352                case RelationshipEvent.REMOVE:
1353                    temp.objRelationshipRemoved(e);
1354                    break;
1355                default:
1356                    throw new IllegalArgumentException JavaDoc("Invalid RelationshipEvent type: "
1357                            + e.getId());
1358            }
1359        }
1360    }
1361
1362    public void fireObjRelationshipDisplayEvent(RelationshipDisplayEvent e) {
1363        boolean changed = e.getRelationship() != currentState.objRel;
1364        e.setRelationshipChanged(changed);
1365        
1366        if (changed){
1367            if (e.getEntity() != currentState.objEntity){
1368                clearState();
1369                currentState.domain = e.getDomain();
1370                currentState.map = e.getDataMap();
1371                currentState.objEntity = (ObjEntity) e.getEntity();
1372            }
1373            currentState.objRel = (ObjRelationship) e.getRelationship();
1374        }
1375        
1376        EventListener JavaDoc[] list = listenerList.getListeners(ObjRelationshipDisplayListener.class);
1377        for (int i = 0; i < list.length; i++) {
1378            ObjRelationshipDisplayListener temp = (ObjRelationshipDisplayListener) list[i];
1379            temp.currentObjRelationshipChanged(e);
1380        }
1381    }
1382
1383    public void addDataMap(Object JavaDoc src, DataMap map) {
1384        addDataMap(src, map, true);
1385    }
1386
1387    public void addDataMap(Object JavaDoc src, DataMap map, boolean makeCurrent) {
1388
1389        // new map was added.. link it to domain (and node if possible)
1390
currentState.domain.addMap(map);
1391
1392        if (currentState.node != null && !currentState.node.getDataMaps().contains(map)) {
1393            currentState.node.addDataMap(map);
1394            fireDataNodeEvent(new DataNodeEvent(this, currentState.node));
1395            currentState.domain.reindexNodes();
1396        }
1397
1398        fireDataMapEvent(new DataMapEvent(src, map, DataMapEvent.ADD));
1399        if (makeCurrent) {
1400            fireDataMapDisplayEvent(new DataMapDisplayEvent(
1401                    src,
1402                    map,
1403                    currentState.domain,
1404                    currentState.node));
1405        }
1406    }
1407
1408    public void setDirty(boolean dirty) {
1409        if (this.dirty != dirty) {
1410            this.dirty = dirty;
1411
1412            application.getAction(SaveAction.getActionName()).setEnabled(dirty);
1413            application.getAction(RevertAction.getActionName()).setEnabled(dirty);
1414
1415            if (dirty) {
1416                CayenneModelerController parent = (CayenneModelerController) getParent();
1417                parent.projectModifiedAction();
1418            }
1419        }
1420    }
1421}
Popular Tags