Search in sources :

Example 16 with Command

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

the class LiteralExpressionPMMLDocumentGridTest method testNewCellHasValueCommand.

@Test
public void testNewCellHasValueCommand() {
    setupGrid(0);
    final Command command = grid.newCellHasValueCommand().apply(tupleWithValue);
    GridFactoryCommandUtils.assertCommands(command, SetCellValueCommand.class, SetCellValueCommand.class);
    verify(pmmlDocumentModelEditorCellHasValueCommandProvider).apply(pmmlValueEditorCellHasValueCommandParameterCaptor.capture());
    final GridCellValueTuple<GridCellValue<String>> gcvt = pmmlValueEditorCellHasValueCommandParameterCaptor.getValue();
    assertThat(gcvt.getRowIndex()).isEqualTo(0);
    assertThat(gcvt.getColumnIndex()).isEqualTo(0);
    assertThat(gcvt.getGridWidget()).isEqualTo(pmmlValueEditor);
    final GridCellValue<String> gcv = gcvt.getValue();
    assertThat(gcv).isNotNull();
    assertThat(gcv.getValue()).isEqualTo("");
    assertThat(gcv.getPlaceHolder()).isEqualTo(DMNEditorConstants.LiteralExpressionPMMLDocumentModelEditorDefinition_Placeholder);
}
Also used : Command(org.kie.workbench.common.stunner.core.command.Command) SetCellValueCommand(org.kie.workbench.common.dmn.client.commands.general.SetCellValueCommand) GridCellValue(org.uberfire.ext.wires.core.grids.client.model.GridCellValue) Test(org.junit.Test)

Example 17 with Command

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

the class LiteralExpressionPMMLDocumentModelEditorDefinition method getEditor.

