use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid in project kie-wb-common by kiegroup.
the class FunctionGrid method doSetKind.
void doSetKind(final FunctionDefinition.Kind kind, final FunctionDefinition function, final Optional<ExpressionEditorDefinition<Expression>> oDefinition) {
oDefinition.ifPresent(definition -> {
final GridCellTuple expressionParent = new GridCellTuple(0, 0, this);
final Optional<Expression> expression = definition.getModelClass();
final Optional<BaseExpressionGrid> gridWidget = definition.getEditor(expressionParent, Optional.empty(), hasExpression, expression, hasName, nesting);
doSetKind(kind, function, expression, gridWidget);
});
}
use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid in project kie-wb-common by kiegroup.
the class FunctionGrid method getItems.
@Override
@SuppressWarnings("unused")
public List<ListSelectorItem> getItems(final int uiRowIndex, final int uiColumnIndex) {
final List<ListSelectorItem> items = new ArrayList<>();
final FunctionDefinition.Kind kind = KindUtilities.getKind(expression.get());
items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.FunctionEditor_FEEL), !FunctionDefinition.Kind.FEEL.equals(kind), () -> {
cellEditorControls.hide();
expression.ifPresent(e -> setKind(FunctionDefinition.Kind.FEEL));
}));
items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.FunctionEditor_JAVA), !FunctionDefinition.Kind.JAVA.equals(kind), () -> {
cellEditorControls.hide();
expression.ifPresent(e -> setKind(FunctionDefinition.Kind.JAVA));
}));
items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.FunctionEditor_PMML), !FunctionDefinition.Kind.PMML.equals(kind), () -> {
cellEditorControls.hide();
expression.ifPresent(e -> setKind(FunctionDefinition.Kind.PMML));
}));
// If cell editor is UndefinedExpressionGrid don't add extra items
final GridCell<?> cell = model.getCell(uiRowIndex, uiColumnIndex);
final ExpressionCellValue ecv = (ExpressionCellValue) cell.getValue();
if (!ecv.getValue().isPresent()) {
return items;
}
final BaseExpressionGrid grid = ecv.getValue().get();
if (grid instanceof UndefinedExpressionGrid) {
return items;
}
items.add(new ListSelectorDividerItem());
items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.ExpressionEditor_Clear), true, () -> {
cellEditorControls.hide();
clearExpressionType();
}));
return items;
}
use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid in project kie-wb-common by kiegroup.
the class FunctionUIModelMapper method setUiModelEditor.
private void setUiModelEditor(final int rowIndex, final int columnIndex, final FunctionDefinition function, final ExpressionEditorDefinition<Expression> ed) {
final GridCellTuple expressionParent = new GridCellTuple(0, 0, gridWidget);
final Optional<Expression> expression = Optional.ofNullable(function.getExpression());
final Optional<BaseExpressionGrid> editor = ed.getEditor(expressionParent, Optional.empty(), function, expression, Optional.empty(), nesting + 1);
uiModel.get().setCell(rowIndex, columnIndex, () -> new FunctionGridCell<>(new ExpressionCellValue(editor), listSelector));
}
use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid in project kie-wb-common by kiegroup.
the class InvocationUIModelMapper method fromDMNModel.
@Override
public void fromDMNModel(final int rowIndex, final int columnIndex) {
dmnModel.get().ifPresent(invocation -> {
switch(columnIndex) {
case ROW_NUMBER_COLUMN_INDEX:
uiModel.get().setCell(rowIndex, columnIndex, () -> new InvocationGridCell<>(new BaseGridCellValue<>(rowIndex + 1), listSelector));
uiModel.get().getCell(rowIndex, columnIndex).setSelectionStrategy(RowSelectionStrategy.INSTANCE);
break;
case BINDING_PARAMETER_COLUMN_INDEX:
final InformationItem variable = invocation.getBinding().get(rowIndex).getParameter();
uiModel.get().setCell(rowIndex, columnIndex, () -> new InformationItemNameCell(() -> variable, listSelector));
break;
case BINDING_EXPRESSION_COLUMN_INDEX:
final Binding binding = invocation.getBinding().get(rowIndex);
final Optional<Expression> expression = Optional.ofNullable(binding.getExpression());
final Optional<ExpressionEditorDefinition<Expression>> expressionEditorDefinition = expressionEditorDefinitionsSupplier.get().getExpressionEditorDefinition(expression);
expressionEditorDefinition.ifPresent(ed -> {
final Optional<BaseExpressionGrid> editor = ed.getEditor(new GridCellTuple(rowIndex, columnIndex, gridWidget), Optional.empty(), binding, expression, Optional.ofNullable(binding.getParameter()), nesting + 1);
uiModel.get().setCell(rowIndex, columnIndex, () -> new InvocationGridCell<>(new ExpressionCellValue(editor), listSelector));
});
}
});
}
use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid in project kie-wb-common by kiegroup.
the class RelationColumn method getMinimumWidthOfPeers.
private double getMinimumWidthOfPeers() {
final GridCellTuple parent = gridWidget.getParentInformation();
final GridData parentUiModel = parent.getGridWidget().getModel();
final int parentUiRowIndex = parent.getRowIndex();
final int parentUiColumnIndex = parent.getColumnIndex();
double minimumWidth = super.getMinimumWidth();
for (int uiRowIndex = 0; uiRowIndex < parentUiModel.getRowCount(); uiRowIndex++) {
if (uiRowIndex != parentUiRowIndex) {
final GridRow row = parentUiModel.getRow(uiRowIndex);
final GridCell<?> cell = row.getCells().get(parentUiColumnIndex);
if (cell != null) {
final GridCellValue<?> value = cell.getValue();
if (value instanceof ExpressionCellValue) {
final ExpressionCellValue ecv = (ExpressionCellValue) value;
final Optional<BaseExpressionGrid> editor = ecv.getValue();
final double padding = editor.map(BaseExpressionGrid::getPadding).get();
minimumWidth = Math.max(minimumWidth, ecv.getMinimumWidth().orElse(0.0) + padding * 2);
}
}
}
}
return minimumWidth;
}
Aggregations