Search in sources :

Example 61 with ActionFieldValue

use of org.drools.workbench.models.datamodel.rule.ActionFieldValue in project drools-wb by kiegroup.

the class ActionSetFieldWidget method showAddFieldPopup.

protected void showAddFieldPopup(ClickEvent w) {
    final AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
    final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorImages508.INSTANCE.Wizard(), GuidedRuleEditorResources.CONSTANTS.AddAField());
    final ListBox box = new ListBox();
    box.addItem("...");
    final ModelField[] availableFieldCompletions = ModelFieldUtil.getAvailableFieldCompletions(fieldCompletions, model);
    final boolean isEnabled = !isReadOnly() && availableFieldCompletions.length > 0;
    if (availableFieldCompletions.length > 0) {
        for (int i = 0; i < availableFieldCompletions.length; i++) {
            box.addItem(availableFieldCompletions[i].getName());
        }
    }
    box.setSelectedIndex(0);
    popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.AddField(), box);
    box.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            String fieldName = box.getItemText(box.getSelectedIndex());
            String fieldType = oracle.getFieldType(variableClass, fieldName);
            model.addFieldValue(new ActionFieldValue(fieldName, "", fieldType));
            setModified(true);
            getModeller().refreshWidget();
            popup.hide();
        }
    });
    box.setEnabled(isEnabled);
    popup.show();
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 62 with ActionFieldValue

use of org.drools.workbench.models.datamodel.rule.ActionFieldValue in project drools-wb by kiegroup.

the class ActionValueEditorTest method testGetDropDownData.

@Test
public void testGetDropDownData() throws Exception {
    final AsyncPackageDataModelOracle oracle = mock(AsyncPackageDataModelOracle.class);
    final String factType = "Car";
    final String factField = "color";
    final ActionFieldValue value = new ActionFieldValue() {

        {
            setField(factField);
        }
    };
    final ActionFieldValue[] values = new ActionFieldValue[0];
    final RuleModeller modeller = mock(RuleModeller.class);
    doReturn(oracle).when(modeller).getDataModelOracle();
    final EventBus eventBus = mock(EventBus.class);
    final String variableType = DataType.TYPE_STRING;
    final boolean readOnly = false;
    actionValueEditor = new ActionValueEditor(factType, value, values, modeller, eventBus, variableType, readOnly);
    // reset oracle due to calls in ActionValueEditor constructor
    reset(oracle);
    actionValueEditor.getDropDownData();
    final Map<String, String> fieldValues = new HashMap<>();
    verify(oracle).getEnums(eq(factType), eq(factField), eq(fieldValues));
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) HashMap(java.util.HashMap) EventBus(com.google.gwt.event.shared.EventBus) Test(org.junit.Test)

Example 63 with ActionFieldValue

use of org.drools.workbench.models.datamodel.rule.ActionFieldValue 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 64 with ActionFieldValue

use of org.drools.workbench.models.datamodel.rule.ActionFieldValue 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 65 with ActionFieldValue

use of org.drools.workbench.models.datamodel.rule.ActionFieldValue in project drools by kiegroup.

the class RuleTemplateModelDRLPersistenceTest method testUpdateModifyMultipleFieldsWithMultipleSkipped1.

@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped1() {
    TemplateModel m = new TemplateModel();
    m.name = "r1";
    FactPattern fp = new FactPattern("Person");
    fp.setBoundName("$p");
    m.addLhsItem(fp);
    ActionUpdateField auf1 = new ActionUpdateField("$p");
    ActionFieldValue afv0 = new ActionFieldValue();
    afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv0.setField("field1");
    afv0.setValue("$f1");
    auf1.addFieldValue(afv0);
    ActionFieldValue afv1 = new ActionFieldValue();
    afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv1.setField("field2");
    afv1.setValue("$f2");
    auf1.addFieldValue(afv1);
    ActionFieldValue afv2 = new ActionFieldValue();
    afv2.setNature(FieldNatureType.TYPE_TEMPLATE);
    afv2.setField("field3");
    afv2.setValue("$f3");
    auf1.addFieldValue(afv2);
    m.addRhsItem(auf1);
    String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "  $p : Person()\n" + "then\n" + "  modify( $p ) {\n" + "    setField1(\"v1\"),\n" + "    setField2(\"v2\"),\n" + "    setField3(\"v3\")\n" + "  }\n" + "end";
    m.addRow(new String[] { "v1", "v2", "v3" });
    checkMarshall(expected, m);
}
Also used : ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test)

Aggregations

ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)136 Test (org.junit.Test)113 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)71 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)71 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)65 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)63 ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)53 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)48 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)41 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)41 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)33 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)30 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)28 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)26 IAction (org.drools.workbench.models.datamodel.rule.IAction)25 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)24 ActionSetField (org.drools.workbench.models.datamodel.rule.ActionSetField)23 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)23 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)21 ArrayList (java.util.ArrayList)19