@Override
public Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> getEditor(final GridCellTuple parent, final Optional<String> nodeUUID, final HasExpression hasExpression, final Optional<HasName> hasName, final boolean isOnlyVisualChangeAllowed, final int nesting) {
    return Optional.of(new LiteralExpressionPMMLGrid(parent, nodeUUID, hasExpression, hasName, getGridPanel(), getGridLayer(), makeGridData(() -> Optional.ofNullable((LiteralExpressionPMMLDocumentModel) hasExpression.getExpression())), definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, getCellEditorControls(), listSelector, translationService, isOnlyVisualChangeAllowed, nesting, headerEditor, readOnlyProvider) {

        @Override
        protected String getPlaceHolder() {
            return translationService.getTranslation(DMNEditorConstants.LiteralExpressionPMMLDocumentModelEditorDefinition_Placeholder);
        }

        @Override
        protected void loadValues(final Consumer<List<String>> consumer) {
            final String pmmlDocumentName = getExpressionPMMLValue(LiteralExpressionPMMLDocument.VARIABLE_DOCUMENT);
            consumer.accept(pmmlDocumentMetadataProvider.getPMMLDocumentModels(pmmlDocumentName));
        }

        @Override
        public Function<GridCellValueTuple, Command> newCellHasValueCommand() {
            return (gridCellValueTuple) -> {
                final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> builder = new CompositeCommand.Builder<>();
                // Command to set the PMMLDocumentModel value
                builder.addCommand(new SetCellValueCommand(gridCellValueTuple, () -> uiModelMapper, gridLayer::batch));
                // Command to set PMMLDocumentModel parameters
                getParentFunctionGrid().ifPresent(parentFunctionGrid -> {
                    final String pmmlDocumentName = getExpressionPMMLValue(LiteralExpressionPMMLDocument.VARIABLE_DOCUMENT);
                    final String pmmlDocumentModelName = StringUtils.createUnquotedString((String) gridCellValueTuple.getValue().getValue());
                    final List<String> parameters = pmmlDocumentMetadataProvider.getPMMLDocumentModelParameterNames(pmmlDocumentName, pmmlDocumentModelName);
                    parentFunctionGrid.getExpression().get().ifPresent(function -> {
                        builder.addCommand(new SetParametersCommand(function, convertParametersToInformationItems(parameters), gridLayer::batch));
                    });
                });
                return builder.build();
            };
        }

        private List<InformationItem> convertParametersToInformationItems(final List<String> parameters) {
            final List<InformationItem> informationItems = new ArrayList<>();
            parameters.forEach(parameter -> informationItems.add(new InformationItem(new Id(), new Description(), new Name(parameter), BuiltInType.ANY.asQName())));
            return informationItems;
        }
    });
}
Also used : DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) ListSelectorView(org.kie.workbench.common.dmn.client.widgets.grid.controls.list.ListSelectorView) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) SetCellValueCommand(org.kie.workbench.common.dmn.client.commands.general.SetCellValueCommand) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) LiteralExpressionPMMLDocument(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocument) LiteralExpressionPMMLDocumentModel(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocumentModel) HasName(org.kie.workbench.common.dmn.api.definition.HasName) List(java.util.List) DefaultCanvasCommandFactory(org.kie.workbench.common.dmn.client.commands.factory.DefaultCanvasCommandFactory) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) BuiltInType(org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) StringUtils(org.kie.workbench.common.stunner.core.util.StringUtils) ValueAndDataTypePopoverView(org.kie.workbench.common.dmn.client.editors.types.ValueAndDataTypePopoverView) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) ExpressionType(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionType) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) DMNEditor(org.kie.workbench.common.dmn.api.qualifiers.DMNEditor) ExpressionEditorChanged(org.kie.workbench.common.dmn.client.widgets.grid.model.ExpressionEditorChanged) Inject(javax.inject.Inject) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) RefreshFormPropertiesEvent(org.kie.workbench.common.stunner.forms.client.event.RefreshFormPropertiesEvent) SetParametersCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.SetParametersCommand) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) ReadOnlyProvider(org.kie.workbench.common.stunner.core.client.ReadOnlyProvider) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Command(org.kie.workbench.common.stunner.core.command.Command) SessionManager(org.kie.workbench.common.stunner.core.client.api.SessionManager) BaseUIModelMapper(org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper) Event(javax.enterprise.event.Event) DMNEditorConstants(org.kie.workbench.common.dmn.client.resources.i18n.DMNEditorConstants) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) TranslationService(org.jboss.errai.ui.client.local.spi.TranslationService) PMMLDocumentMetadataProvider(org.kie.workbench.common.dmn.client.editors.expressions.types.function.supplementary.pmml.PMMLDocumentMetadataProvider) LiteralExpressionPMMLGrid(org.kie.workbench.common.dmn.client.editors.expressions.types.function.supplementary.pmml.LiteralExpressionPMMLGrid) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) SessionCommandManager(org.kie.workbench.common.stunner.core.client.command.SessionCommandManager) Consumer(java.util.function.Consumer) DomainObjectSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.DomainObjectSelectionEvent) GridCellValueTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellValueTuple) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) BaseEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.BaseEditorDefinition) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) SetParametersCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.SetParametersCommand) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) LiteralExpressionPMMLGrid(org.kie.workbench.common.dmn.client.editors.expressions.types.function.supplementary.pmml.LiteralExpressionPMMLGrid) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) HasName(org.kie.workbench.common.dmn.api.definition.HasName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) LiteralExpressionPMMLDocumentModel(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocumentModel) Function(java.util.function.Function) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) SetCellValueCommand(org.kie.workbench.common.dmn.client.commands.general.SetCellValueCommand) List(java.util.List) ArrayList(java.util.ArrayList) Id(org.kie.workbench.common.dmn.api.property.dmn.Id)

Example 18 with Command

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

the class DMNDiagramsSessionTest method testLoadHistoryForTheCurrentDiagram.

