use of org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52 in project drools-wb by kiegroup.
the class FactPatternConstraintsPageViewImpl method initialiseShufflers.
private void initialiseShufflers() {
btnMoveUp.addClickHandler(new ClickHandler() {
@Override
public void onClick(final ClickEvent event) {
final int index = chosenConditions.indexOf(chosenConditionsSelection);
final ConditionCol52 c = chosenConditions.remove(index);
chosenConditions.add(index - 1, c);
setChosenConditions(chosenConditions);
availablePatternsSelection.setChildColumns(chosenConditions);
}
});
btnMoveDown.addClickHandler(new ClickHandler() {
@Override
public void onClick(final ClickEvent event) {
final int index = chosenConditions.indexOf(chosenConditionsSelection);
final ConditionCol52 c = chosenConditions.remove(index);
chosenConditions.add(index + 1, c);
setChosenConditions(chosenConditions);
availablePatternsSelection.setChildColumns(chosenConditions);
}
});
}
use of org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52 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.ConditionCol52 in project drools-wb by kiegroup.
the class FactPatternConstraintsPageViewImpl method btnRemoveClick.
@UiHandler(value = "btnRemove")
public void btnRemoveClick(final ClickEvent event) {
// Don't allow removal if Pattern is used elsewhere and we're removing all constraints
if (chosenConditions.size() == chosenConditionsSelections.size()) {
if (!validator.canPatternBeRemoved(availablePatternsSelection)) {
if (chosenConditions.size() == 1) {
Window.alert(GuidedDecisionTableConstants.INSTANCE.UnableToDeleteConditionColumn0(chosenConditions.get(0).getHeader()));
} else {
Window.alert(GuidedDecisionTableConstants.INSTANCE.UnableToDeleteConditionColumns());
}
return;
}
}
// Otherwise remove constraints
for (ConditionCol52 c : chosenConditionsSelections) {
chosenConditions.remove(c);
}
chosenConditionsSelections.clear();
setChosenConditions(chosenConditions);
availablePatternsSelection.setChildColumns(chosenConditions);
presenter.stateChanged();
txtColumnHeader.setText("");
txtValueList.setText("");
defaultValueContainer.setVisible(false);
conditionDefinition.setVisible(false);
btnRemove.setEnabled(false);
}
use of org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52 in project drools-wb by kiegroup.
the class ColumnExpansionPageViewImpl method btnAddClick.
@UiHandler(value = "btnAdd")
public void btnAddClick(final ClickEvent event) {
for (ConditionCol52 column : availableColumnsSelections) {
chosenColumns.add(column);
availableColumns.remove(column);
}
availableSelectionModel.clear();
availableColumnsSelections.clear();
setChosenColumns(chosenColumns);
setAvailableColumns(availableColumns);
presenter.setColumnsToExpand(getColumnsToExpand());
btnAdd.setEnabled(false);
}
use of org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52 in project drools-wb by kiegroup.
the class ConditionColumnSynchronizerTest method testAppendNegated.
@Test
public void testAppendNegated() throws VetoException {
final Pattern52 pattern = new Pattern52();
pattern.setNegated(true);
pattern.setFactType("Applicant");
final ConditionCol52 condition1 = ageEqualsCondition();
modelSynchronizer.appendColumn(pattern, condition1);
assertEquals(3, model.getExpandedColumns().size());
assertEquals(1, model.getConditions().size());
assertEquals(3, uiModel.getColumns().size());
assertTrue(uiModel.getColumns().get(2) instanceof IntegerUiColumn);
final ConditionCol52 condition2 = nameEqualsCondition();
modelSynchronizer.appendColumn(pattern, condition2);
assertEquals(4, model.getExpandedColumns().size());
assertEquals(1, model.getConditions().size());
assertEquals(2, model.getConditions().get(0).getChildColumns().size());
assertEquals(4, uiModel.getColumns().size());
assertTrue(uiModel.getColumns().get(2) instanceof IntegerUiColumn);
assertTrue(uiModel.getColumns().get(3) instanceof StringUiColumn);
assertEquals("not Applicant", uiModel.getColumns().get(2).getHeaderMetaData().get(0).getTitle());
assertEquals("not Applicant", uiModel.getColumns().get(3).getHeaderMetaData().get(0).getTitle());
}
Aggregations