Package com.pre.web.base

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

package com.pre.web.base;


import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.InputEvent;
import org.zkoss.zk.ui.ext.AfterCompose;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Grid;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

import com.pre.session.base.ItemManager;
import com.pre.web.OptionBinder;
import com.pre.web.WebApplication;
import com.pre.web.base.renderers.ItemRowRenderer;


public class ItemWindow extends Window implements AfterCompose{



  /**
   *
   */
  private static final long serialVersionUID = -2269875934037475234L;
  private ItemManager manager;

  public void onCreate(){
    _init()
    createMenubar();
    search("");

  }

  private void _init() {
    manager=(ItemManager)WebApplication.lookup(ItemManager.LocalJNDIName);
    Grid itemsGrid=(Grid)getFellow("itemsGrid");
    itemsGrid.setRowRenderer(new ItemRowRenderer());
    itemsGrid.setModel(new ListModelList());
    //Setup search
    Textbox searchText=(Textbox)getFellow("searchItemText");
    searchText.addEventListener("onChanging", new EventListener(){
      public void onEvent(Event event) throws Exception {
        search(((InputEvent)event).getValue());
      }
    });
    Combobox searchTypeCombo=(Combobox)getFellow("searchTypeCombo");
    searchTypeCombo.addEventListener("onSelect", new EventListener(){
      public void onEvent(Event event) throws Exception {
        Textbox searchText=(Textbox)getFellow("searchItemText");
        search(searchText.getValue());
      }
    });
  }

  private void setupPaging() {
    Grid itemsGrid=(Grid)getFellow("itemsGrid");

  }

  private void createMenubar() {
    OptionBinder.bindStandardOptions(this, "itemsGrid", "details/ItemDetails.zul");
  }


 

  private void updateGrid(String searchKey) {
    Grid itemsGrid=(Grid)getFellow("itemsGrid");
    ListModelList model=(ListModelList)itemsGrid.getModel();
    model.clear();
    model.addAll(manager.searchByCode(searchKey, 0L, 18));

  }

  private void updateGridWithDescriptionSearch(String searchKey) {
    Grid itemsGrid=(Grid)getFellow("itemsGrid");
    ListModelList model=(ListModelList)itemsGrid.getModel();
    model.clear();
    model.addAll(manager.searchByShortDescription(searchKey, 0L, 18));

  }



  private void updateGridWithEANSearch(String searchKey) {
    Grid itemsGrid=(Grid)getFellow("itemsGrid");
    ListModelList model=(ListModelList)itemsGrid.getModel();
    model.clear();
    model.addAll(manager.searchByEAN(searchKey, 0L, 0));


  }

  private void search(String searchKey){

    //refresh with last search type
    final Combobox searchTypeCombo=(Combobox)getFellow("searchTypeCombo");
    int selectedIndex=searchTypeCombo.getSelectedIndex();
    if(selectedIndex>-1){
      int searchType=new Integer(searchTypeCombo.getSelectedItem().getValue().toString());
      switch(searchType){
      case 1 :
        updateGridWithEANSearch(searchKey);
        break;
      case 2 :
        updateGridWithDescriptionSearch(searchKey);
        break;
      case 3 :             
        updateGrid(searchKey);
        break;
      }
    }else{
      updateGrid("");
    }
  }

  public void onRefresh(){
    System.out.println("onRefresh");
    Textbox searchText=(Textbox)getFellow("searchItemText");
    search(searchText.getValue());
  }
 
  public void afterCompose() {
    setupPaging();

  }

}
TOP

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

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.