@Test
public void testLoadHistoryForTheCurrentDiagram() {
    final Map<String, List<Command<AbstractCanvasHandler, CanvasViolation>>> storedRedoHistory = mock(Map.class);
    final Map<String, List<Command<AbstractCanvasHandler, CanvasViolation>>> storedUndoHistory = mock(Map.class);
    final String diagramId = "diagramId";
    final EditorSession editorSession = mock(EditorSession.class);
    final Optional<EditorSession> optionalEditorSession = Optional.of(editorSession);
    final Registry<Command<AbstractCanvasHandler, CanvasViolation>> undoCommandRegistry = mock(Registry.class);
    final Registry<Command<AbstractCanvasHandler, CanvasViolation>> redoCommandRegistry = mock(Registry.class);
    final List<Command<AbstractCanvasHandler, CanvasViolation>> redoHistory = mock(List.class);
    final List<Command<AbstractCanvasHandler, CanvasViolation>> undoHistory = mock(List.class);
    doReturn(storedRedoHistory).when(dmnDiagramsSession).getStoredRedoHistories();
    doReturn(storedUndoHistory).when(dmnDiagramsSession).getStoredUndoHistories();
    doReturn(diagramId).when(dmnDiagramsSession).getCurrentDiagramId();
    doReturn(optionalEditorSession).when(dmnDiagramsSession).getCurrentSession();
    when(storedRedoHistory.containsKey(diagramId)).thenReturn(true);
    when(storedUndoHistory.containsKey(diagramId)).thenReturn(true);
    when(editorSession.getCommandRegistry()).thenReturn(undoCommandRegistry);
    when(editorSession.getRedoCommandRegistry()).thenReturn(redoCommandRegistry);
    when(storedRedoHistory.get(diagramId)).thenReturn(redoHistory);
    when(storedUndoHistory.get(diagramId)).thenReturn(undoHistory);
    doNothing().when(dmnDiagramsSession).loadHistoryToTheRegistry(redoHistory, redoCommandRegistry);
    doNothing().when(dmnDiagramsSession).loadHistoryToTheRegistry(undoHistory, undoCommandRegistry);
    dmnDiagramsSession.loadHistoryForTheCurrentDiagram();
    verify(dmnDiagramsSession).loadHistoryToTheRegistry(redoHistory, redoCommandRegistry);
    verify(dmnDiagramsSession).loadHistoryToTheRegistry(undoHistory, undoCommandRegistry);
    verify(dmnDiagramsSession).notifyRegistryChanged();
    verify(undoCommandRegistry, never()).clear();
    verify(redoCommandRegistry, never()).clear();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Command(org.kie.workbench.common.stunner.core.command.Command) Arrays.asList(java.util.Arrays.asList) List(java.util.List) EditorSession(org.kie.workbench.common.stunner.core.client.session.impl.EditorSession) Test(org.junit.Test)

Example 19 with Command

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

the class CompositeCommandTest method testExecute2FailedThenUndo.

@Test
@SuppressWarnings("unchecked")
public void testExecute2FailedThenUndo() {
    Command c1 = mockSuccessCommandOperations();
    Command c2 = mockSuccessCommandOperations();
    when(c2.execute(eq(commandExecutionContext))).thenReturn(SOME_ERROR_VIOLATION);
    Command c3 = mockSuccessCommandOperations();
    CompositeCommand command = new CompositeCommand.Builder<>().addCommand(c1).addCommand(c2).addCommand(c3).build();
    CommandResult result = command.execute(commandExecutionContext);
    assertEquals(CommandResult.Type.ERROR, result.getType());
    verify(c1, times(1)).execute(eq(commandExecutionContext));
    verify(c1, times(1)).undo(eq(commandExecutionContext));
    verify(c2, times(1)).execute(eq(commandExecutionContext));
    verify(c2, never()).undo(eq(commandExecutionContext));
    verify(c3, never()).execute(eq(commandExecutionContext));
    verify(c3, never()).undo(eq(commandExecutionContext));
}
Also used : AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) Command(org.kie.workbench.common.stunner.core.command.Command) GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) Test(org.junit.Test)

Example 20 with Command

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

the class CompositeCommandTest method mockSuccessCommandOperations.

@SuppressWarnings("unchecked")
private Command mockSuccessCommandOperations() {
    Command command = mock(Command.class);
    when(command.allow(eq(commandExecutionContext))).thenReturn(GraphCommandResultBuilder.SUCCESS);
    when(command.execute(eq(commandExecutionContext))).thenReturn(GraphCommandResultBuilder.SUCCESS);
    when(command.undo(eq(commandExecutionContext))).thenReturn(GraphCommandResultBuilder.SUCCESS);
    return command;
}
Also used : AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) Command(org.kie.workbench.common.stunner.core.command.Command)

Aggregations

Command (org.kie.workbench.common.stunner.core.command.Command)74 Test (org.junit.Test)53 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)23 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)22 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)19 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)16 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)14 Edge (org.kie.workbench.common.stunner.core.graph.Edge)12 Node (org.kie.workbench.common.stunner.core.graph.Node)12 List (java.util.List)10 GraphCommandResultBuilder (org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder)10 AbstractGraphCommand (org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand)10 View (org.kie.workbench.common.stunner.core.graph.content.view.View)9 SetCellValueCommand (org.kie.workbench.common.dmn.client.commands.general.SetCellValueCommand)7 Consumer (java.util.function.Consumer)6 UpdateElementPositionCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand)6 ArrayList (java.util.ArrayList)5 AddNodeCommand (org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand)5 Element (org.kie.workbench.common.stunner.core.graph.Element)5 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)5