Package com.pre.web.base

Source Code of com.pre.web.base.UOMWindow

package com.pre.web.base;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zul.Checkbox;
import org.zkoss.zul.Grid;
import org.zkoss.zul.Label;
import org.zkoss.zul.Menu;
import org.zkoss.zul.Menubar;
import org.zkoss.zul.Menuitem;
import org.zkoss.zul.Menupopup;
import org.zkoss.zul.Row;
import org.zkoss.zul.Rows;
import org.zkoss.zul.Window;

import com.pre.entity.base.UnitOfMeasure;
import com.pre.session.base.UnitOfMeasureManager;
import com.pre.web.WebApplication;

public class UOMWindow extends Window {

 

  /**
   *
   */
  private static final long serialVersionUID = 5879298692126352891L;

  public void onCreate(){
    createMenubar();
    feedGrid();
  }

  private void createMenubar() {
    Menubar menubar=(Menubar)getFellow("menubar");
    Menu actionsMenu=new Menu("Actions");
    menubar.appendChild(actionsMenu);
    Menupopup popup=new Menupopup();
    actionsMenu.appendChild(popup);
    Menuitem createItem =new Menuitem("Create");
    createItem.addEventListener("onClick", new EventListener(){
      public void onEvent(Event event) throws Exception {
        Map<String, ArrayList<String>> map=new HashMap<String, ArrayList<String>>();
        ArrayList<String> options=new ArrayList<String>();
        options.add("create");
        map.put("options", options);
        openDetails(map);
       
      }
    });
    Menuitem showItem =new Menuitem("Show");
    showItem.addEventListener("onClick", new EventListener(){
      public void onEvent(Event event) throws Exception {
        Map<String, ArrayList<String>> map=new HashMap<String, ArrayList<String>>();
        ArrayList<String> options=new ArrayList<String>();
        options.add("show");
        map.put("options", options);
        openDetails(map);
       
      }
    });
    Menuitem editItem=new Menuitem("Edit");
    editItem.addEventListener("onClick", new EventListener(){
      public void onEvent(Event event) throws Exception {
        Map<String, ArrayList<String>> map=new HashMap<String, ArrayList<String>>();
        ArrayList<String> options=new ArrayList<String>();
        options.add("edit");
        map.put("options", options);
        openDetails(map);
       
      }
    });
    Menuitem deleteItem=new Menuitem("Delete");
    deleteItem.addEventListener("onClick", new EventListener(){
      public void onEvent(Event event) throws Exception {
        Map<String, ArrayList<String>> map=new HashMap<String, ArrayList<String>>();
        ArrayList<String> options=new ArrayList<String>();
        options.add("delete");
        map.put("options", options);
        openDetails(map);
       
      }
    });
    popup.appendChild(createItem);
    popup.appendChild(showItem);
    popup.appendChild(editItem);
    popup.appendChild(deleteItem);
    appendChild(menubar);
   
   
  }

 
  @SuppressWarnings("unchecked")
  private void openDetails(Map map) throws Exception{
    Window child=(Window)Executions.createComponents("./UOMDetails.zul", null, map);
    ArrayList<String> ids=new ArrayList<String>();
    Rows rows=((Grid)getFellow("uomGrid")).getRows();
    List rowList=rows.getChildren();
    Iterator it=rowList.iterator();
    while(it.hasNext()){
      Object next=it.next();
      if(next instanceof Row){
        Iterator fit=((Row)next).getChildren().iterator();
        if(((Checkbox)fit.next()).isChecked()){
          ids.add(((Label)fit.next()).getValue());
        }
      }
    }
    map.put("ids", ids);
    child.setClosable(true);
    child.doModal();
    refresh();
  }
 
  private void feedGrid() {
    Grid companiesGrid=(Grid)getFellow("uomGrid");
    Rows gridRows=companiesGrid.getRows();
    UnitOfMeasureManager manager=(UnitOfMeasureManager)WebApplication.lookup(UnitOfMeasureManager.LocalJNDIName);
    List<UnitOfMeasure> divisions=manager.findAll();
    Iterator<UnitOfMeasure> it=divisions.iterator();
    while(it.hasNext()){
      Row row=new Row();
      UnitOfMeasure c=it.next();
      row.appendChild(new Checkbox());
      row.appendChild(new Label(c.getId().toString()));
      row.appendChild(new Label(c.getName()));
      row.appendChild(new Label(c.getDescription().getShortDescription()));
     
      gridRows.appendChild(row);
    }
   
  }
 
  private void refresh(){
    Grid divisionsGrid=(Grid)getFellow("uomGrid");
    divisionsGrid.removeChild(divisionsGrid.getRows());
    Rows newRows=new Rows();
    divisionsGrid.appendChild(newRows);
    feedGrid();
   
  }

}
TOP

Related Classes of com.pre.web.base.UOMWindow

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.