Search in sources :

Example 1 with DirectedGraph

use of org.eclipse.draw2d.graph.DirectedGraph in project jbosstools-hibernate by jbosstools.

the class DirectedGraphLayoutVisitor method layoutDiagram.

/**
 * Public method for reading graph nodes
 */
public void layoutDiagram(ConfigurationEditPart diagram) {
    partToNodesMap = new HashMap<AbstractGraphicalEditPart, Object>();
    addedAssociations = new HashSet<AssociationEditPart>();
    graph = new DirectedGraph();
    addNodes(diagram);
    if (graph.nodes.size() > 0) {
        addEdges(diagram);
        new NodeJoiningDirectedGraphLayout().visit(graph);
        applyResults(diagram);
    }
}
Also used : DirectedGraph(org.eclipse.draw2d.graph.DirectedGraph) AbstractGraphicalEditPart(org.eclipse.gef.editparts.AbstractGraphicalEditPart) AssociationEditPart(org.hibernate.eclipse.graph.parts.AssociationEditPart)

Example 2 with DirectedGraph

use of org.eclipse.draw2d.graph.DirectedGraph in project archi by archimatetool.

the class DirectedGraphLayoutAlgorithm method applyLayoutInternal.

@Override
protected void applyLayoutInternal(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider, double boundsX, double boundsY, double boundsWidth, double boundsHeight) {
    HashMap mapping = new HashMap(entitiesToLayout.length);
    DirectedGraph graph = new DirectedGraph();
    for (int i = 0; i < entitiesToLayout.length; i++) {
        InternalNode internalNode = entitiesToLayout[i];
        Node node = new Node(internalNode);
        node.setSize(new Dimension(10, 10));
        mapping.put(internalNode, node);
        graph.nodes.add(node);
    }
    for (int i = 0; i < relationshipsToConsider.length; i++) {
        InternalRelationship relationship = relationshipsToConsider[i];
        Node source = (Node) mapping.get(relationship.getSource());
        Node dest = (Node) mapping.get(relationship.getDestination());
        Edge edge = new Edge(relationship, source, dest);
        graph.edges.add(edge);
    }
    DirectedGraphLayout directedGraphLayout = new ExtendedDirectedGraphLayout();
    directedGraphLayout.visit(graph);
    for (Iterator iterator = graph.nodes.iterator(); iterator.hasNext(); ) {
        Node node = (Node) iterator.next();
        InternalNode internalNode = (InternalNode) node.data;
        // For horizontal layout transpose the x and y coordinates
        if ((layout_styles & SWT.HORIZONTAL) == SWT.HORIZONTAL) {
            internalNode.setInternalLocation(node.y, node.x);
        } else {
            internalNode.setInternalLocation(node.x, node.y);
        }
    }
    updateLayoutLocations(entitiesToLayout);
}
Also used : InternalRelationship(org.eclipse.zest.layouts.dataStructures.InternalRelationship) DirectedGraph(org.eclipse.draw2d.graph.DirectedGraph) DirectedGraphLayout(org.eclipse.draw2d.graph.DirectedGraphLayout) HashMap(java.util.HashMap) Node(org.eclipse.draw2d.graph.Node) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) Iterator(java.util.Iterator) InternalNode(org.eclipse.zest.layouts.dataStructures.InternalNode) Dimension(org.eclipse.draw2d.geometry.Dimension) Edge(org.eclipse.draw2d.graph.Edge)

Aggregations

DirectedGraph (org.eclipse.draw2d.graph.DirectedGraph)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 DirectedGraphLayout (org.eclipse.draw2d.graph.DirectedGraphLayout)1 Edge (org.eclipse.draw2d.graph.Edge)1 Node (org.eclipse.draw2d.graph.Node)1 AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)1 InternalNode (org.eclipse.zest.layouts.dataStructures.InternalNode)1 InternalRelationship (org.eclipse.zest.layouts.dataStructures.InternalRelationship)1 AssociationEditPart (org.hibernate.eclipse.graph.parts.AssociationEditPart)1