Search in sources :

Example 1 with GraphConnection

use of org.eclipse.zest.core.widgets.GraphConnection in project archi by archimatetool.

the class AbstractStylingModelFactory method createConnection.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.zest.core.internal.graphmodel.IStylingGraphModelFactory#
     * createConnection(org.eclipse.zest.core.internal.graphmodel.GraphModel,
     * java.lang.Object, java.lang.Object, java.lang.Object)
     */
@Override
public GraphConnection createConnection(Graph graph, Object element, Object source, Object dest) {
    if (source == null || dest == null) {
        return null;
    }
    GraphConnection oldConnection = viewer.getGraphModelConnection(element);
    GraphNode sn = viewer.getGraphModelNode(source);
    GraphNode dn = viewer.getGraphModelNode(dest);
    if (oldConnection != null) {
        if (sn != oldConnection.getSource() || dn != oldConnection.getDestination()) {
            viewer.removeGraphModelConnection(oldConnection);
        } else {
            styleItem(oldConnection);
            return oldConnection;
        }
    }
    IFigureProvider figureProvider = null;
    if (getLabelProvider() instanceof IFigureProvider) {
        figureProvider = (IFigureProvider) getLabelProvider();
    }
    if (sn == null) {
        IFigure figure = null;
        if (figureProvider != null) {
            figure = figureProvider.getFigure(source);
        }
        if (figure != null) {
            sn = createNode(graph, source, figure);
        } else {
            sn = createNode(graph, source);
        }
    }
    if (dn == null) {
        IFigure figure = null;
        if (figureProvider != null) {
            figure = figureProvider.getFigure(dest);
        }
        if (figure != null) {
            dn = createNode(graph, dest, figure);
        } else {
            dn = createNode(graph, dest);
        }
    }
    GraphConnection c = viewer.addGraphModelConnection(element, sn, dn);
    styleItem(c);
    return c;
}
Also used : GraphConnection(org.eclipse.zest.core.widgets.GraphConnection) GraphNode(org.eclipse.zest.core.widgets.GraphNode) IFigureProvider(org.eclipse.zest.core.viewers.IFigureProvider) IFigure(org.eclipse.draw2d.IFigure)

Example 2 with GraphConnection

use of org.eclipse.zest.core.widgets.GraphConnection in project archi by archimatetool.

the class AbstractStylingModelFactory method adjustCurves.

/**
 * Takes a list of IGraphModelConnections and adjusts the curve depths and
 * the bezier curves based on the number of curves in the list.
 *
 * @param connections
 * @param size
 *            + * total number of arcs - may be bigger then connections.size
 */
protected void adjustCurves(List connections, int size) {
    /*
         * The connections should be curved if source and dest are equal, or
         * there are multiple arcs between two nodes
         */
    for (int i = 0; i < connections.size(); i++) {
        GraphConnection conn = (GraphConnection) connections.get(i);
        int radius = 20;
        if (conn.getSource() == conn.getDestination()) {
            radius = 40;
        } else if (size < 2) {
            radius = 0;
        }
        conn.setCurveDepth((i + 1) * radius);
    }
}
Also used : GraphConnection(org.eclipse.zest.core.widgets.GraphConnection)

Example 3 with GraphConnection

use of org.eclipse.zest.core.widgets.GraphConnection in project archi by archimatetool.

the class AbstractStylingModelFactory method getConnectionList.

/**
 * @param source
 * @param dest
 * @return
 */
private LinkedList getConnectionList(GraphNode source, GraphNode dest) {
    LinkedList list = new LinkedList();
    Iterator i = source.getSourceConnections().iterator();
    while (i.hasNext()) {
        GraphConnection c = (GraphConnection) i.next();
        if (c.getDestination() == dest) {
            list.add(c);
        }
    }
    return list;
}
Also used : GraphConnection(org.eclipse.zest.core.widgets.GraphConnection) Iterator(java.util.Iterator) LinkedList(java.util.LinkedList)

Example 4 with GraphConnection

use of org.eclipse.zest.core.widgets.GraphConnection in project archi by archimatetool.

