Search in sources :

Example 1 with ConstraintValueEditor

use of org.drools.workbench.screens.guided.rule.client.editor.ConstraintValueEditor in project drools-wb by kiegroup.

the class RefreshUtilTest method testConstraintValueEditorRefreshMultipleEditors.

@Test
public void testConstraintValueEditorRefreshMultipleEditors() throws Exception {
    final SingleFieldConstraint constraintOne = mock(SingleFieldConstraint.class);
    final SingleFieldConstraint constraintTwo = mock(SingleFieldConstraint.class);
    final ConstraintValueEditor editorOne = mock(ConstraintValueEditor.class);
    final ConstraintValueEditor editorTwo = mock(ConstraintValueEditor.class);
    final Map<SingleFieldConstraint, ConstraintValueEditor> editors = new HashMap<>();
    editors.put(constraintOne, editorOne);
    editors.put(constraintTwo, editorTwo);
    doReturn(BaseSingleFieldConstraint.TYPE_LITERAL).when(constraintOne).getConstraintValueType();
    doReturn(BaseSingleFieldConstraint.TYPE_LITERAL).when(constraintTwo).getConstraintValueType();
    RefreshUtil.refreshConstraintValueEditorsDropDownData(editors, mock(SingleFieldConstraint.class));
    verify(editorOne).refresh();
    verify(editorTwo).refresh();
}
Also used : BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) HashMap(java.util.HashMap) ConstraintValueEditor(org.drools.workbench.screens.guided.rule.client.editor.ConstraintValueEditor) Test(org.junit.Test)

Example 2 with ConstraintValueEditor

use of org.drools.workbench.screens.guided.rule.client.editor.ConstraintValueEditor in project drools-wb by kiegroup.

the class ConnectivesTest method testConstraintValueEditorInitialization.

@Test
public void testConstraintValueEditorInitialization() {
    final ConstraintValueEditor editor = mock(ConstraintValueEditor.class);
    doReturn(editor).when(connectives).connectiveValueEditor(connectiveConstraint);
    connectives.connectives(singleFieldConstraint);
    verify(connectives).connectiveOperatorDropDown(eq(connectiveConstraint), isA(Callback.class));
    verify(editor).init();
}
Also used : Callback(org.uberfire.client.callbacks.Callback) ConstraintValueEditor(org.drools.workbench.screens.guided.rule.client.editor.ConstraintValueEditor) Test(org.junit.Test) OperatorsBaseTest(org.drools.workbench.screens.guided.rule.client.OperatorsBaseTest)

Example 3 with ConstraintValueEditor

use of org.drools.workbench.screens.guided.rule.client.editor.ConstraintValueEditor in project drools-wb by kiegroup.

the class Connectives method connectives.

public Widget connectives(final SingleFieldConstraint c) {
    final HorizontalPanel hp = new HorizontalPanel();
    if (c.getConnectives() != null && c.getConnectives().length > 0) {
        hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
        hp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        for (int i = 0; i < c.getConnectives().length; i++) {
            final int index = i;
            final ConnectiveConstraint con = c.getConnectives()[i];
            connectiveOperatorDropDown(con, new Callback<Widget>() {

                @Override
                public void callback(final Widget w) {
                    hp.add(w);
                    final ConstraintValueEditor editor = connectiveValueEditor(con);
                    editor.init();
                    hp.add(editor);
                    if (!isReadOnly) {
                        Image clear = GuidedRuleEditorImages508.INSTANCE.DeleteItemSmall();
                        clear.setAltText(GuidedRuleEditorResources.CONSTANTS.RemoveThisRestriction());
                        clear.setTitle(GuidedRuleEditorResources.CONSTANTS.RemoveThisRestriction());
                        clear.addClickHandler(createClickHandlerForClearImageButton(c, index));
                        hp.add(clear);
                    }
                }
            });
        }
    }
    return hp;
}
Also used : HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) Widget(com.google.gwt.user.client.ui.Widget) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) ConstraintValueEditor(org.drools.workbench.screens.guided.rule.client.editor.ConstraintValueEditor) Image(com.google.gwt.user.client.ui.Image) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Example 4 with ConstraintValueEditor

