Search in sources :

Example 1 with DomainDisplayEvent

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

the class ShowGraphEntityAction method showEntity.

void showEntity(Entity entity) {
    // we're always in same domain
    EditorView editor = ((CayenneModelerFrame) Application.getInstance().getFrameController().getView()).getView();
    editor.getProjectTreeView().getSelectionModel().setSelectionPath(editor.getProjectTreeView().getSelectionPath().getParentPath().getParentPath());
    DomainDisplayEvent event = new EntityDisplayEvent(editor.getProjectTreeView(), entity, entity.getDataMap(), (DataChannelDescriptor) getProjectController().getProject().getRootNode());
    getProjectController().fireDomainDisplayEvent(event);
}
Also used : DomainDisplayEvent(org.apache.cayenne.modeler.event.DomainDisplayEvent) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) EditorView(org.apache.cayenne.modeler.editor.EditorView) CayenneModelerFrame(org.apache.cayenne.modeler.CayenneModelerFrame)

Example 2 with DomainDisplayEvent

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

the class ProjectController method removeFromHistory.

private void removeFromHistory(EventObject e) {
    int count = controllerStateHistory.size();
    List<ControllerState> removeList = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        ControllerState cs = controllerStateHistory.get(i);
        if (cs == null || cs.event == null) {
            continue;
        }
        EventObject csEvent = cs.event;
        if (e instanceof EntityEvent && csEvent instanceof EntityDisplayEvent) {
            if (((EntityEvent) e).getEntity() == ((EntityDisplayEvent) csEvent).getEntity()) {
                removeList.add(cs);
            }
        } else if (e instanceof EmbeddableEvent && csEvent instanceof EmbeddableDisplayEvent) {
            if (((EmbeddableEvent) e).getEmbeddable() == ((EmbeddableDisplayEvent) csEvent).getEmbeddable()) {
                removeList.add(cs);
            }
        } else if (e instanceof ProcedureEvent && csEvent instanceof ProcedureDisplayEvent) {
            if (((ProcedureEvent) e).getProcedure() == ((ProcedureDisplayEvent) csEvent).getProcedure()) {
                removeList.add(cs);
            }
        } else if (e instanceof QueryEvent && csEvent instanceof QueryDisplayEvent) {
            if (((QueryEvent) e).getQuery() == ((QueryDisplayEvent) csEvent).getQuery()) {
                removeList.add(cs);
            }
        } else if (e instanceof DataMapEvent && csEvent instanceof DataMapDisplayEvent) {
            if (((DataMapEvent) e).getDataMap() == ((DataMapDisplayEvent) csEvent).getDataMap()) {
                removeList.add(cs);
            }
        } else if (e instanceof DataNodeEvent && csEvent instanceof DataNodeDisplayEvent) {
            if (((DataNodeEvent) e).getDataNode() == ((DataNodeDisplayEvent) csEvent).getDataNode()) {
                removeList.add(cs);
            }
        } else if (e instanceof DomainEvent && csEvent instanceof DomainDisplayEvent) {
            if (((DomainEvent) e).getDomain() == ((DomainDisplayEvent) csEvent).getDomain()) {
                removeList.add(cs);
            }
        }
    }
    for (ControllerState o : removeList) {
        controllerStateHistory.remove(o);
    }
}
Also used : ProcedureDisplayEvent(org.apache.cayenne.modeler.event.ProcedureDisplayEvent) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) EmbeddableEvent(org.apache.cayenne.map.event.EmbeddableEvent) DomainEvent(org.apache.cayenne.configuration.event.DomainEvent) ProcedureEvent(org.apache.cayenne.configuration.event.ProcedureEvent) EmbeddableDisplayEvent(org.apache.cayenne.modeler.event.EmbeddableDisplayEvent) ArrayList(java.util.ArrayList) QueryEvent(org.apache.cayenne.configuration.event.QueryEvent) DataMapDisplayEvent(org.apache.cayenne.modeler.event.DataMapDisplayEvent) EventObject(java.util.EventObject) DataMapEvent(org.apache.cayenne.configuration.event.DataMapEvent) QueryDisplayEvent(org.apache.cayenne.modeler.event.QueryDisplayEvent) DomainDisplayEvent(org.apache.cayenne.modeler.event.DomainDisplayEvent) DataNodeEvent(org.apache.cayenne.configuration.event.DataNodeEvent) DataNodeDisplayEvent(org.apache.cayenne.modeler.event.DataNodeDisplayEvent) EntityEvent(org.apache.cayenne.map.event.EntityEvent)

Example 3 with DomainDisplayEvent

use of org.apache.cayenne.modeler.event.DomainDisplayEvent 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)

Example 4 with DomainDisplayEvent

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

the class CreateDataMapUndoableEdit method undo.

@Override
public void undo() throws CannotUndoException {
    RemoveAction action = actionManager.getAction(RemoveAction.class);
    controller.fireDomainDisplayEvent(new DomainDisplayEvent(this, domain));
    action.removeDataMap(map);
}
Also used : DomainDisplayEvent(org.apache.cayenne.modeler.event.DomainDisplayEvent) RemoveAction(org.apache.cayenne.modeler.action.RemoveAction)

Example 5 with DomainDisplayEvent

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

the class ProjectTreeView method processSelection.

/**
 * Processes node selection regardless of whether a new node was selected, or an
 * already selected node was clicked again. Normally called from event listener
 * methods.
 */
