Search in sources :

Example 11 with Command

use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.

the class ItemImplTest method testFocusExecutorDoingUnFocus.

@Test
public void testFocusExecutorDoingUnFocus() {
    final AbstractDecoratorItem decorator = mock(AbstractDecoratorItem.class);
    final Group decPrimitive = mock(Group.class);
    when(decorator.asPrimitive()).thenReturn(decPrimitive);
    final TooltipItem<?> tooltip = mock(TooltipItem.class);
    tested = new ItemImpl(groupItem, shape).setFocusDelay(0).setUnFocusDelay(0).decorate(decorator).tooltip(tooltip);
    final AbstractFocusableGroupItem<ItemImpl>.FocusGroupExecutor focusExecutor = spy(tested.getFocusGroupExecutor());
    doAnswer(invocationOnMock -> {
        ((Command) invocationOnMock.getArguments()[1]).execute();
        return null;
    }).when(focusExecutor).accept(any(Group.class), any(Command.class));
    focusExecutor.unFocus();
    verify(focusExecutor, times(1)).setAlpha(AbstractFocusableGroupItem.ALPHA_UNFOCUSED);
    verify(decorator, times(3)).hide();
    verify(tooltip, times(2)).hide();
}
Also used : Group(com.ait.lienzo.client.core.shape.Group) Command(org.uberfire.mvp.Command) AbstractDecoratorItem(org.kie.workbench.common.stunner.lienzo.toolbox.items.AbstractDecoratorItem) Test(org.junit.Test)

Example 12 with Command

use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.

the class ToolboxImplTest method testShow.

@Test
public void testShow() {
    final Command before = mock(Command.class);
    final Command after = mock(Command.class);
    tested.show(before, after);
    verify(wrapped, times(1)).show(any(Command.class), any(Command.class));
    verify(wrapped, never()).hide(any(Command.class), any(Command.class));
    verify(before, times(1)).execute();
    verify(after, times(1)).execute();
    ArgumentCaptor<Point2D> pc = ArgumentCaptor.forClass(Point2D.class);
    verify(group, times(1)).setLocation(pc.capture());
    Point2D point = pc.getValue();
    assertEquals(33d, point.getX(), 0);
    assertEquals(0d, point.getY(), 0);
}
Also used : Command(org.uberfire.mvp.Command) Point2D(com.ait.lienzo.client.core.types.Point2D) Test(org.junit.Test)

Example 13 with Command

use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.

the class WiresShapeToolboxTest method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() {
    when(toolbox.getBoundingBox()).thenReturn(() -> boundingBox);
    when(toolbox.asPrimitive()).thenReturn(group);
    when(toolbox.setGridSize(anyDouble(), anyDouble())).thenReturn(toolbox);
    when(toolbox.refresh()).thenReturn(toolbox);
    when(group.getComputedLocation()).thenReturn(new Point2D(5d, 10d));
    when(group.getComputedBoundingPoints()).thenReturn(boundingPoints);
    when(group.getBoundingBox()).thenReturn(boundingBox);
    when(boundingPoints.getBoundingBox()).thenReturn(boundingBox);
    when(shape.getGroup()).thenReturn(group);
    when(shape.addWiresMoveHandler(any(WiresMoveHandler.class))).thenReturn(moveRegistration);
    when(shape.addWiresDragStartHandler(any(WiresDragStartHandler.class))).thenReturn(dragStartRegistration);
    when(shape.addWiresDragMoveHandler(any(WiresDragMoveHandler.class))).thenReturn(dragMoveRegistration);
    when(shape.addWiresDragEndHandler(any(WiresDragEndHandler.class))).thenReturn(dragEndRegistration);
    when(shape.addWiresResizeStartHandler(any(WiresResizeStartHandler.class))).thenReturn(resizeStartRegistration);
    when(shape.addWiresResizeStepHandler(any(WiresResizeStepHandler.class))).thenReturn(resizeStepRegistration);
    when(shape.addWiresResizeEndHandler(any(WiresResizeEndHandler.class))).thenReturn(resizeEndRegistration);
    doAnswer(invocationOnMock -> {
        ((Command) invocationOnMock.getArguments()[0]).execute();
        ((Command) invocationOnMock.getArguments()[1]).execute();
        return toolbox;
    }).when(toolbox).show(any(Command.class), any(Command.class));
    doAnswer(invocationOnMock -> {
        ((Command) invocationOnMock.getArguments()[0]).execute();
        ((Command) invocationOnMock.getArguments()[1]).execute();
        return toolbox;
    }).when(toolbox).hide(any(Command.class), any(Command.class));
    tested = new WiresShapeToolbox(shape, toolbox, registrations).useHideExecutor(hideExecutor).useShowExecutor(showExecutor);
}
Also used : WiresMoveHandler(com.ait.lienzo.client.core.shape.wires.event.WiresMoveHandler) WiresDragEndHandler(com.ait.lienzo.client.core.shape.wires.event.WiresDragEndHandler) WiresDragMoveHandler(com.ait.lienzo.client.core.shape.wires.event.WiresDragMoveHandler) WiresResizeEndHandler(com.ait.lienzo.client.core.shape.wires.event.WiresResizeEndHandler) Point2D(com.ait.lienzo.client.core.types.Point2D) Command(org.uberfire.mvp.Command) WiresResizeStepHandler(com.ait.lienzo.client.core.shape.wires.event.WiresResizeStepHandler) WiresResizeStartHandler(com.ait.lienzo.client.core.shape.wires.event.WiresResizeStartHandler) WiresDragStartHandler(com.ait.lienzo.client.core.shape.wires.event.WiresDragStartHandler) Before(org.junit.Before)

