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();
}
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));
}
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();
}
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();
}
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);
}
Aggregations