public void processSelection(TreePath path) {
    if (path == null) {
        return;
    }
    DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) path.getLastPathComponent();
    Object[] data = getUserObjects(currentNode);
    if (data.length == 0) {
        // this should clear the right-side panel
        DomainDisplayEvent domEvent = new DomainDisplayEvent(this, null);
        domEvent.setDomain((DataChannelDescriptor) mediator.getProject().getRootNode());
        mediator.fireDomainDisplayEvent(domEvent);
        return;
    }
    Object obj = data[data.length - 1];
    if (obj instanceof DataChannelDescriptor) {
        mediator.fireDomainDisplayEvent(new DomainDisplayEvent(this, (DataChannelDescriptor) obj));
    } else if (obj instanceof DataMap) {
        if (data.length == 2) {
            mediator.fireDataMapDisplayEvent(new DataMapDisplayEvent(this, (DataMap) obj, (DataChannelDescriptor) mediator.getProject().getRootNode(), (DataNodeDescriptor) data[data.length - 2]));
        } else if (data.length == 1) {
            mediator.fireDataMapDisplayEvent(new DataMapDisplayEvent(this, (DataMap) obj, (DataChannelDescriptor) mediator.getProject().getRootNode()));
        }
    } else if (obj instanceof DataNodeDescriptor) {
        if (data.length == 1) {
            mediator.fireDataNodeDisplayEvent(new DataNodeDisplayEvent(this, (DataChannelDescriptor) mediator.getProject().getRootNode(), (DataNodeDescriptor) obj));
        }
    } else if (obj instanceof Entity) {
        EntityDisplayEvent e = new EntityDisplayEvent(this, (Entity) obj);
        e.setUnselectAttributes(true);
        if (data.length == 3) {
            e.setDataMap((DataMap) data[data.length - 2]);
            e.setDomain((DataChannelDescriptor) mediator.getProject().getRootNode());
            e.setDataNode((DataNodeDescriptor) data[data.length - 3]);
        } else if (data.length == 2) {
            e.setDataMap((DataMap) data[data.length - 2]);
            e.setDomain((DataChannelDescriptor) mediator.getProject().getRootNode());
        }
        if (obj instanceof ObjEntity) {
            mediator.fireObjEntityDisplayEvent(e);
        } else if (obj instanceof DbEntity) {
            mediator.fireDbEntityDisplayEvent(e);
        }
    } else if (obj instanceof Embeddable) {
        EmbeddableDisplayEvent e = new EmbeddableDisplayEvent(this, (Embeddable) obj, (DataMap) data[data.length - 2], (DataChannelDescriptor) mediator.getProject().getRootNode());
        mediator.fireEmbeddableDisplayEvent(e);
    } else if (obj instanceof Procedure) {
        ProcedureDisplayEvent e = new ProcedureDisplayEvent(this, (Procedure) obj, (DataMap) data[data.length - 2], (DataChannelDescriptor) mediator.getProject().getRootNode());
        mediator.fireProcedureDisplayEvent(e);
    } else if (obj instanceof QueryDescriptor) {
        QueryDisplayEvent e = new QueryDisplayEvent(this, (QueryDescriptor) obj, (DataMap) data[data.length - 2], (DataChannelDescriptor) mediator.getProject().getRootNode());
        mediator.fireQueryDisplayEvent(e);
    }
    this.scrollPathToVisible(path);
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Entity(org.apache.cayenne.map.Entity) DbEntity(org.apache.cayenne.map.DbEntity) ProcedureDisplayEvent(org.apache.cayenne.modeler.event.ProcedureDisplayEvent) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) EmbeddableDisplayEvent(org.apache.cayenne.modeler.event.EmbeddableDisplayEvent) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataMapDisplayEvent(org.apache.cayenne.modeler.event.DataMapDisplayEvent) DataMap(org.apache.cayenne.map.DataMap) Embeddable(org.apache.cayenne.map.Embeddable) QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) 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) DataNodeDisplayEvent(org.apache.cayenne.modeler.event.DataNodeDisplayEvent) Procedure(org.apache.cayenne.map.Procedure)

Aggregations

DomainDisplayEvent (org.apache.cayenne.modeler.event.DomainDisplayEvent)8 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)4 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)3 DataMapDisplayEvent (org.apache.cayenne.modeler.event.DataMapDisplayEvent)3 DataNodeDisplayEvent (org.apache.cayenne.modeler.event.DataNodeDisplayEvent)3 EmbeddableDisplayEvent (org.apache.cayenne.modeler.event.EmbeddableDisplayEvent)3 ProcedureDisplayEvent (org.apache.cayenne.modeler.event.ProcedureDisplayEvent)3 QueryDisplayEvent (org.apache.cayenne.modeler.event.QueryDisplayEvent)3 EventObject (java.util.EventObject)2 DbEntity (org.apache.cayenne.map.DbEntity)2 ObjEntity (org.apache.cayenne.map.ObjEntity)2 ArrayList (java.util.ArrayList)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)1 DataMapEvent (org.apache.cayenne.configuration.event.DataMapEvent)1 DataNodeEvent (org.apache.cayenne.configuration.event.DataNodeEvent)1 DomainEvent (org.apache.cayenne.configuration.event.DomainEvent)1 ProcedureEvent (org.apache.cayenne.configuration.event.ProcedureEvent)1 QueryEvent (org.apache.cayenne.configuration.event.QueryEvent)1 DataMap (org.apache.cayenne.map.DataMap)1