Search in sources :

Example 1 with AbstractScesimData

use of org.drools.scenariosimulation.api.model.AbstractScesimData 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 2 with AbstractScesimData

use of org.drools.scenariosimulation.api.model.AbstractScesimData in project drools-wb by kiegroup.

the class ScenarioCsvImportExport method exportData.

public String exportData(AbstractScesimModel<? extends AbstractScesimData> scesimModel) throws IOException {
    StringBuilder stringBuilder = new StringBuilder();
    List<FactMapping> factMappings = scesimModel.getScesimModelDescriptor().getUnmodifiableFactMappings();
    CSVPrinter printer = new CSVPrinter(stringBuilder, CSVFormat.DEFAULT);
    generateHeader(factMappings, printer);
    for (AbstractScesimData scesimData : scesimModel.getUnmodifiableData()) {
        List<Object> values = new ArrayList<>();
        for (FactMapping factMapping : factMappings) {
            Optional<FactMappingValue> factMappingValue = scesimData.getFactMappingValue(factMapping.getFactIdentifier(), factMapping.getExpressionIdentifier());
            values.add(factMappingValue.map(FactMappingValue::getRawValue).orElse(""));
        }
        printer.printRecord(values.toArray());
    }
    printer.close();
    return stringBuilder.toString();
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) ArrayList(java.util.ArrayList)

Example 3 with AbstractScesimData

use of org.drools.scenariosimulation.api.model.AbstractScesimData in project drools-wb by kiegroup.

the class AbstractDataManagementStrategy method getPropertiesToHide.

/**
 * This method returns a <code>List</code> with the properties of a given <b>Type</b> (Fact, class, other dmn defined) instance,
 * to be hidden from the right panel for the selected column.
 * <p>
 * If click happen on an already assigned property, <b>all</b> all the properties of given type should be shown;
 * if, instead, click is on an unassigned property, the already assigned properties must be hidden.
 * (e.g. inside GIVEN there is an "Author" group; if clicking on "books" property header, this method returns  an <b>empty</b> <code>List</code>;
 * if click is on an unassigned property column, this method returns a <code>List</code>.
 * with all the <b>already assigned</b> Author's properties)
 * @param selectedColumn
 * @param abstractScesimGridModel
 * @return
 */
protected <T extends AbstractScesimModel<E>, E extends AbstractScesimData> List<List<String>> getPropertiesToHide(ScenarioGridColumn selectedColumn, AbstractScesimGridModel<T, E> abstractScesimGridModel) {
    List<List<String>> toReturn = new ArrayList<>();
    if (!selectedColumn.isPropertyAssigned()) {
        abstractScesimGridModel.getAbstractScesimModel().ifPresent(simulation -> {
            final ScesimModelDescriptor simulationDescriptor = simulation.getScesimModelDescriptor();
            List<ScenarioGridColumn> instanceColumns = abstractScesimGridModel.getInstanceScenarioGridColumns(selectedColumn);
            toReturn.addAll(instanceColumns.stream().filter(ScenarioGridColumn::isPropertyAssigned).map(instanceColumn -> abstractScesimGridModel.getColumns().indexOf(instanceColumn)).map(columnIndex -> {
                List<String> propertyNameElements = simulationDescriptor.getFactMappingByIndex(columnIndex).getExpressionElementsWithoutClass().stream().map(ExpressionElement::getStep).collect(Collectors.toList());
                if (propertyNameElements.isEmpty()) {
                    propertyNameElements.add(VALUE);
                }
                return Collections.unmodifiableList(propertyNameElements);
            }).collect(Collectors.toList()));
        });
    }
    return toReturn;
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) GridWidget(org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) VALUE(org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE) Map(java.util.Map) AbstractScesimGridModel(org.drools.workbench.screens.scenariosimulation.client.models.AbstractScesimGridModel) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) TestToolsPresenterData(org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsPresenterData) Set(java.util.Set) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) Collectors(java.util.stream.Collectors) TestToolsView(org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsView) Objects(java.util.Objects) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) List(java.util.List) TreeMap(java.util.TreeMap) Collections(java.util.Collections) SortedMap(java.util.SortedMap) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Example 4 with AbstractScesimData

use of org.drools.scenariosimulation.api.model.AbstractScesimData in project drools-wb by kiegroup.

the class ScenarioSimulationMainGridPanelMouseMoveHandler method manageBodyCoordinates.

@Override
protected boolean manageBodyCoordinates(Integer uiRowIndex, Integer uiColumnIndex) {
    /* In this case, the mouse is out ot the GridLayer, then return false, without perform any action */
    if (uiColumnIndex == -1 || uiRowIndex == -1) {
        return false;
    }
    /* If the mouse position is the same of the previous one and the popover is already open, it does nothing.
         * It returns true because the click happened on an column of a grid row */
    if (uiRowIndex.equals(currentlyShownBodyRowIndex) && uiColumnIndex.equals(currentlyShownBodyColumnIndex) && errorReportPopupPresenter.isShown()) {
        return true;
    }
    /* It updates the coordinates of the current shown cell */
    currentlyShownBodyRowIndex = uiRowIndex;
    currentlyShownBodyColumnIndex = uiColumnIndex;
    final Optional<AbstractScesimModel<? extends AbstractScesimData>> optionalAbstractScesimModel = scenarioGrid.getModel().getAbstractScesimModel();
    final AbstractScesimModel<? extends AbstractScesimData> scesimModel = optionalAbstractScesimModel.orElseThrow(IllegalStateException::new);
    final AbstractScesimData scenarioByIndex = scesimModel.getDataByIndex(uiRowIndex);
    final FactMapping factMapping = scesimModel.getScesimModelDescriptor().getFactMappingByIndex(uiColumnIndex);
    final Optional<FactMappingValue> factMappingValueOptional = scenarioByIndex.getFactMappingValue(factMapping);
    factMappingValueOptional.ifPresent(factMappingValue -> manageFactMappingValue(factMappingValue, uiRowIndex, uiColumnIndex));
    return true;
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel)

