Search in sources :

Example 1 with DefaultCellViewFactory

use of org.jgraph.graph.DefaultCellViewFactory 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 2 with DefaultCellViewFactory

use of org.jgraph.graph.DefaultCellViewFactory in project fql by CategoricalData.

the class Overview method initializeOverview.

/**
 * When we initialise the overview, we flush out all the data concerning the
 * sketch itself.
 *
 * This methods serves as a "new overview" function.
 */
public void initializeOverview() {
    clearSelection();
    if (_sketchNodes != null) {
        for (SketchNode node : _sketchNodes.values()) {
            node.getFrame().dispose();
        }
    }
    if (_viewNodes != null) {
        for (ViewNode node : _viewNodes.values()) {
            node.getFrame().dispose();
        }
    }
    setFile(null);
    _sketchNodes = new HashMap<>();
    _viewNodes = new HashMap<>();
    _viewEdges = new HashMap<>();
    _docInfo = new DocumentInfo(_appFrame);
    if (_appFrame.getInfoTreeUI() != null) {
        _appFrame.setInfoTreeUI(new OverviewInfoTreeUI(_appFrame));
        _appFrame.getInfoTreeUI().refreshTree();
    }
    OverviewGraphModel model = new OverviewGraphModel(this);
    GraphLayoutCache glc = new GraphLayoutCache(model, new DefaultCellViewFactory());
    setModel(model);
    setGraphLayoutCache(glc);
}
Also used : DefaultCellViewFactory(org.jgraph.graph.DefaultCellViewFactory) GraphLayoutCache(org.jgraph.graph.GraphLayoutCache) ViewNode(easik.overview.vertex.ViewNode) OverviewGraphModel(easik.overview.util.graph.OverviewGraphModel) OverviewInfoTreeUI(easik.ui.tree.OverviewInfoTreeUI) SketchNode(easik.overview.vertex.SketchNode) DocumentInfo(easik.DocumentInfo)

Aggregations

DefaultCellViewFactory (org.jgraph.graph.DefaultCellViewFactory)2 GraphLayoutCache (org.jgraph.graph.GraphLayoutCache)2 DocumentInfo (easik.DocumentInfo)1 OverviewGraphModel (easik.overview.util.graph.OverviewGraphModel)1 SketchNode (easik.overview.vertex.SketchNode)1 ViewNode (easik.overview.vertex.ViewNode)1 OverviewInfoTreeUI (easik.ui.tree.OverviewInfoTreeUI)1 ArrayList (java.util.ArrayList)1 DataMap (org.apache.cayenne.map.DataMap)1 Entity (org.apache.cayenne.map.Entity)1 JGraph (org.jgraph.JGraph)1 DefaultGraphCell (org.jgraph.graph.DefaultGraphCell)1 DefaultGraphModel (org.jgraph.graph.DefaultGraphModel)1 GraphModel (org.jgraph.graph.GraphModel)1