Package jfix.zk

Source Code of jfix.zk.Searchbox

/*
    Copyright (C) 2010 maik.jablonski@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package jfix.zk;

import jfix.util.I18N;

import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Hbox;
import org.zkoss.zul.Textbox;

public abstract class Searchbox extends Hbox {

  Textbox searchField = new Textbox();
  Button searchButton = new Button(I18N.get("Search"), Images.SystemSearch);
  Button resetButton = new Button(I18N.get("Reset"), Images.ViewRefresh);

  public abstract void searchPerformed(String search);

  public Searchbox() {
    appendChild(searchField);
    appendChild(searchButton);
    appendChild(resetButton);
    initListener();
  }

  private void initListener() {
    EventListener searchAction = new EventListener() {
      public void onEvent(Event e) {
        searchPerformed(searchField.getText());
      }
    };

    EventListener resetAction = new EventListener() {
      public void onEvent(Event e) {
        clearSearch();
        searchPerformed(null);
      }
    };

    searchButton.addEventListener(Events.ON_CLICK, searchAction);
    resetButton.addEventListener(Events.ON_CLICK, resetAction);
    searchField.addEventListener(Events.ON_OK, searchAction);
  }

  public void setSearch(String search) {
    searchField.setText(search);
    searchPerformed(search);
  }
 
  public void clearSearch() {
    searchField.setText(null);
  }
}
TOP

Related Classes of jfix.zk.Searchbox

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.