use of org.kie.workbench.common.stunner.core.client.shape.Shape in project kie-wb-common by kiegroup.
the class AbstractProjectDiagramEditor method getCurrentDiagramHash.
protected int getCurrentDiagramHash() {
if (null == getDiagram()) {
return 0;
}
int hash = getDiagram().hashCode();
if (null == getCanvasHandler() || null == getCanvasHandler().getCanvas() || null == getCanvasHandler().getCanvas().getShapes()) {
return hash;
}
Collection<Shape> collectionOfShapes = getCanvasHandler().getCanvas().getShapes();
ArrayList<Shape> shapes = new ArrayList<>();
shapes.addAll(collectionOfShapes);
shapes.sort((a, b) -> (a.getShapeView().getShapeX() == b.getShapeView().getShapeX()) ? (int) Math.round(a.getShapeView().getShapeY() - b.getShapeView().getShapeY()) : (int) Math.round(a.getShapeView().getShapeX() - b.getShapeView().getShapeX()));
for (Shape shape : shapes) {
hash = HashUtil.combineHashCodes(hash, Double.hashCode(shape.getShapeView().getShapeX()), Double.hashCode(shape.getShapeView().getShapeY()));
}
return hash;
}
use of org.kie.workbench.common.stunner.core.client.shape.Shape in project kie-wb-common by kiegroup.
the class NodeDragProxyImpl method show.
@Override
@SuppressWarnings("unchecked")
public DragProxy<AbstractCanvasHandler, Item, NodeDragProxyCallback> show(final Item item, final int x, final int y, final NodeDragProxyCallback callback) {
final AbstractCanvas canvas = canvasHandler.getAbstractCanvas();
final Node<View<?>, Edge> node = item.getNode();
final ShapeFactory<Object, ?> nodeShapeFactory = item.getNodeShapeFactory();
final Edge<View<?>, Node> inEdge = item.getInEdge();
final Node<View<?>, Edge> inEdgeSourceNode = item.getInEdgeSourceNode();
final ShapeFactory<Object, ?> edgeShapeFactory = item.getInEdgeShapeFactory();
final Shape nodeShape = nodeShapeFactory.newShape(node.getContent().getDefinition());
if (nodeShape instanceof ElementShape) {
((ElementShape) nodeShape).applyProperties(node, MutationContext.STATIC);
}
this.transientEdgeShape = (EdgeShape) edgeShapeFactory.newShape(inEdge.getContent().getDefinition());
canvas.addTransientShape(this.transientEdgeShape);
this.transientEdgeShape.applyProperties(inEdge, MutationContext.STATIC);
final Shape<?> edgeSourceNodeShape = canvasHandler.getCanvas().getShape(inEdgeSourceNode.getUUID());
shapeDragProxyFactory.show(nodeShape, x, y, new DragProxyCallback() {
@Override
public void onStart(final int x, final int y) {
callback.onStart(x, y);
drawEdge();
}
@Override
public void onMove(final int x, final int y) {
callback.onMove(x, y);
drawEdge();
}
@Override
public void onComplete(final int x, final int y) {
final MagnetConnection[] connections = createShapeConnections();
callback.onComplete(x, y);
callback.onComplete(x, y, connections[0], connections[1]);
deleteTransientEdgeShape();
canvas.draw();
}
private void drawEdge() {
if (inEdge.getContent() instanceof ViewConnector) {
final ViewConnector viewConnector = (ViewConnector) inEdge.getContent();
final MagnetConnection[] connections = createShapeConnections();
viewConnector.setSourceConnection(connections[0]);
viewConnector.setTargetConnection(connections[1]);
}
NodeDragProxyImpl.this.transientEdgeShape.applyConnections(inEdge, edgeSourceNodeShape.getShapeView(), nodeShape.getShapeView(), MutationContext.STATIC);
canvas.draw();
}
private MagnetConnection[] createShapeConnections() {
return new MagnetConnection[] { MagnetConnection.Builder.forElement(inEdgeSourceNode), MagnetConnection.Builder.forElement(node) };
}
});
return this;
}
use of org.kie.workbench.common.stunner.core.client.shape.Shape in project kie-wb-common by kiegroup.
the class CanvasDiagramValidator method applyViolation.
private boolean applyViolation(final H canvasHandler, final RuleViolation violation) {
if (hasViolations(violation)) {
final Canvas canvas = canvasHandler.getCanvas();
final Shape shape = getShape(canvasHandler, violation.getUUID());
if (null != shape) {
shape.applyState(ShapeState.INVALID);
canvas.draw();
}
return true;
}
return false;
}
use of org.kie.workbench.common.stunner.core.client.shape.Shape in project kie-wb-common by kiegroup.
the class MapSelectionControlTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
ShapeViewExtStub shapeView = new ShapeViewExtStub(shapeEventHandler, hasControlPoints);
when(element.getUUID()).thenReturn(ELEMENT_UUID);
when(element.getContent()).thenReturn(new ViewImpl<>(definition, BoundsImpl.build(0, 0, 10, 10)));
when(canvasHandler.getDiagram()).thenReturn(diagram);
when(diagram.getMetadata()).thenReturn(metadata);
when(metadata.getCanvasRootUUID()).thenReturn(ROOT_UUID);
when(canvasHandler.getCanvas()).thenReturn(canvas);
when(canvas.getLayer()).thenReturn(layer);
when(canvas.getShape(eq(ELEMENT_UUID))).thenReturn(shape);
when(canvas.getShapes()).thenReturn(Collections.singletonList(shape));
when(shape.getUUID()).thenReturn(ELEMENT_UUID);
when(shape.getShapeView()).thenReturn(shapeView);
when(shapeEventHandler.supports(eq(ViewEventType.MOUSE_CLICK))).thenReturn(true);
this.tested = new MapSelectionControl(e -> elementSelectedEvent.fire((CanvasSelectionEvent) e), e -> clearSelectionEvent.fire((CanvasClearSelectionEvent) e));
this.tested.setReadonly(false);
}
use of org.kie.workbench.common.stunner.core.client.shape.Shape in project kie-wb-common by kiegroup.
the class ToolboxControlTest method testShapeRemovedEvent.
@Test
public void testShapeRemovedEvent() {
final String uuid = "uuid1";
when(delegated.isActive(eq(uuid))).thenReturn(true);
final Shape shape = mock(Shape.class);
when(shape.getUUID()).thenReturn(uuid);
final CanvasShapeRemovedEvent event = new CanvasShapeRemovedEvent(canvas, shape);
tested.onCanvasShapeRemovedEvent(event);
verify(delegated, times(1)).destroy();
verify(delegated, never()).show(any(Element.class));
verify(delegated, never()).show(anyString());
}
Aggregations