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);
}
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;
}
});
}
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();
}
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));
}
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;
}
Aggregations