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()]));
}
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);
}
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();
}
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);
}
}
}
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());
}
}
}
Aggregations