use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.
the class ExpressionContainerGrid method spyHasExpression.
/**
* Proxy {@link HasExpression} to be able intercept interactions with the original
* to update the expression label in {@link ExpressionEditorView} when the {@link Expression} changes.
* @param hasExpression A {@link HasExpression} to be proxied.
* @return A proxy that intercepts interactions with the wrapped {@link HasExpression}
*/
HasExpression spyHasExpression(final HasExpression hasExpression) {
final HasExpression spy = new HasExpression() {
@Override
public Expression getExpression() {
return hasExpression.getExpression();
}
@Override
public void setExpression(final Expression expression) {
hasExpression.setExpression(expression);
onHasExpressionChanged.execute(Optional.ofNullable(expression));
}
@Override
public DMNModelInstrumentedBase asDMNModelInstrumentedBase() {
return hasExpression.asDMNModelInstrumentedBase();
}
@Override
public boolean isClearSupported() {
return hasExpression.isClearSupported();
}
};
return spy;
}
use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.
the class ExpressionEditorColumn method getMinimumWidth.
@Override
public Double getMinimumWidth() {
double minimumWidth = super.getMinimumWidth();
final GridData model = gridWidget.getModel();
final int columnIndex = getLogicalColumnIndex(model);
if (columnIndex != -1) {
for (GridRow row : model.getRows()) {
final GridCell<?> cell = row.getCells().get(columnIndex);
if (cell != null) {
final GridCellValue<?> value = cell.getValue();
if (value instanceof ExpressionCellValue) {
final ExpressionCellValue ecv = (ExpressionCellValue) value;
final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> editor = ecv.getValue();
final double padding = editor.map(BaseExpressionGrid::getPadding).orElse(0.0);
minimumWidth = Math.max(minimumWidth, ecv.getMinimumWidth().orElse(0.0) + padding * 2);
}
}
}
}
return minimumWidth;
}
use of org.kie.workbench.common.dmn.api.definition.model.Expression in project kie-wb-common by kiegroup.
the class ExpressionEditorColumn method updateWidthOfChildren.
protected void updateWidthOfChildren() {
final double columnWidth = getWidth();
final GridData model = gridWidget.getModel();
final int columnIndex = getLogicalColumnIndex(model);
if (columnIndex != -1) {
for (GridRow row : model.getRows()) {
final GridCell<?> cell = row.getCells().get(columnIndex);
if (cell != null) {
final GridCellValue<?> value = cell.getValue();
if (value instanceof ExpressionCellValue) {
final ExpressionCellValue ecv = (ExpressionCellValue) value;
final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> editor = ecv.getValue();
if (editor.isPresent()) {
final BaseExpressionGrid beg = editor.get();
updateWidthOfLastColumn(beg, columnWidth);
}
}
}
}
}
}
use of org.kie.workbench.common.dmn.api.definition.model.Expression 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 parent = new GridCellTuple(0, 1, FunctionGrid.this);
final Optional<Expression> expression = definition.getModelClass();
definition.enrich(nodeUUID, hasExpression, expression);
sessionCommandManager.execute((AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler(), new SetKindCommand(parent, function, kind, expression, (editor) -> {
editor.ifPresent(e -> {
e.resize(BaseExpressionGrid.RESIZE_EXISTING);
e.selectFirstCell();
});
}, () -> {
resize(BaseExpressionGrid.RESIZE_EXISTING_MINIMUM);
selectFirstCell();
}, () -> {
Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> editor = Optional.empty();
editor = definition.getEditor(parent, Optional.empty(), getExpression().get().get(), hasName, isOnlyVisualChangeAllowed, nesting + 1);
return editor;
}));
});
}
use of org.kie.workbench.common.dmn.api.definition.model.Expression 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(rowIndex, columnIndex, gridWidget);
final boolean isOnlyVisualChangeAllowed = this.isOnlyVisualChangeAllowedSupplier.get();
final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> editor = ed.getEditor(expressionParent, Optional.empty(), function, Optional.empty(), isOnlyVisualChangeAllowed, nesting);
uiModel.get().setCell(rowIndex, columnIndex, () -> new FunctionGridCell<>(new ExpressionCellValue(editor), listSelector));
}
Aggregations