Search in sources :

Example 1 with ScenarioGrid

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGrid in project drools-wb by kiegroup.

the class ScenarioGridPanelProducer method initializeGrid.

protected void initializeGrid(ScenarioGridLayer scenarioGridLayer, ScenarioGridPanel scenarioGridPanel, AbstractScesimGridModel abstractScesimGridModel, ScenarioSimulationContext scenarioSimulationContext, int defaultDataCellX, int defaultDataCellY) {
    final ScenarioGrid scenarioGrid = new ScenarioGrid(abstractScesimGridModel, scenarioGridLayer, new ScenarioGridRenderer(false), scenarioContextMenuRegistry);
    scenarioGridLayer.addScenarioGrid(scenarioGrid);
    scenarioGridPanel.add(scenarioGridLayer);
    scenarioGrid.setScenarioSimulationContext(scenarioSimulationContext);
    scenarioGrid.setDefaultSelectedDataCell(defaultDataCellX, defaultDataCellY);
    abstractScesimGridModel.setCollectionEditorSingletonDOMElementFactory(new CollectionEditorSingletonDOMElementFactory(scenarioGridPanel, scenarioGridLayer, scenarioGridLayer.getScenarioGrid(), scenarioSimulationContext, viewsProvider));
    abstractScesimGridModel.setScenarioCellTextAreaSingletonDOMElementFactory(new ScenarioCellTextAreaSingletonDOMElementFactory(scenarioGridPanel, scenarioGridLayer, scenarioGridLayer.getScenarioGrid()));
    abstractScesimGridModel.setScenarioHeaderTextBoxSingletonDOMElementFactory(new ScenarioHeaderTextBoxSingletonDOMElementFactory(scenarioGridPanel, scenarioGridLayer, scenarioGridLayer.getScenarioGrid()));
    abstractScesimGridModel.setScenarioExpressionCellTextAreaSingletonDOMElementFactory(new ScenarioExpressionCellTextAreaSingletonDOMElementFactory(scenarioGridPanel, scenarioGridLayer, scenarioGridLayer.getScenarioGrid()));
    final ScenarioSimulationKeyboardEditHandler scenarioSimulationKeyboardEditHandler = new ScenarioSimulationKeyboardEditHandler(scenarioGridLayer);
    final ScenarioInvokeContextMenuForSelectedCell invokeContextMenuKeyboardOperation = new ScenarioInvokeContextMenuForSelectedCell(scenarioGridLayer, scenarioContextMenuRegistry);
    final BaseGridWidgetKeyboardHandler handler = new BaseGridWidgetKeyboardHandler(scenarioGridLayer);
    handler.addOperation(scenarioSimulationKeyboardEditHandler, new KeyboardOperationSelectTopLeftCell(scenarioGridLayer), new KeyboardOperationMoveLeft(scenarioGridLayer), new KeyboardOperationMoveRight(scenarioGridLayer), new KeyboardOperationMoveUp(scenarioGridLayer), new KeyboardOperationMoveDown(scenarioGridLayer), new KeyboardOperationSelectBottomRightCell(scenarioGridLayer), invokeContextMenuKeyboardOperation);
    scenarioGridPanel.addKeyDownHandler(handler);
    // Hack to enable PINNED MODE i.e. not draggable
    scenarioGridLayer.enterPinnedMode(scenarioGrid, () -> {
    });
}
Also used : ScenarioGridRenderer(org.drools.workbench.screens.scenariosimulation.client.renderers.ScenarioGridRenderer) KeyboardOperationMoveUp(org.uberfire.ext.wires.core.grids.client.widget.grid.impl.KeyboardOperationMoveUp) BaseGridWidgetKeyboardHandler(org.uberfire.ext.wires.core.grids.client.widget.grid.impl.BaseGridWidgetKeyboardHandler) KeyboardOperationMoveDown(org.uberfire.ext.wires.core.grids.client.widget.grid.impl.KeyboardOperationMoveDown) ScenarioCellTextAreaSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioCellTextAreaSingletonDOMElementFactory) ScenarioSimulationKeyboardEditHandler(org.drools.workbench.screens.scenariosimulation.client.handlers.ScenarioSimulationKeyboardEditHandler) ScenarioExpressionCellTextAreaSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioExpressionCellTextAreaSingletonDOMElementFactory) KeyboardOperationMoveRight(org.uberfire.ext.wires.core.grids.client.widget.grid.impl.KeyboardOperationMoveRight) ScenarioGrid(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGrid) KeyboardOperationSelectBottomRightCell(org.uberfire.ext.wires.core.grids.client.widget.grid.impl.KeyboardOperationSelectBottomRightCell) KeyboardOperationSelectTopLeftCell(org.uberfire.ext.wires.core.grids.client.widget.grid.impl.KeyboardOperationSelectTopLeftCell) ScenarioInvokeContextMenuForSelectedCell(org.drools.workbench.screens.scenariosimulation.client.handlers.ScenarioInvokeContextMenuForSelectedCell) ScenarioHeaderTextBoxSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioHeaderTextBoxSingletonDOMElementFactory) CollectionEditorSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.CollectionEditorSingletonDOMElementFactory) KeyboardOperationMoveLeft(org.uberfire.ext.wires.core.grids.client.widget.grid.impl.KeyboardOperationMoveLeft)

