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, () -> {
});
}
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);
}
}
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;
}
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;
}
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);
}
Aggregations