Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 JBoss Inc
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"); you may not
   * use this file except in compliance with the License. You may obtain a copy of
   * the License at
   * 
   * http://www.apache.org/licenses/LICENSE-2.0
   * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  * License for the specific language governing permissions and limitations under
  * the License.
  */
 package org.drools.workbench.screens.guided.dtable.client.widget.table;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
A utility class to get the values of all Constraints\Actions in the scope of a Template Key to drive dependent enumerations. A value is in scope if it is on a Constraint or Action on the same Pattern of the base column.
 
         implements
 
     private final PackageDataModelOracle oracle;
     private final GuidedDecisionTable52 model;
     private final DTCellValueUtilities utilities;
     private DynamicData data;
 
     public DecisionTableDropDownManagerfinal GuidedDecisionTable52 model,
                                          final PackageDataModelOracle oracle ) {
         if ( model == null ) {
             throw new IllegalArgumentException"model cannot be null" );
         }
         if ( oracle == null ) {
             throw new IllegalArgumentException"oracle cannot be null" );
         }
         this. = new DecisionTableCellValueFactorymodel,
                                                                    oracle );
         this. = new DTCellValueUtilitiesmodel,
                                                    oracle );
         this. = model;
         this. = oracle;
     }
 
     public DecisionTableDropDownManagerfinal GuidedDecisionTable52 model,
                                          final DynamicData data,
                                          final PackageDataModelOracle oracle ) {
         if ( model == null ) {
             throw new IllegalArgumentException"model cannot be null" );
         }
         if ( data == null ) {
             throw new IllegalArgumentException"data cannot be null" );
         }
         if ( oracle == null ) {
             throw new IllegalArgumentException"oracle cannot be null" );
         }
         this. = new DecisionTableCellValueFactorymodel,
                                                                    oracle );
         this. = new DTCellValueUtilitiesmodel,
                                                    oracle );
         this. = model;
         this. = data;
         this. = oracle;
     }
 
    @Override
    public void setDataDynamicData data ) {
        if ( data == null ) {
            throw new IllegalArgumentException"data cannot be null" );
        }
        this. = data;
    }

    
Create a map of Field Values keyed on Field Names used by SuggestionCompletionEngine.getEnums(String, String, Map<String, String>) to drive dependent enumerations.

