use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools-wb by kiegroup.
the class FactPatternConstraintsPageViewImpl method initialiseChosenFields.
private void initialiseChosenFields() {
chosenConditionsContainer.add(chosenConditionsWidget);
chosenConditionsWidget.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
chosenConditionsWidget.setMinimumWidth(170);
final Label lstEmpty = new Label(GuidedDecisionTableConstants.INSTANCE.DecisionTableWizardNoChosenFields());
lstEmpty.setStyleName(WizardCellListResources.INSTANCE.cellListStyle().cellListEmptyItem());
chosenConditionsWidget.setEmptyListWidget(lstEmpty);
final MultiSelectionModel<ConditionCol52> selectionModel = new MultiSelectionModel<ConditionCol52>(System::identityHashCode);
chosenConditionsWidget.setSelectionModel(selectionModel);
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
@Override
public void onSelectionChange(final SelectionChangeEvent event) {
chosenConditionsSelections = new HashSet<ConditionCol52>();
final Set<ConditionCol52> selections = selectionModel.getSelectedSet();
for (ConditionCol52 c : selections) {
chosenConditionsSelections.add(c);
}
chosenConditionsSelected(chosenConditionsSelections);
}
private void chosenConditionsSelected(final Set<ConditionCol52> cws) {
btnRemove.setEnabled(true);
if (cws.size() == 1) {
chosenConditionsSelection = cws.iterator().next();
conditionDefinition.setVisible(true);
validateConditionHeader();
validateConditionOperator();
populateConditionDefinition();
enableMoveUpButton();
enableMoveDownButton();
} else {
chosenConditionsSelection = null;
conditionDefinition.setVisible(false);
optLiteral.setEnabled(false);
optFormula.setEnabled(false);
optPredicate.setEnabled(false);
txtColumnHeader.setEnabled(false);
txtValueList.setEnabled(false);
defaultValueContainer.setVisible(false);
btnMoveUp.setEnabled(false);
btnMoveDown.setEnabled(false);
}
}
private void displayCalculationTypes(final Pattern52 selectedPattern, final ConditionCol52 selectedCondition) {
final boolean isPredicate = (selectedCondition.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_PREDICATE);
final boolean hasEnum = presenter.hasEnum(selectedPattern, selectedCondition);
calculationType.setVisible(!isPredicate);
optLiteral.setEnabled(!isPredicate);
optLiteral.setVisible(!isPredicate);
optFormula.setEnabled(!(isPredicate || hasEnum));
optFormula.setVisible(!isPredicate);
operatorContainer.setVisible(!isPredicate);
optPredicate.setEnabled(isPredicate);
optPredicate.setVisible(isPredicate);
txtPredicateExpression.setEnabled(isPredicate);
predicateExpressionContainer.setVisible(isPredicate);
}
private void populateConditionDefinition() {
// Fields common to all table formats
txtColumnHeader.setEnabled(true);
txtColumnHeader.setText(chosenConditionsSelection.getHeader());
presenter.getOperatorCompletions(availablePatternsSelection, chosenConditionsSelection, new Callback<String[]>() {
@Override
public void callback(final String[] ops) {
doPopulateConditionDefinition(ops);
}
});
}
private void doPopulateConditionDefinition(final String[] ops) {
final CEPOperatorsDropdown ddOperator = new CEPOperatorsDropdown(ops, chosenConditionsSelection);
ddOperator.addPlaceholder(GuidedRuleEditorResources.CONSTANTS.pleaseChoose(), "");
ddOperatorContainer.setWidget(ddOperator);
criteriaExtendedEntry.setVisible(presenter.getTableFormat() == GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY);
criteriaLimitedEntry.setVisible(presenter.getTableFormat() == GuidedDecisionTable52.TableFormat.LIMITED_ENTRY);
// Fields specific to the table format
switch(presenter.getTableFormat()) {
case EXTENDED_ENTRY:
txtValueList.setEnabled(!presenter.requiresValueList(availablePatternsSelection, chosenConditionsSelection));
txtValueList.setText(chosenConditionsSelection.getValueList());
makeDefaultValueWidget();
defaultValueContainer.setVisible(validator.doesOperatorNeedValue(chosenConditionsSelection));
if (chosenConditionsSelection.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_PREDICATE) {
txtPredicateExpression.setText(chosenConditionsSelection.getFactField());
}
ddOperator.addValueChangeHandler(new ValueChangeHandler<OperatorSelection>() {
@Override
public void onValueChange(ValueChangeEvent<OperatorSelection> event) {
chosenConditionsSelection.setOperator(event.getValue().getValue());
final boolean requiresValueList = presenter.requiresValueList(availablePatternsSelection, chosenConditionsSelection);
txtValueList.setEnabled(requiresValueList);
if (!requiresValueList) {
txtValueList.setText("");
} else {
txtValueList.setText(chosenConditionsSelection.getValueList());
}
presenter.stateChanged();
validateConditionOperator();
makeDefaultValueWidget();
defaultValueContainer.setVisible(validator.doesOperatorNeedValue(chosenConditionsSelection));
}
});
switch(chosenConditionsSelection.getConstraintValueType()) {
case BaseSingleFieldConstraint.TYPE_LITERAL:
optLiteral.setValue(true);
displayCalculationTypes(availablePatternsSelection, chosenConditionsSelection);
break;
case BaseSingleFieldConstraint.TYPE_RET_VALUE:
optFormula.setValue(true);
displayCalculationTypes(availablePatternsSelection, chosenConditionsSelection);
break;
case BaseSingleFieldConstraint.TYPE_PREDICATE:
optPredicate.setValue(true);
displayCalculationTypes(availablePatternsSelection, chosenConditionsSelection);
}
break;
case LIMITED_ENTRY:
calculationType.setVisible(false);
makeLimitedValueWidget();
// If operator changes the widget used to populate the
// value can change
ddOperator.addValueChangeHandler(new ValueChangeHandler<OperatorSelection>() {
@Override
public void onValueChange(ValueChangeEvent<OperatorSelection> event) {
chosenConditionsSelection.setOperator(event.getValue().getValue());
validateConditionOperator();
makeLimitedValueWidget();
presenter.stateChanged();
}
});
break;
}
}
private void makeLimitedValueWidget() {
if (!(chosenConditionsSelection instanceof LimitedEntryConditionCol52)) {
return;
}
final LimitedEntryConditionCol52 lec = (LimitedEntryConditionCol52) chosenConditionsSelection;
boolean doesOperatorNeedValue = validator.doesOperatorNeedValue(chosenConditionsSelection);
if (!doesOperatorNeedValue) {
limitedEntryValueContainer.setVisible(false);
lec.setValue(null);
return;
}
limitedEntryValueContainer.setVisible(true);
if (lec.getValue() == null) {
lec.setValue(factory.makeNewValue(chosenConditionsSelection));
}
limitedEntryValueWidgetContainer.setWidget(factory.getWidget(availablePatternsSelection, chosenConditionsSelection, lec.getValue()));
}
});
}
use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools-wb by kiegroup.
the class ActionSetFieldsPage method prepareView.
@Override
public void prepareView() {
// Setup the available patterns, that could have changed each time this page is visited
List<Pattern52> availablePatterns = new ArrayList<Pattern52>();
for (Pattern52 p : model.getPatterns()) {
if (p.getChildColumns().size() > 0) {
availablePatterns.add(p);
} else {
patternToActionsMap.remove(p);
}
}
view.setAvailablePatterns(availablePatterns);
}
use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools-wb by kiegroup.
the class ActionSetFieldsPage method initialise.
@Override
public void initialise() {
view.init(this);
view.setValidator(getValidator());
patternToActionsMap.clear();
// Set-up validator for the pattern-to-action mapping voodoo
getValidator().setPatternToActionSetFieldsMap(patternToActionsMap);
// Set-up a factory for value editors
view.setDTCellValueWidgetFactory(DTCellValueWidgetFactory.getInstance(model, oracle, false, allowEmptyValues()));
// Existing ActionSetFieldCols (should be empty for a new Decision Table)
for (ActionCol52 a : model.getActionCols()) {
if (a instanceof ActionSetFieldCol52) {
final ActionSetFieldCol52 asf = (ActionSetFieldCol52) a;
final Pattern52 p = model.getConditionPattern(asf.getBoundName());
if (!patternToActionsMap.containsKey(p)) {
patternToActionsMap.put(p, new ArrayList<ActionSetFieldCol52>());
}
final List<ActionSetFieldCol52> actions = patternToActionsMap.get(p);
actions.add(asf);
}
}
view.setChosenFields(new ArrayList<ActionSetFieldCol52>());
content.setWidget(view);
}
use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools-wb by kiegroup.
the class ActionSetFieldsPage method makeResult.
@Override
public void makeResult(final GuidedDecisionTable52 model) {
// Copy actions to decision table model. Assertion of bindings occurs in FactPatternsPage
for (Map.Entry<Pattern52, List<ActionSetFieldCol52>> ps : patternToActionsMap.entrySet()) {
final Pattern52 p = ps.getKey();
// Patterns with no conditions don't get created
if (p.getChildColumns().size() > 0) {
final String binding = p.getBoundName();
for (ActionSetFieldCol52 a : ps.getValue()) {
a.setBoundName(binding);
model.getActionCols().add(a);
}
}
}
}
use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools-wb by kiegroup.
the class FactPatternsPageViewImpl method initialiseShufflers.
private void initialiseShufflers() {
btnMoveUp.addClickHandler(new ClickHandler() {
@Override
public void onClick(final ClickEvent event) {
int index = chosenPatterns.indexOf(chosenPatternSelection);
final Pattern52 p = chosenPatterns.remove(index);
chosenPatterns.add(index - 1, p);
setChosenPatterns(chosenPatterns);
presenter.setConditionPatterns(chosenPatterns);
}
});
btnMoveDown.addClickHandler(new ClickHandler() {
@Override
public void onClick(final ClickEvent event) {
int index = chosenPatterns.indexOf(chosenPatternSelection);
final Pattern52 p = chosenPatterns.remove(index);
chosenPatterns.add(index + 1, p);
setChosenPatterns(chosenPatterns);
presenter.setConditionPatterns(chosenPatterns);
}
});
}
Aggregations