use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumn in project drools-wb by kiegroup.
the class BaseColumnSynchronizer method findTargetPatternIndex.
protected int findTargetPatternIndex(final MoveColumnToMetaData md) throws ModelSynchronizer.MoveVetoException {
int tgtPatternIndex = -1;
final int tgtColumnIndex = md.getTargetColumnIndex();
final List<BaseColumn> allModelColumns = model.getExpandedColumns();
final List<CompositeColumn<? extends BaseColumn>> allModelConditions = model.getConditions();
for (int patternIndex = 0; patternIndex < allModelConditions.size(); patternIndex++) {
final CompositeColumn<? extends BaseColumn> cc = allModelConditions.get(patternIndex);
final List<? extends BaseColumn> children = cc.getChildColumns();
if (children == null || children.isEmpty()) {
continue;
}
final BaseColumn firstChild = children.get(0);
final BaseColumn lastChild = children.get(children.size() - 1);
final int firstChildIndex = allModelColumns.indexOf(firstChild);
final int lastChildIndex = allModelColumns.indexOf(lastChild);
if (tgtColumnIndex >= firstChildIndex && tgtColumnIndex <= lastChildIndex) {
tgtPatternIndex = patternIndex;
break;
}
}
if (tgtPatternIndex < 0) {
throw new ModelSynchronizer.MoveVetoException();
}
return tgtPatternIndex;
}
use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumn in project drools-wb by kiegroup.
the class ConditionColumnSynchronizer method doMovePattern.
private void doMovePattern(final List<MoveColumnToMetaData> metaData) throws VetoException {
final MoveColumnToMetaData md = metaData.get(0);
final ConditionCol52 srcModelColumn = (ConditionCol52) md.getColumn();
final Pattern52 srcModelPattern = model.getPattern(srcModelColumn);
if (srcModelPattern == null) {
throw new ModelSynchronizer.MoveVetoException();
}
final List<ConditionCol52> srcModelPatternConditionColumns = srcModelPattern.getChildColumns();
final int srcModelPatternConditionColumnCount = srcModelPatternConditionColumns.size();
if (srcModelPatternConditionColumnCount == 0) {
throw new ModelSynchronizer.MoveVetoException();
}
if (srcModelPatternConditionColumnCount != metaData.size()) {
throw new ModelSynchronizer.MoveVetoException();
}
final int tgtColumnIndex = md.getTargetColumnIndex();
final int tgtPatternIndex = findTargetPatternIndex(md);
final List<BaseColumn> allModelColumns = model.getExpandedColumns();
moveModelData(tgtColumnIndex, allModelColumns.indexOf(srcModelPatternConditionColumns.get(0)), allModelColumns.indexOf(srcModelPatternConditionColumns.get(0)) + srcModelPatternConditionColumnCount - 1);
model.getConditions().remove(srcModelPattern);
model.getConditions().add(tgtPatternIndex, srcModelPattern);
}
use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumn in project drools-wb by kiegroup.
the class ConditionColumnSynchronizer method doMoveSingleCondition.
// Move a single Condition column; it must remain within the bounds of it's parent Pattern's columns
private void doMoveSingleCondition(final MoveColumnToMetaData metaData) throws VetoException {
final ConditionCol52 modelColumn = (ConditionCol52) metaData.getColumn();
final Pattern52 modelPattern = model.getPattern(modelColumn);
if (modelPattern == null) {
throw new ModelSynchronizer.MoveVetoException();
}
final List<ConditionCol52> modelPatternConditionColumns = modelPattern.getChildColumns();
final int modelPatternConditionColumnCount = modelPatternConditionColumns.size();
if (modelPatternConditionColumnCount == 0) {
throw new ModelSynchronizer.MoveVetoException();
}
final List<BaseColumn> allModelColumns = model.getExpandedColumns();
final int minColumnIndex = allModelColumns.indexOf(modelPatternConditionColumns.get(0));
final int maxColumnIndex = allModelColumns.indexOf(modelPatternConditionColumns.get(modelPatternConditionColumnCount - 1));
final int targetColumnIndex = metaData.getTargetColumnIndex();
final int sourceColumnIndex = metaData.getSourceColumnIndex();
if (targetColumnIndex < minColumnIndex || targetColumnIndex > maxColumnIndex) {
throw new ModelSynchronizer.MoveVetoException();
}
moveModelData(targetColumnIndex, sourceColumnIndex, sourceColumnIndex);
modelPatternConditionColumns.remove(modelColumn);
modelPatternConditionColumns.add(targetColumnIndex - minColumnIndex, modelColumn);
}
use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumn in project drools-wb by kiegroup.
the class GuidedDecisionTableTheme method getModelColumnType.
ModelColumnType getModelColumnType(final GridColumn<?> uiColumn) {
final int uiColumnIndex = uiModel.getColumns().indexOf(uiColumn);
final BaseColumn modelColumn = model.getExpandedColumns().get(uiColumnIndex);
if (modelColumn instanceof RowNumberCol52) {
return ModelColumnType.ROW_NUMBER;
} else if (modelColumn instanceof DescriptionCol52) {
return ModelColumnType.DESCRIPTION;
} else if (modelColumn instanceof MetadataCol52) {
return ModelColumnType.METADATA;
} else if (modelColumn instanceof AttributeCol52) {
return ModelColumnType.ATTRIBUTE;
} else if (modelColumn instanceof ConditionCol52) {
return ModelColumnType.CONDITION;
} else if (modelColumn instanceof ActionCol52) {
return ModelColumnType.ACTION;
}
// proof rendering than throw an exception.
return ModelColumnType.UNKNOWN;
}
use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumn in project drools-wb by kiegroup.
the class DependentEnumsUtilities method getDependentColumnIndexes.
@Override
public Set<Integer> getDependentColumnIndexes(final Context context) {
final int iBaseColIndex = context.getColumnIndex();
final Set<Integer> dependentColumnIndexes = new HashSet<Integer>();
// Get the column for the cell being edited
final List<BaseColumn> allColumns = this.model.getExpandedColumns();
final BaseColumn baseColumn = allColumns.get(iBaseColIndex);
// Get values for all Constraints or Actions on the same pattern as the baseColumn
if (baseColumn instanceof BRLConditionVariableColumn) {
final BRLConditionVariableColumn baseBRLConditionColumn = (BRLConditionVariableColumn) baseColumn;
final BRLConditionColumn brl = model.getBRLColumn(baseBRLConditionColumn);
final RuleModel rm = new RuleModel();
IPattern[] lhs = new IPattern[brl.getDefinition().size()];
brl.getDefinition().toArray(lhs);
rm.lhs = lhs;
final RuleModelPeerVariableVisitor peerVariableVisitor = new RuleModelPeerVariableVisitor(rm, baseBRLConditionColumn.getVarName());
List<ValueHolder> peerVariables = peerVariableVisitor.getPeerVariables();
// Add other variables values
for (ValueHolder valueHolder : peerVariables) {
switch(valueHolder.getType()) {
case TEMPLATE_KEY:
if (oracle.isDependentEnum(baseBRLConditionColumn.getFactType(), baseBRLConditionColumn.getFactField(), valueHolder.getFieldName())) {
final BRLConditionVariableColumn vc = getConditionVariableColumnIndex(brl.getChildColumns(), valueHolder.getValue());
final int iCol = allColumns.indexOf(vc);
dependentColumnIndexes.add(iCol);
}
break;
}
}
} else if (baseColumn instanceof BRLActionVariableColumn) {
final BRLActionVariableColumn baseBRLActionColumn = (BRLActionVariableColumn) baseColumn;
final BRLActionColumn brl = model.getBRLColumn(baseBRLActionColumn);
final RuleModel rm = new RuleModel();
IAction[] rhs = new IAction[brl.getDefinition().size()];
brl.getDefinition().toArray(rhs);
rm.rhs = rhs;
final RuleModelPeerVariableVisitor peerVariableVisitor = new RuleModelPeerVariableVisitor(rm, baseBRLActionColumn.getVarName());
List<ValueHolder> peerVariables = peerVariableVisitor.getPeerVariables();
// Add other variables values
for (ValueHolder valueHolder : peerVariables) {
switch(valueHolder.getType()) {
case TEMPLATE_KEY:
if (oracle.isDependentEnum(baseBRLActionColumn.getFactType(), baseBRLActionColumn.getFactField(), valueHolder.getFieldName())) {
final BRLActionVariableColumn vc = getActionVariableColumnIndex(brl.getChildColumns(), valueHolder.getValue());
final int iCol = allColumns.indexOf(vc);
dependentColumnIndexes.add(iCol);
}
break;
}
}
} else if (baseColumn instanceof ConditionCol52) {
final ConditionCol52 baseConditionColumn = (ConditionCol52) baseColumn;
final Pattern52 basePattern = this.model.getPattern(baseConditionColumn);
for (ConditionCol52 cc : basePattern.getChildColumns()) {
if (oracle.isDependentEnum(basePattern.getFactType(), baseConditionColumn.getFactField(), cc.getFactField())) {
dependentColumnIndexes.add(allColumns.indexOf(cc));
}
}
} else if (baseColumn instanceof ActionSetFieldCol52) {
final ActionSetFieldCol52 baseActionColumn = (ActionSetFieldCol52) baseColumn;
final Pattern52 basePattern = model.getConditionPattern(baseActionColumn.getBoundName());
final String binding = baseActionColumn.getBoundName();
for (ActionCol52 ac : this.model.getActionCols()) {
if (ac instanceof ActionSetFieldCol52) {
final ActionSetFieldCol52 asf = (ActionSetFieldCol52) ac;
if (asf.getBoundName().equals(binding)) {
if (oracle.isDependentEnum(basePattern.getFactType(), baseActionColumn.getFactField(), asf.getFactField())) {
dependentColumnIndexes.add(allColumns.indexOf(ac));
}
}
}
}
} else if (baseColumn instanceof ActionInsertFactCol52) {
final ActionInsertFactCol52 baseActionColumn = (ActionInsertFactCol52) baseColumn;
final String binding = baseActionColumn.getBoundName();
for (ActionCol52 ac : this.model.getActionCols()) {
if (ac instanceof ActionInsertFactCol52) {
final ActionInsertFactCol52 aif = (ActionInsertFactCol52) ac;
if (aif.getBoundName().equals(binding)) {
if (oracle.isDependentEnum(baseActionColumn.getFactType(), baseActionColumn.getFactField(), aif.getFactField())) {
dependentColumnIndexes.add(allColumns.indexOf(ac));
}
}
}
}
}
return dependentColumnIndexes;
}
Aggregations