use of org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle 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.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle in project drools-wb by kiegroup.
the class ConstraintValueEditorHelperTest method testSimplePattern.
@Test
public void testSimplePattern() throws Exception {
AsyncPackageDataModelOracle oracle = mock(AsyncPackageDataModelOracle.class);
FactPattern pattern = new FactPattern();
pattern.setBoundName("pp");
pattern.setFactType("House");
model.addLhsItem(pattern);
FactPattern pattern2 = new FactPattern();
SingleFieldConstraint constraint = new SingleFieldConstraint();
constraint.setFactType("House");
constraint.setFieldName("this");
constraint.setFieldName("org.mortgages.House");
pattern2.addConstraint(constraint);
model.addLhsItem(pattern);
when(oracle.getFieldClassName("House", "this")).thenReturn("org.mortgages.House");
ConstraintValueEditorHelper helper = new ConstraintValueEditorHelper(model, oracle, "House", "this", constraint, "House", new DropDownData());
helper.isApplicableBindingsInScope("pp", new Callback<Boolean>() {
@Override
public void callback(Boolean result) {
assertTrue(result);
}
});
}
use of org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle in project drools-wb by kiegroup.
the class ConstraintValueEditorHelperTest method testEvents_BoundTypeIsNotEvent.
@Test
public void testEvents_BoundTypeIsNotEvent() throws Exception {
AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(serviceCaller, validatorInstance);
oracle.setPackageName("org.test");
oracle.addModelFields(new HashMap<String, ModelField[]>() {
{
put("org.test.Event1", new ModelField[] { modelField("this", "org.test.Event1") });
put("org.test.Event2", new ModelField[] { modelField("this", "org.test.Event2") });
}
});
oracle.addEventTypes(new HashMap<String, Boolean>() {
{
put("org.test.Event1", false);
put("org.test.Event2", true);
}
});
oracle.addSuperTypes(new HashMap<String, List<String>>() {
{
put("org.test.Event1", Collections.EMPTY_LIST);
put("org.test.Event2", Collections.EMPTY_LIST);
}
});
oracle.filter();
FactPattern pattern1 = new FactPattern();
pattern1.setFactType("Event1");
pattern1.setBoundName("$e");
SingleFieldConstraint constraint = new SingleFieldConstraint();
constraint.setFactType("Event1");
constraint.setFieldName("this");
constraint.setFieldType("Event1");
constraint.setOperator(OperatorsOracle.SIMPLE_CEP_OPERATORS[0]);
pattern1.addConstraint(constraint);
model.addLhsItem(pattern1);
ConstraintValueEditorHelper helper = new ConstraintValueEditorHelper(model, oracle, "Event2", "this", constraint, "Event2", new DropDownData());
helper.isApplicableBindingsInScope("$e", new Callback<Boolean>() {
@Override
public void callback(Boolean result) {
assertFalse(result);
}
});
}
use of org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle in project drools-wb by kiegroup.
the class ActionCallMethodWidget method showAddFieldPopup.
protected void showAddFieldPopup(Widget w) {
final AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorImages508.INSTANCE.Wizard(), GuidedRuleEditorResources.CONSTANTS.ChooseAMethodToInvoke());
final ListBox box = new ListBox();
box.addItem("...");
for (int i = 0; i < fieldCompletionTexts.length; i++) {
box.addItem(fieldCompletionValues[i], fieldCompletionTexts[i]);
}
box.setSelectedIndex(0);
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.ChooseAMethodToInvoke(), box);
box.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
final String methodNameWithParams = box.getItemText(box.getSelectedIndex());
oracle.getMethodParams(variableClass, methodNameWithParams, new Callback<List<String>>() {
@Override
public void callback(final List<String> methodParameters) {
final String methodName = box.getValue(box.getSelectedIndex());
model.setMethodName(methodName);
model.setState(ActionCallMethod.TYPE_DEFINED);
for (String methodParameter : methodParameters) {
model.addFieldValue(new ActionFieldFunction(methodName, null, methodParameter));
}
getModeller().refreshWidget();
popup.hide();
}
});
}
});
popup.show();
}
use of org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle in project drools-wb by kiegroup.
the class FromCompositeFactPatternWidget method showFactTypeSelector.
/**
* Pops up the fact selector.
*/
protected void showFactTypeSelector() {
AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
final ListBox box = new ListBox();
String[] facts = oracle.getFactTypes();
box.addItem(GuidedRuleEditorResources.CONSTANTS.Choose());
for (int i = 0; i < facts.length; i++) {
box.addItem(facts[i]);
}
box.setSelectedIndex(0);
final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorResources.CONSTANTS.NewFactPattern());
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.chooseFactType(), box);
box.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
pattern.setFactPattern(new FactPattern(box.getItemText(box.getSelectedIndex())));
setModified(true);
getModeller().refreshWidget();
popup.hide();
}
});
popup.show();
}
Aggregations