Search in sources :

Example 1 with DisplayEvent

use of org.apache.cayenne.modeler.event.DisplayEvent in project cayenne by apache.

the class ProjectController method fireNavigationEvent.

public void fireNavigationEvent(EventObject e) {
    Object source = e.getSource();
    if (source == null) {
        return;
    }
    int size = controllerStateHistory.size();
    if (size == 0)
        return;
    int i = controllerStateHistory.indexOf(currentState);
    ControllerState cs;
    if (size == 1) {
        cs = controllerStateHistory.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 = controllerStateHistory.get(0);
            } else if (i + 1 < size) {
                // move forward
                cs = controllerStateHistory.get(i + 1);
            } else {
                // wrap around
                cs = controllerStateHistory.get(0);
            }
            if (!cs.isEquivalent(currentState)) {
                break;
            }
            // 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 = controllerStateHistory.get(size - 2);
                } catch (ArrayIndexOutOfBoundsException ex) {
                    cs = controllerStateHistory.get(size - 1);
                }
            } else if (i - 1 >= 0) {
                // move to the previous one
                cs = controllerStateHistory.get(i - 1);
            } else {
                // wrap around
                cs = controllerStateHistory.get(size - 1);
            }
            if (!cs.isEquivalent(currentState)) {
                break;
            }
            // if it doesn't find it within 5 tries it is probably stuck in a loop
            if (++counter > 5) {
                break;
            }
            i--;
        }
    } else {
        throw new IllegalStateException("Unknown source for navigation event: " + e.getSource());
    }
    // reset the current state to the one we just navigated to
    currentState = 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
    currentState.isRefiring = true;
    // the order of the following is checked in most specific to generic
    // because of the inheritance hierarchy
    de.setRefired(true);
    if (de instanceof EntityDisplayEvent) {
        EntityDisplayEvent ede = (EntityDisplayEvent) de;
        ede.setEntityChanged(true);
        if (ede.getEntity() instanceof ObjEntity) {
            fireObjEntityDisplayEvent(ede);
        } else if (ede.getEntity() instanceof DbEntity) {
            fireDbEntityDisplayEvent(ede);
        }
    } else if (de instanceof EmbeddableDisplayEvent) {
        EmbeddableDisplayEvent ede = (EmbeddableDisplayEvent) de;
        ede.setEmbeddableChanged(true);
        fireEmbeddableDisplayEvent(ede);
    } else if (de instanceof ProcedureDisplayEvent) {
        ProcedureDisplayEvent pde = (ProcedureDisplayEvent) de;
        pde.setProcedureChanged(true);
        fireProcedureDisplayEvent(pde);
    } else if (de instanceof QueryDisplayEvent) {
        QueryDisplayEvent qde = (QueryDisplayEvent) de;
        qde.setQueryChanged(true);
        fireQueryDisplayEvent(qde);
    } else if (de instanceof DataMapDisplayEvent) {
        DataMapDisplayEvent dmde = (DataMapDisplayEvent) de;
        dmde.setDataMapChanged(true);
        fireDataMapDisplayEvent(dmde);
    } else if (de instanceof DataNodeDisplayEvent) {
        DataNodeDisplayEvent dnde = (DataNodeDisplayEvent) de;
        dnde.setDataNodeChanged(true);
        fireDataNodeDisplayEvent(dnde);
    } else if (de instanceof DomainDisplayEvent) {
        DomainDisplayEvent dde = (DomainDisplayEvent) de;
        dde.setDomainChanged(true);
        fireDomainDisplayEvent(dde);
    }
    // turn off refiring
    currentState.isRefiring = false;
}
Also used : ProcedureDisplayEvent(org.apache.cayenne.modeler.event.ProcedureDisplayEvent) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) EmbeddableDisplayEvent(org.apache.cayenne.modeler.event.EmbeddableDisplayEvent) NavigateForwardAction(org.apache.cayenne.modeler.action.NavigateForwardAction) DataMapDisplayEvent(org.apache.cayenne.modeler.event.DataMapDisplayEvent) QueryDisplayEvent(org.apache.cayenne.modeler.event.QueryDisplayEvent) ObjEntity(org.apache.cayenne.map.ObjEntity) DomainDisplayEvent(org.apache.cayenne.modeler.event.DomainDisplayEvent) DbEntity(org.apache.cayenne.map.DbEntity) NavigateBackwardAction(org.apache.cayenne.modeler.action.NavigateBackwardAction) DataNodeDisplayEvent(org.apache.cayenne.modeler.event.DataNodeDisplayEvent) EventObject(java.util.EventObject) EmbeddableAttributeDisplayEvent(org.apache.cayenne.modeler.event.EmbeddableAttributeDisplayEvent) MultipleObjectsDisplayEvent(org.apache.cayenne.modeler.event.MultipleObjectsDisplayEvent) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) QueryDisplayEvent(org.apache.cayenne.modeler.event.QueryDisplayEvent) ProcedureParameterDisplayEvent(org.apache.cayenne.modeler.event.ProcedureParameterDisplayEvent) AttributeDisplayEvent(org.apache.cayenne.modeler.event.AttributeDisplayEvent) DataMapDisplayEvent(org.apache.cayenne.modeler.event.DataMapDisplayEvent) DataNodeDisplayEvent(org.apache.cayenne.modeler.event.DataNodeDisplayEvent) ProcedureDisplayEvent(org.apache.cayenne.modeler.event.ProcedureDisplayEvent) RelationshipDisplayEvent(org.apache.cayenne.modeler.event.RelationshipDisplayEvent) DomainDisplayEvent(org.apache.cayenne.modeler.event.DomainDisplayEvent) DisplayEvent(org.apache.cayenne.modeler.event.DisplayEvent) EmbeddableDisplayEvent(org.apache.cayenne.modeler.event.EmbeddableDisplayEvent)

Aggregations

EventObject (java.util.EventObject)1 DbEntity (org.apache.cayenne.map.DbEntity)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 NavigateBackwardAction (org.apache.cayenne.modeler.action.NavigateBackwardAction)1 NavigateForwardAction (org.apache.cayenne.modeler.action.NavigateForwardAction)1 AttributeDisplayEvent (org.apache.cayenne.modeler.event.AttributeDisplayEvent)1 DataMapDisplayEvent (org.apache.cayenne.modeler.event.DataMapDisplayEvent)1 DataNodeDisplayEvent (org.apache.cayenne.modeler.event.DataNodeDisplayEvent)1 DisplayEvent (org.apache.cayenne.modeler.event.DisplayEvent)1 DomainDisplayEvent (org.apache.cayenne.modeler.event.DomainDisplayEvent)1 EmbeddableAttributeDisplayEvent (org.apache.cayenne.modeler.event.EmbeddableAttributeDisplayEvent)1 EmbeddableDisplayEvent (org.apache.cayenne.modeler.event.EmbeddableDisplayEvent)1 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)1 MultipleObjectsDisplayEvent (org.apache.cayenne.modeler.event.MultipleObjectsDisplayEvent)1 ProcedureDisplayEvent (org.apache.cayenne.modeler.event.ProcedureDisplayEvent)1 ProcedureParameterDisplayEvent (org.apache.cayenne.modeler.event.ProcedureParameterDisplayEvent)1 QueryDisplayEvent (org.apache.cayenne.modeler.event.QueryDisplayEvent)1 RelationshipDisplayEvent (org.apache.cayenne.modeler.event.RelationshipDisplayEvent)1