Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
  
  
  package org.apache.cayenne.modeler;
  
  import java.util.Arrays;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Vector;
  
  
  import  org.apache.cayenne.CayenneRuntimeException;
  import  org.apache.cayenne.access.DataDomain;
  import  org.apache.cayenne.access.DataNode;
  import  org.apache.cayenne.map.DataMap;
  import  org.apache.cayenne.map.DbAttribute;
  import  org.apache.cayenne.map.DbEntity;
  import  org.apache.cayenne.map.DbRelationship;
  import  org.apache.cayenne.map.Embeddable;
  import  org.apache.cayenne.map.EmbeddableAttribute;
  import  org.apache.cayenne.map.ObjAttribute;
  import  org.apache.cayenne.map.ObjEntity;
  import  org.apache.cayenne.map.ObjRelationship;
  import  org.apache.cayenne.map.Procedure;
  import  org.apache.cayenne.map.ProcedureParameter;
  import  org.apache.cayenne.map.event.AttributeEvent;
  import  org.apache.cayenne.map.event.DataMapEvent;
  import  org.apache.cayenne.map.event.DataMapListener;
  import  org.apache.cayenne.map.event.DataNodeEvent;
  import  org.apache.cayenne.map.event.DataNodeListener;
  import  org.apache.cayenne.map.event.DbAttributeListener;
  import  org.apache.cayenne.map.event.DbEntityListener;
  import  org.apache.cayenne.map.event.DbRelationshipListener;
  import  org.apache.cayenne.map.event.DomainEvent;
  import  org.apache.cayenne.map.event.DomainListener;
  import  org.apache.cayenne.map.event.EmbeddableAttributeEvent;
  import  org.apache.cayenne.map.event.EmbeddableAttributeListener;
  import  org.apache.cayenne.map.event.EmbeddableEvent;
  import  org.apache.cayenne.map.event.EmbeddableListener;
  import  org.apache.cayenne.map.event.EntityEvent;
  import  org.apache.cayenne.map.event.MapEvent;
  import  org.apache.cayenne.map.event.ObjAttributeListener;
  import  org.apache.cayenne.map.event.ObjEntityListener;
  import  org.apache.cayenne.map.event.ObjRelationshipListener;
  import  org.apache.cayenne.map.event.ProcedureEvent;
  import  org.apache.cayenne.map.event.ProcedureListener;
  import  org.apache.cayenne.map.event.ProcedureParameterEvent;
  import  org.apache.cayenne.map.event.ProcedureParameterListener;
  import  org.apache.cayenne.map.event.QueryEvent;
  import  org.apache.cayenne.map.event.QueryListener;
  import  org.apache.cayenne.map.event.RelationshipEvent;
 import  org.apache.cayenne.project.ApplicationProject;
 import  org.apache.cayenne.project.Project;
 import  org.apache.cayenne.project.ProjectPath;
 import  org.apache.cayenne.query.Query;
 import  org.apache.cayenne.util.IDUtil;

A controller that works with the project tree, tracking selection and dispatching project events.