Example 2 with ScenarioGrid

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGrid in project drools-wb by kiegroup.

the class ScenarioHeaderTextAreaDOMElement method internalFlush.

@Override
protected void internalFlush(final String value) {
    final int rowIndex = context.getRowIndex();
    final int columnIndex = context.getColumnIndex();
    try {
        boolean isInstanceHeader = scenarioHeaderMetaData != null && Objects.equals(scenarioHeaderMetaData.getMetadataType(), ScenarioHeaderMetaData.MetadataType.INSTANCE);
        boolean isPropertyHeader = scenarioHeaderMetaData != null && Objects.equals(scenarioHeaderMetaData.getMetadataType(), ScenarioHeaderMetaData.MetadataType.PROPERTY);
        ((ScenarioGrid) gridWidget).getEventBus().fireEvent(new SetHeaderCellValueEvent(((ScenarioGrid) gridWidget).getGridWidget(), rowIndex, columnIndex, value, isInstanceHeader, isPropertyHeader));
        ((ScenarioGrid) gridWidget).getEventBus().fireEvent(new ReloadTestToolsEvent(true));
    } catch (Exception e) {
        throw new IllegalArgumentException(new StringBuilder().append("Impossible to update header (").append(rowIndex).append(") of column ").append(columnIndex).toString(), e);
    }
}
Also used : ReloadTestToolsEvent(org.drools.workbench.screens.scenariosimulation.client.events.ReloadTestToolsEvent) ScenarioGrid(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGrid) SetHeaderCellValueEvent(org.drools.workbench.screens.scenariosimulation.client.events.SetHeaderCellValueEvent)

Example 3 with ScenarioGrid

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGrid in project drools-wb by kiegroup.

the class CollectionEditorSingletonDOMElementFactory method createDomElement.

