Search in sources :

Example 1 with IGraphEntityContentProvider

use of org.eclipse.zest.core.viewers.IGraphEntityContentProvider in project archi by archimatetool.

the class GraphModelEntityFactory method doBuildGraph.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.zest.core.internal.graphmodel.AbstractStylingModelFactory
     * #doBuildGraph(org.eclipse.zest.core.internal.graphmodel.GraphModel)
     */
@Override
protected void doBuildGraph(Graph model) {
    super.doBuildGraph(model);
    Object inputElement = getViewer().getInput();
    Object[] entities = getContentProvider().getElements(inputElement);
    if (entities == null) {
        return;
    }
    for (int i = 0; i < entities.length; i++) {
        Object data = entities[i];
        IFigureProvider figureProvider = null;
        if (getLabelProvider() instanceof IFigureProvider) {
            figureProvider = (IFigureProvider) getLabelProvider();
        }
        if (!filterElement(inputElement, data)) {
            if (figureProvider != null) {
                createNode(model, data, figureProvider.getFigure(data));
            } else {
                createNode(model, data);
            }
        }
    }
    // We may have other entities (such as children of containers)
    Set keySet = ((AbstractStructuredGraphViewer) getViewer()).getNodesMap().keySet();
    entities = keySet.toArray();
    for (int i = 0; i < entities.length; i++) {
        Object data = entities[i];
        // If this element is filtered, continue to the next one.
        if (filterElement(inputElement, data)) {
            continue;
        }
        Object[] related = ((IGraphEntityContentProvider) getContentProvider()).getConnectedTo(data);
        if (related != null) {
            for (int j = 0; j < related.length; j++) {
                // don't display this edge
                if (filterElement(inputElement, related[j])) {
                    continue;
                }
                EntityConnectionData connectionData = new EntityConnectionData(data, related[j]);
                if (filterElement(inputElement, connectionData)) {
                    continue;
                }
                createConnection(model, connectionData, data, related[j]);
            }
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) EntityConnectionData(org.eclipse.zest.core.viewers.EntityConnectionData) IFigureProvider(org.eclipse.zest.core.viewers.IFigureProvider) IGraphEntityContentProvider(org.eclipse.zest.core.viewers.IGraphEntityContentProvider)

Example 2 with IGraphEntityContentProvider

use of org.eclipse.zest.core.viewers.IGraphEntityContentProvider in project archi by archimatetool.

the class GraphModelEntityFactory method reconnect.

/**
 * @param graph
 * @param element
 * @param refreshLabels
 */
private void reconnect(Graph graph, Object element, boolean refreshLabels) {
    GraphNode node = viewer.getGraphModelNode(element);
    Object[] related = ((IGraphEntityContentProvider) getContentProvider()).getConnectedTo(element);
    List connections = node.getSourceConnections();
    LinkedList toAdd = new LinkedList();
    LinkedList toDelete = new LinkedList();
    LinkedList toKeep = new LinkedList();
    HashSet oldExternalConnections = new HashSet();
    HashSet newExternalConnections = new HashSet();
    for (Iterator it = connections.iterator(); it.hasNext(); ) {
        oldExternalConnections.add(((GraphConnection) it.next()).getExternalConnection());
    }
    for (int i = 0; i < related.length; i++) {
        newExternalConnections.add(new EntityConnectionData(element, related[i]));
    }
    for (Iterator it = oldExternalConnections.iterator(); it.hasNext(); ) {
        Object next = it.next();
        if (!newExternalConnections.contains(next)) {
            toDelete.add(next);
        } else {
            toKeep.add(next);
        }
    }
    for (Iterator it = newExternalConnections.iterator(); it.hasNext(); ) {
        Object next = it.next();
        if (!oldExternalConnections.contains(next)) {
            toAdd.add(next);
        }
    }
    for (Iterator it = toDelete.iterator(); it.hasNext(); ) {
        viewer.removeGraphModelConnection(it.next());
    }
    toDelete.clear();
    LinkedList newNodeList = new LinkedList();
    for (Iterator it = toAdd.iterator(); it.hasNext(); ) {
        EntityConnectionData data = (EntityConnectionData) it.next();
        GraphNode dest = viewer.getGraphModelNode(data.dest);
        if (dest == null) {
            newNodeList.add(data.dest);
        }
        createConnection(graph, data, data.source, data.dest);
    }
    toAdd.clear();
    if (refreshLabels) {
        for (Iterator i = toKeep.iterator(); i.hasNext(); ) {
            styleItem(viewer.getGraphModelConnection(i.next()));
        }
    }
    for (Iterator it = newNodeList.iterator(); it.hasNext(); ) {
        // refresh the new nodes so that we get a fully-up-to-date graph.
        refresh(graph, it.next());
    }
}
Also used : EntityConnectionData(org.eclipse.zest.core.viewers.EntityConnectionData) Iterator(java.util.Iterator) GraphNode(org.eclipse.zest.core.widgets.GraphNode) List(java.util.List) LinkedList(java.util.LinkedList) IGraphEntityContentProvider(org.eclipse.zest.core.viewers.IGraphEntityContentProvider) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)2 EntityConnectionData (org.eclipse.zest.core.viewers.EntityConnectionData)2 IGraphEntityContentProvider (org.eclipse.zest.core.viewers.IGraphEntityContentProvider)2 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Set (java.util.Set)1 IFigureProvider (org.eclipse.zest.core.viewers.IFigureProvider)1 GraphNode (org.eclipse.zest.core.widgets.GraphNode)1