the class GraphModelFactory method refresh.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.zest.core.internal.graphmodel.IStylingGraphModelFactory#refresh(org.eclipse.zest.core.internal.graphmodel.GraphModel,
     *      java.lang.Object, boolean)
     */
@Override
public void refresh(Graph graph, Object element, boolean updateLabels) {
    GraphConnection conn = viewer.getGraphModelConnection(element);
    if (conn == null) {
        // did the user send us a node? Check all of the connections on the
        // node.
        GraphNode node = viewer.getGraphModelNode(element);
        if (node != null) {
            List connections = node.getSourceConnections();
            for (Iterator it = connections.iterator(); it.hasNext(); ) {
                GraphConnection c = (GraphConnection) it.next();
                refresh(graph, c.getExternalConnection(), updateLabels);
            }
            connections = node.getTargetConnections();
            for (Iterator it = connections.iterator(); it.hasNext(); ) {
                GraphConnection c = (GraphConnection) it.next();
                refresh(graph, c.getExternalConnection(), updateLabels);
            }
        }
        return;
    }
    Object oldSource = conn.getSource().getData();
    Object oldDest = conn.getDestination().getData();
    Object newSource = getCastedContent().getSource(element);
    Object newDest = getCastedContent().getDestination(element);
    if (!(oldSource.equals(newSource) && oldDest.equals(newDest))) {
        GraphNode internalSource = viewer.getGraphModelNode(newSource);
        GraphNode internalDest = viewer.getGraphModelNode(newDest);
        if (internalSource == null) {
            internalSource = createNode(graph, newSource);
        } else if (updateLabels) {
            styleItem(internalSource);
        }
        if (internalDest == null) {
            internalDest = createNode(graph, newDest);
        } else if (updateLabels) {
            styleItem(internalDest);
        }
        // conn.reconnect(internalSource, internalDest);
        if (updateLabels) {
            styleItem(conn);
        }
    }
}
Also used : GraphConnection(org.eclipse.zest.core.widgets.GraphConnection) Iterator(java.util.Iterator) GraphNode(org.eclipse.zest.core.widgets.GraphNode) List(java.util.List)

Example 5 with GraphConnection

use of org.eclipse.zest.core.widgets.GraphConnection in project archi by archimatetool.

the class AbstractStructuredGraphViewer method addGraphModelConnection.

GraphConnection addGraphModelConnection(Object element, GraphNode source, GraphNode target) {
    GraphConnection connection = this.getGraphModelConnection(element);
    if (connection == null) {
        connection = new GraphConnection((Graph) getControl(), SWT.NONE, source, target);
        this.connectionsMap.put(element, connection);
        connection.setData(element);
    }
    return connection;
}
Also used : Graph(org.eclipse.zest.core.widgets.Graph) GraphConnection(org.eclipse.zest.core.widgets.GraphConnection)

Aggregations

GraphConnection (org.eclipse.zest.core.widgets.GraphConnection)13 GraphNode (org.eclipse.zest.core.widgets.GraphNode)10 Iterator (java.util.Iterator)7 CGraphNode (org.eclipse.zest.core.widgets.CGraphNode)6 LinkedList (java.util.LinkedList)4 List (java.util.List)4 ArrayList (java.util.ArrayList)3 Graph (org.eclipse.zest.core.widgets.Graph)3 Widget (org.eclipse.swt.widgets.Widget)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 IFigure (org.eclipse.draw2d.IFigure)1 IColorProvider (org.eclipse.jface.viewers.IColorProvider)1 IFontProvider (org.eclipse.jface.viewers.IFontProvider)1 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)1 IConnectionStyleProvider (org.eclipse.zest.core.viewers.IConnectionStyleProvider)1 IEntityConnectionStyleProvider (org.eclipse.zest.core.viewers.IEntityConnectionStyleProvider)1 IEntityStyleProvider (org.eclipse.zest.core.viewers.IEntityStyleProvider)1 IFigureProvider (org.eclipse.zest.core.viewers.IFigureProvider)1