Search in sources :

Example 16 with ScenarioGridColumn

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.

the class AbstractDataManagementStrategy method getPropertiesToHide.

/**
 * This method returns a <code>Map</code> with the properties of a given <b>Type</b> (Fact, class, other dmn defined) instance,
 * to be hidden from the right panel.
 * key: the name of the Fact class (ex. Author), value: list of properties to hide from right panel
 * 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, the <b>value</b> of the <code>Map</code> returned by this method is an <b>empty</b> <code>List</code>;
 * if click is on an unassigned property column, the <b>value</b> of the <code>Map</code> returned by this method is a <code>List</code>.
 * with all the <b>already assigned</b> Author's properties)
 * @param abstractScesimGridModel
 * @return
 */
public <T extends AbstractScesimModel<E>, E extends AbstractScesimData> Map<String, List<List<String>>> getPropertiesToHide(AbstractScesimGridModel<T, E> abstractScesimGridModel) {
    final Map<String, List<List<String>>> toReturn = new HashMap<>();
    final ScenarioGridColumn selectedColumn = (ScenarioGridColumn) abstractScesimGridModel.getSelectedColumn();
    if (selectedColumn != null && selectedColumn.isInstanceAssigned()) {
        toReturn.put(selectedColumn.getInformationHeaderMetaData().getTitle(), getPropertiesToHide(selectedColumn, abstractScesimGridModel));
    }
    return toReturn;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Example 17 with ScenarioGridColumn

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn 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 18 with ScenarioGridColumn

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.

the class AbstractSelectedColumnCommand method insertNewColumn.

/**
 * It inserts a new <code>ScenarioGridColumn</code> in <code>ScenarioGridModel</code>
 * @param context It contains the <b>Context</b> inside which the commands will be executed
 * @param selectedColumn The selected <code>ScenarioGridColumn</code> where the command was launched
 * @param columnPosition Used to define in which position the new column should be added
 * @param cloneInstance If true, it create a new column inside the same instance of the selected column
 * @return The created <code>ScenarioGridColumn</code>
 */
protected ScenarioGridColumn insertNewColumn(ScenarioSimulationContext context, ScenarioGridColumn selectedColumn, int columnPosition, boolean cloneInstance) {
    final ScenarioHeaderMetaData selectedInformationHeaderMetaData = selectedColumn.getInformationHeaderMetaData();
    String columnGroup = selectedInformationHeaderMetaData.getColumnGroup();
    String originalInstanceTitle = selectedInformationHeaderMetaData.getTitle();
    final FactMappingType factMappingType = FactMappingType.valueOf(columnGroup.toUpperCase());
    final Map.Entry<String, String> validPlaceholders = context.getAbstractScesimGridModelByGridWidget(gridWidget).getValidPlaceholders();
    String instanceTitle = cloneInstance ? originalInstanceTitle : validPlaceholders.getKey();
    String propertyTitle = validPlaceholders.getValue();
    String placeHolder = ScenarioSimulationEditorConstants.INSTANCE.defineValidType();
    final ScenarioGridColumn scenarioGridColumnLocal = getScenarioGridColumnLocal(instanceTitle, propertyTitle, String.valueOf(new Date().getTime()), columnGroup, factMappingType, context.getScenarioHeaderTextBoxSingletonDOMElementFactory(gridWidget), context.getScenarioCellTextAreaSingletonDOMElementFactory(gridWidget), placeHolder);
    if (cloneInstance) {
        scenarioGridColumnLocal.setFactIdentifier(selectedColumn.getFactIdentifier());
    }
    scenarioGridColumnLocal.setInstanceAssigned(cloneInstance);
    scenarioGridColumnLocal.setPropertyAssigned(false);
    context.getAbstractScesimGridModelByGridWidget(gridWidget).insertColumn(columnPosition, scenarioGridColumnLocal);
    return scenarioGridColumnLocal;
}
Also used : ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) Map(java.util.Map) SortedMap(java.util.SortedMap) Date(java.util.Date)

Example 19 with ScenarioGridColumn

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.

the class AbstractSelectedColumnCommand method setPropertyHeader.

/**
 * It assigns a property to the selected <code>ScenarioGridColumn</code>
 * @param context It contains the <b>Context</b> inside which the commands will be executed
 * @param selectedColumn The selected <code>ScenarioGridColumn</code> where the command was launched
 * @param factIdentifier The <code>FactIdentifier</code> associated to the selected column
 * @param propertyNameElements The <code>List</code> with the path instance_name.property.name (eg. Author.isAlive)
 * @param propertyClass it contains the full classname of the property (eg. com.Author)
 * @param propertyTitle The title to assign to this property.
 */