@Override
public CollectionEditorDOMElement createDomElement(final GridLayer gridLayer, final GridWidget gridWidget) {
    if (this.widget != null) {
        this.widget.close();
    }
    this.widget = createWidget();
    /* Don't propagate MouseWheel and RightClick events to the Grid */
    this.widget.addDomHandler(MouseWheelEvent::stopPropagation, MouseWheelEvent.getType());
    this.widget.addDomHandler(event -> {
        event.stopPropagation();
        event.preventDefault();
    }, ContextMenuEvent.getType());
    this.widget.addDomHandler(ClickEvent::stopPropagation, ClickEvent.getType());
    this.widget.addDomHandler(KeyDownEvent::stopPropagation, KeyDownEvent.getType());
    final AbstractScesimGridModel<? extends AbstractScesimModel, ? extends AbstractScesimData> model = ((ScenarioGrid) gridWidget).getModel();
    final GridData.SelectedCell selectedCellsOrigin = model.getSelectedCellsOrigin();
    final Optional<GridColumn<?>> selectedColumn = model.getColumns().stream().filter(col -> col.getIndex() == selectedCellsOrigin.getColumnIndex()).findFirst();
    selectedColumn.ifPresent(col -> {
        final int actualIndex = model.getColumns().indexOf(col);
        final FactMapping factMapping = model.getAbstractScesimModel().get().getScesimModelDescriptor().getFactMappingByIndex(actualIndex);
        setCollectionEditorStructureData(this.widget, factMapping);
        this.e = createDomElementInternal(widget, gridLayer, gridWidget);
    });
    return e;
}
Also used : RULE(org.drools.scenariosimulation.api.model.ScenarioSimulationModel.Type.RULE) ContextMenuEvent(com.google.gwt.event.dom.client.ContextMenuEvent) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) HashMap(java.util.HashMap) CollectionEditorDOMElement(org.drools.workbench.screens.scenariosimulation.client.domelements.CollectionEditorDOMElement) ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) GridLienzoPanel(org.uberfire.ext.wires.core.grids.client.widget.layer.impl.GridLienzoPanel) CollectionViewImpl(org.drools.workbench.screens.scenariosimulation.client.collectioneditor.CollectionViewImpl) VALUE(org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE) ScenarioSimulationSharedUtils(org.drools.scenariosimulation.api.utils.ScenarioSimulationSharedUtils) Map(java.util.Map) AbstractScesimGridModel(org.drools.workbench.screens.scenariosimulation.client.models.AbstractScesimGridModel) ViewsProvider(org.drools.workbench.screens.scenariosimulation.client.utils.ViewsProvider) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) ScenarioSimulationUtils(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationUtils) BaseSingletonDOMElementFactory(org.uberfire.ext.wires.core.grids.client.widget.dom.single.impl.BaseSingletonDOMElementFactory) ScenarioSimulationUtils.isSimpleJavaType(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationUtils.isSimpleJavaType) ScenarioGrid(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGrid) MouseWheelEvent(com.google.gwt.event.dom.client.MouseWheelEvent) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) Collectors(java.util.stream.Collectors) GridWidget(org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget) GridLayer(org.uberfire.ext.wires.core.grids.client.widget.layer.GridLayer) List(java.util.List) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Optional(java.util.Optional) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) MouseWheelEvent(com.google.gwt.event.dom.client.MouseWheelEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ScenarioGrid(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGrid) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn)

Example 4 with ScenarioGrid

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGrid in project drools-wb by kiegroup.

the class ScenarioSimulationGridWidgetMouseEventHandler method handleHeaderCell.

