use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.
the class ScenarioSimulationGridWidgetMouseEventHandler method handleBodyCell.
/**
* Checks if a {@link AbstractNodeMouseEvent} happened within a {@link GridCell}. If the
* {@link AbstractNodeMouseEvent} is found to have happened within a cell, the {@link GridCell#getSupportedEditAction()}
* is checked to {@link Object#equals(Object)} that for the {@link AbstractNodeMouseEvent}. If they equal then the
* {@link GridCell} is put into "edit" mode via {@link GridWidget#startEditingCell(Point2D)}.
*/
@Override
public boolean handleBodyCell(final GridWidget gridWidget, final Point2D relativeLocation, final int uiRowIndex, final int uiColumnIndex, final AbstractNodeMouseEvent event) {
final GridData gridData = gridWidget.getModel();
if (gridData.getSelectedCells().size() == 1) {
final GridCell<?> cell = gridData.getCell(uiRowIndex, uiColumnIndex);
final GridCellEditAction cellEditAction = cell == null ? GridCell.DEFAULT_EDIT_ACTION : cell.getSupportedEditAction();
if (editSupportedLocal(cellEditAction, event)) {
ScenarioGridColumn scenarioGridColumn = (ScenarioGridColumn) gridWidget.getModel().getColumns().get(uiColumnIndex);
return startEditLocal((ScenarioGrid) gridWidget, uiColumnIndex, scenarioGridColumn, uiRowIndex, false);
}
}
return false;
}
use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.
the class ScenarioSimulationGridHeaderUtilitiesTest method mockGridColumn.
private ScenarioGridColumn mockGridColumn(final double width, final List<GridColumn.HeaderMetaData> headerMetaData, final String columnTitle, final String COLUMN_GROUP) {
final ScenarioGridColumn uiColumn = mock(ScenarioGridColumn.class);
doReturn(headerMetaData).when(uiColumn).getHeaderMetaData();
doReturn(width).when(uiColumn).getWidth();
final ScenarioHeaderMetaData informationHeader = mock(ScenarioHeaderMetaData.class);
when(informationHeader.getColumnGroup()).thenReturn(COLUMN_GROUP);
when(informationHeader.getTitle()).thenReturn(columnTitle);
when(uiColumn.getInformationHeaderMetaData()).thenReturn(informationHeader);
when(uiColumn.isEditableHeaders()).thenReturn(true);
return uiColumn;
}
use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.
the class ScenarioSimulationBuildersTest method testScenarioGridColumnBuilder.
@Test
public void testScenarioGridColumnBuilder() {
ScenarioSimulationBuilders.ScenarioGridColumnBuilder builder = ScenarioSimulationBuilders.ScenarioGridColumnBuilder.get(scenarioCellTextAreaSingletonDOMElementFactoryMock, headerBuilderMock);
builder.setPlaceHolder(PLACEHOLDER);
ScenarioGridColumn retrieved = builder.build();
assertNotNull(retrieved);
assertEquals(PLACEHOLDER, retrieved.getPlaceHolder());
assertTrue(retrieved.isReadOnly());
assertFalse(retrieved.isMovable());
assertNotNull(retrieved.getHeaderMetaData());
assertFalse(retrieved.getHeaderMetaData().isEmpty());
assertEquals(ColumnWidthMode.AUTO, retrieved.getColumnWidthMode());
}
use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.
the class ScenarioSimulationGridHeaderUtilitiesTest method testHeaderMetadataInstanceOf.
@Test
public void testHeaderMetadataInstanceOf() {
final ScenarioGridColumn invalidColumn = mockGridColumn(100, Collections.singletonList(mock(GridColumn.HeaderMetaData.class)));
assertThatThrownBy(() -> ScenarioSimulationGridHeaderUtilities.isEditableHeader(invalidColumn, 0)).isInstanceOf(IllegalStateException.class).hasMessage("Header metadata has to be an instance of ScenarioHeaderMetaData");
}
use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.
the class DuplicateInstanceCommand method executeIfSelectedColumn.
@Override
protected void executeIfSelectedColumn(ScenarioSimulationContext context, ScenarioGridColumn selectedColumn) {
final AbstractScesimGridModel<? extends AbstractScesimModel, ? extends AbstractScesimData> selectedScenarioGridModel = context.getAbstractScesimGridModelByGridWidget(gridWidget);
/* Generating the new instance alias with following schema: <original instance name> + '_copy_' + <number of existing instances> */
int instancesCount = selectedScenarioGridModel.getInstancesCount(selectedColumn.getFactIdentifier().getClassName());
String alias = selectedColumn.getInformationHeaderMetaData().getTitle().split(COPY_LABEL)[0] + COPY_LABEL + instancesCount;
/* For every columns which belongs to the selected instance, it creates a new column and assign it the duplicated instance
* and the duplicated property, if are assigned */
int columnPosition = selectedScenarioGridModel.getInstanceLimits(selectedScenarioGridModel.getColumns().indexOf(selectedColumn)).getMaxRowIndex() + 1;
AtomicInteger nextColumnPosition = new AtomicInteger(columnPosition);
selectedScenarioGridModel.getInstanceScenarioGridColumns(selectedColumn).forEach(originalColumn -> {
ScenarioGridColumn createdColumn = insertNewColumn(context, originalColumn, nextColumnPosition.getAndIncrement(), false);
if (originalColumn.isInstanceAssigned()) {
setInstanceHeader(context, createdColumn, alias, originalColumn.getFactIdentifier().getClassName());
if (originalColumn.isPropertyAssigned()) {
int originalColumnIndex = selectedScenarioGridModel.getColumns().indexOf(originalColumn);
final FactMapping originalFactMapping = selectedScenarioGridModel.getAbstractScesimModel().get().getScesimModelDescriptor().getFactMappingByIndex(originalColumnIndex);
factMappingValueType = originalFactMapping.getFactMappingValueType();
/* Rebuilt propertyNameElements, which is composed by: factName.property . The property MUST be the original property name */
List<String> propertyNameElements = new ArrayList<>();
propertyNameElements.add(alias);
propertyNameElements.addAll(originalFactMapping.getExpressionElementsWithoutClass().stream().map(ExpressionElement::getStep).collect(Collectors.toList()));
setPropertyHeader(context, createdColumn, originalColumn.getFactIdentifier().getClassName(), propertyNameElements, originalFactMapping.getClassName(), originalColumn.getPropertyHeaderMetaData().getTitle());
/* It copies the properties values */
int createdColumnIndex = selectedScenarioGridModel.getColumns().indexOf(createdColumn);
selectedScenarioGridModel.duplicateColumnValues(originalColumnIndex, createdColumnIndex);
}
}
});
}
Aggregations