Search in sources :

Example 6 with GraphConnection

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

the class AbstractStructuredGraphViewer method setSelectionToWidget.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.jface.viewers.StructuredViewer#setSelectionToWidget(java.
     * util.List, boolean)
     */
@Override
protected void setSelectionToWidget(List l, boolean reveal) {
    Graph control = (Graph) getControl();
    List selection = new LinkedList();
    for (Iterator i = l.iterator(); i.hasNext(); ) {
        Object obj = i.next();
        GraphNode node = (GraphNode) nodesMap.get(obj);
        GraphConnection conn = (GraphConnection) connectionsMap.get(obj);
        if (node != null) {
            selection.add(node);
        }
        if (conn != null) {
            selection.add(conn);
        }
    }
    control.setSelection((GraphNode[]) selection.toArray(new GraphNode[selection.size()]));
}
Also used : Graph(org.eclipse.zest.core.widgets.Graph) GraphConnection(org.eclipse.zest.core.widgets.GraphConnection) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) GraphNode(org.eclipse.zest.core.widgets.GraphNode) CGraphNode(org.eclipse.zest.core.widgets.CGraphNode) LinkedList(java.util.LinkedList)

Example 7 with GraphConnection

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

the class AbstractStructuredGraphViewer method getRawChildren.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.jface.viewers.StructuredViewer#getRawChildren(java.lang.Object
     * )
     */
@Override
protected Object[] getRawChildren(Object parent) {
    if (parent == getInput()) {
        // get the children from the model.
        LinkedList children = new LinkedList();
        if (getGraphControl() != null) {
            List connections = getGraphControl().getConnections();
            List nodes = getGraphControl().getNodes();
            for (Iterator i = connections.iterator(); i.hasNext(); ) {
                GraphConnection c = (GraphConnection) i.next();
                if (c.getExternalConnection() != null) {
                    children.add(c.getExternalConnection());
                }
            }
            for (Iterator i = nodes.iterator(); i.hasNext(); ) {
                GraphNode n = (GraphNode) i.next();
                if (n.getData() != null) {
                    children.add(n.getData());
                }
            }
            return children.toArray();
        }
    }
    return super.getRawChildren(parent);
}
Also used : GraphConnection(org.eclipse.zest.core.widgets.GraphConnection) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) GraphNode(org.eclipse.zest.core.widgets.GraphNode) CGraphNode(org.eclipse.zest.core.widgets.CGraphNode) LinkedList(java.util.LinkedList)

Example 8 with GraphConnection

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

the class AbstractStructuredGraphViewer method inputChanged.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object,
     * java.lang.Object)
     */
