All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tools.dynamia.zk.ui.ZKCombobox Maven / Gradle / Ivy

There is a newer version: 5.2.1
Show newest version
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);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy