use of org.eclipse.zest.core.widgets.GraphConnection 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;
}
use of org.eclipse.zest.core.widgets.GraphConnection in project archi by archimatetool.
the class AbstractStylingModelFactory method adjustCurves.
/**
* Takes a list of IGraphModelConnections and adjusts the curve depths and
* the bezier curves based on the number of curves in the list.
*
* @param connections
* @param size
* + * total number of arcs - may be bigger then connections.size
*/
protected void adjustCurves(List connections, int size) {
/*
* The connections should be curved if source and dest are equal, or
* there are multiple arcs between two nodes
*/
for (int i = 0; i < connections.size(); i++) {
GraphConnection conn = (GraphConnection) connections.get(i);
int radius = 20;
if (conn.getSource() == conn.getDestination()) {
radius = 40;
} else if (size < 2) {
radius = 0;
}
conn.setCurveDepth((i + 1) * radius);
}
}
use of org.eclipse.zest.core.widgets.GraphConnection in project archi by archimatetool.
the class AbstractStylingModelFactory method getConnectionList.
/**
* @param source
* @param dest
* @return
*/
private LinkedList getConnectionList(GraphNode source, GraphNode dest) {
LinkedList list = new LinkedList();
Iterator i = source.getSourceConnections().iterator();
while (i.hasNext()) {
GraphConnection c = (GraphConnection) i.next();
if (c.getDestination() == dest) {
list.add(c);
}
}
return list;
}
use of org.eclipse.zest.core.widgets.GraphConnection in project archi by archimatetool.
the class GraphModelFactory method refresh.
/*
* (non-Javadoc)
*
* @see org.eclipse.zest.core.internal.graphmodel.IStylingGraphModelFactory#refresh(org.eclipse.zest.core.internal.graphmodel.GraphModel,
* java.lang.Object, boolean)
*/
@Override
public void refresh(Graph graph, Object element, boolean updateLabels) {
GraphConnection conn = viewer.getGraphModelConnection(element);
if (conn == null) {
// did the user send us a node? Check all of the connections on the
// node.
GraphNode node = viewer.getGraphModelNode(element);
if (node != null) {
List connections = node.getSourceConnections();
for (Iterator it = connections.iterator(); it.hasNext(); ) {
GraphConnection c = (GraphConnection) it.next();
refresh(graph, c.getExternalConnection(), updateLabels);
}
connections = node.getTargetConnections();
for (Iterator it = connections.iterator(); it.hasNext(); ) {
GraphConnection c = (GraphConnection) it.next();
refresh(graph, c.getExternalConnection(), updateLabels);
}
}
return;
}
Object oldSource = conn.getSource().getData();
Object oldDest = conn.getDestination().getData();
Object newSource = getCastedContent().getSource(element);
Object newDest = getCastedContent().getDestination(element);
if (!(oldSource.equals(newSource) && oldDest.equals(newDest))) {
GraphNode internalSource = viewer.getGraphModelNode(newSource);
GraphNode internalDest = viewer.getGraphModelNode(newDest);
if (internalSource == null) {
internalSource = createNode(graph, newSource);
} else if (updateLabels) {
styleItem(internalSource);
}
if (internalDest == null) {
internalDest = createNode(graph, newDest);
} else if (updateLabels) {
styleItem(internalDest);
}
// conn.reconnect(internalSource, internalDest);
if (updateLabels) {
styleItem(conn);
}
}
}
use of org.eclipse.zest.core.widgets.GraphConnection in project archi by archimatetool.
the class AbstractStructuredGraphViewer method addGraphModelConnection.
GraphConnection addGraphModelConnection(Object element, GraphNode source, GraphNode target) {
GraphConnection connection = this.getGraphModelConnection(element);
if (connection == null) {
connection = new GraphConnection((Graph) getControl(), SWT.NONE, source, target);
this.connectionsMap.put(element, connection);
connection.setData(element);
}
return connection;
}
Aggregations