Search in sources :

Example 1 with CanvasViolation

use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.

the class ProjectMessagesListenerTest method testFireNotificationInfo.

@Test
public void testFireNotificationInfo() {
    NotificationContext context = new NotificationContext.Builder().build("test", "test", "test");
    Command<?, CanvasViolation> source = mock(Command.class);
    CommandNotification commandNotification = CommandNotification.Builder.build(context, source, Notification.Type.INFO, "message");
    projectMessagesListener.fireNotification(commandNotification);
    ArgumentCaptor<PublishMessagesEvent> eventCaptor = ArgumentCaptor.forClass(PublishMessagesEvent.class);
    verify(publishMessagesEvent, times(1)).fire(eventCaptor.capture());
    final List<SystemMessage> messagesToPublish = eventCaptor.getValue().getMessagesToPublish();
    assertEquals(messagesToPublish.size(), 1);
    SystemMessage message = messagesToPublish.get(0);
    assertEquals(message.getText(), "message");
    assertEquals(message.getLevel(), Level.INFO);
}
Also used : NotificationContext(org.kie.workbench.common.stunner.client.widgets.notification.NotificationContext) SystemMessage(org.guvnor.messageconsole.events.SystemMessage) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) PublishMessagesEvent(org.guvnor.messageconsole.events.PublishMessagesEvent) CommandNotification(org.kie.workbench.common.stunner.client.widgets.notification.CommandNotification) Test(org.junit.Test)

Example 2 with CanvasViolation

use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.

the class ProjectMessagesListenerTest method testFireNotificationWarning.

@Test
public void testFireNotificationWarning() {
    NotificationContext context = new NotificationContext.Builder().build("test", "test", "test");
    Command<?, CanvasViolation> source = mock(Command.class);
    CommandNotification commandNotification = CommandNotification.Builder.build(context, source, Notification.Type.WARNING, "message");
    projectMessagesListener.fireNotification(commandNotification);
    ArgumentCaptor<PublishMessagesEvent> eventCaptor = ArgumentCaptor.forClass(PublishMessagesEvent.class);
    verify(publishMessagesEvent, times(1)).fire(eventCaptor.capture());
    final List<SystemMessage> messagesToPublish = eventCaptor.getValue().getMessagesToPublish();
    assertEquals(messagesToPublish.size(), 1);
    SystemMessage message = messagesToPublish.get(0);
    assertEquals(message.getText(), "message");
    assertEquals(message.getLevel(), Level.WARNING);
}
Also used : NotificationContext(org.kie.workbench.common.stunner.client.widgets.notification.NotificationContext) SystemMessage(org.guvnor.messageconsole.events.SystemMessage) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) PublishMessagesEvent(org.guvnor.messageconsole.events.PublishMessagesEvent) CommandNotification(org.kie.workbench.common.stunner.client.widgets.notification.CommandNotification) Test(org.junit.Test)

Example 3 with CanvasViolation

use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.

the class AddCanvasNodeCommandTest method testExecuteAndSetViewBounds.

@Test
@SuppressWarnings("unchecked")
public void testExecuteAndSetViewBounds() {
    when(content.getBounds()).thenReturn(BoundsImpl.build(0d, 0d, 0d, 0d));
    final CommandResult<CanvasViolation> result = tested.execute(canvasHandler);
    assertNotEquals(CommandResult.Type.ERROR, result.getType());
    verify(canvasHandler, times(1)).register(eq(SHAPE_SET_ID), eq(candidate));
    verify(canvasHandler, times(1)).applyElementMutation(eq(candidate), any(MutationContext.class));
    final ArgumentCaptor<Bounds> boundsArgumentCaptor = ArgumentCaptor.forClass(Bounds.class);
    verify(content, times(1)).setBounds(boundsArgumentCaptor.capture());
    final BoundsImpl bounds = (BoundsImpl) boundsArgumentCaptor.getValue();
    assertEquals(0d, bounds.getX(), 0d);
    assertEquals(0d, bounds.getY(), 0d);
    assertEquals(50d, bounds.getWidth(), 0d);
    assertEquals(50d, bounds.getHeight(), 0d);
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) MutationContext(org.kie.workbench.common.stunner.core.client.shape.MutationContext) Test(org.junit.Test)

