Search in sources :

Example 1 with IFigureProvider

use of org.eclipse.zest.core.viewers.IFigureProvider 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 IFigureProvider

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

the class GraphModelFactory 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);
    // make the model have the same styles as the viewer
    Object[] rels = getContentProvider().getElements(getViewer().getInput());
    if (rels != null) {
        IFigureProvider figureProvider = null;
        if (getLabelProvider() instanceof IFigureProvider) {
            figureProvider = (IFigureProvider) getLabelProvider();
        }
        // @tag zest(bug(134928(fix))) : An empty graph causes an NPE
        for (int i = 0; i < rels.length; i++) {
            // Check the filter on the source
            Object source = getCastedContent().getSource(rels[i]);
            source = filterElement(getViewer().getInput(), source) ? null : source;
            // Check the filter on the dest
            Object dest = getCastedContent().getDestination(rels[i]);
            dest = filterElement(getViewer().getInput(), dest) ? null : dest;
            if (source == null) {
                // just create the node for the destination
                if (dest != null) {
                    if (figureProvider != null) {
                        createNode(model, dest, figureProvider.getFigure(dest));
                    } else {
                        createNode(model, dest);
                    }
                }
                continue;
            } else if (dest == null) {
                // just create the node for the source
                if (source != null) {
                    if (figureProvider != null) {
                        createNode(model, source, figureProvider.getFigure(source));
                    } else {
                        createNode(model, source);
                    }
                }
                continue;
            }
            // don't create the graph.
            if (source != null && dest != null && !filterElement(getViewer().getInput(), rels[i])) {
                createConnection(model, rels[i], source, dest);
            }
        }
    }
}
Also used : IFigureProvider(org.eclipse.zest.core.viewers.IFigureProvider)

Example 3 with IFigureProvider

use of org.eclipse.zest.core.viewers.IFigureProvider 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)

Aggregations

IFigureProvider (org.eclipse.zest.core.viewers.IFigureProvider)3 HashSet (java.util.HashSet)1 Set (java.util.Set)1 IFigure (org.eclipse.draw2d.IFigure)1 EntityConnectionData (org.eclipse.zest.core.viewers.EntityConnectionData)1 IGraphEntityContentProvider (org.eclipse.zest.core.viewers.IGraphEntityContentProvider)1 GraphConnection (org.eclipse.zest.core.widgets.GraphConnection)1 GraphNode (org.eclipse.zest.core.widgets.GraphNode)1