Search in sources :

Example 6 with Entity

use of org.apache.cayenne.map.Entity in project cayenne by apache.

the class DbEntityTabbedView method currentDbEntityChanged.

/**
 * If entity is null hides it's contents, otherwise makes it visible.
 */
public void currentDbEntityChanged(EntityDisplayEvent e) {
    Entity entity = e.getEntity();
    if (e.isMainTabFocus() && entity instanceof DbEntity) {
        if (getSelectedComponent() != entityPanel) {
            setSelectedComponent(entityPanel);
            entityPanel.setVisible(true);
        }
    }
    resetRemoveButtons();
    setVisible(e.getEntity() != null);
    if (projectController.getEntityTabSelection() < getTabCount()) {
        setSelectedIndex(projectController.getEntityTabSelection());
    }
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) Entity(org.apache.cayenne.map.Entity) DbEntity(org.apache.cayenne.map.DbEntity)

Example 7 with Entity

use of org.apache.cayenne.map.Entity in project cayenne by apache.

the class BaseGraphBuilder method buildGraph.

@Override
public void buildGraph(ProjectController mediator, DataChannelDescriptor domain, boolean doLayout) {
    if (graph != null) {
        // graph already built, exiting silently
        return;
    }
    graph = new JGraph();
    GraphModel model = new DefaultGraphModel();
    graph.setModel(model);
    setProjectController(mediator);
    setDataDomain(domain);
    GraphLayoutCache view = new GraphLayoutCache(model, new DefaultCellViewFactory());
    graph.setGraphLayoutCache(view);
    addMouseListeners();
    entityCells = new HashMap<>();
    createdObjects = new ArrayList<>();
    relCells = new HashMap<>();
    /*
         * an array for entities that are not connected to anyone. We add them
         * separately so that layout doesn't touch them
         */
    List<DefaultGraphCell> isolatedObjects = new ArrayList<>();
    /*
         * 1. Add all entities
         */
    for (DataMap map : domain.getDataMaps()) {
        DefaultGraphCell mapCell = new DefaultGraphCell();
        createdObjects.add(mapCell);
        for (Entity entity : getEntities(map)) {
            DefaultGraphCell cell = createEntityCell(entity);
            // mapCell.add(cell);
            // cell.setParent(mapCell);
            List<DefaultGraphCell> array = !isIsolated(domain, entity) ? createdObjects : isolatedObjects;
            array.add(cell);
            // port
            array.add((DefaultGraphCell) cell.getChildAt(0));
        }
    }
    /*
         * 2. Add all relationships
         */
    for (DataMap map : domain.getDataMaps()) {
        for (Entity entity : getEntities(map)) {
            DefaultGraphCell sourceCell = entityCells.get(entity.getName());
            postProcessEntity(entity, sourceCell);
        }
    }
    view.insert(createdObjects.toArray());
    setLayout(doLayout);
    /*
         * Adding isolated objects
         * 
         * We're placing them so that they will take maximum space in left top
         * corner. The sample order is below:
         * 
         * 1 2 6 7... 3 5 8 ... 4 9... 10 ...
         */
    addIsolatedObjects(isolatedObjects);
    view.insert(isolatedObjects.toArray());
    graph.getModel().addUndoableEditListener(this);
}
Also used : JGraph(org.jgraph.JGraph) Entity(org.apache.cayenne.map.Entity) DefaultCellViewFactory(org.jgraph.graph.DefaultCellViewFactory) DefaultGraphCell(org.jgraph.graph.DefaultGraphCell) GraphLayoutCache(org.jgraph.graph.GraphLayoutCache) DefaultGraphModel(org.jgraph.graph.DefaultGraphModel) GraphModel(org.jgraph.graph.GraphModel) ArrayList(java.util.ArrayList) DefaultGraphModel(org.jgraph.graph.DefaultGraphModel) DataMap(org.apache.cayenne.map.DataMap)

Example 8 with Entity

use of org.apache.cayenne.map.Entity in project cayenne by apache.

the class DataDomainGraphTab method currentDomainChanged.

public void currentDomainChanged(DomainDisplayEvent e) {
    if (e instanceof EntityDisplayEvent) {
        // selecting an event
        // choose type of diagram
        Entity entity = ((EntityDisplayEvent) e).getEntity();
        diagramCombo.setSelectedIndex(entity instanceof ObjEntity ? 1 : 0);
        refresh();
        GraphBuilder builder = getGraphRegistry().getGraphMap(domain).get(getSelectedType());
        Object cell = builder.getEntityCell(entity.getName());
        if (cell != null) {
            graph.setSelectionCell(cell);
            graph.scrollCellToVisible(cell);
        }
    } else if (domain != e.getDomain()) {
        needRebuild = true;
        domain = e.getDomain();
        if (isVisible()) {
            refresh();
        }
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Entity(org.apache.cayenne.map.Entity) ObjEntity(org.apache.cayenne.map.ObjEntity) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent)

Example 9 with Entity

use of org.apache.cayenne.map.Entity in project cayenne by apache.

the class EntityCellMetadata method createLabel.

/**
 * Creates label for this cell
 */
String createLabel() {
    Entity entity = fetchEntity();
    StringBuilder label = new StringBuilder("<html><center><u><b>").append(entity.getName()).append("</b></u></center>");
    for (Attribute attr : entity.getAttributes()) {
        if (isPrimary(attr)) {
            label.append("<br><i>").append(attr.getName()).append("</i>");
        }
    }
    for (Attribute attr : entity.getAttributes()) {
        if (!isPrimary(attr)) {
            label.append("<br>").append(attr.getName());
        }
    }
    return label.toString();
}
Also used : Entity(org.apache.cayenne.map.Entity) Attribute(org.apache.cayenne.map.Attribute)

Example 10 with Entity

use of org.apache.cayenne.map.Entity in project cayenne by apache.

the class EntityDisplayAction method display.

private boolean display() {
    Entity entity = builder.getSelectedEntity();
    if (entity == null) {
        return false;
    }
    // reusing logic from FindAction
    FindAction.jumpToResult(new FindAction.SearchResultEntry(entity, entity.getName()));
    return true;
}
Also used : Entity(org.apache.cayenne.map.Entity) FindAction(org.apache.cayenne.modeler.action.FindAction)

Aggregations

Entity (org.apache.cayenne.map.Entity)38 DbEntity (org.apache.cayenne.map.DbEntity)24 ObjEntity (org.apache.cayenne.map.ObjEntity)23 DataMap (org.apache.cayenne.map.DataMap)10 DbRelationship (org.apache.cayenne.map.DbRelationship)9 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)6 DbAttribute (org.apache.cayenne.map.DbAttribute)6 Attribute (org.apache.cayenne.map.Attribute)5 ObjAttribute (org.apache.cayenne.map.ObjAttribute)5 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)5 Relationship (org.apache.cayenne.map.Relationship)5 EntityEvent (org.apache.cayenne.map.event.EntityEvent)5 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)4 ObjRelationship (org.apache.cayenne.map.ObjRelationship)4 SelectQueryDescriptor (org.apache.cayenne.map.SelectQueryDescriptor)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2