Search in sources :

Example 26 with ScenarioGridColumn

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;
}
Also used : GridCellEditAction(org.uberfire.ext.wires.core.grids.client.model.GridCellEditAction) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Example 27 with ScenarioGridColumn

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;
}
Also used : ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Example 28 with ScenarioGridColumn

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());
}
Also used : ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) Test(org.junit.Test)

Example 29 with ScenarioGridColumn

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");
}
Also used : GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) AbstractScenarioSimulationTest(org.drools.workbench.screens.scenariosimulation.client.AbstractScenarioSimulationTest) Test(org.junit.Test)

Example 30 with ScenarioGridColumn

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);
            }
        }
    });
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Aggregations

ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)32 ScenarioHeaderMetaData (org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData)10 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)9 FactMappingType (org.drools.scenariosimulation.api.model.FactMappingType)8 ScenarioGridCellValue (org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)8 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 ScenarioGridCell (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell)7 GridColumn (org.uberfire.ext.wires.core.grids.client.model.GridColumn)7 List (java.util.List)6 Objects (java.util.Objects)6 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)6 ExpressionElement (org.drools.scenariosimulation.api.model.ExpressionElement)6 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)6 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)6 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)6 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)6 Collections (java.util.Collections)5 Optional (java.util.Optional)5 Set (java.util.Set)5