use of org.drools.workbench.screens.guided.rule.client.editor.ConstraintValueEditor in project drools-wb by kiegroup.

the class RefreshUtilTest method testConstraintValueEditorRefreshPredicateNotRefreshed.

@Test
public void testConstraintValueEditorRefreshPredicateNotRefreshed() throws Exception {
    final SingleFieldConstraint constraintOne = mock(SingleFieldConstraint.class);
    final SingleFieldConstraint constraintTwo = mock(SingleFieldConstraint.class);
    final ConstraintValueEditor editorOne = mock(ConstraintValueEditor.class);
    final ConstraintValueEditor editorTwo = mock(ConstraintValueEditor.class);
    final Map<SingleFieldConstraint, ConstraintValueEditor> editors = new HashMap<>();
    editors.put(constraintOne, editorOne);
    editors.put(constraintTwo, editorTwo);
    doReturn(BaseSingleFieldConstraint.TYPE_LITERAL).when(constraintOne).getConstraintValueType();
    doReturn(BaseSingleFieldConstraint.TYPE_PREDICATE).when(constraintTwo).getConstraintValueType();
    RefreshUtil.refreshConstraintValueEditorsDropDownData(editors, mock(SingleFieldConstraint.class));
    verify(editorOne).refresh();
    verify(editorTwo, never()).refresh();
}
Also used : BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) HashMap(java.util.HashMap) ConstraintValueEditor(org.drools.workbench.screens.guided.rule.client.editor.ConstraintValueEditor) Test(org.junit.Test)

Example 5 with ConstraintValueEditor

use of org.drools.workbench.screens.guided.rule.client.editor.ConstraintValueEditor in project drools-wb by kiegroup.

the class FactPatternWidgetTest method testOnChangeCallbackRegisteredForConstraintValueEditor.

@Test
public void testOnChangeCallbackRegisteredForConstraintValueEditor() throws Exception {
    final SingleFieldConstraint constraint = new SingleFieldConstraint();
    constraint.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    constraint.setFieldName("a");
    final ConstraintValueEditor editor = mock(ConstraintValueEditor.class);
    doReturn(editor).when(factPatternWidget).constraintValueEditor(constraint);
    final SingleFieldConstraint constraintTwo = new SingleFieldConstraint();
    constraintTwo.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    constraintTwo.setFieldName("b");
    final ConstraintValueEditor editorTwo = mock(ConstraintValueEditor.class);
    doReturn(editorTwo).when(factPatternWidget).constraintValueEditor(constraintTwo);
    factPatternWidget.createValueEditor(constraint);
    factPatternWidget.createValueEditor(constraintTwo);
    verify(editor).init();
    verify(editorTwo).init();
    verify(editor).setOnValueChangeCommand(commandCaptor.capture());
    commandCaptor.getValue().execute();
    verify(editorTwo).hideError();
    verify(factPatternWidget).setModified(true);
    verify(editorTwo).refresh();
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ConstraintValueEditor(org.drools.workbench.screens.guided.rule.client.editor.ConstraintValueEditor) OperatorsBaseTest(org.drools.workbench.screens.guided.rule.client.OperatorsBaseTest) Test(org.junit.Test)

Aggregations

ConstraintValueEditor (org.drools.workbench.screens.guided.rule.client.editor.ConstraintValueEditor)5 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)4 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)2 OperatorsBaseTest (org.drools.workbench.screens.guided.rule.client.OperatorsBaseTest)2 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)1 Image (com.google.gwt.user.client.ui.Image)1 Widget (com.google.gwt.user.client.ui.Widget)1 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)1 Callback (org.uberfire.client.callbacks.Callback)1