use of org.kie.workbench.common.widgets.client.widget.EnumDropDownUtilities in project drools-wb by kiegroup.
the class DTCellValueWidgetFactory method makeListBox.
private ListBox makeListBox(final DropDownData dd, final boolean isMultipleSelect, final DTCellValue52 value) {
final ListBox lb = new ListBox();
lb.setMultipleSelect(isMultipleSelect);
final EnumDropDownUtilities utilities = new EnumDropDownUtilities() {
@Override
protected int addItems(final ListBox listBox) {
if (allowEmptyValues) {
listBox.addItem(GuidedDecisionTableConstants.INSTANCE.Choose(), "");
}
return allowEmptyValues ? 1 : 0;
}
@Override
protected void selectItem(final ListBox listBox) {
final int itemCount = listBox.getItemCount();
listBox.setEnabled(itemCount > 0);
if (itemCount > 0) {
listBox.setSelectedIndex(0);
value.setStringValue(listBox.getValue(0));
} else {
value.setStringValue(null);
}
}
};
final String strValue = value.getStringValue() == null ? "" : value.getStringValue();
utilities.setDropDownData(strValue, dd, isMultipleSelect, oracle.getResourcePath(), lb);
return lb;
}
use of org.kie.workbench.common.widgets.client.widget.EnumDropDownUtilities in project drools-wb by kiegroup.
the class ValueEditorFactory method makeListBox.
private ListBox makeListBox(final DropDownData dd, final HasValue hasValue, final AsyncPackageDataModelOracle oracle, final boolean isMultipleSelect) {
final ListBox lb = new ListBox(isMultipleSelect);
final EnumDropDownUtilities utilities = new EnumDropDownUtilities() {
@Override
protected int addItems(final ListBox listBox) {
return 0;
}
@Override
protected void selectItem(final ListBox listBox) {
final int itemCount = listBox.getItemCount();
listBox.setEnabled(itemCount > 0);
if (itemCount > 0) {
listBox.setSelectedIndex(0);
hasValue.getValue().setValue(listBox.getValue(0));
} else {
hasValue.getValue().setValue("");
}
}
};
final String value = hasValue.getValue().getValue().toString();
utilities.setDropDownData(value, dd, isMultipleSelect, oracle.getResourcePath(), lb);
// Wire up update handler
lb.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
String value = null;
if (lb.isMultipleSelect()) {
for (int i = 0; i < lb.getItemCount(); i++) {
if (lb.isItemSelected(i)) {
if (value == null) {
value = lb.getValue(i);
} else {
value = value + "," + lb.getValue(i);
}
}
}
} else {
int index = lb.getSelectedIndex();
if (index > -1) {
value = lb.getValue(index);
}
}
hasValue.getValue().setValue(value);
}
});
return lb;
}
Aggregations