/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.webgocommerce.client.view.tree;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.CheckboxCell;
import com.google.gwt.cell.client.CompositeCell;
import com.google.gwt.cell.client.FieldUpdater;
import com.google.gwt.cell.client.HasCell;
import com.google.gwt.dom.client.Element;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.view.client.DefaultSelectionEventManager;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.MultiSelectionModel;
import com.google.gwt.view.client.TreeViewModel;
import com.webgocommerce.server.beans.MenuBar;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
*
* @author jofrantoba
*/
public class TreeMenuModel implements TreeViewModel {
private final DefaultSelectionEventManager<MenuBar> selectionManager
= DefaultSelectionEventManager.createCheckboxManager();
private Cell<MenuBar> menuBarCell;
private final MultiSelectionModel<MenuBar> selectionModel = new MultiSelectionModel<MenuBar>(new ListDataProvider<MenuBar>());
private MenuBar rootMenu;
public TreeMenuModel(MenuBar rootMenu) {
this.rootMenu = rootMenu;
initComponents();
initListener();
}
public TreeMenuModel() {
initComponents();
initListener();
}
private void initComponents() {
List<HasCell<MenuBar, ?>> hasCells = new ArrayList<HasCell<MenuBar, ?>>();
hasCells.add(new HasCell<MenuBar, Boolean>() {
private CheckboxCell cell = new CheckboxCell(true, true);
@Override
public Cell<Boolean> getCell() {
return cell;
}
@Override
public FieldUpdater<MenuBar, Boolean> getFieldUpdater() {
return new FieldUpdater<MenuBar, Boolean>() {
public void update(int index, MenuBar object, Boolean value) {
selectionModel.setSelected(object, value);
object.setOperacion("A");
object.setEstado(value==true?"A":"D");
if (object.getPadre() != null && !object.getPadre().getVariable().equalsIgnoreCase("root")) {
if (value) {
SelectedFather(object);
}
}
isSelectedChild(object, value);
}
};
}
@Override
public Boolean getValue(MenuBar object) {
if (object.getEstado().equalsIgnoreCase("A") && object.getOperacion().equalsIgnoreCase("N")) {
selectionModel.setSelected(object, true);
return true;
}
return selectionModel.isSelected(object);
}
public void SelectedFather(MenuBar menuBar) {
if (!selectionModel.isSelected(menuBar.getPadre())) {
selectionModel.setSelected(menuBar.getPadre(), true);
menuBar.getPadre().setOperacion("A");
menuBar.getPadre().setEstado("A");
if (menuBar.getPadre() != null) {
SelectedFather(menuBar.getPadre());
}
}
}
public void isSelectedChild(MenuBar menuBar, Boolean val) {
Iterator<MenuBar> iterador = menuBar.getHijos().iterator();
while (iterador.hasNext()) {
MenuBar bean = iterador.next();
selectionModel.setSelected(bean, val);
bean.setOperacion("A");
bean.setEstado(val==true?"A":"D");
isSelectedChild(bean, val);
}
}
});
menuBarCell = new CompositeCell<MenuBar>(hasCells) {
@Override
public void render(Cell.Context context, MenuBar value, SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<table><tbody><tr>");
super.render(context, value, sb);
sb.appendHtmlConstant("</tr></tbody></table>");
}
@Override
protected Element getContainerElement(Element parent) {
return parent.getFirstChildElement().getFirstChildElement().getFirstChildElement();
}
@Override
protected <X> void render(Cell.Context context, MenuBar value,
SafeHtmlBuilder sb, HasCell<MenuBar, X> hasCell) {
Cell<X> cell = hasCell.getCell();
sb.appendHtmlConstant("<td>");
cell.render(context, hasCell.getValue(value), sb);
sb.appendHtmlConstant(" " + value.getOrden());
sb.appendHtmlConstant(" " + value.getDescripcion());
sb.appendHtmlConstant("</td>");
}
};
}
private void initListener() {
}
@Override
public <T> NodeInfo<?> getNodeInfo(T value) {
ListDataProvider<MenuBar> dataProvider
= new ListDataProvider<MenuBar>(((MenuBar) value).getHijos());
return new DefaultNodeInfo<MenuBar>(dataProvider, menuBarCell, selectionModel, selectionManager, null);
}
@Override
public boolean isLeaf(Object value) {
return ((MenuBar) value).getNumSubMenu() == 0;
}
public MenuBar getRootMenu() {
return rootMenu;
}
public void setRootMenu(MenuBar rootMenu) {
this.rootMenu = rootMenu;
}
}
Here Class MenuBar
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.webgocommerce.server.beans;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
*
* @author jofrantoba
*/
public class MenuBar implements Serializable{
private Integer idMenuBar;
private String variable;
private String descripcion;
private String tipo;
private Integer orden;
private Integer nivel;
private Integer idMenuPadre;
private Integer grupo;
private Integer numSubMenu;
private List<MenuBar> hijos=new ArrayList<MenuBar>();
private Long version;
private String operacion="N";
private MenuBar padre;
private Integer idBdUsuario;
private String estado="D";
private String comando;
public String getComando() {
return comando;
}
public void setComando(String comando) {
this.comando = comando;
}
public Integer getIdBdUsuario() {
return idBdUsuario;
}
public void setIdBdUsuario(Integer idBdUsuario) {
this.idBdUsuario = idBdUsuario;
}
public String getEstado() {
return estado;
}
public void setEstado(String estado) {
this.estado = estado;
}
public MenuBar getPadre() {
return padre;
}
public void setPadre(MenuBar padre) {
this.padre = padre;
}
public Integer getIdMenuBar() {
return idMenuBar;
}
public void setIdMenuBar(Integer idMenuBar) {
this.idMenuBar = idMenuBar;
}
public String getVariable() {
return variable;
}
public void setVariable(String variable) {
this.variable = variable;
}
public String getDescripcion() {
return descripcion;
}
public void setDescripcion(String descripcion) {
this.descripcion = descripcion;
}
public String getTipo() {
return tipo;
}
public void setTipo(String tipo) {
this.tipo = tipo;
}
public Integer getOrden() {
return orden;
}
public void setOrden(Integer orden) {
this.orden = orden;
}
public Integer getNivel() {
return nivel;
}
public void setNivel(Integer nivel) {
this.nivel = nivel;
}
public Integer getIdMenuPadre() {
return idMenuPadre;
}
public void setIdMenuPadre(Integer idMenuPadre) {
this.idMenuPadre = idMenuPadre;
}
public Integer getGrupo() {
return grupo;
}
public void setGrupo(Integer grupo) {
this.grupo = grupo;
}
public Integer getNumSubMenu() {
return numSubMenu;
}
public void setNumSubMenu(Integer numSubMenu) {
this.numSubMenu = numSubMenu;
}
public List<MenuBar> getHijos() {
return hijos;
}
public void setHijos(List<MenuBar> hijos) {
this.hijos = hijos;
}
public Long getVersion() {
return version;
}
public void setVersion(Long version) {
this.version = version;
}
public String getOperacion() {
return operacion;
}
public void setOperacion(String operacion) {
this.operacion = operacion;
}
public void setHijo(MenuBar bean){
this.hijos.add(bean);
}
@Override
public int hashCode() {
int hash = 7;
hash = 37 * hash + Objects.hashCode(this.idMenuBar);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final MenuBar other = (MenuBar) obj;
if (!Objects.equals(this.idMenuBar, other.idMenuBar)) {
return false;
}
return true;
}
}
La información contenida en este e-mail es confidencial, privilegiada y está dirigida exclusivamente a su destinatario. Su revisión, difusión, distribución o copiado está prohibido. Si ha recibido este e-mail por error por favor bórrelo y envíe un mensaje al remitente.
The information contained in this e-mail is privileged and confidential and is intended only for its addressee. Any review, dissemination, distribution or copying of this is prohibited. If you have received this mail in error please delete the original message and e-mail us.
2015-05-28 1:27 GMT-05:00 Mohammed Sameen <sameen.cse@gmail.com>:
--See the below image
I need to create a widget similar to the above one.Is there any built-in widget available to integarate in my GWT Application or How to create this custom checkbox selectable tree widget using GWT?Is it possible?Any suggestion.
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment