Search in sources :

Example 6 with BaseExpressionGrid

use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid in project kie-wb-common by kiegroup.

the class UndefinedExpressionGrid method onExpressionTypeChanged.

void onExpressionTypeChanged(final ExpressionType type) {
    final Optional<Expression> expression = expressionEditorDefinitionsSupplier.get().stream().filter(e -> e.getType().equals(type)).map(ExpressionEditorDefinition::getModelClass).findFirst().get();
    final Optional<ExpressionEditorDefinition<Expression>> expressionEditorDefinition = expressionEditorDefinitionsSupplier.get().getExpressionEditorDefinition(expression);
    expressionEditorDefinition.ifPresent(ed -> {
        final Optional<BaseExpressionGrid> editor = ed.getEditor(parent, nodeUUID, hasExpression, expression, hasName, nesting);
        final GridCellValueTuple gcv = new GridCellValueTuple<>(parent.getRowIndex(), parent.getColumnIndex(), parent.getGridWidget(), new ExpressionCellValue(editor));
        sessionCommandManager.execute((AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler(), new SetCellValueCommand(gcv, () -> uiModelMapper, () -> editor.ifPresent(e -> {
            e.selectFirstCell();
            synchroniseViewWhenExpressionEditorChanged(e);
        })));
    });
}
Also used : NodeMouseClickHandler(com.ait.lienzo.client.core.event.NodeMouseClickHandler) CellEditorControlsView(org.kie.workbench.common.dmn.client.widgets.grid.controls.container.CellEditorControlsView) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) ExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition) HasCellEditorControls(org.kie.workbench.common.dmn.client.widgets.grid.controls.HasCellEditorControls) HasListSelectorControl(org.kie.workbench.common.dmn.client.widgets.grid.controls.list.HasListSelectorControl) ListSelectorView(org.kie.workbench.common.dmn.client.widgets.grid.controls.list.ListSelectorView) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) DMNGridLayer(org.kie.workbench.common.dmn.client.widgets.layer.DMNGridLayer) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) ExpressionType(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionType) GridSelectionManager(org.uberfire.ext.wires.core.grids.client.widget.layer.GridSelectionManager) ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) Supplier(java.util.function.Supplier) BaseHeaderMetaData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseHeaderMetaData) ArrayList(java.util.ArrayList) DMNGridRow(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Expression(org.kie.workbench.common.dmn.api.definition.v1_1.Expression) SessionManager(org.kie.workbench.common.stunner.core.client.api.SessionManager) DMNGridPanel(org.kie.workbench.common.dmn.client.widgets.panel.DMNGridPanel) EventPropagationMode(com.ait.lienzo.shared.core.types.EventPropagationMode) SetCellValueCommand(org.kie.workbench.common.dmn.client.commands.general.SetCellValueCommand) TranslationService(org.jboss.errai.ui.client.local.spi.TranslationService) CanvasCommandFactory(org.kie.workbench.common.stunner.core.client.command.CanvasCommandFactory) GridCell(org.uberfire.ext.wires.core.grids.client.model.GridCell) GridDataCache(org.kie.workbench.common.dmn.client.widgets.grid.model.GridDataCache) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) SessionCommandManager(org.kie.workbench.common.stunner.core.client.command.SessionCommandManager) HasName(org.kie.workbench.common.dmn.api.definition.HasName) List(java.util.List) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) Optional(java.util.Optional) GridCellValueTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellValueTuple) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.v1_1.Expression) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) ExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition) SetCellValueCommand(org.kie.workbench.common.dmn.client.commands.general.SetCellValueCommand) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) GridCellValueTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellValueTuple)

Example 7 with BaseExpressionGrid

use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid in project kie-wb-common by kiegroup.

the class CommandUtils method updateParentInformation.

public static void updateParentInformation(final GridData uiModel) {
    final Optional<ExpressionEditorColumn> expressionColumn = uiModel.getColumns().stream().filter(c -> c instanceof ExpressionEditorColumn).map(c -> (ExpressionEditorColumn) c).findFirst();
    expressionColumn.ifPresent(c -> {
        final int columnIndex = uiModel.getColumns().indexOf(c);
        for (int rowIndex = 0; rowIndex < uiModel.getRowCount(); rowIndex++) {
            final GridCell<?> cell = uiModel.getCell(rowIndex, columnIndex);
            if (cell != null) {
                final GridCellValue<?> value = cell.getValue();
                if (value instanceof ExpressionCellValue) {
                    final ExpressionCellValue ecv = (ExpressionCellValue) value;
                    if (ecv.getValue().isPresent()) {
                        final BaseExpressionGrid beg = ecv.getValue().get();
                        beg.getParentInformation().setRowIndex(rowIndex);
                        beg.getParentInformation().setColumnIndex(columnIndex);
                    }
                }
            }
        }
    });
}
Also used : IntStream(java.util.stream.IntStream) GridCell(org.uberfire.ext.wires.core.grids.client.model.GridCell) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) List(java.util.List) RowNumberColumn(org.uberfire.ext.wires.core.grids.client.widget.grid.columns.RowNumberColumn) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue) GridCellValue(org.uberfire.ext.wires.core.grids.client.model.GridCellValue) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) Optional(java.util.Optional) ExpressionEditorColumn(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionEditorColumn) ExpressionEditorColumn(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionEditorColumn) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)

Example 8 with BaseExpressionGrid

use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid 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> editor = ecv.getValue();
                    final double padding = editor.map(BaseExpressionGrid::getPadding).get();
                    minimumWidth = Math.max(minimumWidth, ecv.getMinimumWidth().orElse(0.0) + padding * 2);
                }
            }
        }
    }
    return minimumWidth;
}
Also used : BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow)

Example 9 with BaseExpressionGrid

use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid 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> editor = ecv.getValue();
                    if (editor.isPresent()) {
                        final BaseExpressionGrid beg = editor.get();
                        updateWidthOfLastColumn(beg, columnWidth);
                    }
                }
            }
        }
    }
}
Also used : BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow)

Example 10 with BaseExpressionGrid

use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid in project kie-wb-common by kiegroup.

the class ContextEditorDefinitionTest method testEditor.

@Test
public void testEditor() {
    final Optional<Context> expression = definition.getModelClass();
    final Optional<BaseExpressionGrid> oEditor = definition.getEditor(parent, Optional.empty(), hasExpression, expression, hasName, 0);
    assertTrue(oEditor.isPresent());
    final GridWidget editor = oEditor.get();
    assertTrue(editor instanceof ContextGrid);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.v1_1.Context) GridWidget(org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) Test(org.junit.Test)

Aggregations

BaseExpressionGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)32 Test (org.junit.Test)15 ExpressionCellValue (org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)13 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)13 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)11 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)11 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)8 List (java.util.List)7 Optional (java.util.Optional)7 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)7 Expression (org.kie.workbench.common.dmn.api.definition.v1_1.Expression)7 GridCell (org.uberfire.ext.wires.core.grids.client.model.GridCell)7 ArrayList (java.util.ArrayList)6 HasName (org.kie.workbench.common.dmn.api.definition.HasName)6 HasListSelectorControl (org.kie.workbench.common.dmn.client.widgets.grid.controls.list.HasListSelectorControl)6 DMNGridRow (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow)6 DMNGridLayer (org.kie.workbench.common.dmn.client.widgets.layer.DMNGridLayer)6 InformationItem (org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem)5 ExpressionEditorDefinition (org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition)5 ExpressionEditorColumn (org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionEditorColumn)5