use of org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellValueTuple 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.dmn.client.widgets.grid.model.GridCellValueTuple in project kie-wb-common by kiegroup.
the class LiteralExpressionPMMLDocumentEditorDefinition 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((LiteralExpressionPMMLDocument) hasExpression.getExpression())), definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, getCellEditorControls(), listSelector, translationService, isOnlyVisualChangeAllowed, nesting, headerEditor, readOnlyProvider) {
@Override
protected String getPlaceHolder() {
return translationService.getTranslation(DMNEditorConstants.LiteralExpressionPMMLDocumentEditorDefinition_Placeholder);
}
@Override
protected void loadValues(final Consumer<List<String>> consumer) {
consumer.accept(pmmlDocumentMetadataProvider.getPMMLDocumentNames());
}
@Override
@SuppressWarnings("unchecked")
public Function<GridCellValueTuple, Command> newCellHasValueCommand() {
return (gridCellValueTuple) -> {
final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> builder = new CompositeCommand.Builder<>();
// Command to set the PMMLDocument value
builder.addCommand(new SetCellValueCommand(gridCellValueTuple, () -> uiModelMapper, gridLayer::batch));
// Command to clear the PMMLDocumentModel value. Unfortunately we need to reset the cells' placeholder too.
getExpressionPMMLValueEditor(LiteralExpressionPMMLDocumentModel.VARIABLE_MODEL).ifPresent(editor -> {
if (editor instanceof LiteralExpressionPMMLGrid) {
final LiteralExpressionPMMLGrid pmmlModelEditor = (LiteralExpressionPMMLGrid) editor;
builder.addCommand(pmmlModelEditor.newCellHasValueCommand().apply(new GridCellValueTuple(0, 0, pmmlModelEditor, new BaseGridCellValue("", translationService.getTranslation(DMNEditorConstants.LiteralExpressionPMMLDocumentModelEditorDefinition_Placeholder)))));
}
});
return builder.build();
};
}
});
}
use of org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellValueTuple in project kie-wb-common by kiegroup.
the class DecisionTableGridTest method testHeaderTextBoxFactoryWhenNested.
@Test
public void testHeaderTextBoxFactoryWhenNested() {
setupGrid(makeHasNameForDecision(), 1);
final GridCellTuple tupleWithoutValue = new GridCellTuple(0, 2, gridWidget);
final GridCellValueTuple tupleWithValue = new GridCellValueTuple<>(0, 2, gridWidget, new BaseGridCellValue<>("value"));
final TextBoxSingletonDOMElementFactory factory = grid.getHeaderTextBoxFactory();
assertThat(factory.getHasNoValueCommand().apply(tupleWithoutValue)).isInstanceOf(DeleteHeaderValueCommand.class);
assertThat(factory.getHasValueCommand().apply(tupleWithValue)).isInstanceOf(SetHeaderValueCommand.class);
}
use of org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellValueTuple in project kie-wb-common by kiegroup.
the class DecisionTableGridTest method testHeaderTextAreaFactoryWhenNested.
@Test
public void testHeaderTextAreaFactoryWhenNested() {
setupGrid(makeHasNameForDecision(), 1);
final GridCellTuple tupleWithoutValue = new GridCellTuple(0, 1, gridWidget);
final GridCellValueTuple tupleWithValue = new GridCellValueTuple<>(0, 1, gridWidget, new BaseGridCellValue<>("value"));
final TextBoxSingletonDOMElementFactory factory = grid.getHeaderTextBoxFactory();
assertThat(factory.getHasNoValueCommand().apply(tupleWithoutValue)).isInstanceOf(DeleteHeaderValueCommand.class);
assertThat(factory.getHasValueCommand().apply(tupleWithValue)).isInstanceOf(SetHeaderValueCommand.class);
}
use of org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellValueTuple in project kie-wb-common by kiegroup.
the class DecisionTableGridTest method testHeaderHasNameTextBoxFactoryWhenNested.
@Test
public void testHeaderHasNameTextBoxFactoryWhenNested() {
setupGrid(makeHasNameForDecision(), 1);
final GridCellTuple tupleWithoutValue = new GridCellTuple(0, 2, gridWidget);
final GridCellValueTuple tupleWithValue = new GridCellValueTuple<>(0, 2, gridWidget, new BaseGridCellValue<>("value"));
final TextBoxSingletonDOMElementFactory factory = grid.getHeaderHasNameTextBoxFactory();
assertCommands(factory.getHasNoValueCommand().apply(tupleWithoutValue), DeleteHeaderValueCommand.class);
assertCommands(factory.getHasValueCommand().apply(tupleWithValue), SetHeaderValueCommand.class);
}
Aggregations