Example 4 with CanvasViolation

use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.

the class SetCanvasConnectionCommandTest method testExecuteAndUpdateMagnetLocations.

@Test
@SuppressWarnings("unchecked")
public void testExecuteAndUpdateMagnetLocations() {
    final MagnetConnection sourceConnection = new MagnetConnection.Builder().magnet(0).build();
    final MagnetConnection targetConnection = new MagnetConnection.Builder().magnet(0).build();
    when(edgeContent.getSourceConnection()).thenReturn(Optional.of(sourceConnection));
    when(edgeContent.getTargetConnection()).thenReturn(Optional.of(targetConnection));
    final CommandResult<CanvasViolation> result = tested.execute(canvasHandler);
    assertNotEquals(CommandResult.Type.ERROR, result.getType());
    verify(edgeShape, times(1)).applyConnections(eq(edge), eq(sourceShapeView), eq(targetShapeView), any(MutationContext.class));
    verify(canvasHandler, times(1)).notifyCanvasElementUpdated(eq(source));
    verify(canvasHandler, times(1)).notifyCanvasElementUpdated(eq(target));
    assertEquals(5d, sourceConnection.getLocation().getX(), 0d);
    assertEquals(5d, sourceConnection.getLocation().getY(), 0d);
    assertEquals(10d, targetConnection.getLocation().getX(), 0d);
    assertEquals(10d, targetConnection.getLocation().getY(), 0d);
}
Also used : MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) MutationContext(org.kie.workbench.common.stunner.core.client.shape.MutationContext) Test(org.junit.Test)

Example 5 with CanvasViolation

use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.

the class ResizeControlImpl method registerResizeHandlers.

@SuppressWarnings("unchecked")
private void registerResizeHandlers(final Element element, final Shape<?> shape) {
    if (shape.getShapeView() instanceof HasEventHandlers) {
        final HasEventHandlers hasEventHandlers = (HasEventHandlers) shape.getShapeView();
        final ResizeHandler resizeHandler = new ResizeHandler() {

            @Override
            public void start(final ResizeEvent event) {
            }

            @Override
            public void handle(final ResizeEvent event) {
            }

            @Override
            public void end(final ResizeEvent event) {
                LOGGER.log(Level.FINE, "Shape [" + element.getUUID() + "] resized to size {" + event.getWidth() + ", " + event.getHeight() + "] " + "& Coordinates [" + event.getX() + ", " + event.getY() + "]");
                final Shape shape = canvasHandler.getCanvas().getShape(element.getUUID());
                final double x = shape.getShapeView().getShapeX();
                final double y = shape.getShapeView().getShapeY();
                final CommandResult<CanvasViolation> result = doResize(element, x + event.getX(), y + event.getY(), event.getWidth(), event.getHeight());
                if (CommandUtils.isError(result)) {
                    LOGGER.log(Level.WARNING, "Command failed at resize end [result=" + result + "]");
                }
            }
        };
        hasEventHandlers.addHandler(ViewEventType.RESIZE, resizeHandler);
        registerHandler(element.getUUID(), resizeHandler);
    }
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) ResizeHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeHandler) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) ResizeEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeEvent)

Aggregations

CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)48 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)35 Test (org.junit.Test)32 DMNGridRow (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow)14 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)11 Node (org.kie.workbench.common.stunner.core.graph.Node)11 Edge (org.kie.workbench.common.stunner.core.graph.Edge)9 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)8 List (org.kie.workbench.common.dmn.api.definition.v1_1.List)7 Command (org.kie.workbench.common.stunner.core.command.Command)7 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)7 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)6 DecisionRule (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)5 View (org.kie.workbench.common.stunner.core.graph.content.view.View)5 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)4 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)4 Element (org.kie.workbench.common.stunner.core.graph.Element)4 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)4 Collection (java.util.Collection)3 Optional (java.util.Optional)3