Search in sources :

Example 1 with ISelfStyleProvider

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

Aggregations

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 ISelfStyleProvider (org.eclipse.zest.core.viewers.ISelfStyleProvider)1 GraphConnection (org.eclipse.zest.core.widgets.GraphConnection)1 GraphNode (org.eclipse.zest.core.widgets.GraphNode)1