TODO: Refactor the event model, so that events are generic and contain "path" to a project node in question. After this is done, EventController should no longer maintain the selection model (currentXYZ ivars), rather it should update internal model.

 
 public class ProjectController extends CayenneController {
 
     /*
      * A snapshot of the current state of the project controller. This was added so that
      * we could support history of recent objects.
      */
     public class ControllerState {
 
         private boolean isRefiring;
         private DisplayEvent event;
         private DataDomain domain;
         private DataNode node;
         private DataMap map;
         private ObjEntity objEntity;
         private DbEntity dbEntity;
         private Embeddable embeddable;
 
         private EmbeddableAttribute[] embAttrs;
 
         private ObjAttribute[] objAttrs;
         private DbAttribute[] dbAttrs;
         private ObjRelationship[] objRels;
         private DbRelationship[] dbRels;
 
         private Procedure procedure;
         private ProcedureParameter[] procedureParameters;
         private Query query;

        
Paths of multiple selection
 
         private ProjectPath[] paths;

        
currently selecte entity listener class
 
         private String listenerClass;
        
currently selected callback type
 
         private CallbackType callbackType;
        
currently selected callback methods
 
         private String[] callbackMethods;
 
         public ControllerState() {
              = null;
              = null;
              = null;
 
              = null;
              = null;
 
              = null;
 
              = null;
 
             // life is much easier if these guys are never null
              = new EmbeddableAttribute[0];
              = new DbAttribute[0];
              = new DbRelationship[0];
              = new ProcedureParameter[0];
              = new ObjAttribute[0];
              = new ObjRelationship[0];
 
              = new String[0];
 
              = null;
 
              = null;
              = null;
 
              = false;
         }
 
         /*
          * Used to determine if the val ControllerState is equivalent, which means if the
          * event is refired again, will it end up in the same place on the screen. This
          * get's a bit messy at the end, because of inheritance heirarchy issues.
          */
         public boolean isEquivalent(ControllerState val) {
 
             if (val == null)
                 return false;
 
             if ( instanceof EntityDisplayEvent
                     && val.event instanceof EntityDisplayEvent) {
                 if (((EntityDisplayEventval.event).getEntity() instanceof ObjEntity) {
                     return  == val.objEntity;
                 }
                 else {
                     return  == val.dbEntity;
                 }
             }
             else if ( instanceof ProcedureDisplayEvent
                     && val.event instanceof ProcedureDisplayEvent) {
                 return  == val.procedure;
             }
             else if ( instanceof QueryDisplayEvent
                     && val.event instanceof QueryDisplayEvent) {
                 return  == val.query;
             }
             else if ( instanceof EmbeddableDisplayEvent
                     && val.event instanceof EmbeddableDisplayEvent) {
                 return  == val.embeddable;
             }
             else if (.getClass() == DataMapDisplayEvent.class
                     && .getClass() == val.event.getClass()) {
                 return  == val.map;
             }
             else if (.getClass() == DataNodeDisplayEvent.class
                     && .getClass() == val.event.getClass()) {
                 return  == val.node;
             }
             else if (.getClass() == DomainDisplayEvent.class
                     && .getClass() == val.event.getClass()) {
                 return  == val.domain;
             }
 
             return false;
         }
     }
 
     protected EventListenerList listenerList;
     protected boolean dirty;
 
     protected Project project;
     protected Domain projectPreferences;
 
     protected ControllerState currentState;
     protected int maxHistorySize = 20;

    
Project files watcher. When project file is changed, user will be asked to confirm loading the changes
 
     protected ProjectWatchdog watchdog;
 
     public ProjectController(CayenneModelerController parent) {
         super(parent);
         this. = new EventListenerList();
          = new ControllerState();
     }
 
     @Override
     public Component getView() {
         return .getView();
     }
 
     public Project getProject() {
         return ;
     }
 
     public void setProject(Project currentProject) {
         if (this. != currentProject// strange enough, this method is called twice
         // during project opening. Not to disturb
         // watchdog extra time, adding this check
         {
             this. = currentProject;
             this. = null;
 
             if ( == null// null project -> no files to watch
             {
                 if ( != null) {
                     .interrupt();
                      = null;
                 }
             }
             else {
                 if ( == null) {
                      = new ProjectWatchdog(this);
                     .start();
                 }
 
                 .reconfigure();
             }
         }
     }

    
Returns top preferences Domain for the application.
 
         return getApplication().getPreferenceDomain();
     }

    
Returns top preferences Domain for the current project, throwing an exception if no project is selected.
 
         if (getProject() == null) {
             throw new CayenneRuntimeException("No Project selected");
         }
 
         if ( == null) {
             String key = getProject().isLocationUndefined() ? new String(IDUtil
                     .pseudoUniqueByteSequence16()) : 
                     .getMainFile()
                     .getAbsolutePath();
 
                     Project.class).getSubdomain(key);
         }
 
         return ;
     }

    
Returns top preferences Domain for the current project, throwing an exception if no project is selected.
 
         DataDomain dataDomain = getCurrentDataDomain();
         if (dataDomain == null) {
             throw new CayenneRuntimeException("No DataDomain selected");
         }
 
         return getPreferenceDomainForProject()
                 .getSubdomain(DataDomain.class)
                 .getSubdomain(dataDomain.getName());
     }

    
Returns preferences object for the current DataMap. If no preferences exist for the current DataMap, a new Preferences object is created. If no DataMap is currently selected, an exception is thrown. An optional nameSuffix allows to address more than one defaults instance for a single DataMap.
 
     public DataMapDefaults getDataMapPreferences(String nameSuffix) {
         DataMap map = getCurrentDataMap();
         if (map == null) {
             throw new CayenneRuntimeException("No DataMap selected");
         }
 
         if (nameSuffix == null) {
             nameSuffix = "";
         }
 
                 map.getName() + nameSuffix,
                 DataMapDefaults.class,
                 true);
     }

    
