use of org.kie.workbench.common.stunner.core.graph.Element in project kie-wb-common by kiegroup.
the class ClientFactoryServicesTest method testNewElementLocal.
@Test
@SuppressWarnings("unchecked")
public void testNewElementLocal() {
String id = "id1";
String defSetId = "defSet1";
ServiceCallback<Element> callback = mock(ServiceCallback.class);
Element def = mock(Element.class);
when(clientFactoryManager.newElement(eq(id), eq(defSetId))).thenReturn(def);
tested.newElement(id, defSetId, callback);
verify(callback, times(1)).onSuccess(eq(def));
verify(clientFactoryManager, times(1)).newElement(eq(id), eq(defSetId));
verify(clientFactoryManager, times(0)).newElement(anyString(), any(Class.class));
verify(factoryService, times(0)).newElement(anyString(), anyString());
verify(factoryService, times(0)).newElement(anyString(), any(Class.class));
}
use of org.kie.workbench.common.stunner.core.graph.Element in project kie-wb-common by kiegroup.
the class AddChildNodeCommand method allow.
@Override
@SuppressWarnings("unchecked")
public CommandResult<RuleViolation> allow(final GraphCommandExecutionContext context) {
ensureInitialized(context);
// Check if rules are present.
if (null == context.getRuleManager()) {
return GraphCommandResultBuilder.SUCCESS;
}
final Element<? extends Definition<?>> parent = (Element<? extends Definition<?>>) getParent(context);
final Collection<RuleViolation> containmentRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.containment(getGraph(context), parent, candidate));
final Collection<RuleViolation> cardinalityRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.cardinality(getGraph(context), Optional.of(candidate), Optional.of(CardinalityContext.Operation.ADD)));
final Collection<RuleViolation> violations = new LinkedList<RuleViolation>();
violations.addAll(containmentRuleViolations);
violations.addAll(cardinalityRuleViolations);
return new GraphCommandResultBuilder(violations).build();
}
use of org.kie.workbench.common.stunner.core.graph.Element in project kie-wb-common by kiegroup.
the class CanvasControlRegistrationHandler method initializeListeners.
private void initializeListeners() {
// Canvas listeners.
final C canvas = getCanvas();
this.shapeListener = new CanvasShapeListener() {
@Override
public void register(final Shape item) {
onRegisterShape(item);
}
@Override
public void deregister(final Shape item) {
onDeregisterShape(item);
}
@Override
public void clear() {
onClear();
}
};
canvas.addRegistrationListener(shapeListener);
// Canvas handler listeners.
this.elementListener = new CanvasElementListener() {
@Override
public void update(final Element item) {
onElementRegistration(item, false, true);
}
@Override
public void register(final Element item) {
onRegisterElement(item);
}
@Override
public void deregister(final Element item) {
onDeregisterElement(item);
}
@Override
public void clear() {
onClear();
}
};
getCanvasHandler().addRegistrationListener(elementListener);
}
use of org.kie.workbench.common.stunner.core.graph.Element in project kie-wb-common by kiegroup.
the class CanvasLayoutUtils method getNext.
public Point2D getNext(final CanvasHandler canvasHandler, final Node<View<?>, Edge> root, final double rootNodeWidth, final double rootNodeHeight, final double newNodeWidth, final double newNodeHeight, Point2D offset, Point2D rootNodeCoordinates) {
checkNotNull("canvasHandler", canvasHandler);
checkNotNull("root", root);
final int canvasHeight = canvasHandler.getCanvas().getHeight();
final int canvasWidth = canvasHandler.getCanvas().getWidth();
Point2D newPositionUL = getNextPositionWithOffset(rootNodeCoordinates, offset);
graphBoundsIndexer.build(canvasHandler.getDiagram().getGraph());
Element parentNode = GraphUtils.getParent(root.asNode());
boolean checkParent = false;
if (parentNode != null) {
if (!(isCanvasRoot(canvasHandler.getDiagram(), parentNode.getUUID()))) {
checkParent = true;
}
}
Node targetNodeContainer = graphBoundsIndexer.getAt(newPositionUL.getX(), newPositionUL.getY(), newNodeWidth, newNodeHeight, parentNode);
boolean canContain = false;
if (targetNodeContainer != null) {
canContain = canContain(canvasHandler, targetNodeContainer, root);
}
if ((!canContain) || isOutOfCanvas(newPositionUL, newNodeHeight, canvasHeight) || checkParent) {
if (checkParent) {
newPositionUL = getNextPositionFromParent(rootNodeCoordinates, offset, parentNode, rootNodeHeight, rootNodeWidth, newNodeWidth);
}
while (((!isCanvasPositionAvailable(graphBoundsIndexer, newPositionUL, newNodeWidth, newNodeHeight, parentNode)) && !canContain) && (newPositionUL.getY() < canvasHeight) && (newPositionUL.getX() < canvasWidth) || isOutOfCanvas(newPositionUL, newNodeHeight, canvasHeight)) {
parentNode = GraphUtils.getParent(root.asNode());
checkParent = false;
if (parentNode != null) {
if (!(isCanvasRoot(canvasHandler.getDiagram(), parentNode.getUUID()))) {
checkParent = true;
}
}
double[] nodeAtPositionSize;
nodeAtPositionSize = getNodeSizeAt(graphBoundsIndexer, newPositionUL, newNodeWidth, newNodeHeight, parentNode);
if (checkParent) {
final Node targetNodeNewPos = graphBoundsIndexer.getAt(newPositionUL.getX(), newPositionUL.getY(), newNodeWidth, newNodeHeight, parentNode);
if (parentNode != targetNodeNewPos) {
offset.setY(offset.getY() + PADDING_Y);
}
} else {
if (nodeAtPositionSize == null) {
nodeAtPositionSize = new double[] { 0.0d };
offset.setY(offset.getY() + PADDING_Y);
} else {
offset.setY(offset.getY() + nodeAtPositionSize[1] + PADDING_Y);
}
}
newPositionUL = getNextPositionWithOffset(rootNodeCoordinates, offset);
if (isOutOfCanvas(newPositionUL, newNodeHeight, canvasHeight)) {
rootNodeCoordinates.setY(0);
offset.setY(PADDING_Y);
offset.setX(offset.getX() + nodeAtPositionSize[0] + PADDING_X);
newPositionUL = getNextPositionWithOffset(rootNodeCoordinates, offset);
}
if (checkParent) {
newPositionUL = getNextPositionFromParent(rootNodeCoordinates, offset, parentNode, rootNodeHeight, rootNodeWidth, newNodeWidth);
}
targetNodeContainer = graphBoundsIndexer.getAt(newPositionUL.getX(), newPositionUL.getY(), newNodeWidth, newNodeHeight, parentNode);
canContain = targetNodeContainer == null || canContain(canvasHandler, targetNodeContainer, root);
}
} else {
if (checkParent) {
newPositionUL = getNextPositionFromParent(rootNodeCoordinates, offset, parentNode, rootNodeHeight, rootNodeWidth, newNodeWidth);
} else {
newPositionUL = getNextPositionWithOffset(rootNodeCoordinates, offset);
}
}
return newPositionUL;
}
use of org.kie.workbench.common.stunner.core.graph.Element in project kie-wb-common by kiegroup.
the class CreateNodeAction method onMouseClick.
@Override
@SuppressWarnings("unchecked")
public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) {
// Obtain the connector and source node instances for proxying.
final Element<View<?>> element = (Element<View<?>>) getElement(canvasHandler, uuid);
final Node<View<?>, Edge> sourceNode = element.asNode();
final Edge<? extends ViewConnector<?>, Node> connector = (Edge<? extends ViewConnector<?>, Node>) clientFactoryManager.newElement(UUID.uuid(), edgeId).asEdge();
final Node<View<?>, Edge> targetNode = (Node<View<?>, Edge>) clientFactoryManager.newElement(UUID.uuid(), nodeId).asNode();
final DeferredCompositeCommand.Builder builder = new DeferredCompositeCommand.Builder().deferCommand(() -> addNode(canvasHandler, sourceNode, targetNode)).deferCommand(() -> updateNodeLocation(canvasHandler, sourceNode, targetNode)).deferCommand(() -> addEdge(canvasHandler, sourceNode, connector)).deferCommand(() -> setEdgeTarget(canvasHandler, connector, targetNode));
final CommandResult result = sessionCommandManager.execute(canvasHandler, builder.build());
if (!CommandUtils.isError(result)) {
fireElementSelectedEvent(selectionEvent, canvasHandler, targetNode.getUUID());
}
return this;
}
Aggregations