protected void setPropertyHeader(ScenarioSimulationContext context, ScenarioGridColumn selectedColumn, FactIdentifier factIdentifier, List<String> propertyNameElements, String propertyClass, String propertyTitle) {
    final ScenarioSimulationModel.Type simulationModelType = context.getScenarioSimulationModel().getSettings().getType();
    if (propertyTitle == null) {
        throw new IllegalArgumentException("Property title can not be null");
    }
    int columnIndex = context.getAbstractScesimGridModelByGridWidget(gridWidget).getColumns().indexOf(selectedColumn);
    String instanceAliasName = propertyNameElements.get(0);
    if (selectedColumn.isInstanceAssigned() && !instanceAliasName.equals(selectedColumn.getInformationHeaderMetaData().getTitle())) {
        throw new IllegalArgumentException("It's not possible to assign this property");
    }
    String factName = simulationModelType.equals(ScenarioSimulationModel.Type.DMN) ? factIdentifier.getName() : factIdentifier.getClassNameWithoutPackage();
    final GridData.Range instanceLimits = context.getAbstractScesimGridModelByGridWidget(gridWidget).getInstanceLimits(columnIndex);
    IntStream.range(instanceLimits.getMinRowIndex(), instanceLimits.getMaxRowIndex() + 1).forEach(index -> {
        final ScenarioGridColumn scenarioGridColumn = (ScenarioGridColumn) context.getAbstractScesimGridModelByGridWidget(gridWidget).getColumns().get(index);
        if (!scenarioGridColumn.isInstanceAssigned()) {
            // We have not defined the instance, yet
            setInstanceHeaderMetaData(scenarioGridColumn, instanceAliasName, factIdentifier);
        }
    });
    selectedColumn.setPropertyAssigned(true);
    selectedColumn.getPropertyHeaderMetaData().setColumnGroup(getColumnSubGroup(selectedColumn.getInformationHeaderMetaData().getColumnGroup()));
    setPropertyMetaData(selectedColumn.getPropertyHeaderMetaData(), propertyTitle, false, selectedColumn, ScenarioSimulationUtils.getPlaceHolder(selectedColumn.isInstanceAssigned(), selectedColumn.isPropertyAssigned(), factMappingValueType, propertyClass));
    context.getAbstractScesimGridModelByGridWidget(gridWidget).updateColumnProperty(columnIndex, selectedColumn, propertyNameElements, propertyClass, context.getStatus().isKeepData(), factMappingValueType, context.getScenarioSimulationModel().getSettings().getType());
    if (ScenarioSimulationSharedUtils.isCollectionOrMap(propertyClass) && factMappingValueType.equals(FactMappingValueType.NOT_EXPRESSION)) {
        manageCollectionProperty(context, selectedColumn, factName, columnIndex, propertyNameElements);
    } else {
        selectedColumn.setFactory(context.getAbstractScesimGridModelByGridWidget(gridWidget).getDOMElementFactory(propertyClass, context.getScenarioSimulationModel().getSettings().getType(), factMappingValueType));
    }
    if (context.getScenarioSimulationEditorPresenter() != null) {
        context.getScenarioSimulationEditorPresenter().reloadTestTools(false);
    }
}
Also used : GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel)

Example 20 with ScenarioGridColumn

use of org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn in project drools-wb by kiegroup.

the class AbstractInsertColumnCommand method commonInsertColumnCommand.

public void commonInsertColumnCommand(ScenarioSimulationContext context, ScenarioSimulationContext.Status status, int index) {
    FactMappingType factMappingType = FactMappingType.valueOf(status.getColumnGroup().toUpperCase());
    Map.Entry<String, String> validPlaceholders = context.getAbstractScesimGridModelByGridWidget(gridWidget).getValidPlaceholders();
    String instanceTitle = validPlaceholders.getKey();
    String propertyTitle = validPlaceholders.getValue();
    final ScenarioGridColumn scenarioGridColumnLocal = getScenarioGridColumnLocal(instanceTitle, propertyTitle, status.getColumnId(), status.getColumnGroup(), factMappingType, context.getScenarioHeaderTextBoxSingletonDOMElementFactory(gridWidget), context.getScenarioCellTextAreaSingletonDOMElementFactory(gridWidget), ScenarioSimulationEditorConstants.INSTANCE.defineValidType());
    context.getAbstractScesimGridModelByGridWidget(gridWidget).insertColumn(index, scenarioGridColumnLocal);
    context.getSelectedScenarioGridLayer().ifPresent(layer -> layer.getScenarioGrid().selectCurrentHeaderCellGroup());
}
Also used : FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) Map(java.util.Map)

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