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;
}
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;
}
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;
}
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);
}
}
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());
}
Aggregations