use of org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown 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.screens.guided.rule.client.editor.CEPOperatorsDropdown in project drools-wb by kiegroup.
the class OperatorPageTest method testOperatorDropdownSelectedNotFirstItem.
@Test
public void testOperatorDropdownSelectedNotFirstItem() {
registerFakeProvider();
when(plugin.getFactField()).thenReturn("factField");
when(plugin.operatorPlaceholder()).thenReturn("please choose");
when(editingCol.getOperator()).thenReturn("not equal to");
mockGetOperatorCompletionsToReturn(OperatorsOracle.STANDARD_OPERATORS);
spyOperatorsDropdown();
mockListBox("please choose", "equal to", "not equal to");
page.operatorDropdown(widget -> {
assertTrue(widget instanceof CEPOperatorsDropdown);
final CEPOperatorsDropdown operatorsDropdown = (CEPOperatorsDropdown) widget;
verify(operatorsDropdown.getBox()).setSelectedIndex(2);
});
}
use of org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown in project drools-wb by kiegroup.
the class OperatorPage method newCepOperatorsDropdown.
private CEPOperatorsDropdown newCepOperatorsDropdown(final String[] operatorsArray) {
final CEPOperatorsDropdown dropdown = newCepOperatorsDropdown(operatorsArray, editingCol());
dropdown.addPlaceholder(plugin().operatorPlaceholder(), plugin().operatorPlaceholder());
dropdown.insertItem(translate(GuidedDecisionTableErraiConstants.OperatorPage_NoOperator), "", 1);
return dropdown;
}
use of org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown in project drools-wb by kiegroup.
the class OperatorPage method cepOperatorsDropdown.
private void cepOperatorsDropdown(final Consumer<IsWidget> widgetSupplier) {
getOperatorCompletions(options -> {
final String[] operatorsArray = filterOptionsForConstraintTypeLiteral(options);
final CEPOperatorsDropdown dropdown = newCepOperatorsDropdown(operatorsArray);
final ListBox box = dropdown.getBox();
final int currentValueIndex = getCurrentIndexFromList(getOperator(), box);
box.addChangeHandler((ChangeEvent valueChangeEvent) -> setOperator(box.getValue(box.getSelectedIndex())));
if (currentValueIndex != box.getSelectedIndex()) {
box.setSelectedIndex(currentValueIndex);
}
widgetSupplier.accept(dropdown);
});
}
use of org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown in project drools-wb by kiegroup.
the class OperatorPageTest method testOperatorPlaceholderSelectedWhenNothingSelectedPreviously.
@Test
public void testOperatorPlaceholderSelectedWhenNothingSelectedPreviously() {
registerFakeProvider();
when(plugin.getFactField()).thenReturn("factField");
when(plugin.operatorPlaceholder()).thenReturn("please choose");
mockGetOperatorCompletionsToReturn(OperatorsOracle.STANDARD_OPERATORS);
spyOperatorsDropdown();
mockListBox("please choose", "equal to");
page.operatorDropdown(widget -> {
assertTrue(widget instanceof CEPOperatorsDropdown);
final CEPOperatorsDropdown operatorsDropdown = (CEPOperatorsDropdown) widget;
verify(operatorsDropdown.getBox()).setSelectedIndex(0);
});
}
Aggregations