Search in sources :

Example 1 with ActionValueEditor

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

the class ActionInsertFactWidget method valueEditor.

ActionValueEditor valueEditor(final ActionFieldValue actionFieldValue) {
    final ActionValueEditor actionValueEditor = actionValueEditor(factType, actionFieldValue, model.getFieldValues(), readOnly);
    actionValueEditor.setOnChangeCommand(new Command() {

        public void execute() {
            RefreshUtil.refreshActionValueEditorsDropDownData(actionValueEditors, actionFieldValue);
            setModified(true);
        }
    });
    // Keep a reference to the value editors so they can be refreshed for dependent enums
    actionValueEditors.put(actionFieldValue, actionValueEditor);
    return actionValueEditor;
}
Also used : ActionValueEditor(org.drools.workbench.screens.guided.rule.client.editor.ActionValueEditor) Command(com.google.gwt.user.client.Command)

Example 2 with ActionValueEditor

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

the class RefreshUtilTest method testActionValueEditorRefreshPredicateNotRefreshed.

@Test
public void testActionValueEditorRefreshPredicateNotRefreshed() throws Exception {
    final ActionFieldValue valueOne = mock(ActionFieldValue.class);
    final ActionFieldValue valueTwo = mock(ActionFieldValue.class);
    final ActionValueEditor editorOne = mock(ActionValueEditor.class);
    final ActionValueEditor editorTwo = mock(ActionValueEditor.class);
    final Map<ActionFieldValue, ActionValueEditor> editors = new HashMap<>();
    editors.put(valueOne, editorOne);
    editors.put(valueTwo, editorTwo);
    doReturn(FieldNatureType.TYPE_LITERAL).when(valueOne).getNature();
    doReturn(FieldNatureType.TYPE_PREDICATE).when(valueTwo).getNature();
    RefreshUtil.refreshActionValueEditorsDropDownData(editors, mock(ActionFieldValue.class));
    verify(editorOne).refresh();
    verify(editorTwo, never()).refresh();
}
Also used : ActionValueEditor(org.drools.workbench.screens.guided.rule.client.editor.ActionValueEditor) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with ActionValueEditor

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

the class ActionSetFieldWidgetTest method testOnChangeCallbackRegisteredForActionValueEditor.

@Test
public void testOnChangeCallbackRegisteredForActionValueEditor() throws Exception {
    final ActionFieldValue value = new ActionFieldValue();
    value.setNature(FieldNatureType.TYPE_LITERAL);
    value.setField("a");
    final ActionValueEditor editor = mock(ActionValueEditor.class);
    doReturn(editor).when(testedWidget).actionValueEditor(any(), eq(value), any(), anyBoolean());
    final ActionFieldValue valueTwo = new ActionFieldValue();
    valueTwo.setNature(FieldNatureType.TYPE_LITERAL);
    valueTwo.setField("b");
    final ActionValueEditor editorTwo = mock(ActionValueEditor.class);
    doReturn(editorTwo).when(testedWidget).actionValueEditor(any(), eq(valueTwo), any(), anyBoolean());
    testedWidget.valueEditor(value);
    testedWidget.valueEditor(valueTwo);
    verify(editor).setOnChangeCommand(commandCaptor.capture());
    commandCaptor.getValue().execute();
    verify(testedWidget).setModified(true);
    verify(editorTwo).refresh();
}
Also used : ActionValueEditor(org.drools.workbench.screens.guided.rule.client.editor.ActionValueEditor) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) Test(org.junit.Test)

Example 4 with ActionValueEditor

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

the class ActionSetFieldWidget method valueEditor.

ActionValueEditor valueEditor(final ActionFieldValue actionFieldValue) {
    AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
    String type = "";
    if (oracle.isGlobalVariable(this.model.getVariable())) {
        type = oracle.getGlobalVariable(this.model.getVariable());
    } else {
        type = this.getModeller().getModel().getLHSBindingType(this.model.getVariable());
        /*
             * to take in account if the using a rhs bound variable
             */
        if (type == null && !this.readOnly) {
            type = this.getModeller().getModel().getRHSBoundFact(this.model.getVariable()).getFactType();
        }
    }
    ActionValueEditor actionValueEditor = actionValueEditor(type, actionFieldValue, model.getFieldValues(), readOnly);
    actionValueEditor.setOnChangeCommand(new Command() {

        public void execute() {
            RefreshUtil.refreshActionValueEditorsDropDownData(actionValueEditors, actionFieldValue);
            setModified(true);
        }
    });
    // Keep a reference to the value editors so they can be refreshed for dependent enums
    actionValueEditors.put(actionFieldValue, actionValueEditor);
    return actionValueEditor;
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) ActionValueEditor(org.drools.workbench.screens.guided.rule.client.editor.ActionValueEditor) Command(com.google.gwt.user.client.Command)

Example 5 with ActionValueEditor

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

the class RefreshUtilTest method testActionValueEditorRefreshMultipleEditors.

@Test
public void testActionValueEditorRefreshMultipleEditors() throws Exception {
    final ActionFieldValue valueOne = mock(ActionFieldValue.class);
    final ActionFieldValue valueTwo = mock(ActionFieldValue.class);
    final ActionValueEditor editorOne = mock(ActionValueEditor.class);
    final ActionValueEditor editorTwo = mock(ActionValueEditor.class);
    final Map<ActionFieldValue, ActionValueEditor> editors = new HashMap<>();
    editors.put(valueOne, editorOne);
    editors.put(valueTwo, editorTwo);
    doReturn(FieldNatureType.TYPE_LITERAL).when(valueOne).getNature();
    doReturn(FieldNatureType.TYPE_LITERAL).when(valueTwo).getNature();
    RefreshUtil.refreshActionValueEditorsDropDownData(editors, mock(ActionFieldValue.class));
    verify(editorOne).refresh();
    verify(editorTwo).refresh();
}
Also used : ActionValueEditor(org.drools.workbench.screens.guided.rule.client.editor.ActionValueEditor) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

ActionValueEditor (org.drools.workbench.screens.guided.rule.client.editor.ActionValueEditor)6 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)4 Test (org.junit.Test)4 Command (com.google.gwt.user.client.Command)2 HashMap (java.util.HashMap)2 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)1