Search in sources :

Example 1 with ListBoxDOMElement

use of org.drools.workbench.screens.guided.dtable.client.widget.table.columns.dom.listbox.ListBoxDOMElement in project drools-wb by kiegroup.

the class EnumMultiSelectUiColumn method doEdit.

@Override
public void doEdit(final GridCell<String> cell, final GridBodyCellRenderContext context, final Callback<GridCellValue<String>> callback) {
    final String value = extractValue(cell);
    // 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".
    presenter.getEnumLookups(this.factType, this.factField, new DependentEnumsUtilities.Context(context.getRowIndex(), context.getColumnIndex()), new Callback<Map<String, String>>() {

        @Override
        public void callback(final Map<String, String> enumLookups) {
            factory.attachDomElement(context, new Callback<ListBoxDOMElement<String, ListBox>>() {

                @Override
                public void callback(final ListBoxDOMElement<String, ListBox> e) {
                    final ListBox widget = e.getWidget();
                    for (Map.Entry<String, String> lookup : enumLookups.entrySet()) {
                        widget.addItem(lookup.getValue(), lookup.getKey());
                    }
                    final List<String> values = Arrays.asList(value.split(","));
                    for (int i = 0; i < widget.getItemCount(); i++) {
                        widget.setItemSelected(i, values.contains(widget.getValue(i)));
                    }
                    factory.toWidget(cell, widget);
                }
            }, CallbackFactory.makeOnDisplayListBoxCallback());
        }
    });
}
Also used : ListBoxDOMElement(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.dom.listbox.ListBoxDOMElement) Callback(org.uberfire.client.callbacks.Callback) DependentEnumsUtilities(org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.DependentEnumsUtilities) Map(java.util.Map) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Aggregations

Map (java.util.Map)1 ListBoxDOMElement (org.drools.workbench.screens.guided.dtable.client.widget.table.columns.dom.listbox.ListBoxDOMElement)1 DependentEnumsUtilities (org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.DependentEnumsUtilities)1 ListBox (org.gwtbootstrap3.client.ui.ListBox)1 Callback (org.uberfire.client.callbacks.Callback)1