Search in sources :

Example 1 with HasConstraints

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>&nbsp;");
    }
    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;
}
Also used : CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) DataType(org.kie.soup.project.datamodel.oracle.DataType) FlexTable(com.google.gwt.user.client.ui.FlexTable) Image(com.google.gwt.user.client.ui.Image) SingleFieldConstraintOperatorSelector(org.drools.workbench.screens.guided.rule.client.widget.operator.SingleFieldConstraintOperatorSelector) HumanReadable(org.kie.workbench.common.widgets.client.resources.HumanReadable) HTML(com.google.gwt.user.client.ui.HTML) Label(com.google.gwt.user.client.ui.Label) Map(java.util.Map) RuleModeller(org.drools.workbench.screens.guided.rule.client.editor.RuleModeller) ToStringExpressionVisitor(org.drools.workbench.models.datamodel.rule.visitors.ToStringExpressionVisitor) EventBus(com.google.gwt.event.shared.EventBus) DOM(com.google.gwt.user.client.DOM) ConstraintValueEditor(org.drools.workbench.screens.guided.rule.client.editor.ConstraintValueEditor) TextBox(org.gwtbootstrap3.client.ui.TextBox) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) MoveUpButton(org.drools.workbench.screens.guided.rule.client.editor.MoveUpButton) ClickableLabel(org.uberfire.ext.widgets.common.client.common.ClickableLabel) List(java.util.List) Widget(com.google.gwt.user.client.ui.Widget) GuidedRuleEditorImages508(org.drools.workbench.screens.guided.rule.client.resources.images.GuidedRuleEditorImages508) DRLConstraintValueBuilder(org.drools.workbench.models.datamodel.rule.builder.DRLConstraintValueBuilder) HumanReadableConstants(org.kie.workbench.common.widgets.client.resources.i18n.HumanReadableConstants) CEPWindowOperatorsDropdown(org.drools.workbench.screens.guided.rule.client.editor.CEPWindowOperatorsDropdown) OperatorSelection(org.drools.workbench.screens.guided.rule.client.editor.OperatorSelection) RefreshUtil(org.drools.workbench.screens.guided.rule.client.util.RefreshUtil) SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) HasCEPWindow(org.drools.workbench.models.datamodel.rule.HasCEPWindow) MoveDownButton(org.drools.workbench.screens.guided.rule.client.editor.MoveDownButton) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) GuidedRuleEditorResources(org.drools.workbench.screens.guided.rule.client.resources.GuidedRuleEditorResources) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) HashMap(java.util.HashMap) GWT(com.google.gwt.core.client.GWT) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ArrayList(java.util.ArrayList) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) Window(com.google.gwt.user.client.Window) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) Connectives(org.drools.workbench.screens.guided.rule.client.editor.factPattern.Connectives) HasHorizontalAlignment(com.google.gwt.user.client.ui.HasHorizontalAlignment) HasConstraints(org.drools.workbench.models.datamodel.rule.HasConstraints) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) HasVerticalAlignment(com.google.gwt.user.client.ui.HasVerticalAlignment) PopupCreator(org.drools.workbench.screens.guided.rule.client.editor.factPattern.PopupCreator) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) ClickableLabel(org.uberfire.ext.widgets.common.client.common.ClickableLabel)

Example 2 with HasConstraints

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();
}
Also used : SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) RuleModeller(org.drools.workbench.screens.guided.rule.client.editor.RuleModeller) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) HasConstraints(org.drools.workbench.models.datamodel.rule.HasConstraints) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) Test(org.junit.Test)

