Search in sources :

Example 26 with DropDownData

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]);
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) TestJavaEnum2(org.kie.workbench.common.widgets.client.datamodel.testclasses.TestJavaEnum2) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Example 27 with DropDownData

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]);
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) TestJavaEnum1(org.kie.workbench.common.widgets.client.datamodel.testclasses.TestJavaEnum1) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Example 28 with DropDownData

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);
                }
            });
        }
    });
}
Also used : PositionCallback(com.google.gwt.user.client.ui.PopupPanel.PositionCallback) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData)

Example 29 with DropDownData

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);
}
Also used : DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) LimitedEntryDropDownManager(org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.LimitedEntryDropDownManager)

Example 30 with DropDownData

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"));
}
Also used : DependentEnumsUtilities(org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.DependentEnumsUtilities) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) Map(java.util.Map) Test(org.junit.Test)

Aggregations

DropDownData (org.kie.soup.project.datamodel.oracle.DropDownData)40 Test (org.junit.Test)31 Path (org.uberfire.backend.vfs.Path)13 Map (java.util.Map)9 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)7 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)7 ConstraintValueEditorHelper (org.drools.workbench.screens.guided.rule.client.editor.util.ConstraintValueEditorHelper)7 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)7 ListBox (org.gwtbootstrap3.client.ui.ListBox)6 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)4 HashMap (java.util.HashMap)3 GuidedDecisionTablePresenter (org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTablePresenter)3 GuidedDecisionTableView (org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView)3 DependentEnumsUtilities (org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.DependentEnumsUtilities)3 Caller (org.jboss.errai.common.client.api.Caller)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 Assert.assertFalse (org.junit.Assert.assertFalse)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 Before (org.junit.Before)3 RunWith (org.junit.runner.RunWith)3