Search in sources :

Example 16 with ScenarioHeaderMetaData

use of org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData in project drools-wb by kiegroup.

the class ScenarioSimulationGridHeaderUtilitiesTest method testIsHeaderEditableInstanceAssignedButPropertySelected.

@Test
public void testIsHeaderEditableInstanceAssignedButPropertySelected() {
    when(scenarioGridColumnOne.isInstanceAssigned()).thenReturn(true);
    final ScenarioHeaderMetaData metaDataMock = (ScenarioHeaderMetaData) scenarioGridColumnOne.getHeaderMetaData().get(0);
    when(metaDataMock.isPropertyHeader()).thenReturn(true);
    final boolean result = ScenarioSimulationGridHeaderUtilities.isEditableHeader(scenarioGridColumnOne, 0);
    assertThat(result).as("Instance Assigned but Property selected").isFalse();
}
Also used : ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) AbstractScenarioSimulationTest(org.drools.workbench.screens.scenariosimulation.client.AbstractScenarioSimulationTest) Test(org.junit.Test)

Example 17 with ScenarioHeaderMetaData

use of org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData in project drools-wb by kiegroup.

the class AbstractScesimGridModel method getInstanceLimits.

/**
 * This methods returns the <code>Range</code> of a <b>single</b> block of columns of the same instance/data object.
 * A <code>single</code> block is made of all the columns immediately to the left and right of the selected one with the same "label".
 * If there is another column with the same "label" but separated by a different column, it is not part of the group.
 * @param columnIndex
 * @param columnIndexStart the leftmost index to consider when evaluating the range
 * @return
 */
protected Range getInstanceLimits(int columnIndex, int columnIndexStart) {
    final ScenarioGridColumn column = (ScenarioGridColumn) columns.get(columnIndex);
    final String originalColumnGroup = column.getInformationHeaderMetaData().getColumnGroup();
    final ScenarioHeaderMetaData selectedInformationHeaderMetaData = column.getInformationHeaderMetaData();
    String originalColumnTitle = selectedInformationHeaderMetaData.getTitle();
    int leftPosition = columnIndex;
    while (leftPosition > columnIndexStart && ((ScenarioGridColumn) columns.get(leftPosition - 1)).getInformationHeaderMetaData().getColumnGroup().equals(originalColumnGroup) && ((ScenarioGridColumn) columns.get(leftPosition - 1)).getInformationHeaderMetaData().getTitle().equals(originalColumnTitle)) {
        leftPosition--;
    }
    int rightPosition = columnIndex;
    while (rightPosition < columns.size() - 1 && ((ScenarioGridColumn) columns.get(rightPosition + 1)).getInformationHeaderMetaData().getColumnGroup().equals(originalColumnGroup) && ((ScenarioGridColumn) columns.get(rightPosition + 1)).getInformationHeaderMetaData().getTitle().equals(originalColumnTitle)) {
        rightPosition++;
    }
    return new Range(leftPosition, rightPosition);
}
Also used : ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Example 18 with ScenarioHeaderMetaData

use of org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData in project drools-wb by kiegroup.

the class ScenarioSimulationGridHeaderUtilities method isEditableHeader.

/**
 * Checks whether the edit mode can be invoked on header cell from given column on given row.
 * @param column
 * @param uiHeaderRowIndex
 * @return true if conditions are met, false otherwise
 */
public static boolean isEditableHeader(final ScenarioGridColumn column, final Integer uiHeaderRowIndex) {
    final GridColumn.HeaderMetaData headerMetaData = column.getHeaderMetaData().get(uiHeaderRowIndex);
    if (!(headerMetaData instanceof ScenarioHeaderMetaData)) {
        throw new IllegalStateException("Header metadata has to be an instance of ScenarioHeaderMetaData");
    }
    final ScenarioHeaderMetaData scenarioHeaderMetaData = (ScenarioHeaderMetaData) headerMetaData;
    if (scenarioHeaderMetaData.isEditingMode() || scenarioHeaderMetaData.isReadOnly()) {
        return false;
    }
    if (!column.isInstanceAssigned() || !column.isEditableHeaders()) {
        return false;
    }
    return scenarioHeaderMetaData.isInstanceHeader() || (scenarioHeaderMetaData.isPropertyHeader() && column.isPropertyAssigned());
}
Also used : ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Example 19 with ScenarioHeaderMetaData

use of org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData in project drools-wb by kiegroup.

the class CommonEditHandler method manageHeaderLeftClick.

/**
 * This method check if the click happened on an <b>second level header</b> (i.e. the header of a specific column) cell. If it is so, manage it and returns <code>true</code>,
 * otherwise returns <code>false</code>
 * @param scenarioGrid
 * @param uiColumnIndex
 * @param scenarioGridColumn
 * @param uiHeaderRowIndex
 * @return
 */
protected static boolean manageHeaderLeftClick(ScenarioGrid scenarioGrid, Integer uiColumnIndex, ScenarioGridColumn scenarioGridColumn, Integer uiHeaderRowIndex) /*, EventBus eventBus*/
{
    if (!isEditableHeaderLocal(scenarioGridColumn, uiHeaderRowIndex)) {
        return false;
    }
    ScenarioHeaderMetaData clickedScenarioHeaderMetadata = (ScenarioHeaderMetaData) scenarioGridColumn.getHeaderMetaData().get(uiHeaderRowIndex);
    if (clickedScenarioHeaderMetadata == null) {
        return false;
    }
    String group = ScenarioSimulationUtils.getOriginalColumnGroup(clickedScenarioHeaderMetadata.getColumnGroup());
    switch(group) {
        case "GIVEN":
        case "EXPECT":
            return manageGivenExpectHeaderLeftClick(scenarioGrid, clickedScenarioHeaderMetadata, uiColumnIndex, uiHeaderRowIndex);
        default:
            return false;
    }
}
Also used : ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) ScenarioSimulationGridHeaderUtilities.getColumnScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationGridHeaderUtilities.getColumnScenarioHeaderMetaData)

Aggregations

ScenarioHeaderMetaData (org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData)19 ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)6 Test (org.junit.Test)6 AbstractScenarioSimulationTest (org.drools.workbench.screens.scenariosimulation.client.AbstractScenarioSimulationTest)4 GridColumn (org.uberfire.ext.wires.core.grids.client.model.GridColumn)3 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)2 FactMappingType (org.drools.scenariosimulation.api.model.FactMappingType)2 EnableTestToolsEvent (org.drools.workbench.screens.scenariosimulation.client.events.EnableTestToolsEvent)2 ReloadTestToolsEvent (org.drools.workbench.screens.scenariosimulation.client.events.ReloadTestToolsEvent)2 Before (org.junit.Before)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 AbstractNodeMouseEvent (com.ait.lienzo.client.core.event.AbstractNodeMouseEvent)1 Viewport (com.ait.lienzo.client.core.shape.Viewport)1 Point2D (com.ait.lienzo.client.core.types.Point2D)1 Date (java.util.Date)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 SortedMap (java.util.SortedMap)1 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)1