139 lines
4.0 KiB
Java
139 lines
4.0 KiB
Java
/*
|
|
* To change this template, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
package com.rjconsultores.ventaboletos.web.utilerias;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.zkoss.util.resource.Labels;
|
|
import org.zkoss.zk.ui.WrongValueException;
|
|
import org.zkoss.zk.ui.event.Event;
|
|
import org.zkoss.zk.ui.event.EventListener;
|
|
import org.zkoss.zk.ui.event.InputEvent;
|
|
import org.zkoss.zkplus.databind.BindingListModel;
|
|
import org.zkoss.zkplus.databind.BindingListModelList;
|
|
import org.zkoss.zkplus.spring.SpringUtil;
|
|
import org.zkoss.zul.Combobox;
|
|
import org.zkoss.zul.Comboitem;
|
|
|
|
import com.rjconsultores.ventaboletos.entidad.Usuario;
|
|
import com.rjconsultores.ventaboletos.service.UsuarioService;
|
|
|
|
/**
|
|
*
|
|
* @author Wilian Domingues
|
|
*/
|
|
public class MyComboboxUsuario extends Combobox {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private UsuarioService usuarioService;
|
|
private List<Usuario> lsUsuario;
|
|
private Usuario initialValue;
|
|
|
|
public MyComboboxUsuario() {
|
|
|
|
super();
|
|
|
|
usuarioService = (UsuarioService) SpringUtil.getBean("usuarioService");
|
|
lsUsuario = new ArrayList<Usuario>();
|
|
|
|
this.setAutodrop(false);
|
|
this.setAutocomplete(false);
|
|
|
|
this.addEventListener("onOK", new EventListener() {
|
|
|
|
@Override
|
|
public void onEvent(Event event) throws Exception {
|
|
String strUsuario = MyComboboxUsuario.this.getText().toUpperCase();
|
|
|
|
if (strUsuario.length() < MyComboboxParada.minLength) {
|
|
return;
|
|
}
|
|
if (!strUsuario.isEmpty()) {
|
|
lsUsuario = usuarioService.buscarPeloNomeLike(strUsuario);
|
|
|
|
BindingListModel listModelUsuario = new BindingListModelList(lsUsuario, true);
|
|
MyComboboxUsuario.this.setModel(listModelUsuario);
|
|
|
|
MyComboboxUsuario.this.open();
|
|
} else {
|
|
lsUsuario.clear();
|
|
|
|
BindingListModel listModelUsuario = new BindingListModelList(lsUsuario, true);
|
|
MyComboboxUsuario.this.setModel(listModelUsuario);
|
|
}
|
|
}
|
|
});
|
|
|
|
this.addEventListener("onChanging", new EventListener() {
|
|
|
|
public void onEvent(Event event) throws Exception {
|
|
InputEvent ev = (InputEvent) event;
|
|
String strUsuario = ev.getValue();
|
|
if (strUsuario.length() < 2) {
|
|
lsUsuario.clear();
|
|
|
|
BindingListModel listModelUsuario = new BindingListModelList(lsUsuario, true);
|
|
MyComboboxUsuario.this.setModel(listModelUsuario);
|
|
|
|
MyComboboxUsuario.this.close();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public Usuario getInitialValue() {
|
|
return initialValue;
|
|
}
|
|
|
|
public void setInitialValue(Usuario initialValue) {
|
|
if (initialValue == null) {
|
|
return;
|
|
}
|
|
List<Usuario> ls = new ArrayList<Usuario>();
|
|
ls.add(initialValue);
|
|
|
|
this.setModel(new BindingListModelList(ls, false));
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param checaBusqueda
|
|
* @throws WrongValueException
|
|
*/
|
|
public String getValue(boolean checaBusqueda) throws WrongValueException {
|
|
if (checaBusqueda) {
|
|
if (this.getSelectedItem() == null) {
|
|
throw new WrongValueException(this, Labels.getLabel("MSG.Error.combobox.hacerBusqueda"));
|
|
}
|
|
}
|
|
|
|
return super.getValue();
|
|
}
|
|
|
|
public Usuario getSelectedUsuario() {
|
|
return this.getSelectedItem() != null ? (Usuario)this.getSelectedItem().getValue(): null;
|
|
}
|
|
|
|
public void setSelectedUsuario(Integer usuarioRepId) {
|
|
if(usuarioRepId != null ){
|
|
Usuario usuario = usuarioService.obtenerID(usuarioRepId);
|
|
setSelectedUsuario(usuario);
|
|
}
|
|
}
|
|
|
|
public void setSelectedUsuario(Usuario usuario) {
|
|
if(usuario != null ){
|
|
Comboitem ciUser = new Comboitem(usuario.toString());
|
|
ciUser.setAttribute("value", usuario);
|
|
ciUser.setValue(usuario);
|
|
ciUser.setParent(this);
|
|
this.setSelectedItem(ciUser);
|
|
}
|
|
|
|
}
|
|
}
|