Returns preferences object for the current DataMap, throwing an exception if no DataMap is selected.
 
         DataNode node = getCurrentDataNode();
         if (node == null) {
             throw new CayenneRuntimeException("No DataNode selected");
         }
 
                 node.getName(),
                 DataNodeDefaults.class,
                 true);
     }
 
     public void projectOpened() {
         CayenneModelerFrame frame = (CayenneModelerFramegetView();
         addDataNodeDisplayListener(frame);
         addDataMapDisplayListener(frame);
         addObjEntityDisplayListener(frame);
         addDbEntityDisplayListener(frame);
         addQueryDisplayListener(frame);
         addProcedureDisplayListener(frame);
         addMultipleObjectsDisplayListener(frame);
         addEmbeddableDisplayListener(frame);
     }
 
     public void reset() {
         clearState();
         setDirty(false);
          = new EventListenerList();
         .clear();
     }
 
     /*
      * Allow the user to change the default history size. TODO When a user changes their
      * preferences it should call this method. I don't know how the preferences work, so I
      * will leave this to someone else to do. Garry
      */
     public void setHistorySize(int newSize) {
         .resize(newSize);
     }
 
     public boolean isDirty() {
         return ;
     }

    
Resets all current models to null.
 
     private void clearState() {
         // don't clear if we are refiring events for history navigation
         if (.)
             return;
 
          = new ControllerState();
     }
 
     private void saveState(DisplayEvent e) {
         if (!.contains()) {
             . = e;
             .add();
         }
     }
 
     protected void refreshNamespace() {
     }
 
     protected void refreshNamespace(DataDomain domain) {
         if (domain != null) {
             domain.getEntityResolver().clearCache();
         }
     }

    
Finds a domain containing specified DataNode.
 
     public DataDomain findDomain(DataNode node) {
         Collection<DataDomain> domains = ((ApplicationProject) getProject())
                 .getConfiguration()
                 .getDomains();
 
         for (DataDomain domain : domains) {
             if (domain.getNode(node.getName()) == node) {
                 return domain;
             }
         }
 
         return null;
     }

    
Finds a domain containing specified DataMap.
 
     public DataDomain findDomain(DataMap map) {
         Collection<DataDomain> domains = ((ApplicationProject) getProject())
                 .getConfiguration()
                 .getDomains();
 
         if (map == null) {
             map = getCurrentDataMap();
         }
 
         for (DataDomain domain : domains) {
             if (domain.getMap(map.getName()) == map) {
                 return domain;
             }
         }
 
         return null;
     }
 
     private void removeFromHistory(EventObject e) {
 
         synchronized () {
             int count = .size();
             List<ObjectremoveList = new ArrayList<Object>();
 
             for (int i = 0; i < counti++) {
                 ControllerState cs = (ControllerState.get(i);
 
                 EventObject csEvent = cs.event;
 
                 if (csEvent == null) {
                     continue;
                 }
 
                 if (e instanceof EntityEvent && csEvent instanceof EntityDisplayEvent) {
                     if (((EntityEvent) e).getEntity() == ((EntityDisplayEventcsEvent)
                             .getEntity()) {
                         removeList.add(cs);
                     }
                 }
                 else if (e instanceof EmbeddableEvent
                         && csEvent instanceof EmbeddableDisplayEvent) {
                     if (((EmbeddableEvent) e).getEmbeddable() == ((EmbeddableDisplayEventcsEvent)
                             .getEmbeddable()) {
                         removeList.add(cs);
                     }
                 }
                 else if (e instanceof ProcedureEvent
                         && csEvent instanceof ProcedureDisplayEvent) {
                     if (((ProcedureEvent) e).getProcedure() == ((ProcedureDisplayEventcsEvent)
                             .getProcedure()) {
                         removeList.add(cs);
                     }
                 }
                 else if (e instanceof QueryEvent && csEvent instanceof QueryDisplayEvent) {
                     if (((QueryEvent) e).getQuery() == ((QueryDisplayEventcsEvent)
                             .getQuery()) {
                         removeList.add(cs);
                     }
                 }
                 else if (e instanceof DataMapEvent
                         && csEvent instanceof DataMapDisplayEvent) {
                     if (((DataMapEvent) e).getDataMap() == ((DataMapDisplayEventcsEvent)
                             .getDataMap()) {
                         removeList.add(cs);
                     }
                 }
                 else if (e instanceof DataNodeEvent
                         && csEvent instanceof DataNodeDisplayEvent) {
                     if (((DataNodeEvent) e).getDataNode() == ((DataNodeDisplayEventcsEvent)
                             .getDataNode()) {
                         removeList.add(cs);
                     }
                 }
                 else if (e instanceof DomainEvent
                         && csEvent instanceof DomainDisplayEvent) {
                     if (((DomainEvent) e).getDomain() == ((DomainDisplayEventcsEvent)
                             .getDomain()) {
                         removeList.add(cs);
                     }
                 }
             }
             Iterator it = removeList.iterator();
             while (it.hasNext()) {
                 .remove(it.next());
             }
 
         }
     }
 
     public DataNode getCurrentDataNode() {
         return .;
     }
 
     public DataDomain getCurrentDataDomain() {
         return .;
     }
 
     public DataMap getCurrentDataMap() {
         return .;
     }
 
     public ObjEntity getCurrentObjEntity() {
         return .;
     }
 
     public Embeddable getCurrentEmbeddable() {
         return .;
     }
 
     public DbEntity getCurrentDbEntity() {
         return .;
     }

    

Returns:
Array of selected ObjAttributes
 
     public ObjAttribute[] getCurrentObjAttributes() {
         return .;
     }

    

Returns:
Array of selected DbAttributes
 
     public DbAttribute[] getCurrentDbAttributes() {
         return .;
     }

    

Returns:
Array of selected EmbeddableAttribute
 
     public EmbeddableAttribute[] getCurrentEmbAttrs() {
         return .;
     }

    

Returns:
Array of selected ObjRelationships
 
     public ObjRelationship[] getCurrentObjRelationships() {
         return .;
     }

    

Returns:
Array of selected DbRelationships
 
     public DbRelationship[] getCurrentDbRelationships() {
         return .;
     }
 
     public Query getCurrentQuery() {
         return .;
     }
 
     public Procedure getCurrentProcedure() {
         return .;
     }
 
     public ProcedureParameter[] getCurrentProcedureParameters() {
         return .;
     }
 
     public ProjectPath[] getCurrentPaths() {
         return .;
     }
 
     public void addDomainDisplayListener(DomainDisplayListener listener) {
         .add(DomainDisplayListener.classlistener);
     }
 
     public void addDomainListener(DomainListener listener) {
         .add(DomainListener.classlistener);
     }
 
     public void addDataNodeDisplayListener(DataNodeDisplayListener listener) {
         .add(DataNodeDisplayListener.classlistener);
     }
 
     public void addDataNodeListener(DataNodeListener listener) {
         .add(DataNodeListener.classlistener);
     }
 
     public void addDataMapDisplayListener(DataMapDisplayListener listener) {
         .add(DataMapDisplayListener.classlistener);
     }
 
     public void addDataMapListener(DataMapListener listener) {
         .add(DataMapListener.classlistener);
     }
 
     public void addDbEntityListener(DbEntityListener listener) {
         .add(DbEntityListener.classlistener);
     }
 
     public void addObjEntityListener(ObjEntityListener listener) {
         .add(ObjEntityListener.classlistener);
     }
 
     public void addDbEntityDisplayListener(DbEntityDisplayListener listener) {
         .add(DbEntityDisplayListener.classlistener);
     }
 
     public void addObjEntityDisplayListener(ObjEntityDisplayListener listener) {
         .add(ObjEntityDisplayListener.classlistener);
     }
 
     public void addEmbeddableDisplayListener(EmbeddableDisplayListener listener) {
         .add(EmbeddableDisplayListener.classlistener);
     }
 
             EmbeddableAttributeDisplayListener listener) {
         .add(EmbeddableAttributeDisplayListener.classlistener);
     }
 
     public void addDbAttributeListener(DbAttributeListener listener) {
         .add(DbAttributeListener.classlistener);
     }
 
     public void addDbAttributeDisplayListener(DbAttributeDisplayListener listener) {
         .add(DbAttributeDisplayListener.classlistener);
     }
 
     public void addObjAttributeListener(ObjAttributeListener listener) {
         .add(ObjAttributeListener.classlistener);
     }
 
         .add(ObjAttributeDisplayListener.classlistener);
     }
 
     public void addDbRelationshipListener(DbRelationshipListener listener) {
         .add(DbRelationshipListener.classlistener);
     }
 
         .add(DbRelationshipDisplayListener.classlistener);
     }
 
     public void addObjRelationshipListener(ObjRelationshipListener listener) {
         .add(ObjRelationshipListener.classlistener);
     }
 
         .add(ObjRelationshipDisplayListener.classlistener);
     }
 
     public void addQueryDisplayListener(QueryDisplayListener listener) {
         .add(QueryDisplayListener.classlistener);
     }
 
     public void addQueryListener(QueryListener listener) {
         .add(QueryListener.classlistener);
     }
 
     public void addProcedureDisplayListener(ProcedureDisplayListener listener) {
         .add(ProcedureDisplayListener.classlistener);
     }
 
     public void addProcedureListener(ProcedureListener listener) {
         .add(ProcedureListener.classlistener);
     }
 
     public void addProcedureParameterListener(ProcedureParameterListener listener) {
         .add(ProcedureParameterListener.classlistener);
     }
 
             ProcedureParameterDisplayListener listener) {
         .add(ProcedureParameterDisplayListener.classlistener);
     }
 
         .add(MultipleObjectsDisplayListener.classlistener);
     }
 
     public void fireDomainDisplayEvent(DomainDisplayEvent e) {
         boolean changed = e.getDomain() != .;
         if (!changed) {
             changed = . != null
                     || . != null
                     || . != null
                     || . != null
                     || . != null
                     || . != null
                     || . != null;
         }
 
         if (!e.isRefired()) {
             e.setDomainChanged(changed);
             if (changed) {
                 clearState();
                 . = e.getDomain();
             }
         }
 
         if (changed) {
             saveState(e);
         }
 
         for (EventListener listener : 
                 .getListeners(DomainDisplayListener.class)) {
             DomainDisplayListener temp = (DomainDisplayListenerlistener;
             temp.currentDomainChanged(e);
         }
 
         // call different methods depending on whether domain was opened or closed
         if (e.getDomain() == null) {
             getApplication().getActionManager().projectOpened();
         }
         else {
             getApplication().getActionManager().domainSelected();
         }
     }

    
Informs all listeners of the DomainEvent. Does not send the event to its originator.
 
     public void fireDomainEvent(DomainEvent e) {
         setDirty(true);
 
         if (e.getId() == MapEvent.REMOVE) {
             refreshNamespace(e.getDomain());
             removeFromHistory(e);
         }
 
         for (EventListener listener : .getListeners(DomainListener.class)) {
             DomainListener temp = (DomainListener) listener;
             switch (e.getId()) {
                 case MapEvent.ADD:
                     temp.domainAdded(e);
                     break;
                 case MapEvent.CHANGE:
                     temp.domainChanged(e);
                     break;
                 case MapEvent.REMOVE:
                     temp.domainRemoved(e);
                     break;
                 default:
                     throw new IllegalArgumentException("Invalid DomainEvent type: "
                             + e.getId());
             }
         }
     }
 
     public void fireDataNodeDisplayEvent(DataNodeDisplayEvent e) {
         boolean changed = e.getDataNode() != .;
 
         if (!changed) {
             changed = . != null
                     || . != null
                     || . != null
                     || . != null
                     || . != null
                     || . != null;
         }
 
         if (!e.isRefired()) {
             e.setDataNodeChanged(changed);
 
             if (changed) {
                 clearState();
                 . = e.getDomain();
                 . = e.getDataNode();
             }
         }
 
         if (changed) {
             saveState(e);
         }
 
         for (EventListener listener : list) {
             ((DataNodeDisplayListenerlistener).currentDataNodeChanged(e);
         }
     }

    
Informs all listeners of the DataNodeEvent. Does not send the event to its originator.
 
     public void fireDataNodeEvent(DataNodeEvent e) {
         setDirty(true);
 
         if (e.getId() == MapEvent.REMOVE) {
             refreshNamespace(e.getDomain());
             removeFromHistory(e);
         }
 
         for (EventListener listener : .getListeners(DataNodeListener.class)) {
             DataNodeListener temp = (DataNodeListener) listener;
             switch (e.getId()) {
                 case MapEvent.ADD:
                     temp.dataNodeAdded(e);
                     break;
                 case MapEvent.CHANGE:
                     temp.dataNodeChanged(e);
                     break;
                 case MapEvent.REMOVE:
                     temp.dataNodeRemoved(e);
                     break;
                 default:
                     throw new IllegalArgumentException("Invalid DataNodeEvent type: "
                             + e.getId());
             }
         }
     }
 
     public void fireDataMapDisplayEvent(DataMapDisplayEvent e) {
         boolean changed = e.getDataMap() != .;
         if (!changed) {
             changed = . != null
                     || . != null
                     || . != null
                     || . != null
                     || . != null;
         }
 
         if (!e.isRefired()) {
             e.setDataMapChanged(changed);
 
             if (changed) {
                 clearState();
                 . = e.getDomain();
                 . = e.getDataNode();
                 . = e.getDataMap();
             }
         }
 
         if (changed) {
             saveState(e);
         }
 
         for (EventListener listener : list) {
             DataMapDisplayListener temp = (DataMapDisplayListenerlistener;
             temp.currentDataMapChanged(e);
         }
     }

    
Informs all listeners of the DataMapEvent. Does not send the event to its originator.
 
     public void fireDataMapEvent(DataMapEvent e) {
         setDirty(true);
 
         if (e.getId() == MapEvent.REMOVE) {
             refreshNamespace(e.getDomain());
             removeFromHistory(e);
         }
 
         for (EventListener eventListener : 
                 .getListeners(DataMapListener.class)) {
             DataMapListener listener = (DataMapListener) eventListener;
             switch (e.getId()) {
                 case MapEvent.ADD:
                     listener.dataMapAdded(e);
                     break;
                 case MapEvent.CHANGE:
                     listener.dataMapChanged(e);
                     break;
                 case MapEvent.REMOVE:
                     listener.dataMapRemoved(e);
                     break;
                 default:
                     throw new IllegalArgumentException("Invalid DataMapEvent type: "
                             + e.getId());
             }
         }
     }

    
Informs all listeners of the EntityEvent. Does not send the event to its originator.
 
     public void fireObjEntityEvent(EntityEvent e) {
         setDirty(true);
 
         if (e.getEntity().getDataMap() != null && e.getId() == MapEvent.CHANGE) {
             e.getEntity().getDataMap().objEntityChanged(e);
         }
 
         if (e.getId() == MapEvent.REMOVE) {
             refreshNamespace(e.getDomain());
             removeFromHistory(e);
         }
 
         for (EventListener listener : .getListeners(ObjEntityListener.class)) {
             ObjEntityListener temp = (ObjEntityListener) listener;
             switch (e.getId()) {
                 case MapEvent.ADD:
                     temp.objEntityAdded(e);
                     break;
                 case MapEvent.CHANGE:
                     temp.objEntityChanged(e);
                     break;
                 case MapEvent.REMOVE:
                     temp.objEntityRemoved(e);
                     break;
                 default:
                     throw new IllegalArgumentException("Invalid EntityEvent type: "
                             + e.getId());
             }
         }
     }

    
Informs all listeners of the EntityEvent. Does not send the event to its originator.
 
     public void fireDbEntityEvent(EntityEvent e) {
         setDirty(true);
 
         if (e.getEntity().getDataMap() != null && e.getId() == MapEvent.CHANGE) {
             e.getEntity().getDataMap().dbEntityChanged(e);
         }
 
         if (e.getId() == MapEvent.REMOVE) {
             refreshNamespace(e.getDomain());
             removeFromHistory(e);
         }
 
         for (EventListener listener : .getListeners(DbEntityListener.class)) {
             DbEntityListener temp = (DbEntityListener) listener;
            switch (e.getId()) {
                case MapEvent.ADD:
                    temp.dbEntityAdded(e);
                    break;
                case MapEvent.CHANGE:
                    temp.dbEntityChanged(e);
                    break;
                case MapEvent.REMOVE:
                    temp.dbEntityRemoved(e);
                    break;
                default:
                    throw new IllegalArgumentException("Invalid EntityEvent type: "
                            + e.getId());
            }
        }
    }

    
Informs all listeners of the ProcedureEvent. Does not send the event to its originator.
    public void fireQueryEvent(QueryEvent e) {
        setDirty(true);
        if (e.getId() == MapEvent.REMOVE) {
            refreshNamespace(e.getDomain());
            removeFromHistory(e);
        }
        for (EventListener eventListener : .getListeners(QueryListener.class)) {
            QueryListener listener = (QueryListener) eventListener;
            switch (e.getId()) {
                case MapEvent.ADD:
                    listener.queryAdded(e);
                    break;
                case MapEvent.CHANGE:
                    listener.queryChanged(e);
                    break;
                case MapEvent.REMOVE:
                    listener.queryRemoved(e);
                    break;
                default:
                    throw new IllegalArgumentException("Invalid ProcedureEvent type: "
                            + e.getId());
            }
        }
    }

    
Informs all listeners of the ProcedureEvent. Does not send the event to its originator.
    public void fireProcedureEvent(ProcedureEvent e) {
        setDirty(true);
        if (e.getId() == MapEvent.REMOVE) {
            refreshNamespace(e.getDomain());
            removeFromHistory(e);
        }
        for (EventListener eventListener : 
                .getListeners(ProcedureListener.class)) {
            ProcedureListener listener = (ProcedureListener) eventListener;
            switch (e.getId()) {
                case MapEvent.ADD:
                    listener.procedureAdded(e);
                    break;
                case MapEvent.CHANGE:
                    listener.procedureChanged(e);
                    break;
                case MapEvent.REMOVE:
                    listener.procedureRemoved(e);
                    break;
                default:
                    throw new IllegalArgumentException("Invalid ProcedureEvent type: "
                            + e.getId());
            }
        }
    }

    
Informs all listeners of the ProcedureEvent. Does not send the event to its originator.
    public void fireProcedureParameterEvent(ProcedureParameterEvent e) {
        setDirty(true);
        EventListener[] list = 
                .getListeners(ProcedureParameterListener.class);
        for (EventListener eventListener : list) {
            ProcedureParameterListener listener = (ProcedureParameterListener) eventListener;
            switch (e.getId()) {
                case MapEvent.ADD:
                    listener.procedureParameterAdded(e);
                    break;
                case MapEvent.CHANGE:
                    listener.procedureParameterChanged(e);
                    break;
                case MapEvent.REMOVE:
                    listener.procedureParameterRemoved(e);
                    break;
                default:
                    throw new IllegalArgumentException(
                            "Invalid ProcedureParameterEvent type: " + e.getId());
            }
        }
    }
    public void fireNavigationEvent(EventObject e) {
        Object source = e.getSource();
        if (source == null)
            return;
        int size = .size();
        if (size == 0)
            return;
        int i = .indexOf();
        ControllerState cs = null;
        if (size == 1) {
            cs = (ControllerState.get(0);
        }
        else if (source instanceof NavigateForwardAction) {
            int counter = 0;
            while (true) {
                if (i < 0) {
                    // a new state got created without it being saved.
                    // just move to the beginning of the list
                    cs = (ControllerState.get(0);
                }
                else if (i + 1 < size) {
                    // move forward
                    cs = (ControllerState.get(i + 1);
                }
                else {
                    // wrap around
                    cs = (ControllerState.get(0);
                }
                if (!cs.isEquivalent()) {
                    break;
                }
                // if it doesn't find it within 5 tries it is probably stuck in a loop
                if (++counter > 5) {
                    break;
                }
                i++;
            }
        }
        else if (source instanceof NavigateBackwardAction) {
            int counter = 0;
            while (true) {
                if (i < 0) {
                    // a new state got created without it being saved.
                    try {
                        cs = (ControllerState.get(size - 2);
                    }
                    catch (ArrayIndexOutOfBoundsException ex) {
                        cs = (ControllerState.get(size - 1);
                    }
                }
                else if (i - 1 >= 0) {
                    // move to the previous one
                    cs = (ControllerState.get(i - 1);
                }
                else {
                    // wrap around
                    cs = (ControllerState.get(size - 1);
                }
                if (!cs.isEquivalent()) {
                    break;
                }
                // if it doesn't find it within 5 tries it is probably stuck in a loop
                if (++counter > 5) {
                    break;
                }
                i--;
            }
        }
        // reset the current state to the one we just navigated to
         = cs;
        DisplayEvent de = cs.event;
        if (de == null)
            return;
        // make sure that isRefiring is turned off prior to exiting this routine
        // this flag is used to tell the controller to not create new states
        // when we are refiring the event that we saved earlier
        . = true;
        // the order of the following is checked in most specific to generic because
        // of the inheritance heirarchy
        de.setRefired(true);
        if (