Example 14 with Command

use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.

the class AbstractProjectDiagramEditor method save.

/**
 * This method is called just once clicking on save.
 * Before starting the save process, let's perform a diagram validation
 * to check all it's valid.
 * It's allowed to continue with the save process event if warnings found,
 * but cannot save if any error is present in order to
 * guarantee the diagram's consistency.
 */
@Override
protected void save() {
    final Command continueSaveOnceValid = () -> super.save();
    getCommand(ValidateSessionCommand.class).execute(new ClientSessionCommand.Callback<Collection<DiagramElementViolation<RuleViolation>>>() {

        @Override
        public void onSuccess() {
            continueSaveOnceValid.execute();
        }

        @Override
        public void onError(final Collection<DiagramElementViolation<RuleViolation>> violations) {
            final Violation.Type maxSeverity = ValidationUtils.getMaxSeverity(violations);
            if (maxSeverity.equals(Violation.Type.ERROR)) {
                onValidationFailed(violations);
            } else {
                // Allow saving when only warnings founds.
                continueSaveOnceValid.execute();
            }
        }
    });
}
Also used : ValidateSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ValidateSessionCommand) ClientResourceType(org.uberfire.client.workbench.type.ClientResourceType) CopySelectionSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.CopySelectionSessionCommand) ClearStatesSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ClearStatesSessionCommand) ExportToPdfSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ExportToPdfSessionCommand) ClearSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ClearSessionCommand) DeleteSelectionSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.DeleteSelectionSessionCommand) PasteSelectionSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.PasteSelectionSessionCommand) RedoSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.RedoSessionCommand) CutSelectionSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.CutSelectionSessionCommand) UndoSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.UndoSessionCommand) ExportToPngSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ExportToPngSessionCommand) ExportToBpmnSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ExportToBpmnSessionCommand) ValidateSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ValidateSessionCommand) VisitGraphSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.VisitGraphSessionCommand) ClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand) Command(org.uberfire.mvp.Command) ExportToJpgSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.ExportToJpgSessionCommand) SwitchGridSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.impl.SwitchGridSessionCommand) Collection(java.util.Collection) DiagramElementViolation(org.kie.workbench.common.stunner.core.validation.DiagramElementViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ClientSessionCommand(org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand)

Example 15 with Command

use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.

the class AbstractPaletteDefinitionBuilder method build.

private void build(final Metadata metadata, final Consumer<DefaultPaletteDefinition> paletteDefinitionConsumer) {
    final String definitionSetId = metadata.getDefinitionSetId();
    final Object definitionSet = getDefinitionManager().definitionSets().getDefinitionSetById(definitionSetId);
    final Set<String> definitions = getDefinitionManager().adapters().forDefinitionSet().getDefinitions(definitionSet);
    if (null != definitions) {
        final Map<String, DefaultPaletteItem> items = new LinkedHashMap<>();
        final Set<String> consumed = new HashSet<>(definitions);
        // Once all item definitions consumed, build the resulting palette definition
        // and let the consumer do its job.
        final Command checkConsumedAndComplete = () -> {
            if (consumed.isEmpty()) {
                paletteDefinitionConsumer.accept(new DefaultPaletteDefinition(getSortedItems(items.values(), getDefaultComparator()), definitionSetId));
            }
        };
        for (final String defId : definitions) {
            consumed.remove(defId);
            // Check if this concrete definition is excluded from the palette model.
            if (itemFilter.test(defId)) {
                clientFactoryServices.newDefinition(defId, new ServiceCallback<Object>() {

                    @Override
                    public void onSuccess(final Object definition) {
                        buildItem(definition, metadata, items);
                        checkConsumedAndComplete.execute();
                    }

                    @Override
                    public void onError(final ClientRuntimeError error) {
                        LOGGER.severe("Error while building the palette definition. " + "[Message=" + error.getMessage() + "]");
                    }
                });
            } else {
                checkConsumedAndComplete.execute();
            }
        }
    }
}
Also used : Command(org.uberfire.mvp.Command) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet)

Aggregations

Command (org.uberfire.mvp.Command)117 Test (org.junit.Test)66 ParameterizedCommand (org.uberfire.mvp.ParameterizedCommand)15 ClientSessionCommand (org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand)11 Group (com.ait.lienzo.client.core.shape.Group)9 YesNoCancelPopup (org.uberfire.ext.widgets.common.client.common.popups.YesNoCancelPopup)9 Before (org.junit.Before)8 HasListSelectorControl (org.kie.workbench.common.dmn.client.widgets.grid.controls.list.HasListSelectorControl)7 Path (org.uberfire.backend.vfs.Path)7 ArrayList (java.util.ArrayList)6 Collection (java.util.Collection)6 PlaceRequest (org.uberfire.mvp.PlaceRequest)5 MenuItem (org.uberfire.workbench.model.menu.MenuItem)5 IsWidget (com.google.gwt.user.client.ui.IsWidget)4 Inject (javax.inject.Inject)4 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)4 RemoteCallback (org.jboss.errai.common.client.api.RemoteCallback)4 DeleteHeaderValueCommand (org.kie.workbench.common.dmn.client.commands.general.DeleteHeaderValueCommand)4 SetCellValueCommand (org.kie.workbench.common.dmn.client.commands.general.SetCellValueCommand)4 SetHeaderValueCommand (org.kie.workbench.common.dmn.client.commands.general.SetHeaderValueCommand)4