use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.
the class SetParentNodeCommand method execute.
@Override
@SuppressWarnings("unchecked")
public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
final CommandResult<RuleViolation> results = allow(context);
if (!results.getType().equals(CommandResult.Type.ERROR)) {
final Node<?, Edge> parent = getParent(context);
final Node<?, Edge> candidate = getCandidate(context);
// TODO: Create a ParentEdgeFactory iface extending EdgeFactory using as content generics type Relationship
final String uuid = UUID.uuid();
final Edge<Parent, Node> edge = new EdgeImpl<>(uuid);
edge.setContent(new Parent());
edge.setSourceNode(parent);
edge.setTargetNode(candidate);
parent.getOutEdges().add(edge);
candidate.getInEdges().add(edge);
getMutableIndex(context).addEdge(edge);
}
return results;
}
use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.
the class GraphImpl method hashCode.
@Override
public int hashCode() {
// dirty trick to allow inner class to modify variable
int[] hashArr = { 0 };
final TreeWalkTraverseProcessor treeWalkTraverseProcessor = new TreeWalkTraverseProcessorImpl();
treeWalkTraverseProcessor.traverse(this, new AbstractTreeTraverseCallback<Graph, Node, Edge>() {
int[] myHashArr = hashArr;
@Override
public boolean startEdgeTraversal(final Edge edge) {
super.startEdgeTraversal(edge);
final Object content = edge.getContent();
myHashArr[0] = HashUtil.combineHashCodes(myHashArr[0], content.hashCode());
return true;
}
@Override
public boolean startNodeTraversal(final Node node) {
super.startNodeTraversal(node);
myHashArr[0] = HashUtil.combineHashCodes(myHashArr[0], node.hashCode());
if (!(node.getContent() instanceof DefinitionSet) && node.getContent() instanceof Definition) {
Object def = ((Definition) (node.getContent())).getDefinition();
myHashArr[0] = HashUtil.combineHashCodes(myHashArr[0], def.hashCode());
}
return true;
}
});
// Get the hash from the graph traversal
return hashArr[0];
}
use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.
the class GraphBoundsIndexerImpl method getAt.
@Override
public Node<View<?>, Edge> getAt(final double x, final double y, final double width, final double height, final Element parentNode) {
Point2D parentNodePosition;
double xToCheck = 0;
double yToCheck = 0;
if (parentNode != null) {
parentNodePosition = GraphUtils.getPosition((View) parentNode.asNode().getContent());
xToCheck = x + parentNodePosition.getX();
yToCheck = y + parentNodePosition.getY();
}
Node<View<?>, Edge> element;
Point2D[] pointsToCheck = new Point2D[5];
pointsToCheck[0] = new Point2D(xToCheck, yToCheck);
pointsToCheck[1] = new Point2D(xToCheck + width, yToCheck);
pointsToCheck[2] = new Point2D(xToCheck + (width / 2), yToCheck + (height / 2));
pointsToCheck[3] = new Point2D(xToCheck, yToCheck + height);
pointsToCheck[4] = new Point2D(xToCheck + width, yToCheck + height);
for (Point2D point : pointsToCheck) {
element = findElementAt(point.getX(), point.getY());
if (element != null) {
if (element != parentNode) {
return element;
}
}
}
return null;
}
use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.
the class MapIndexBuilder method doWork.
private MapIndex doWork(final Graph<?, Node> graph, final MapIndex current) {
final Map<String, Node> nodes = new HashMap<>();
final Map<String, Edge> edges = new HashMap<>();
Iterable<Node> nodesIter = graph.nodes();
for (Node node : nodesIter) {
processNode(nodes, edges, node);
}
if (null == current) {
// Requesting a new index.
return new MapIndex(graph, nodes, edges);
} else {
// Updating an existing index.
current.nodes.clear();
current.nodes.putAll(nodes);
current.edges.clear();
current.edges.putAll(edges);
return current;
}
}
use of org.kie.workbench.common.stunner.core.graph.Edge in project kie-wb-common by kiegroup.
the class MapIndexBuilder method processNode.
@SuppressWarnings("unchecked")
private void processNode(final Map<String, Node> nodes, final Map<String, Edge> edges, final Node node) {
if (!nodes.containsKey(node.getUUID())) {
nodes.put(node.getUUID(), node);
final List<Edge> outEdges = node.getOutEdges();
if (null != outEdges && !outEdges.isEmpty()) {
for (final Edge edge : outEdges) {
processEdge(nodes, edges, edge);
}
}
}
}
Aggregations