@Override
public boolean handleHeaderCell(final GridWidget gridWidget, final Point2D relativeLocation, final int uiHeaderRowIndex, final int uiHeaderColumnIndex, final AbstractNodeMouseEvent event) {
    // Get column information
    final double cx = relativeLocation.getX();
    final BaseGridRendererHelper rendererHelper = gridWidget.getRendererHelper();
    final BaseGridRendererHelper.ColumnInformation ci = rendererHelper.getColumnInformation(cx);
    final GridColumn<?> column = ci.getColumn();
    if (column == null) {
        return false;
    }
    final ScenarioHeaderMetaData headerMetaData = (ScenarioHeaderMetaData) column.getHeaderMetaData().get(uiHeaderRowIndex);
    final GridData gridData = gridWidget.getModel();
    if (!gridData.getSelectedHeaderCells().isEmpty() && editSupportedLocal(headerMetaData.getSupportedEditAction(), event)) {
        final GridData.SelectedCell firstSelectedHeaderCell = gridData.getSelectedHeaderCells().get(0);
        final Optional<GridColumn<?>> firstSelectedColumnOptional = gridData.getColumns().stream().filter(col -> col.getIndex() == firstSelectedHeaderCell.getColumnIndex()).findFirst();
        final int firstSelectedColumnPosition = gridData.getColumns().indexOf(firstSelectedColumnOptional.orElseThrow(IllegalStateException::new));
        return startEditLocal((ScenarioGrid) gridWidget, firstSelectedColumnPosition, (ScenarioGridColumn) column, uiHeaderRowIndex, true);
    }
    return true;
}
Also used : GridCellEditAction(org.uberfire.ext.wires.core.grids.client.model.GridCellEditAction) GridCell(org.uberfire.ext.wires.core.grids.client.model.GridCell) ScenarioGrid(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGrid) DefaultGridWidgetEditCellMouseEventHandler(org.uberfire.ext.wires.core.grids.client.widget.grid.impl.DefaultGridWidgetEditCellMouseEventHandler) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) AbstractNodeMouseEvent(com.ait.lienzo.client.core.event.AbstractNodeMouseEvent) GridWidget(org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget) Objects(java.util.Objects) ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) BaseGridRendererHelper(org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.grids.impl.BaseGridRendererHelper) Point2D(com.ait.lienzo.client.core.types.Point2D) Optional(java.util.Optional) ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) BaseGridRendererHelper(org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.grids.impl.BaseGridRendererHelper)

Example 5 with ScenarioGrid

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGrid in project drools-wb by kiegroup.

the class ScenarioSimulationKeyboardEditHandler method perform.

@Override
public boolean perform(final GridWidget gridWidget, final boolean isShiftKeyDown, final boolean isControlKeyDown) {
    ScenarioGrid scenarioGrid = (ScenarioGrid) gridWidget;
    final AbstractScesimGridModel<? extends AbstractScesimModel, ? extends AbstractScesimData> scenarioGridModel = scenarioGrid.getModel();
    // Allows editing only if a single cell is selected
    if (!scenarioGridModel.getSelectedHeaderCells().isEmpty() && !scenarioGridModel.getSelectedCells().isEmpty()) {
        return false;
    }
    GridData.SelectedCell selectedCell = null;
    boolean isHeader = true;
    if (!scenarioGridModel.getSelectedHeaderCells().isEmpty()) {
        selectedCell = scenarioGridModel.getSelectedHeaderCells().get(0);
    } else if (scenarioGridModel.getSelectedCells().size() == 1) {
        selectedCell = scenarioGridModel.getSelectedCellsOrigin();
        isHeader = false;
    }
    if (selectedCell == null) {
        return false;
    }
    final int uiRowIndex = selectedCell.getRowIndex();
    final int uiColumnIndex = ColumnIndexUtilities.findUiColumnIndex(scenarioGridModel.getColumns(), selectedCell.getColumnIndex());
    ScenarioGridColumn scenarioGridColumn = (ScenarioGridColumn) scenarioGridModel.getColumns().get(uiColumnIndex);
    if (scenarioGridColumn == null) {
        return false;
    }
    return startEdit(scenarioGrid, uiColumnIndex, uiRowIndex, scenarioGridColumn, isHeader);
}
Also used : ScenarioGrid(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGrid) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Aggregations

ScenarioGrid (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGrid)7 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)3 Optional (java.util.Optional)2 SetGridCellValueEvent (org.drools.workbench.screens.scenariosimulation.client.events.SetGridCellValueEvent)2 ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)2 GridColumn (org.uberfire.ext.wires.core.grids.client.model.GridColumn)2 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)2 AbstractNodeMouseEvent (com.ait.lienzo.client.core.event.AbstractNodeMouseEvent)1 Point2D (com.ait.lienzo.client.core.types.Point2D)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ContextMenuEvent (com.google.gwt.event.dom.client.ContextMenuEvent)1 KeyDownEvent (com.google.gwt.event.dom.client.KeyDownEvent)1 MouseWheelEvent (com.google.gwt.event.dom.client.MouseWheelEvent)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)1 AbstractScesimModel (org.drools.scenariosimulation.api.model.AbstractScesimModel)1