Example 5 with AbstractScesimData

use of org.drools.scenariosimulation.api.model.AbstractScesimData in project drools-wb by kiegroup.

the class ScenarioGridTest method setup.

@Before
public void setup() {
    simulation = getSimulation();
    when(scenarioGridColumnMock.getPropertyHeaderMetaData()).thenReturn(propertyHeaderMetadataMock);
    when(scenarioGridModelMock.getAbstractScesimModel()).thenReturn(Optional.of(simulation));
    when(scenarioGridModelMock.getGridWidget()).thenReturn(GridWidget.SIMULATION);
    when(scenarioGridModelMock.getScenarioExpressionCellTextAreaSingletonDOMElementFactory()).thenReturn(expressionCellTextAreaSingletonDOMElementFactoryMock);
    when(scenarioGridModelMock.getCollectionEditorSingletonDOMElementFactory()).thenReturn(collectionEditorSingletonDOMElementFactory);
    factIdentifierGiven = FactIdentifier.create("GIVEN", "GIVEN");
    factIdentifierInteger = FactIdentifier.create("Integer", "java.lang.Integer");
    factMappingDescription = new FactMapping(EXPRESSION_ALIAS_DESCRIPTION, FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION);
    factMappingGiven = new FactMapping(EXPRESSION_ALIAS_GIVEN, factIdentifierGiven, new ExpressionIdentifier("GIVEN", FactMappingType.GIVEN));
    factMappingInteger = new FactMapping(EXPRESSION_ALIAS_INTEGER, factIdentifierInteger, new ExpressionIdentifier("GIVEN", FactMappingType.GIVEN));
    scenarioGridSpy = spy(new ScenarioGrid(scenarioGridModelMock, scenarioGridLayerMock, scenarioGridRendererMock, scenarioContextMenuRegistryMock) {

        @Override
        protected <T extends AbstractScesimData> void appendRow(int rowIndex, T scesimData) {
        // do nothing
        }

        @Override
        protected ScenarioSimulationBuilders.HeaderBuilder getHeaderBuilderLocal(String instanceTitle, String propertyTitle, String columnId, String columnGroup, FactMappingType factMappingType) {
            return headerBuilderMock;
        }

        @Override
        protected ScenarioGridColumn getScenarioGridColumnLocal(ScenarioSimulationBuilders.HeaderBuilder headerBuilder, String placeHolder) {
            return scenarioGridColumnMock;
        }

        @Override
        protected BaseGridRendererHelper getBaseGridRendererHelper() {
            return rendererHelperMock;
        }

        @Override
        public Viewport getViewport() {
            return viewportMock;
        }

        @Override
        protected ScenarioHeaderMetaData getColumnScenarioHeaderMetaData(final ScenarioGridColumn scenarioGridColumn, final int rowIndex) {
            return propertyHeaderMetadataMock;
        }

        @Override
        protected EnableTestToolsEvent getEnableTestToolsEvent(final ScenarioGrid scenarioGrid, final ScenarioGridColumn scenarioGridColumn, final ScenarioHeaderMetaData scenarioHeaderMetaData, int uiColumnIndex, String group) {
            return new EnableTestToolsEvent();
        }

        @Override
        public Layer getLayer() {
            return scenarioGridLayerMock;
        }
    });
    when(rendererHelperMock.getRenderingInformation()).thenReturn(renderingInformationMock);
    when(renderingInformationMock.getHeaderRowsHeight()).thenReturn(HEADER_ROWS_HEIGHT);
    when(renderingInformationMock.getFloatingBlockInformation()).thenReturn(floatingBlockInformationMock);
    when(propertyHeaderMetadataMock.getColumnGroup()).thenReturn(GRID_COLUMN_GROUP);
    scenarioGridSpy.setEventBus(eventBusMock);
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioSimulationBuilders(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationBuilders) HEADER_ROWS_HEIGHT(org.drools.workbench.screens.scenariosimulation.client.TestProperties.HEADER_ROWS_HEIGHT) TEST(org.drools.workbench.screens.scenariosimulation.client.TestProperties.TEST) ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) EnableTestToolsEvent(org.drools.workbench.screens.scenariosimulation.client.events.EnableTestToolsEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Before(org.junit.Before)

Aggregations

AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)6 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)5 AbstractScesimModel (org.drools.scenariosimulation.api.model.AbstractScesimModel)3 ScenarioSimulationContext (org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 FactMappingType (org.drools.scenariosimulation.api.model.FactMappingType)2 FactMappingValue (org.drools.scenariosimulation.api.model.FactMappingValue)2 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)2 VALUE (org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE)2 AbstractScesimGridModel (org.drools.workbench.screens.scenariosimulation.client.models.AbstractScesimGridModel)2 ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)2 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 Collections (java.util.Collections)1