Search in sources :

Example 26 with InterpolationVariable

use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools-wb by kiegroup.

the class DefaultGuidedDecisionTableLinkManager method hasTemplateKeys.

private boolean hasTemplateKeys(final BRLActionColumn column) {
    final Map<InterpolationVariable, Integer> ivs = new HashMap<>();
    final RuleModel rm = new RuleModel();
    column.getDefinition().forEach(rm::addRhsItem);
    final RuleModelVisitor rmv = new RuleModelVisitor(ivs);
    rmv.visit(rm);
    return ivs.size() > 0;
}
Also used : RuleModelVisitor(org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor) InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) HashMap(java.util.HashMap) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel)

Example 27 with InterpolationVariable

use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools-wb by kiegroup.

the class AbstractDecoratedTemplateDataGridWidget method setupInternalModel.

private void setupInternalModel(TemplateModel model, List<DynamicColumn<TemplateDataColumn>> columns, DynamicData data) {
    // Get interpolation variables
    InterpolationVariable[] vars = model.getInterpolationVariablesList();
    if (vars.length == 0) {
        return;
    }
    int colIndex = 0;
    String[][] modelData = model.getTableAsArray();
    // to be enough rows to receive the columns data
    for (int iRow = 0; iRow < modelData.length; iRow++) {
        data.addRow();
    }
    // Add corresponding columns to table
    for (InterpolationVariable var : vars) {
        TemplateDataColumn col = new TemplateDataColumn(var.getVarName(), var.getDataType(), var.getFactType(), var.getFactField());
        DynamicColumn<TemplateDataColumn> column = new DynamicColumn<TemplateDataColumn>(col, cellFactory.getCell(col), colIndex, eventBus);
        columns.add(column);
        data.addColumn(colIndex, makeColumnData(modelData, col, colIndex++), true);
    }
}
Also used : InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) DynamicColumn(org.kie.workbench.common.widgets.decoratedgrid.client.widget.DynamicColumn)

Example 28 with InterpolationVariable

use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools-wb by kiegroup.

the class TemplateDataCellValueFactory method makeUIRowData.

/**
 * Construct a new row of data for the MergableGridWidget
 *
 * @return
 */
@Override
public DynamicDataRow makeUIRowData() {
    DynamicDataRow data = new DynamicDataRow();
    InterpolationVariable[] variables = model.getInterpolationVariablesList();
    for (InterpolationVariable var : variables) {
        TemplateDataColumn column = makeModelColumn(var);
        String dcv = makeModelCellValue(column);
        CellValue<? extends Comparable<?>> cell = convertModelCellValue(column, dcv);
        data.add(cell);
    }
    return data;
}
Also used : InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) DynamicDataRow(org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.DynamicDataRow)

Example 29 with InterpolationVariable

use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools-wb by kiegroup.

the class TemplateDataTableWidget method onUpdateModel.

public void onUpdateModel(UpdateModelEvent event) {
    // Copy data into the underlying model
    Map<Coordinate, List<List<CellValue<? extends Comparable<?>>>>> updates = event.getUpdates();
    for (Map.Entry<Coordinate, List<List<CellValue<? extends Comparable<?>>>>> e : updates.entrySet()) {
        // Coordinate of change
        Coordinate originCoordinate = e.getKey();
        int originRowIndex = originCoordinate.getRow();
        int originColumnIndex = originCoordinate.getCol();
        // Changed data
        List<List<CellValue<? extends Comparable<?>>>> data = e.getValue();
        InterpolationVariable[] vars = model.getInterpolationVariablesList();
        for (int iRow = 0; iRow < data.size(); iRow++) {
            List<CellValue<? extends Comparable<?>>> rowData = data.get(iRow);
            int targetRowIndex = originRowIndex + iRow;
            for (int iCol = 0; iCol < rowData.size(); iCol++) {
                int targetColumnIndex = originColumnIndex + iCol;
                CellValue<? extends Comparable<?>> changedCell = rowData.get(iCol);
                InterpolationVariable var = vars[targetColumnIndex];
                TemplateDataColumn col = new TemplateDataColumn(var.getVarName(), var.getDataType(), var.getFactType(), var.getFactField());
                String dcv = cellValueFactory.convertToModelCell(col, changedCell);
                List<String> columnData = model.getTable().get(var.getVarName());
                columnData.set(targetRowIndex, dcv);
            }
        }
    }
}
Also used : InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) Coordinate(org.kie.workbench.common.widgets.decoratedgrid.client.widget.data.Coordinate) ArrayList(java.util.ArrayList) List(java.util.List) CellValue(org.kie.workbench.common.widgets.decoratedgrid.client.widget.CellValue) Map(java.util.Map)

Example 30 with InterpolationVariable

use of org.drools.workbench.models.datamodel.rule.InterpolationVariable in project drools-wb by kiegroup.

the class TemplateDropDownManager method getDependentColumnIndexes.

@Override
public Set<Integer> getDependentColumnIndexes(final Context context) {
    final int iBaseColIndex = context.getColumn();
    final Set<Integer> dependentColumnIndexes = new HashSet<Integer>();
    // Get variable for the column being edited
    final InterpolationVariable[] allVariables = this.model.getInterpolationVariablesList();
    final InterpolationVariable baseVariable = allVariables[iBaseColIndex];
    final String baseVariableName = baseVariable.getVarName();
    // Get other variables (and literals) in the same scope as the base variable
    final RuleModelPeerVariableVisitor peerVariableVisitor = new RuleModelPeerVariableVisitor(model, baseVariableName);
    List<RuleModelPeerVariableVisitor.ValueHolder> peerVariables = peerVariableVisitor.getPeerVariables();
    // Add other variables values
    for (RuleModelPeerVariableVisitor.ValueHolder valueHolder : peerVariables) {
        switch(valueHolder.getType()) {
            case TEMPLATE_KEY:
                final int iCol = getVariableColumnIndex(valueHolder.getValue());
                final InterpolationVariable variable = allVariables[iCol];
                final String field = variable.getFactField();
                if (oracle.isDependentEnum(baseVariable.getFactType(), baseVariable.getFactField(), field)) {
                    dependentColumnIndexes.add(iCol);
                }
                break;
        }
    }
    return dependentColumnIndexes;
}
Also used : InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) HashSet(java.util.HashSet)

Aggregations

InterpolationVariable (org.drools.workbench.models.datamodel.rule.InterpolationVariable)31 HashMap (java.util.HashMap)14 RuleModelVisitor (org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor)10 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)8 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)8 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)6 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)6 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)6 Map (java.util.Map)4 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)4 IAction (org.drools.workbench.models.datamodel.rule.IAction)3 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)3 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)3 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)3 BRLRuleModel (org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel)3 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)2 BRLVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLVariableColumn)2 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)2