@Override
protected void inputChanged(Object input, Object oldInput) {
    IStylingGraphModelFactory factory = getFactory();
    factory.setConnectionStyle(getConnectionStyle());
    factory.setNodeStyle(getNodeStyle());
    // Save the old map so we can set the size and position of any nodes
    // that are the same
    Map oldNodesMap = nodesMap;
    Graph graph = (Graph) getControl();
    graph.setSelection(new GraphNode[0]);
    Iterator iterator = nodesMap.values().iterator();
    while (iterator.hasNext()) {
        GraphNode node = (GraphNode) iterator.next();
        if (!node.isDisposed()) {
            node.dispose();
        }
    }
    iterator = connectionsMap.values().iterator();
    while (iterator.hasNext()) {
        GraphConnection connection = (GraphConnection) iterator.next();
        if (!connection.isDisposed()) {
            connection.dispose();
        }
    }
    nodesMap = new HashMap();
    connectionsMap = new HashMap();
    graph = factory.createGraphModel(graph);
    ((Graph) getControl()).setNodeStyle(getNodeStyle());
    ((Graph) getControl()).setConnectionStyle(getConnectionStyle());
    // in this case we want them to keep the same location & size
    for (Iterator iter = oldNodesMap.keySet().iterator(); iter.hasNext(); ) {
        Object data = iter.next();
        GraphNode newNode = (GraphNode) nodesMap.get(data);
        if (newNode != null) {
            GraphNode oldNode = (GraphNode) oldNodesMap.get(data);
            newNode.setLocation(oldNode.getLocation().x, oldNode.getLocation().y);
            if (oldNode.isSizeFixed()) {
                newNode.setSize(oldNode.getSize().width, oldNode.getSize().height);
            }
        }
    }
    applyLayout();
}
Also used : Graph(org.eclipse.zest.core.widgets.Graph) HashMap(java.util.HashMap) GraphConnection(org.eclipse.zest.core.widgets.GraphConnection) Iterator(java.util.Iterator) GraphNode(org.eclipse.zest.core.widgets.GraphNode) CGraphNode(org.eclipse.zest.core.widgets.CGraphNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with GraphConnection

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

the class GraphItemStyler method styleItem.

public static void styleItem(GraphItem item, final IBaseLabelProvider labelProvider) {
    if (item instanceof GraphNode) {
        GraphNode node = (GraphNode) item;
        // set defaults.
        if (node.getGraphModel().getNodeStyle() != ZestStyles.NONE) {
            node.setNodeStyle(node.getGraphModel().getNodeStyle());
        } else {
            node.setNodeStyle(SWT.NONE);
        }
        Object entity = node.getData();
        if (labelProvider instanceof IEntityStyleProvider) {
            styleNode(node, (IEntityStyleProvider) labelProvider);
        }
        if (labelProvider instanceof IColorProvider) {
            IColorProvider colorProvider = (IColorProvider) labelProvider;
            node.setForegroundColor(colorProvider.getForeground(entity));
            node.setBackgroundColor(colorProvider.getBackground(entity));
        }
        if (labelProvider instanceof IFontProvider) {
            IFontProvider fontProvider = (IFontProvider) labelProvider;
            node.setFont(fontProvider.getFont(entity));
        }
        if (labelProvider instanceof ILabelProvider) {
            String text = ((ILabelProvider) labelProvider).getText(node.getData());
            // $NON-NLS-1$
            node.setText((text != null) ? text : "");
            node.setImage(((ILabelProvider) labelProvider).getImage(node.getData()));
        }
        if (labelProvider instanceof ISelfStyleProvider) {
            ((ISelfStyleProvider) labelProvider).selfStyleNode(entity, node);
        }
    } else if (item instanceof GraphConnection) {
        GraphConnection conn = (GraphConnection) item;
        // set defaults
        if (conn.getGraphModel().getConnectionStyle() != ZestStyles.NONE) {
            int s = conn.getGraphModel().getConnectionStyle();
            conn.setConnectionStyle(s);
        } else {
            conn.setConnectionStyle(SWT.NONE);
        }
        if (labelProvider instanceof ILabelProvider) {
            String text = ((ILabelProvider) labelProvider).getText(conn.getExternalConnection());
            // $NON-NLS-1$
            conn.setText((text != null) ? text : "");
            conn.setImage(((ILabelProvider) labelProvider).getImage(conn.getExternalConnection()));
        }
        if (labelProvider instanceof IEntityConnectionStyleProvider) {
            styleEntityConnection(conn, (IEntityConnectionStyleProvider) labelProvider);
        } else if (labelProvider instanceof IConnectionStyleProvider) {
            styleConnection(conn, (IConnectionStyleProvider) labelProvider);
        }
        int swt = getLineStyleForZestStyle(conn.getConnectionStyle());
        conn.setLineStyle(swt);
        if (labelProvider instanceof ISelfStyleProvider) {
            ((ISelfStyleProvider) labelProvider).selfStyleConnection(conn.getData(), conn);
        }
    }
}
Also used : IColorProvider(org.eclipse.jface.viewers.IColorProvider) IFontProvider(org.eclipse.jface.viewers.IFontProvider) IEntityConnectionStyleProvider(org.eclipse.zest.core.viewers.IEntityConnectionStyleProvider) IConnectionStyleProvider(org.eclipse.zest.core.viewers.IConnectionStyleProvider) GraphConnection(org.eclipse.zest.core.widgets.GraphConnection) ISelfStyleProvider(org.eclipse.zest.core.viewers.ISelfStyleProvider) GraphNode(org.eclipse.zest.core.widgets.GraphNode) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) IEntityStyleProvider(org.eclipse.zest.core.viewers.IEntityStyleProvider)

Example 10 with GraphConnection

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

the class GraphModelEntityFactory method refresh.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.zest.core.internal.graphmodel.IStylingGraphModelFactory#refresh
     * (org.eclipse.zest.core.internal.graphmodel.GraphModel, java.lang.Object)
     */
@Override
public void refresh(Graph graph, Object element, boolean refreshLabels) {
    if (element == null) {
        return;
    }
    GraphNode node = viewer.getGraphModelNode(element);
    if (node == null) {
        // check to make sure that the user didn't send us an edge.
        GraphConnection conn = viewer.getGraphModelConnection(element);
        if (conn != null) {
            // refresh on the connected nodes.
            refresh(graph, conn.getSource().getData(), refreshLabels);
            refresh(graph, conn.getDestination().getData(), refreshLabels);
            return;
        }
    }
    // can only refresh on nodes in this kind of factory.
    if (node == null) {
        // do nothing
        return;
    }
    reconnect(graph, element, refreshLabels);
    if (refreshLabels) {
        update(node);
        for (Iterator it = node.getSourceConnections().iterator(); it.hasNext(); ) {
            update((GraphItem) it.next());
        }
        for (Iterator it = node.getTargetConnections().iterator(); it.hasNext(); ) {
            update((GraphItem) it.next());
        }
    }
}
Also used : GraphConnection(org.eclipse.zest.core.widgets.GraphConnection) Iterator(java.util.Iterator) GraphNode(org.eclipse.zest.core.widgets.GraphNode)

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