Search in sources :

Example 1 with DropDownData

use of org.kie.soup.project.datamodel.oracle.DropDownData in project kie-wb-common by kiegroup.

the class AbstractProxyPopupDropDownEditCell method startEditing.

// Start editing the cell
@Override
protected void startEditing(final Context context, final Element parent, final C 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) {
        // If no enumeration exists show a TextBox
        delegate = singleValueEditor;
        delegate.setValue(value);
        vPanel.clear();
        vPanel.add(delegate.asWidget());
    } else {
        // Otherwise show a drop-down list box
        delegate = multipleValueEditor;
        delegate.setDropDownData(dd);
        vPanel.clear();
        vPanel.add(delegate.asWidget());
    }
    delegate.startEditing(context, parent, value);
    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() {
                    delegate.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 2 with DropDownData

use of org.kie.soup.project.datamodel.oracle.DropDownData in project kie-wb-common by kiegroup.

the class AbstractProxyPopupDropDownEditCell method render.

@Override
public void render(final Context context, final C value, final SafeHtmlBuilder sb) {
    // We need to get the list of potential values to lookup the "Display" value from the "Stored" value.
    // 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) {
        // If no enumeration exists show a TextBox
        delegate = singleValueEditor;
        delegate.setValue(value);
        vPanel.clear();
        vPanel.add(delegate.asWidget());
    } else {
        // Otherwise show a drop-down list box
        delegate = multipleValueEditor;
        delegate.setDropDownData(dd);
        vPanel.clear();
        vPanel.add(delegate.asWidget());
    }
    delegate.render(context, value, sb, renderer);
}
Also used : DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData)

Example 3 with DropDownData

use of org.kie.soup.project.datamodel.oracle.DropDownData in project kie-wb-common by kiegroup.

the class PopupDropDownEditCell method render.

@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
    // We need to get the list of potential values to lookup the "Display" value from the "Stored" value.
    // 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);
    // Render value
    if (value != null) {
        String label = getLabel(value);
        sb.append(renderer.render(label));
    }
}
Also used : DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData)

Example 4 with DropDownData

use of org.kie.soup.project.datamodel.oracle.DropDownData in project drools-wb by kiegroup.

the class GuidedRuleTemplateEditorServiceImplCDITest method testLoadContent.

@Test
public void testLoadContent() throws Exception {
    final Path testedPath = getPath(CARS);
    final GuidedTemplateEditorContent testedContent = testedService.loadContent(testedPath);
    oracleFactory.makeAsyncPackageDataModelOracle(testedPath, testedContent.getModel(), testedContent.getDataModel());
    final String declaredFactInEnum = "Car";
    final String declaredFieldInEnum = "price";
    final Map<String, String> actualFieldValues = new HashMap<String, String>() {

        {
            put("color", "red");
        }
    };
    final DropDownData dropDownData = asyncOracle.getEnums(declaredFactInEnum, declaredFieldInEnum, actualFieldValues);
    Assertions.assertThat(dropDownData.getQueryExpression()).isEqualTo("(new org.kiegroup.PriceHelper()).getPrices(\"@{color}\")");
    Assertions.assertThat(dropDownData.getValuePairs()).hasSize(1);
    Assertions.assertThat(dropDownData.getValuePairs()[0]).isEqualTo("color=red");
}
Also used : Path(org.uberfire.backend.vfs.Path) GuidedTemplateEditorContent(org.drools.workbench.screens.guided.template.model.GuidedTemplateEditorContent) HashMap(java.util.HashMap) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) Test(org.junit.Test)

Example 5 with DropDownData

use of org.kie.soup.project.datamodel.oracle.DropDownData in project drools-wb by kiegroup.

the class VerifyFieldConstraintEditor method refreshEditor.

private void refreshEditor() {
    String flType = oracle.getFieldType(factType, field.getFieldName());
    panel.clear();
    if (flType != null && flType.equals(DataType.TYPE_BOOLEAN)) {
        String[] c = new String[] { "true", "false" };
        panel.add(new EnumDropDown(field.getExpected(), new DropDownValueChanged() {

            public void valueChanged(String newText, String newValue) {
                callback.valueChanged(newValue);
            }
        }, DropDownData.create(c), oracle.getResourcePath()));
    } else if (flType != null && flType.equals(DataType.TYPE_DATE)) {
        FieldDatePicker fieldDatePicker = new FieldDatePicker(new FieldDatePickerViewImpl());
        fieldDatePicker.setValue(field.getExpected());
        fieldDatePicker.addValueChangeHandler(new ValueChangeHandler<String>() {

            @Override
            public void onValueChange(ValueChangeEvent<String> event) {
                field.setExpected(event.getValue());
            }
        });
        panel.add(fieldDatePicker);
    } else {
        Map<String, String> currentValueMap = new HashMap<String, String>();
        // TODO fill currentValueMap with values of other VerifyFields (if any)
        DropDownData dropDownData = oracle.getEnums(factType, field.getFieldName(), currentValueMap);
        if (dropDownData != null) {
            // GUVNOR-1324: Java enums are of type TYPE_COMPARABLE whereas Guvnor enums are not.
            // The distinction here controls whether the EXPECTED value is handled as a true
            // Java enum or a literal with a selection list (i.e. Guvnor enum)
            String dataType = oracle.getFieldType(factType, field.getFieldName());
            if (dataType.equals(DataType.TYPE_COMPARABLE)) {
                field.setNature(FieldData.TYPE_ENUM);
            } else {
                field.setNature(FieldData.TYPE_LITERAL);
            }
            panel.add(new EnumDropDown(field.getExpected(), new DropDownValueChanged() {

                public void valueChanged(String newText, String newValue) {
                    callback.valueChanged(newValue);
                }
            }, dropDownData, oracle.getResourcePath()));
        } else {
            if (field.getExpected() != null && field.getExpected().length() > 0 && field.getNature() == FieldData.TYPE_UNDEFINED) {
                if (field.getExpected().charAt(0) == '=') {
                    field.setNature(FieldData.TYPE_VARIABLE);
                } else {
                    field.setNature(FieldData.TYPE_LITERAL);
                }
            }
            if (field.getNature() == FieldData.TYPE_UNDEFINED && isThereABoundVariableToSet() == true) {
                Image clickme = CommonAltedImages.INSTANCE.Edit();
                clickme.addClickHandler(new ClickHandler() {

                    public void onClick(ClickEvent event) {
                        showTypeChoice((Widget) event.getSource(), field);
                    }
                });
                panel.add(clickme);
            } else if (field.getNature() == FieldData.TYPE_VARIABLE) {
                panel.add(variableEditor());
            } else {
                panel.add(editableTextBox(callback, flType, field.getFieldName(), field.getExpected()));
            }
        }
    }
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) Image(com.google.gwt.user.client.ui.Image) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) EnumDropDown(org.drools.workbench.screens.guided.rule.client.widget.EnumDropDown) DropDownValueChanged(org.uberfire.ext.widgets.common.client.common.DropDownValueChanged) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DropDownData (org.kie.soup.project.datamodel.oracle.DropDownData)32 Test (org.junit.Test)23 Map (java.util.Map)9 Path (org.uberfire.backend.vfs.Path)8 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)5 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)5 ConstraintValueEditorHelper (org.drools.workbench.screens.guided.rule.client.editor.util.ConstraintValueEditorHelper)5 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)5 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 EnumDropdownService (org.kie.workbench.common.services.shared.enums.EnumDropdownService)3