Example 3 with HasConstraints

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();
            }));
        }
    }
}
Also used : CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) DataType(org.kie.soup.project.datamodel.oracle.DataType) FlexTable(com.google.gwt.user.client.ui.FlexTable) Image(com.google.gwt.user.client.ui.Image) SingleFieldConstraintOperatorSelector(org.drools.workbench.screens.guided.rule.client.widget.operator.SingleFieldConstraintOperatorSelector) HumanReadable(org.kie.workbench.common.widgets.client.resources.HumanReadable) HTML(com.google.gwt.user.client.ui.HTML) Label(com.google.gwt.user.client.ui.Label) Map(java.util.Map) RuleModeller(org.drools.workbench.screens.guided.rule.client.editor.RuleModeller) ToStringExpressionVisitor(org.drools.workbench.models.datamodel.rule.visitors.ToStringExpressionVisitor) EventBus(com.google.gwt.event.shared.EventBus) DOM(com.google.gwt.user.client.DOM) ConstraintValueEditor(org.drools.workbench.screens.guided.rule.client.editor.ConstraintValueEditor) TextBox(org.gwtbootstrap3.client.ui.TextBox) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) MoveUpButton(org.drools.workbench.screens.guided.rule.client.editor.MoveUpButton) ClickableLabel(org.uberfire.ext.widgets.common.client.common.ClickableLabel) List(java.util.List) Widget(com.google.gwt.user.client.ui.Widget) GuidedRuleEditorImages508(org.drools.workbench.screens.guided.rule.client.resources.images.GuidedRuleEditorImages508) DRLConstraintValueBuilder(org.drools.workbench.models.datamodel.rule.builder.DRLConstraintValueBuilder) HumanReadableConstants(org.kie.workbench.common.widgets.client.resources.i18n.HumanReadableConstants) CEPWindowOperatorsDropdown(org.drools.workbench.screens.guided.rule.client.editor.CEPWindowOperatorsDropdown) OperatorSelection(org.drools.workbench.screens.guided.rule.client.editor.OperatorSelection) RefreshUtil(org.drools.workbench.screens.guided.rule.client.util.RefreshUtil) SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) HasCEPWindow(org.drools.workbench.models.datamodel.rule.HasCEPWindow) MoveDownButton(org.drools.workbench.screens.guided.rule.client.editor.MoveDownButton) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) GuidedRuleEditorResources(org.drools.workbench.screens.guided.rule.client.resources.GuidedRuleEditorResources) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) HashMap(java.util.HashMap) GWT(com.google.gwt.core.client.GWT) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ArrayList(java.util.ArrayList) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) Window(com.google.gwt.user.client.Window) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) Connectives(org.drools.workbench.screens.guided.rule.client.editor.factPattern.Connectives) HasHorizontalAlignment(com.google.gwt.user.client.ui.HasHorizontalAlignment) HasConstraints(org.drools.workbench.models.datamodel.rule.HasConstraints) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) HasVerticalAlignment(com.google.gwt.user.client.ui.HasVerticalAlignment) PopupCreator(org.drools.workbench.screens.guided.rule.client.editor.factPattern.PopupCreator) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) MoveDownButton(org.drools.workbench.screens.guided.rule.client.editor.MoveDownButton) FlexTable(com.google.gwt.user.client.ui.FlexTable) ArrayList(java.util.ArrayList) MoveUpButton(org.drools.workbench.screens.guided.rule.client.editor.MoveUpButton) Image(com.google.gwt.user.client.ui.Image) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Example 4 with HasConstraints

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);
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) HasConstraints(org.drools.workbench.models.datamodel.rule.HasConstraints) Button(org.gwtbootstrap3.client.ui.Button) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) Test(org.junit.Test)

Aggregations

ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 HasConstraints (org.drools.workbench.models.datamodel.rule.HasConstraints)4 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)3 SingleFieldConstraintEBLeftSide (org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide)3 RuleModeller (org.drools.workbench.screens.guided.rule.client.editor.RuleModeller)3 GWT (com.google.gwt.core.client.GWT)2 EventBus (com.google.gwt.event.shared.EventBus)2 DOM (com.google.gwt.user.client.DOM)2 Window (com.google.gwt.user.client.Window)2 FlexTable (com.google.gwt.user.client.ui.FlexTable)2 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)2 HTML (com.google.gwt.user.client.ui.HTML)2 HasHorizontalAlignment (com.google.gwt.user.client.ui.HasHorizontalAlignment)2 HasVerticalAlignment (com.google.gwt.user.client.ui.HasVerticalAlignment)2 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)2 Image (com.google.gwt.user.client.ui.Image)2 Label (com.google.gwt.user.client.ui.Label)2 Widget (com.google.gwt.user.client.ui.Widget)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2