use of org.kie.workbench.common.stunner.core.client.shape.view.ShapeView in project kie-wb-common by kiegroup.
the class ShapeUtils method updateEdgeConnection.
@SuppressWarnings("unchecked")
public static void updateEdgeConnection(final AbstractCanvasHandler context, final Connection connection, final Node<? extends View<?>, Edge> node) {
if (null != node && null == connection.getLocation() && connection instanceof MagnetConnection) {
final MagnetConnection magnetConnection = (MagnetConnection) connection;
final OptionalInt magnetIndex = magnetConnection.getMagnetIndex();
if (magnetIndex.orElse(-1) == MagnetConnection.MAGNET_CENTER) {
final Shape<ShapeView<?>> nodeShape = context.getCanvas().getShape(node.getUUID());
final BoundingBox boundingBox = nodeShape.getShapeView().getBoundingBox();
magnetConnection.setLocation(new Point2D(boundingBox.getWidth() / 2, boundingBox.getHeight() / 2));
}
}
}
use of org.kie.workbench.common.stunner.core.client.shape.view.ShapeView 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.view.ShapeView in project kie-wb-common by kiegroup.
the class ShapeUtilsTest method testApplyConnections.
@Test
@SuppressWarnings("unchecked")
public void testApplyConnections() {
final Shape startNodeShape = mock(Shape.class);
final ShapeView startNodeShapeView = mock(ShapeView.class);
final Shape intermNodeShape = mock(Shape.class);
final ShapeView intermNodeShapeView = mock(ShapeView.class);
final EdgeShape edge1EdgeShape = mock(EdgeShape.class);
when(canvas.getShape(eq(instance2.startNode.getUUID()))).thenReturn(startNodeShape);
when(canvas.getShape(eq(instance2.intermNode.getUUID()))).thenReturn(intermNodeShape);
when(canvas.getShape(eq(instance2.edge1.getUUID()))).thenReturn(edge1EdgeShape);
when(startNodeShape.getShapeView()).thenReturn(startNodeShapeView);
when(intermNodeShape.getShapeView()).thenReturn(intermNodeShapeView);
when(edge1EdgeShape.getShapeView()).thenReturn(edge1ShapeView);
ShapeUtils.applyConnections(instance2.edge1, canvasHandler, MutationContext.STATIC);
verify(edge1EdgeShape, times(1)).applyConnections(eq(instance2.edge1), eq(startNodeShapeView), eq(intermNodeShapeView), eq(MutationContext.STATIC));
}
use of org.kie.workbench.common.stunner.core.client.shape.view.ShapeView in project kie-wb-common by kiegroup.
the class LienzoSelectionControl method onRegister.
@Override
protected void onRegister(final Element element) {
super.onRegister(element);
final Shape<?> shape = getSelectionControl().getCanvas().getShape(element.getUUID());
if (null != shape) {
final ShapeView shapeView = shape.getShapeView();
if (shapeView instanceof HasEventHandlers) {
final HasEventHandlers hasEventHandlers = (HasEventHandlers) shapeView;
if (hasEventHandlers.supports(ViewEventType.MOUSE_CLICK)) {
final MouseClickHandler clickHandler = new MouseClickHandler() {
@Override
public void handle(final MouseClickEvent event) {
if (event.isButtonLeft() || event.isButtonRight()) {
singleSelect(element);
}
}
};
hasEventHandlers.addHandler(ViewEventType.MOUSE_CLICK, clickHandler);
registerHandler(shape.getUUID(), clickHandler);
}
}
}
}
use of org.kie.workbench.common.stunner.core.client.shape.view.ShapeView in project kie-wb-common by kiegroup.
the class AbstractRegistrationCanvasNodeCommand method register.
@SuppressWarnings("unchecked")
protected void register(final AbstractCanvasHandler context) {
context.register(shapeSetId, candidate);
// Update view bounds for the element, if not set, by using the values from the shape view.
final double[] size = GraphUtils.getNodeSize(candidate.getContent());
if (size[0] <= 0 || size[1] <= 0) {
final Shape shape = context.getCanvas().getShape(candidate.getUUID());
final ShapeView shapeView = shape.getShapeView();
final Point2D location = GraphUtils.getPosition(candidate.getContent());
final BoundingBox boundingBox = shapeView.getBoundingBox();
candidate.getContent().setBounds(new BoundsImpl(new BoundImpl(location.getX(), location.getY()), new BoundImpl(location.getX() + boundingBox.getWidth(), location.getY() + boundingBox.getHeight())));
}
}
Aggregations