diff --git a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/resources/i18n/GuidedDecisionTableErraiConstants.java b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/resources/i18n/GuidedDecisionTableErraiConstants.java index 36fe9ad4027..91b55dccedf 100644 --- a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/resources/i18n/GuidedDecisionTableErraiConstants.java +++ b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/resources/i18n/GuidedDecisionTableErraiConstants.java @@ -152,6 +152,12 @@ public class GuidedDecisionTableErraiConstants { @TranslationKey(defaultValue = "") public static final String PatternPageView_SelectPattern = "PatternPageView.SelectPattern"; + @TranslationKey(defaultValue = "") + public static final String PatternPageView_PatternPageDescriptionConditions = "PatternPageView.PatternPageDescriptionConditions"; + + @TranslationKey(defaultValue = "") + public static final String PatternPageView_PatternPageDescriptionActions = "PatternPageView.PatternPageDescriptionActions"; + @TranslationKey(defaultValue = "") public static final String PatternPageView_EntryPointDescription = "PatternPageView.EntryPointDescription"; diff --git a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/commons/HasPatternPage.java b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/commons/HasPatternPage.java index 7b8ff4be26a..b06bc7b9ae3 100644 --- a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/commons/HasPatternPage.java +++ b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/commons/HasPatternPage.java @@ -30,5 +30,7 @@ public interface HasPatternPage { String getEntryPointName(); + String getPatternPageDescription(); + Set getPatterns(); } diff --git a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/commons/HasValueOptionsPage.java b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/commons/HasValueOptionsPage.java index 707fb381423..1a932431ac9 100644 --- a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/commons/HasValueOptionsPage.java +++ b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/commons/HasValueOptionsPage.java @@ -25,6 +25,8 @@ public interface HasValueOptionsPage { Boolean isValueOptionsPageCompleted(); + Boolean isFieldBindingValid(); + int constraintValue(); String getFactType(); diff --git a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/PatternPage.java b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/PatternPage.java index fc13ec8c808..adae04a5773 100644 --- a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/PatternPage.java +++ b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/PatternPage.java @@ -98,12 +98,17 @@ public void prepareView() { setupPattern(); setupEntryPoint(); + setPatternPageDescription(); } private void setupEntryPoint() { view.setupEntryPointName(getEntryPointName()); } + private void setPatternPageDescription() { + view.setPatternPageDescription(getPatternPageDescription()); + } + void setupPattern() { view.clearPatternList(); @@ -210,6 +215,10 @@ String getEntryPointName() { return plugin().getEntryPointName(); } + String getPatternPageDescription() { + return plugin().getPatternPageDescription(); + } + void setEntryPoint() { plugin().setEntryPointName(view.getEntryPointName()); } @@ -239,6 +248,8 @@ public interface View extends HasList, void selectPattern(String currentPatternValue); + void setPatternPageDescription(final String description); + void showPatternWarning(); void hidePatternWarning(); diff --git a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/PatternPageView.html b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/PatternPageView.html index 85febb9ecda..f3c0ccb6911 100644 --- a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/PatternPageView.html +++ b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/PatternPageView.html @@ -19,7 +19,7 @@
- +
diff --git a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/PatternPageView.java b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/PatternPageView.java index e3479a90bf7..1f7fbc93882 100644 --- a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/PatternPageView.java +++ b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/PatternPageView.java @@ -30,6 +30,7 @@ import org.drools.workbench.screens.guided.dtable.client.wizard.column.commons.HasPatternPage; import org.drools.workbench.screens.guided.dtable.client.wizard.column.pages.common.DecisionTablePopoverUtils; import org.jboss.errai.common.client.dom.Div; +import org.jboss.errai.common.client.dom.Span; import org.jboss.errai.ui.client.local.api.IsElement; import org.jboss.errai.ui.client.local.spi.TranslationService; import org.jboss.errai.ui.shared.api.annotations.DataField; @@ -45,7 +46,9 @@ public class PatternPageView implements IsElement, private PatternPage page; - @Inject + @DataField("patternPageDescription") + private Span patternPageDescription; + @DataField("patternWarning") private Div patternWarning; @@ -66,12 +69,16 @@ public class PatternPageView implements IsElement, private DecisionTablePopoverUtils popoverUtils; @Inject - public PatternPageView(final ListBox patternList, + public PatternPageView(final Span patternPageDescription, + final Div patternWarning, + final ListBox patternList, final TextBox entryPointName, final Button createANewFactPattern, final Div entryPointContainer, final TranslationService translationService, final DecisionTablePopoverUtils popoverUtils) { + this.patternPageDescription = patternPageDescription; + this.patternWarning = patternWarning; this.patternList = patternList; this.entryPointName = entryPointName; this.createANewFactPattern = createANewFactPattern; @@ -161,6 +168,11 @@ public void addItem(final String itemName, itemKey); } + @Override + public void setPatternPageDescription(final String description) { + this.patternPageDescription.setInnerHTML(description); + } + @Override public void showPatternWarning() { patternWarning.setHidden(false); diff --git a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/ValueOptionsPage.java b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/ValueOptionsPage.java index 48d282b7c1f..f560618d8e3 100644 --- a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/ValueOptionsPage.java +++ b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/ValueOptionsPage.java @@ -71,7 +71,17 @@ public String getTitle() { @Override public void isComplete(final Callback callback) { - callback.callback(plugin().isValueOptionsPageCompleted()); + boolean isFieldBindingValid = plugin().isFieldBindingValid(); + boolean isValueOptionPageComplete = plugin().isValueOptionsPageCompleted(); + boolean isComplete = isValueOptionPageComplete && isFieldBindingValid; + + if (!isFieldBindingValid) { + view.showFieldBindingWarning(); + } else { + view.hideFieldBindingWarning(); + } + + callback.callback(isComplete); } @Override @@ -384,5 +394,9 @@ public interface View extends UberElement { void hideCepOperators(); void setupCepOperators(IsWidget widget); + + void showFieldBindingWarning(); + + void hideFieldBindingWarning(); } } diff --git a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/ValueOptionsPageView.html b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/ValueOptionsPageView.html index 5da3433ea18..46837073fea 100644 --- a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/ValueOptionsPageView.html +++ b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/ValueOptionsPageView.html @@ -22,6 +22,11 @@
+
+ + +
+
diff --git a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/ValueOptionsPageView.java b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/ValueOptionsPageView.java index 6912ff343e1..9f654186c9c 100644 --- a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/ValueOptionsPageView.java +++ b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/ValueOptionsPageView.java @@ -69,6 +69,9 @@ public class ValueOptionsPageView implements IsElement, @DataField("bindingContainer") private Div bindingContainer; + @DataField("fieldBindingWarning") + private Div fieldBindingWarning; + private ValueOptionsPage page; private TranslationService translationService; @@ -86,6 +89,7 @@ public ValueOptionsPageView(final Div valueListGroupContainer, final Div defaultValueContainer, final Div limitedValueContainer, final Div bindingContainer, + final Div fieldBindingWarning, final TranslationService translationService, final DecisionTablePopoverUtils popoverUtils) { this.valueListGroupContainer = valueListGroupContainer; @@ -98,6 +102,7 @@ public ValueOptionsPageView(final Div valueListGroupContainer, this.defaultValueContainer = defaultValueContainer; this.limitedValueContainer = limitedValueContainer; this.bindingContainer = bindingContainer; + this.fieldBindingWarning = fieldBindingWarning; this.translationService = translationService; this.popoverUtils = popoverUtils; } @@ -187,6 +192,16 @@ public void hideCepOperators() { cepWindowOperatorsGroupContainer.setHidden(true); } + @Override + public void showFieldBindingWarning() { + fieldBindingWarning.setHidden(false); + } + + @Override + public void hideFieldBindingWarning() { + fieldBindingWarning.setHidden(true); + } + private String translate(final String key, final Object... args) { return translationService.format(key, diff --git a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ActionSetFactPlugin.java b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ActionSetFactPlugin.java index fc0d357dec2..c843a3b0d90 100644 --- a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ActionSetFactPlugin.java +++ b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ActionSetFactPlugin.java @@ -198,6 +198,11 @@ public Boolean isValueOptionsPageCompleted() { return valueOptionsPageCompleted; } + @Override + public Boolean isFieldBindingValid() { + return Boolean.TRUE; + } + @Override public PatternWrapper patternWrapper() { return Optional.ofNullable(patternWrapper).orElse(new PatternWrapper()); @@ -219,6 +224,11 @@ public String getEntryPointName() { return ""; } + @Override + public String getPatternPageDescription() { + return translate(GuidedDecisionTableErraiConstants.PatternPageView_PatternPageDescriptionActions); + } + @Override public void setEntryPointName(final String entryPointName) { } diff --git a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ActionWorkItemSetFieldPlugin.java b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ActionWorkItemSetFieldPlugin.java index a53f6b91b78..a9fda771514 100644 --- a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ActionWorkItemSetFieldPlugin.java +++ b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ActionWorkItemSetFieldPlugin.java @@ -404,6 +404,11 @@ public String getEntryPointName() { return ""; } + @Override + public String getPatternPageDescription() { + return translate(GuidedDecisionTableErraiConstants.PatternPageView_PatternPageDescriptionActions); + } + @Override public void setEntryPointName(final String entryPointName) { // empty diff --git a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ConditionColumnPlugin.java b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ConditionColumnPlugin.java index 4915f660496..14e78de7578 100644 --- a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ConditionColumnPlugin.java +++ b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ConditionColumnPlugin.java @@ -35,11 +35,12 @@ import org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn; import org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52; import org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52; -import org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52.TableFormat; import org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52; +import org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52.TableFormat; import org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryCol; import org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52; import org.drools.workbench.models.guided.dtable.shared.model.Pattern52; +import org.drools.workbench.models.guided.dtable.shared.model.adaptors.FactPatternPattern52Adaptor; import org.drools.workbench.screens.guided.dtable.client.resources.i18n.GuidedDecisionTableErraiConstants; import org.drools.workbench.screens.guided.dtable.client.widget.Validator; import org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.CellUtilities; @@ -182,6 +183,7 @@ void appendColumn() { } } + @Override public Pattern52 editingPattern() { return wrappedPattern(); } @@ -256,6 +258,11 @@ public String getEntryPointName() { return patternWrapper().getEntryPointName(); } + @Override + public String getPatternPageDescription() { + return translate(GuidedDecisionTableErraiConstants.PatternPageView_PatternPageDescriptionConditions); + } + @Override public void setEntryPointName(final String entryPointName) { patternWrapper().setEntryPointName(entryPointName); @@ -264,14 +271,17 @@ public void setEntryPointName(final String entryPointName) { @Override public Set getPatterns() { final Set patterns = new HashSet<>(); - final BRLRuleModel brlRuleModel = new BRLRuleModel(presenter.getModel()); + final BRLRuleModel brlRuleModel = new BRLRuleModel(getPresenter().getModel()); final List variables = brlRuleModel.getLHSPatternVariables(); variables.forEach(var -> { - final String factType = brlRuleModel.getLHSBoundFact(var).getFactType(); - final boolean isNegated = brlRuleModel.getLHSBoundFact(var).isNegated(); - patterns.add(new PatternWrapper(factType, - var, - isNegated)); + final Pattern52 pattern = getPresenter().getModel().getConditionPattern(var); + if (!(pattern instanceof FactPatternPattern52Adaptor)) { + final String factType = brlRuleModel.getLHSBoundFact(var).getFactType(); + final boolean isNegated = brlRuleModel.getLHSBoundFact(var).isNegated(); + patterns.add(new PatternWrapper(factType, + var, + isNegated)); + } }); return patterns; @@ -383,6 +393,8 @@ public String getBinding() { @Override public void setBinding(final String binding) { editingCol().setBinding(binding); + + fireChangeEvent(valueOptionsPage); } @Override @@ -395,6 +407,7 @@ public boolean isBindable() { return tableFormat() == LIMITED_ENTRY || constraintValue() == BaseSingleFieldConstraint.TYPE_LITERAL; } + @Override public int constraintValue() { final boolean factHasEnums = presenter.getDataModelOracle().hasEnums(getFactType(), getFactField()); @@ -426,6 +439,7 @@ public String getValueList() { return editingCol().getValueList(); } + @Override public void setValueList(final String valueList) { editingCol().setValueList(valueList); @@ -463,6 +477,7 @@ public void setConstraintValue(final int constraintValue) { fireChangeEvent(operatorPage); } + @Override public void setValueOptionsPageAsCompleted() { if (!isValueOptionsPageCompleted()) { setValueOptionsPageCompleted(); @@ -471,10 +486,32 @@ public void setValueOptionsPageAsCompleted() { } } + @Override public Boolean isValueOptionsPageCompleted() { return valueOptionsPageCompleted; } + @Override + public Boolean isFieldBindingValid() { + if (!isBindable()) { + return Boolean.TRUE; + } + + final String binding = getBinding(); + if ((binding == null || binding.isEmpty())) { + return Boolean.TRUE; + } + + if (!isNewColumn()) { + if (binding.equals(originalCondition().getBinding())) { + return Boolean.TRUE; + } + } + + final BRLRuleModel brlRuleModel = new BRLRuleModel(getPresenter().getModel()); + return !brlRuleModel.isVariableNameUsed(binding); + } + public String getFactType() { return patternWrapper().getFactType(); } diff --git a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/resources/org/drools/workbench/screens/guided/dtable/client/resources/i18n/GuidedDecisionTableErraiConstants.properties b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/resources/org/drools/workbench/screens/guided/dtable/client/resources/i18n/GuidedDecisionTableErraiConstants.properties index cf292d7c56d..2d7130151c7 100644 --- a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/resources/org/drools/workbench/screens/guided/dtable/client/resources/i18n/GuidedDecisionTableErraiConstants.properties +++ b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/main/resources/org/drools/workbench/screens/guided/dtable/client/resources/i18n/GuidedDecisionTableErraiConstants.properties @@ -120,7 +120,10 @@ PatternPageView.Metadata=Metadata: PatternPageView.SelectPattern=Select a pattern PatternPageView.EntryPoint=Entry Point: PatternPageView.YouMustEnterAColumnPattern=You must select a Pattern. -PatternPageView.PatternPageDescription=Select from the list of fact patterns already used in your table or create a new fact pattern. A fact pattern is a combination of \ +PatternPageView.PatternPageDescriptionConditions=Select from the list of fact patterns already used in Conditions in your table or create a new fact pattern. A fact pattern is a combination of \ + an available data object in the package and a model class binding that you specify. (Examples: LoanApplication [application] or \ + IncomeSource [income] where the bracketed portion is the binding to the given fact type). +PatternPageView.PatternPageDescriptionActions=Select from the list of fact patterns already used in Conditions or Condition BRL fragments in your table or create a new fact pattern. A fact pattern is a combination of \ an available data object in the package and a model class binding that you specify. (Examples: LoanApplication [application] or \ IncomeSource [income] where the bracketed portion is the binding to the given fact type). PatternPageView.EntryPointDescription=Define the entry point for the fact pattern, if applicable. An entry point is a gate or stream through which facts enter the rule engine, \ @@ -145,6 +148,7 @@ ValueOptionsPageView.Binding=Binding: ValueOptionsPageView.ValueOptionsPageDescription=(optional) Enter a list of value options, delimited by a comma and space, to limit table input data for the condition ("WHEN") portion of the rule. \ When this value list is defined, the values will be provided in the table cells for that column as a drop-down list, from which users can select only one option. \ (Example list: Monday, Wednesday, Friday to specify only these three options) +ValueOptionsPageView.PleaseEnterANameThatIsNotAlreadyUsed=That binding name is already in use by another Pattern or Field - please pick another. WorkItemPageView.Select=Select a Work Item WorkItemPageView.WorkItem=Work Item: WorkItemPageView.NoWorkItemsAvailable= @@ -161,7 +165,7 @@ NewPatternView.Cancel=Cancel NewPatternView.OK=OK NewPatternPresenter.PleaseEnterANameForFact=You have to bind the fact to a name. Please enter a binding name. NewPatternPresenter.PleaseEnterANameThatIsNotTheSameAsTheFactType=Please enter a name that is not the same as the fact type. -NewPatternPresenter.PleaseEnterANameThatIsNotAlreadyUsedByAnotherPattern=That binding name is already in use by another Pattern or Field - please pick another +NewPatternPresenter.PleaseEnterANameThatIsNotAlreadyUsedByAnotherPattern=That binding name is already in use by another Pattern or Field - please pick another. AdditionalInfoPage.AdditionalInfo=Additional info AdditionalInfoPage.HideColumnDescription=Select this to hide the column, or clear this to display the column. AdditionalInfoPage.LogicalInsertDescription=Select this to insert the fact pattern logically into the inference engine, or clear this to insert it regularly. \ diff --git a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/test/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/ValueOptionsPageTest.java b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/test/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/ValueOptionsPageTest.java index 983f98c018e..2b231bc243f 100644 --- a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/test/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/ValueOptionsPageTest.java +++ b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/test/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/pages/ValueOptionsPageTest.java @@ -41,8 +41,16 @@ import org.mockito.InjectMocks; import org.mockito.Mock; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.doCallRealMethod; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @RunWith(GwtMockitoTestRunner.class) public class ValueOptionsPageTest { @@ -359,8 +367,29 @@ public void testIsCompleteWhenValueOptionsPageIsNotCompleted() throws Exception @Test public void testIsCompleteWhenValueOptionsPageIsCompleted() throws Exception { + when(plugin.isFieldBindingValid()).thenReturn(true); when(plugin.isValueOptionsPageCompleted()).thenReturn(true); page.isComplete(Assert::assertTrue); } + + @Test + public void testIsCompleteWhenValueOptionsPageIsCompletedWithValidBinding() throws Exception { + when(plugin.isFieldBindingValid()).thenReturn(true); + when(plugin.isValueOptionsPageCompleted()).thenReturn(true); + + page.isComplete(Assert::assertTrue); + + verify(view).hideFieldBindingWarning(); + } + + @Test + public void testIsCompleteWhenValueOptionsPageIsCompletedWithInvalidBinding() throws Exception { + when(plugin.isFieldBindingValid()).thenReturn(false); + when(plugin.isValueOptionsPageCompleted()).thenReturn(true); + + page.isComplete(Assert::assertFalse); + + verify(view).showFieldBindingWarning(); + } } diff --git a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/test/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ActionSetFactPluginTest.java b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/test/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ActionSetFactPluginTest.java index a99007a096b..4dc2e1b50a1 100644 --- a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/test/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ActionSetFactPluginTest.java +++ b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/test/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ActionSetFactPluginTest.java @@ -799,6 +799,11 @@ public void testIsNewFactPatternWhenIsExisting() throws Exception { assertFalse(plugin.isNewFactPattern()); } + @Test + public void testIsFieldBindingValid() { + assertTrue(plugin.isFieldBindingValid()); + } + private void mockPatterns() { final GuidedDecisionTable52 model = mock(GuidedDecisionTable52.class); final List> patterns = Collections.singletonList(fakePattern()); diff --git a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/test/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ConditionColumnPluginTest.java b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/test/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ConditionColumnPluginTest.java index 9814afc3aef..16beeb01455 100644 --- a/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/test/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ConditionColumnPluginTest.java +++ b/drools-wb-screens/drools-wb-guided-dtable-editor/drools-wb-guided-dtable-editor-client/src/test/java/org/drools/workbench/screens/guided/dtable/client/wizard/column/plugins/ConditionColumnPluginTest.java @@ -30,6 +30,7 @@ import org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52; import org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52; import org.drools.workbench.models.guided.dtable.shared.model.Pattern52; +import org.drools.workbench.models.guided.dtable.shared.model.adaptors.FactPatternPattern52Adaptor; import org.drools.workbench.screens.guided.dtable.client.resources.i18n.GuidedDecisionTableErraiConstants; import org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView; import org.drools.workbench.screens.guided.dtable.client.wizard.column.NewGuidedDecisionTableColumnWizard; @@ -58,6 +59,7 @@ import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.doReturn; @@ -722,24 +724,127 @@ public void testGetPatterns() throws Exception { setFactType("FactType"); setBoundName("$fact"); }}; + + doReturn(Collections.singletonList(pattern)).when(model).getConditions(); + doReturn(pattern).when(model).getConditionPattern(eq("$fact")); + + final Set patterns = plugin.getPatterns(); + + assertEquals(1, + patterns.size()); + assertTrue(patterns.contains(new PatternWrapper("FactType", + "$fact", + false))); + } + + @Test + public void testGetPatternsWithBRLCondition() throws Exception { + final Pattern52 pattern = new Pattern52() {{ + setFactType("FactType"); + setBoundName("$fact"); + }}; final BRLConditionColumn brlColumn = new BRLConditionColumn(); - brlColumn.setDefinition(Collections.singletonList(new FactPattern("AnotherFact") {{ + final FactPattern fp = new FactPattern("AnotherFact") {{ setBoundName("$another"); - }})); + }}; + brlColumn.setDefinition(Collections.singletonList(fp)); doReturn(Arrays.asList(pattern, brlColumn)).when(model).getConditions(); + doReturn(pattern).when(model).getConditionPattern(eq("$fact")); + doReturn(new FactPatternPattern52Adaptor(fp)).when(model).getConditionPattern(eq("$another")); final Set patterns = plugin.getPatterns(); - assertEquals(2, + assertEquals(1, patterns.size()); assertTrue(patterns.contains(new PatternWrapper("FactType", "$fact", false))); - assertTrue(patterns.contains(new PatternWrapper("AnotherFact", - "$another", - false))); + } + + @Test + public void testSetBinding() { + plugin.setBinding("$a"); + + verify(plugin).fireChangeEvent(eq(valueOptionsPage)); + } + + @Test + public void testIsFieldBindingValidWhenNotBindable() { + doReturn(false).when(plugin).isBindable(); + + assertTrue(plugin.isFieldBindingValid()); + } + + @Test + public void testIsFieldBindingValidWhenBindableNewColumnNoExistingBindings() { + doReturn(true).when(plugin).isBindable(); + doReturn(true).when(plugin).isNewColumn(); + + assertTrue(plugin.isFieldBindingValid()); + } + + @Test + public void testIsFieldBindingValidWhenBindableNewColumnWithExistingBindingsNoClash() { + doReturn(true).when(plugin).isBindable(); + doReturn(true).when(plugin).isNewColumn(); + doReturn("$n").when(plugin).getBinding(); + + doReturn(Collections.singletonList(mockFactPattern("$a"))).when(model).getConditions(); + + assertTrue(plugin.isFieldBindingValid()); + } + + @Test + public void testIsFieldBindingValidWhenBindableNewColumnWithExistingBindingsWithClash() { + doReturn(true).when(plugin).isBindable(); + doReturn(true).when(plugin).isNewColumn(); + doReturn("$n").when(plugin).getBinding(); + + doReturn(Collections.singletonList(mockFactPattern("$n"))).when(model).getConditions(); + + assertFalse(plugin.isFieldBindingValid()); + } + + @Test + public void testIsFieldBindingValidWhenBindableEditColumnWithExistingBindingsNoClash() { + final ConditionCol52 originalColumn = mock(ConditionCol52.class); + doReturn(originalColumn).when(plugin).originalCondition(); + doReturn(true).when(plugin).isBindable(); + doReturn(false).when(plugin).isNewColumn(); + doReturn("$n").when(plugin).getBinding(); + doReturn("$n").when(originalColumn).getBinding(); + + assertTrue(plugin.isFieldBindingValid()); + } + + @Test + public void testIsFieldBindingValidWhenBindableEditColumnWithExistingBindingsWithClash() { + final ConditionCol52 originalColumn = mock(ConditionCol52.class); + doReturn(originalColumn).when(plugin).originalCondition(); + doReturn(true).when(plugin).isBindable(); + doReturn(false).when(plugin).isNewColumn(); + doReturn("$a").when(plugin).getBinding(); + doReturn("$n").when(originalColumn).getBinding(); + + doReturn(Collections.singletonList(mockFactPattern("$a"))).when(model).getConditions(); + + assertFalse(plugin.isFieldBindingValid()); + } + + @Test + public void testIsFieldBindingValidWhenNullBinding() { + doReturn(true).when(plugin).isBindable(); + doReturn(null).when(plugin).getBinding(); + + assertTrue(plugin.isFieldBindingValid()); + } + + private Pattern52 mockFactPattern(final String binding) { + final Pattern52 p = new Pattern52(); + p.setBoundName(binding); + return p; } private ConditionCol52 makeConditionCol52(final int constraintValueType,