Parameters:
context The Context of the cell being edited containing physical coordinate in the data-space.
    @Override
    public Map<StringStringgetCurrentValueMapContext context ) {
        Map<StringStringcurrentValueMap = new HashMap<StringString>();
        final int iBaseRowIndex = context.getIndex();
        final int iBaseColIndex = context.getColumn();
        final DynamicDataRow rowData = this..getiBaseRowIndex );
        //Get the column for the cell being edited
        List<BaseColumnallColumns = this..getExpandedColumns();
        BaseColumn baseColumn = allColumns.getiBaseColIndex );
        //Get values for all Constraints or Actions on the same pattern as the baseColumn
        if ( baseColumn instanceof BRLConditionVariableColumn ) {
            final BRLConditionVariableColumn baseBRLConditionColumn = (BRLConditionVariableColumnbaseColumn;
            final BRLConditionColumn brl = .getBRLColumnbaseBRLConditionColumn );
            final RuleModel rm = new RuleModel();
            IPattern[] lhs = new IPatternbrl.getDefinition().size() ];
            brl.getDefinition().toArraylhs );
            rm.lhs = lhs;
            final RuleModelPeerVariableVisitor peerVariableVisitor = new RuleModelPeerVariableVisitorrm,
                                                                                                       baseBRLConditionColumn.getVarName() );
            List<RuleModelPeerVariableVisitor.ValueHolderpeerVariables = peerVariableVisitor.getPeerVariables();
            //Add other variables values
            for ( ValueHolder valueHolder : peerVariables ) {
                switch ( valueHolder.getType() ) {
                    case :
                        final BRLConditionVariableColumn vc = getConditionVariableColumnIndexbrl.getChildColumns(),
                                                                                               valueHolder.getValue() );
                        final int iCol = .getExpandedColumns().indexOfvc );
                        final CellValue<?> cv = this..getiBaseRowIndex ).getiCol );
                        final String field = vc.getFactField();
                        final String value = getValuevc,
                                                       cv );
                        currentValueMap.putfield,
                                             value );
                        break;
                    case :
                        currentValueMap.putvalueHolder.getFieldName(),
                                             valueHolder.getValue() );
                }
            }
        } else if ( baseColumn instanceof BRLActionVariableColumn ) {
            final BRLActionVariableColumn baseBRLActionColumn = (BRLActionVariableColumnbaseColumn;
            final BRLActionColumn brl = .getBRLColumnbaseBRLActionColumn );
            final RuleModel rm = new RuleModel();
            IAction[] rhs = new IActionbrl.getDefinition().size() ];
            brl.getDefinition().toArrayrhs );
            rm.rhs = rhs;
            final RuleModelPeerVariableVisitor peerVariableVisitor = new RuleModelPeerVariableVisitorrm,
                                                                                                       baseBRLActionColumn.getVarName() );
            List<ValueHolderpeerVariables = peerVariableVisitor.getPeerVariables();
            //Add other variables values
            for ( ValueHolder valueHolder : peerVariables ) {
                switch ( valueHolder.getType() ) {
                    case :
                        final BRLActionVariableColumn vc = getActionVariableColumnIndexbrl.getChildColumns(),
                                                                                         valueHolder.getValue() );
                        final int iCol = .getExpandedColumns().indexOfvc );
                        final CellValue<?> cv = this..getiBaseRowIndex ).getiCol );
                        final String field = vc.getFactField();
                        final String value = getValuevc,
                                                       cv );
                        currentValueMap.putfield,
                                             value );
                        break;
                    case :
                        currentValueMap.putvalueHolder.getFieldName(),
                                             valueHolder.getValue() );
                }
            }
        } else if ( baseColumn instanceof ConditionCol52 ) {
            final ConditionCol52 baseConditionColumn = (ConditionCol52baseColumn;
            final Pattern52 basePattern = this..getPatternbaseConditionColumn );
            for ( ConditionCol52 cc : basePattern.getChildColumns() ) {
                final int iCol = allColumns.indexOfcc );
                currentValueMap.putcc.getFactField(),
                                     getValuecc,
                                               rowData.getiCol ) ) );
            }
        } else if ( baseColumn instanceof ActionSetFieldCol52 ) {
            ActionSetFieldCol52 baseActionColumn = (ActionSetFieldCol52baseColumn;
            final String binding = baseActionColumn.getBoundName();
            for ( ActionCol52 ac : this..getActionCols() ) {
                if ( ac instanceof ActionSetFieldCol52 ) {
                    final ActionSetFieldCol52 asf = (ActionSetFieldCol52ac;
                    if ( asf.getBoundName().equalsbinding ) ) {
                        final int iCol = allColumns.indexOfasf );
                        currentValueMap.putasf.getFactField(),
                                             getValueasf,
                                                       rowData.getiCol ) ) );
                    }
                }
            }
        } else if ( baseColumn instanceof ActionInsertFactCol52 ) {
            ActionInsertFactCol52 baseActionColumn = (ActionInsertFactCol52baseColumn;
            final String binding = baseActionColumn.getBoundName();
            for ( ActionCol52 ac : this..getActionCols() ) {
                if ( ac instanceof ActionInsertFactCol52 ) {
                    final ActionInsertFactCol52 aif = (ActionInsertFactCol52ac;
                    if ( aif.getBoundName().equalsbinding ) ) {
                        final int iCol = allColumns.indexOfaif );
                        currentValueMap.putaif.getFactField(),
                                             getValueaif,
                                                       rowData.getiCol ) ) );
                    }
                }
            }
        }
        return currentValueMap;
    }
    //The generic class CellValue can have different data-types so 
    //we need to convert the cell's value to a String used by the 
    //dependent enumerations services
    private String getValuefinal BaseColumn column,
                             final CellValue<? extends Comparable<?>> cv ) {
        if ( cv == null || cv.getValue() == null ) {
            return "";
        }
        final DTCellValue52 dcv = .convertToModelCellcolumn,
                                                                       cv );
        final String value = .asStringdcv );
        return value;
    }
                                                                        final String variableName ) {
        for ( BRLConditionVariableColumn vc : definition ) {
            if ( vc.getVarName().equalsvariableName ) ) {
                return vc;
            }
        }
        //This should never happen
        throw new IllegalArgumentException"Variable '" + variableName + "' not found. This suggests an programming error." );
    }
                                                                  final String variableName ) {
        for ( BRLActionVariableColumn ac : definition ) {
            if ( ac.getVarName().equalsvariableName ) ) {
                return ac;
            }
        }
        //This should never happen
        throw new IllegalArgumentException"Variable '" + variableName + "' not found. This suggests an programming error." );
    }
    @Override
    public Set<IntegergetDependentColumnIndexesfinal Context context ) {
        final int iBaseColIndex = context.getColumn();
        final Set<IntegerdependentColumnIndexes = new HashSet<Integer>();
        //Get the column for the cell being edited
        final List<BaseColumnallColumns = this..getExpandedColumns();
        final BaseColumn baseColumn = allColumns.getiBaseColIndex );
        //Get values for all Constraints or Actions on the same pattern as the baseColumn
        if ( baseColumn instanceof BRLConditionVariableColumn ) {
            final BRLConditionVariableColumn baseBRLConditionColumn = (BRLConditionVariableColumnbaseColumn;
            final BRLConditionColumn brl = .getBRLColumnbaseBRLConditionColumn );
            final RuleModel rm = new RuleModel();
            IPattern[] lhs = new IPatternbrl.getDefinition().size() ];
            brl.getDefinition().toArraylhs );
            rm.lhs = lhs;
            final RuleModelPeerVariableVisitor peerVariableVisitor = new RuleModelPeerVariableVisitorrm,
                                                                                                       baseBRLConditionColumn.getVarName() );
            List<ValueHolderpeerVariables = peerVariableVisitor.getPeerVariables();
            //Add other variables values
            for ( ValueHolder valueHolder : peerVariables ) {
                switch ( valueHolder.getType() ) {
                    case :
                        if ( .isDependentEnumbaseBRLConditionColumn.getFactType(),
                                                     baseBRLConditionColumn.getFactField(),
                                                     valueHolder.getFieldName() ) ) {
                            final BRLConditionVariableColumn vc = getConditionVariableColumnIndexbrl.getChildColumns(),
                                                                                                   valueHolder.getValue() );
                            final int iCol = .getExpandedColumns().indexOfvc );
                            dependentColumnIndexes.addiCol );
                        }
                        break;
                }
            }
        } else if ( baseColumn instanceof BRLActionVariableColumn ) {
            final BRLActionVariableColumn baseBRLActionColumn = (BRLActionVariableColumnbaseColumn;
            final BRLActionColumn brl = .getBRLColumnbaseBRLActionColumn );
            final RuleModel rm = new RuleModel();
            IAction[] rhs = new IActionbrl.getDefinition().size() ];
            brl.getDefinition().toArrayrhs );
            rm.rhs = rhs;
            final RuleModelPeerVariableVisitor peerVariableVisitor = new RuleModelPeerVariableVisitorrm,
                                                                                                       baseBRLActionColumn.getVarName() );
            List<ValueHolderpeerVariables = peerVariableVisitor.getPeerVariables();
            //Add other variables values
            for ( ValueHolder valueHolder : peerVariables ) {
                switch ( valueHolder.getType() ) {
                    case :
                        if ( .isDependentEnumbaseBRLActionColumn.getFactType(),
                                                     baseBRLActionColumn.getFactField(),
                                                     valueHolder.getFieldName() ) ) {
                            final BRLActionVariableColumn vc = getActionVariableColumnIndexbrl.getChildColumns(),
                                                                                             valueHolder.getValue() );
                            final int iCol = .getExpandedColumns().indexOfvc );
                            dependentColumnIndexes.addiCol );
                        }
                        break;
                }
            }
        } else if ( baseColumn instanceof ConditionCol52 ) {
            final ConditionCol52 baseConditionColumn = (ConditionCol52baseColumn;
            final Pattern52 basePattern = this..getPatternbaseConditionColumn );
            for ( ConditionCol52 cc : basePattern.getChildColumns() ) {
                if ( .isDependentEnumbasePattern.getFactType(),
                                             baseConditionColumn.getFactField(),
                                             cc.getFactField() ) ) {
                    dependentColumnIndexes.addallColumns.indexOfcc ) );
                }
            }
        } else if ( baseColumn instanceof ActionSetFieldCol52 ) {
            final ActionSetFieldCol52 baseActionColumn = (ActionSetFieldCol52baseColumn;
            final Pattern52 basePattern = .getConditionPatternbaseActionColumn.getBoundName() );
            final String binding = baseActionColumn.getBoundName();
            for ( ActionCol52 ac : this..getActionCols() ) {
                if ( ac instanceof ActionSetFieldCol52 ) {
                    final ActionSetFieldCol52 asf = (ActionSetFieldCol52ac;
                    if ( asf.getBoundName().equalsbinding ) ) {
                        if ( .isDependentEnumbasePattern.getFactType(),
                                                     baseActionColumn.getFactField(),
                                                     asf.getFactField() ) ) {
                            dependentColumnIndexes.addallColumns.indexOfac ) );
                        }
                    }
                }
            }
        } else if ( baseColumn instanceof ActionInsertFactCol52 ) {
            final ActionInsertFactCol52 baseActionColumn = (ActionInsertFactCol52baseColumn;
            final String binding = baseActionColumn.getBoundName();
            for ( ActionCol52 ac : this..getActionCols() ) {
                if ( ac instanceof ActionInsertFactCol52 ) {
                    final ActionInsertFactCol52 aif = (ActionInsertFactCol52ac;
                    if ( aif.getBoundName().equalsbinding ) ) {
                        if ( .isDependentEnumbaseActionColumn.getFactType(),
                                                     baseActionColumn.getFactField(),
                                                     aif.getFactField() ) ) {
                            dependentColumnIndexes.addallColumns.indexOfac ) );
                        }
                    }
                }
            }
        }
        return dependentColumnIndexes;
    }
New to GrepCode? Check out our FAQ X