use of org.kie.workbench.common.stunner.core.client.api.SessionManager 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.client.api.SessionManager in project kie-wb-common by kiegroup.
the class PasteSelectionSessionCommandTest method executeWithMultiSelection.
@Test
@SuppressWarnings("unchecked")
public void executeWithMultiSelection() {
pasteSelectionSessionCommand.bind(session);
pasteSelectionSessionCommand.setTestEdgeFoundInCanvas(true);
pasteSelectionSessionCommand.setTestEdgeFoundInClipboard(false);
// Mock the callback of CloneNodeCommand
ArgumentCaptor<Consumer> consumerNode = ArgumentCaptor.forClass(Consumer.class);
ArgumentCaptor<Consumer> consumerNode2 = ArgumentCaptor.forClass(Consumer.class);
when(cloneNodeCommand.getCandidate()).thenReturn(node);
when(cloneNodeCommand2.getCandidate()).thenReturn(node2);
when(canvasCommandFactory.cloneNode(eq(node), any(), any(), consumerNode.capture())).thenReturn(cloneNodeCommand);
when(canvasCommandFactory.cloneNode(eq(node2), any(), any(), consumerNode2.capture())).thenReturn(cloneNodeCommand2);
Map<Node, ArgumentCaptor<Consumer>> consumerMap = new HashMap() {
{
put(node, consumerNode);
put(node2, consumerNode2);
}
};
// Mock the callback of CloneConnectorCommand
ArgumentCaptor<Consumer> consumerEdge = ArgumentCaptor.forClass(Consumer.class);
when(canvasCommandFactory.cloneConnector(any(), Mockito.<String>any(), Mockito.<String>any(), Mockito.<String>any(), consumerEdge.capture())).thenReturn(cloneConnectorCommand);
// apply callbacks mocks
when(sessionCommandManager.execute(eq(canvasHandler), any())).thenAnswer(param -> {
CompositeCommand argument = param.getArgument(1, CompositeCommand.class);
// callback to nodes
argument.getCommands().stream().filter(c -> c instanceof CloneNodeCommand).forEach(c -> {
CloneNodeCommand cloneNodeCommand = (CloneNodeCommand) c;
Node candidate = cloneNodeCommand.getCandidate();
consumerMap.get(candidate).getValue().accept(cloneMap.get(candidate));
});
// callback to connectors
argument.getCommands().stream().filter(c -> c instanceof CloneConnectorCommand).forEach(c -> consumerEdge.getValue().accept(cloneEdge));
return commandResult;
});
// Executing the command
clipboardControl.set(graphInstance.startNode, graphInstance.edge1, graphInstance.intermNode);
when(selectionControl.getSelectedItems()).thenReturn(Arrays.asList(graphInstance.startNode.getUUID(), graphInstance.edge1.getUUID(), graphInstance.intermNode.getUUID()));
CopySelectionSessionCommand.getInstance(sessionManager).bind(session);
pasteSelectionSessionCommand.execute(callback);
verify(canvasCommandFactory, times(1)).cloneNode(eq(graphInstance.startNode), eq(graphInstance.parentNode.getUUID()), eq(new Point2D(X, DEFAULT_PADDING + Y + NODE_SIZE)), any());
verify(canvasCommandFactory, times(1)).cloneConnector(eq(graphInstance.edge1), Mockito.<String>any(), Mockito.<String>any(), Mockito.<String>any(), any());
// check command registry update after execution to allow a single undo/redo
verify(commandRegistry, times(2)).pop();
ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
verify(commandRegistry, times(1)).register(commandArgumentCaptor.capture());
assertTrue(commandArgumentCaptor.getValue() instanceof CompositeCommand);
assertEquals(2, ((CompositeCommand) commandArgumentCaptor.getValue()).size());
}
use of org.kie.workbench.common.stunner.core.client.api.SessionManager in project kie-wb-common by kiegroup.
the class PasteSelectionSessionCommandTest method executeWithMultiSelectionWithEdgesClipboard.
@Test
@SuppressWarnings("unchecked")
public void executeWithMultiSelectionWithEdgesClipboard() {
final Connection sourceConnection = (Connection) ((ViewConnector) graphInstance.edge1.getContent()).getSourceConnection().orElse(null);
final Connection targetConnection = (Connection) ((ViewConnector) graphInstance.edge1.getContent()).getTargetConnection().orElse(null);
final EdgeClipboard clipboard = clipboardControl.buildNewEdgeClipboard(graphInstance.startNode.getUUID(), sourceConnection, graphInstance.intermNode.getUUID(), targetConnection);
clipboardControl.set(graphInstance.startNode, graphInstance.edge1, graphInstance.intermNode);
final Map<String, EdgeClipboard> map = new HashMap<>();
map.put(graphInstance.edge1.getUUID(), clipboard);
when(clipboardControl.getEdgeMap()).thenReturn(map);
assertEquals(1, clipboardControl.getEdgeMap().size());
pasteSelectionSessionCommand.bind(session);
pasteSelectionSessionCommand.setTestEdgeFoundInCanvas(false);
pasteSelectionSessionCommand.setTestEdgeFoundInClipboard(true);
assertEquals(false, pasteSelectionSessionCommand.isEdgeFoundInCanvas(graphInstance.edge1));
assertEquals(true, pasteSelectionSessionCommand.isEdgeFoundInClipboard(graphInstance.edge1));
// Mock the callback of CloneNodeCommand
ArgumentCaptor<Consumer> consumerNode = ArgumentCaptor.forClass(Consumer.class);
ArgumentCaptor<Consumer> consumerNode2 = ArgumentCaptor.forClass(Consumer.class);
when(cloneNodeCommand.getCandidate()).thenReturn(node);
when(cloneNodeCommand2.getCandidate()).thenReturn(node2);
when(canvasCommandFactory.cloneNode(eq(node), any(), any(), consumerNode.capture())).thenReturn(cloneNodeCommand);
when(canvasCommandFactory.cloneNode(eq(node2), any(), any(), consumerNode2.capture())).thenReturn(cloneNodeCommand2);
Map<Node, ArgumentCaptor<Consumer>> consumerMap = new HashMap() {
{
put(node, consumerNode);
put(node2, consumerNode2);
}
};
// Mock the callback of CloneConnectorCommand
ArgumentCaptor<Consumer> consumerEdge = ArgumentCaptor.forClass(Consumer.class);
when(canvasCommandFactory.cloneConnector(any(), Mockito.<String>any(), Mockito.<String>any(), Mockito.<String>any(), consumerEdge.capture())).thenReturn(cloneConnectorCommand);
// apply callbacks mocks
when(sessionCommandManager.execute(eq(canvasHandler), any())).thenAnswer(param -> {
CompositeCommand argument = param.getArgument(1, CompositeCommand.class);
// callback to nodes
argument.getCommands().stream().filter(c -> c instanceof CloneNodeCommand).forEach(c -> {
CloneNodeCommand cloneNodeCommand = (CloneNodeCommand) c;
Node candidate = cloneNodeCommand.getCandidate();
consumerMap.get(candidate).getValue().accept(cloneMap.get(candidate));
});
// callback to connectors
argument.getCommands().stream().filter(c -> c instanceof CloneConnectorCommand).forEach(c -> consumerEdge.getValue().accept(cloneEdge));
return commandResult;
});
// Executing the command
clipboardControl.set(graphInstance.startNode, graphInstance.edge1, graphInstance.intermNode);
when(selectionControl.getSelectedItems()).thenReturn(Arrays.asList(graphInstance.startNode.getUUID(), graphInstance.edge1.getUUID(), graphInstance.intermNode.getUUID()));
CopySelectionSessionCommand.getInstance(sessionManager).bind(session);
pasteSelectionSessionCommand.execute(callback);
verify(canvasCommandFactory, times(1)).cloneNode(eq(graphInstance.startNode), eq(graphInstance.parentNode.getUUID()), eq(new Point2D(X, DEFAULT_PADDING + Y + NODE_SIZE)), any());
verify(canvasCommandFactory, times(1)).cloneConnector(eq(graphInstance.edge1), Mockito.<String>any(), Mockito.<String>any(), Mockito.<String>any(), any());
// check command registry update after execution to allow a single undo/redo
verify(commandRegistry, times(2)).pop();
ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
verify(commandRegistry, times(1)).register(commandArgumentCaptor.capture());
assertTrue(commandArgumentCaptor.getValue() instanceof CompositeCommand);
assertEquals(2, ((CompositeCommand) commandArgumentCaptor.getValue()).size());
}
Aggregations