tools.dynamia.zk.ui.ZKCombobox Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tools.dynamia.zk Show documentation
Show all versions of tools.dynamia.zk Show documentation
Classes for ZK web application
package tools.dynamia.zk.ui;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.ComboitemRenderer;
import org.zkoss.zul.ListModelList;
import tools.dynamia.ui.ComboboxComponent;
import tools.dynamia.ui.UIComponent;
import java.util.List;
/**
* ZK implementation of {@link ComboboxComponent}
*/
public class ZKCombobox extends Combobox implements ComboboxComponent {
private ListModelList model;
private List data;
@Override
public void setData(List data) {
this.data = data;
model = new ListModelList<>(data);
setModel(model);
}
@Override
public List getData() {
return data;
}
@Override
public T getSelected() {
if (model != null) {
var selection = model.getSelection();
if (selection != null) {
return selection.stream().findFirst().orElse(null);
}
}
return null;
}
@Override
public void setSelected(T item) {
if (model != null && item != null) {
model.addToSelection(item);
}
}
@Override
public void clear() {
if (model != null) {
model.clear();
}
}
@Override
public void refresh() {
setData(data);
}
@Override
public void setItemRenderer(Object itemRenderer) {
if (itemRenderer instanceof ComboitemRenderer> renderer) {
super.setItemRenderer(renderer);
}
}
}