use of org.drools.workbench.models.datamodel.rule.HasConstraints in project drools-wb by kiegroup.
the class FactPatternWidget method fieldLabel.
/**
* get the field widget. This may be a simple label, or it may be bound (and
* show the var name) or a icon to create a binding. It will only show the
* binding option of showBinding is true.
*/
private Widget fieldLabel(final SingleFieldConstraint con, final HasConstraints hasConstraints, final boolean showBinding, final int padding) {
HorizontalPanel ab = new HorizontalPanel();
ab.setStyleName("modeller-field-Label");
StringBuilder bindingLabel = new StringBuilder();
if (con.isBound()) {
bindingLabel.append("<b>[");
bindingLabel.append(con.getFieldBinding());
bindingLabel.append("]</b> ");
}
String fieldName = con.getFieldName();
bindingLabel.append(fieldName);
if (bindable && showBinding && !this.readOnly) {
ClickHandler click = event -> {
// If field name is "this" use parent FactPattern type otherwise we can use the Constraint's field type
if (DataType.TYPE_THIS.equals(fieldName)) {
getConnectives().getDataModelOracle().getFieldCompletions(pattern.getFactType(), fields -> popupCreator.showBindFieldPopup(pattern, con, fields, popupCreator));
} else {
getConnectives().getDataModelOracle().getFieldCompletions(con.getFieldType(), fields -> popupCreator.showBindFieldPopup(pattern, con, fields, popupCreator));
}
};
ClickableLabel cl = new ClickableLabel(bindingLabel.toString(), click, !this.readOnly);
DOM.setStyleAttribute(cl.getElement(), "marginLeft", "" + padding + "pt");
ab.add(cl);
} else {
ab.add(new SmallLabel(bindingLabel.toString()));
}
return ab;
}
use of org.drools.workbench.models.datamodel.rule.HasConstraints in project drools-wb by kiegroup.
the class PopupCreatorTest method testOnExpressionEditorButtonClick.
@Test
public void testOnExpressionEditorButtonClick() {
final String factType = "factType";
final FactPattern factPattern = mock(FactPattern.class);
final HasConstraints hasConstraints = mock(HasConstraints.class);
final FormStylePopup popup = mock(FormStylePopup.class);
final SingleFieldConstraintEBLeftSide constraint = mock(SingleFieldConstraintEBLeftSide.class);
final RuleModeller ruleModeller = mock(RuleModeller.class);
final ClickEvent clickEvent = mock(ClickEvent.class);
doReturn(factType).when(factPattern).getFactType();
doReturn(constraint).when(popupCreator).makeSingleFieldConstraintEBLeftSide(factType);
doReturn(ruleModeller).when(popupCreator).getModeller();
doReturn(factPattern).when(popupCreator).getPattern();
final ClickHandler clickHandler = popupCreator.onExpressionEditorButtonClick(hasConstraints, popup);
clickHandler.onClick(clickEvent);
verify(hasConstraints).addConstraint(constraint);
verify(ruleModeller).refreshWidget();
verify(popup).hide();
}
use of org.drools.workbench.models.datamodel.rule.HasConstraints in project drools-wb by kiegroup.
the class FactPatternWidget method drawConstraints.
/**
* Render a hierarchy of constraints, hierarchy here means constraints that
* may themselves depend on members of constraint objects. With this code,
* the GUI enables clicking rules of the form: $result = RoutingResult(
* NerOption.types contains "arzt" )
* @param sortedConst a sorted list of constraints to display.
*/
protected void drawConstraints(List<FieldConstraint> sortedConst, HasConstraints hasConstraints) {
final FlexTable table = new FlexTable();
layout.setWidget(1, 0, table);
List<FieldConstraint> parents = new ArrayList<>();
for (int i = 0; i < sortedConst.size(); i++) {
traverseSingleFieldConstraints(sortedConst, table, parents, hasConstraints, i);
// now the clear icon
final int currentRow = i;
Image clear = GuidedRuleEditorImages508.INSTANCE.DeleteItemSmall();
clear.setTitle(GuidedRuleEditorResources.CONSTANTS.RemoveThisWholeRestriction());
clear.addClickHandler(createClickHandlerForClearImageButton(currentRow));
if (!this.readOnly) {
// This used to be 5 and Connectives were not rendered
table.setWidget(currentRow, 6, clear);
table.setWidget(currentRow, 7, new MoveUpButton(event -> {
hasConstraints.moveUp(currentRow);
getModeller().refreshWidget();
}));
table.setWidget(currentRow, 8, new MoveDownButton(event -> {
hasConstraints.moveDown(currentRow);
getModeller().refreshWidget();
}));
}
}
}
use of org.drools.workbench.models.datamodel.rule.HasConstraints in project drools-wb by kiegroup.
the class PopupCreatorTest method testMakeExpressionEditorButton.
@Test
public void testMakeExpressionEditorButton() {
final HasConstraints hasConstraints = mock(HasConstraints.class);
final FormStylePopup popup = mock(FormStylePopup.class);
final Button button = mock(Button.class);
final ClickHandler clickHandler = mock(ClickHandler.class);
doReturn(button).when(popupCreator).makeExpressionEditorButton();
doReturn(clickHandler).when(popupCreator).onExpressionEditorButtonClick(hasConstraints, popup);
popupCreator.makeExpressionEditorButton(hasConstraints, popup);
verify(button).addClickHandler(clickHandler);
}
Aggregations