Search in sources :

Example 1 with DecisionServiceSVGShapeView

use of org.kie.workbench.common.dmn.client.shape.view.decisionservice.DecisionServiceSVGShapeView in project kie-wb-common by kiegroup.

the class DecisionServiceMoveDividerControlTest method testRegisterDecisionServiceElementDragEnd.

@Test
@SuppressWarnings("unchecked")
public void testRegisterDecisionServiceElementDragEnd() {
    final DefinitionManager definitionManager = mock(DefinitionManager.class);
    final AdapterManager adapterManager = mock(AdapterManager.class);
    final AdapterRegistry adapterRegistry = mock(AdapterRegistry.class);
    final PropertyAdapter<Object, Object> propertyAdapter = mock(PropertyAdapter.class);
    final DefinitionAdapter<Object> definitionAdapter = mock(DefinitionAdapter.class);
    final DecisionServiceDividerLineY dividerLineY = new DecisionServiceDividerLineY();
    final Optional dividerYProperty = Optional.of(dividerLineY);
    final UpdateElementPropertyCommand updateElementPropertyCommand = mock(UpdateElementPropertyCommand.class);
    final DecisionService decisionService = mock(DecisionService.class);
    final DecisionServiceSVGShapeView decisionServiceShapeView = mock(DecisionServiceSVGShapeView.class);
    final DragEvent dragEvent = mock(DragEvent.class);
    when(canvasHandler.getDefinitionManager()).thenReturn(definitionManager);
    when(definitionManager.adapters()).thenReturn(adapterManager);
    when(adapterManager.registry()).thenReturn(adapterRegistry);
    when(adapterManager.forProperty()).thenReturn(propertyAdapter);
    when(adapterRegistry.getDefinitionAdapter(Mockito.<Class>any())).thenReturn(definitionAdapter);
    when(definitionAdapter.getProperty(decisionService, DIVIDER_Y_PROPERTY_ID)).thenReturn(dividerYProperty);
    when(propertyAdapter.getId(dividerLineY)).thenReturn(DIVIDER_Y_PROPERTY_ID);
    when(canvasCommandFactory.updatePropertyValue(eq(element), eq(DIVIDER_Y_PROPERTY_ID), Mockito.<Object>any())).thenReturn(updateElementPropertyCommand);
    when(definition.getDefinition()).thenReturn(decisionService);
    when(shape.getShapeView()).thenReturn(decisionServiceShapeView);
    control.register(element);
    verify(decisionServiceShapeView).addDividerDragHandler(dragHandlerCaptor.capture());
    when(decisionServiceShapeView.getDividerLineY()).thenReturn(DIVIDER_Y);
    final DragHandler dragHandler = dragHandlerCaptor.getValue();
    dragHandler.end(dragEvent);
    verify(canvasCommandFactory).updatePropertyValue(eq(element), eq(DIVIDER_Y_PROPERTY_ID), eq(DIVIDER_Y));
    verify(commandManager).execute(eq(canvasHandler), eq(updateElementPropertyCommand));
}
Also used : Optional(java.util.Optional) DragHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.DragHandler) AdapterRegistry(org.kie.workbench.common.stunner.core.registry.definition.AdapterRegistry) UpdateElementPropertyCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) DragEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.DragEvent) DecisionServiceDividerLineY(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) AdapterManager(org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager) DecisionServiceSVGShapeView(org.kie.workbench.common.dmn.client.shape.view.decisionservice.DecisionServiceSVGShapeView) Test(org.junit.Test)

Example 2 with DecisionServiceSVGShapeView

use of org.kie.workbench.common.dmn.client.shape.view.decisionservice.DecisionServiceSVGShapeView in project kie-wb-common by kiegroup.

the class DecisionServiceMoveDividerControl method register.

@Override
@SuppressWarnings("unchecked")
public void register(final Element element) {
    if (checkNotRegistered(element)) {
        final Object definition = ((Definition) element.getContent()).getDefinition();
        if (!isDecisionServiceDefinition(definition)) {
            return;
        }
        final Canvas<?> canvas = canvasHandler.getCanvas();
        final Shape<?> shape = canvas.getShape(element.getUUID());
        final ShapeView<?> shapeView = shape.getShapeView();
        if (!isDecisionServiceShapeView(shapeView)) {
            return;
        }
        final DecisionServiceSVGShapeView decisionServiceShapeView = (DecisionServiceSVGShapeView) shapeView;
        final DragHandler dragHandler = new DragHandler() {

            @Override
            public void end(final DragEvent event) {
                final CommandResult<CanvasViolation> result = doMoveDivider(element, decisionServiceShapeView.getDividerLineY());
                if (CommandUtils.isError(result)) {
                    LOGGER.log(Level.WARNING, "Command failed at resize end [result=" + result + "]");
                }
            }
        };
        decisionServiceShapeView.addDividerDragHandler(dragHandler);
        registerHandler(element.getUUID(), dragHandler);
    }
}
Also used : DragEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.DragEvent) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DragHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.DragHandler) DecisionServiceSVGShapeView(org.kie.workbench.common.dmn.client.shape.view.decisionservice.DecisionServiceSVGShapeView)

Example 3 with DecisionServiceSVGShapeView

use of org.kie.workbench.common.dmn.client.shape.view.decisionservice.DecisionServiceSVGShapeView in project kie-wb-common by kiegroup.

the class DMNDecisionServiceSVGMutableShapeImpl method applyCustomProperties.

@Override
protected void applyCustomProperties(final Node<View<DecisionService>, Edge> element, final MutationContext mutationContext) {
    final DecisionService instance = getDefinition(element);
    final DecisionServiceSVGShapeView decisionServiceSVGShapeView = (DecisionServiceSVGShapeView) getShapeView();
    decisionServiceSVGShapeView.setDividerLineY(instance.getDividerLineY().getValue());
}
Also used : DecisionServiceSVGShapeView(org.kie.workbench.common.dmn.client.shape.view.decisionservice.DecisionServiceSVGShapeView) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService)

Example 4 with DecisionServiceSVGShapeView

use of org.kie.workbench.common.dmn.client.shape.view.decisionservice.DecisionServiceSVGShapeView in project kie-wb-common by kiegroup.

the class DecisionServiceMoveDividerControlTest method testRegisterDecisionServiceElement.

@Test
@SuppressWarnings("unchecked")
public void testRegisterDecisionServiceElement() {
    final DecisionService decisionService = mock(DecisionService.class);
    final DecisionServiceSVGShapeView decisionServiceShapeView = mock(DecisionServiceSVGShapeView.class);
    when(definition.getDefinition()).thenReturn(decisionService);
    when(shape.getShapeView()).thenReturn(decisionServiceShapeView);
    control.register(element);
    verify(control).registerHandler(Mockito.<String>any(), Mockito.<ViewHandler>any());
}
Also used : DecisionServiceSVGShapeView(org.kie.workbench.common.dmn.client.shape.view.decisionservice.DecisionServiceSVGShapeView) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Test(org.junit.Test)

Aggregations

DecisionServiceSVGShapeView (org.kie.workbench.common.dmn.client.shape.view.decisionservice.DecisionServiceSVGShapeView)4 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)3 Test (org.junit.Test)2 DragEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.DragEvent)2 DragHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.DragHandler)2 Optional (java.util.Optional)1 DecisionServiceDividerLineY (org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY)1 DefinitionManager (org.kie.workbench.common.stunner.core.api.DefinitionManager)1 UpdateElementPropertyCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand)1 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)1 AdapterManager (org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager)1 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)1 AdapterRegistry (org.kie.workbench.common.stunner.core.registry.definition.AdapterRegistry)1