use of org.kie.soup.project.datamodel.oracle.DropDownData in project kie-wb-common by kiegroup.
the class PackageDataModelOracleEnumTest method testJavaEnum2.
@Test
public void testJavaEnum2() throws IOException {
final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(TestJavaEnum2.class).build();
final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses").setModuleOracle(projectLoader).build();
// Emulate server-to-client conversions
final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
dataModel.setPackageName(packageLoader.getPackageName());
dataModel.setModelFields(packageLoader.getModuleModelFields());
dataModel.setJavaEnumDefinitions(packageLoader.getModuleJavaEnumDefinitions());
dataModel.setWorkbenchEnumDefinitions(packageLoader.getPackageWorkbenchDefinitions());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
assertEquals(2, oracle.getFactTypes().length);
assertEquals(TestJavaEnum2.class.getSimpleName(), oracle.getFactTypes()[1]);
final DropDownData dd = oracle.getEnums(TestJavaEnum2.class.getSimpleName(), "field1");
assertNotNull(dd);
assertEquals(3, dd.getFixedList().length);
assertEquals("TestExternalEnum.ZERO=TestExternalEnum.ZERO", dd.getFixedList()[0]);
assertEquals("TestExternalEnum.ONE=TestExternalEnum.ONE", dd.getFixedList()[1]);
assertEquals("TestExternalEnum.TWO=TestExternalEnum.TWO", dd.getFixedList()[2]);
final String[] ddValues = oracle.getEnumValues(TestJavaEnum2.class.getSimpleName(), "field1");
assertNotNull(ddValues);
assertEquals(3, ddValues.length);
assertEquals("TestExternalEnum.ZERO=TestExternalEnum.ZERO", ddValues[0]);
assertEquals("TestExternalEnum.ONE=TestExternalEnum.ONE", ddValues[1]);
assertEquals("TestExternalEnum.TWO=TestExternalEnum.TWO", ddValues[2]);
}
use of org.kie.soup.project.datamodel.oracle.DropDownData in project kie-wb-common by kiegroup.
the class PackageDataModelOracleEnumTest method testJavaEnum1.
@Test
public void testJavaEnum1() throws IOException {
final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(TestJavaEnum1.class).build();
final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses").setModuleOracle(projectLoader).build();
// Emulate server-to-client conversions
final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
dataModel.setPackageName(packageLoader.getPackageName());
dataModel.setModelFields(packageLoader.getModuleModelFields());
dataModel.setJavaEnumDefinitions(packageLoader.getModuleJavaEnumDefinitions());
dataModel.setWorkbenchEnumDefinitions(packageLoader.getPackageWorkbenchDefinitions());
PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
assertEquals(2, oracle.getFactTypes().length);
assertEquals("TestJavaEnum1.TestEnum", oracle.getFactTypes()[1]);
final DropDownData dd = oracle.getEnums(TestJavaEnum1.class.getSimpleName(), "field1");
assertNotNull(dd);
assertEquals(3, dd.getFixedList().length);
assertEquals("TestJavaEnum1.TestEnum.ZERO=TestJavaEnum1.TestEnum.ZERO", dd.getFixedList()[0]);
assertEquals("TestJavaEnum1.TestEnum.ONE=TestJavaEnum1.TestEnum.ONE", dd.getFixedList()[1]);
assertEquals("TestJavaEnum1.TestEnum.TWO=TestJavaEnum1.TestEnum.TWO", dd.getFixedList()[2]);
final String[] ddValues = oracle.getEnumValues(TestJavaEnum1.class.getSimpleName(), "field1");
assertNotNull(ddValues);
assertEquals(3, ddValues.length);
assertEquals("TestJavaEnum1.TestEnum.ZERO=TestJavaEnum1.TestEnum.ZERO", ddValues[0]);
assertEquals("TestJavaEnum1.TestEnum.ONE=TestJavaEnum1.TestEnum.ONE", ddValues[1]);
assertEquals("TestJavaEnum1.TestEnum.TWO=TestJavaEnum1.TestEnum.TWO", ddValues[2]);
}
use of org.kie.soup.project.datamodel.oracle.DropDownData in project kie-wb-common by kiegroup.
the class PopupDropDownEditCell method startEditing.
// Start editing the cell
@Override
protected void startEditing(final Context context, final Element parent, final String value) {
// We need to get the list of potential values for the enumeration. Since the content
// of the list may be different for each cell (dependent enumerations) the list
// has to be populated "on demand".
DropDownData dd = dmo.getEnums(this.factType, this.factField, this.dropDownManager.getCurrentValueMap(context));
if (dd == null) {
return;
}
utilities.setDropDownData(value, dd, isMultipleSelect, dmo.getResourcePath(), listBox);
// Select the appropriate item
boolean emptyValue = (value == null);
if (emptyValue) {
listBox.setSelectedIndex(0);
} else {
if (listBox.isMultipleSelect()) {
final List<String> values = Arrays.asList(value.split(","));
for (int i = 0; i < listBox.getItemCount(); i++) {
listBox.setItemSelected(i, values.contains(listBox.getValue(i)));
}
} else {
for (int i = 0; i < listBox.getItemCount(); i++) {
if (listBox.getValue(i).equals(value)) {
listBox.setSelectedIndex(i);
break;
}
}
}
}
panel.setPopupPositionAndShow(new PositionCallback() {
public void setPosition(int offsetWidth, int offsetHeight) {
panel.setPopupPosition(parent.getAbsoluteLeft() + offsetX, parent.getAbsoluteTop() + offsetY);
// Focus the first enabled control
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
listBox.setFocus(true);
}
});
}
});
}
use of org.kie.soup.project.datamodel.oracle.DropDownData in project drools-wb by kiegroup.
the class DTCellValueWidgetFactory method makeHasEnumsListBox.
private ListBox makeHasEnumsListBox(Pattern52 pattern, BaseColumn column, DTCellValue52 value, boolean isMultipleSelect, String factField, String factType) {
final LimitedEntryDropDownManager.Context context = new LimitedEntryDropDownManager.Context(pattern, column);
final Map<String, String> currentValueMap = dropDownManager.getCurrentValueMap(context);
final DropDownData dd = oracle.getEnums(factType, factField, currentValueMap);
// No drop-down data defined
if (dd == null) {
return makeListBoxForColumn(DropDownData.create(new String[0]), pattern, column, value, isMultipleSelect);
}
return makeListBoxForColumn(dd, pattern, column, value, isMultipleSelect);
}
use of org.kie.soup.project.datamodel.oracle.DropDownData in project drools-wb by kiegroup.
the class GuidedDecisionTablePresenterTest method getEnumLookupsWithFixedListDefinition.
@Test
@SuppressWarnings("unchecked")
public void getEnumLookupsWithFixedListDefinition() {
final DependentEnumsUtilities.Context context = mock(DependentEnumsUtilities.Context.class);
final Callback<Map<String, String>> callback = mock(Callback.class);
final DropDownData dd = DropDownData.create(new String[] { "one", "two" });
when(oracle.getEnums(eq("FactType"), eq("field"), any(Map.class))).thenReturn(dd);
dtPresenter.getEnumLookups("FactType", "field", context, callback);
verify(callback, times(1)).callback(callbackValueCaptor.capture());
final Map<String, String> callbackValue = callbackValueCaptor.getValue();
assertNotNull(callbackValue);
assertFalse(callbackValue.isEmpty());
assertTrue(callbackValue.containsKey("one"));
assertTrue(callbackValue.containsKey("two"));
}
Aggregations