All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gxt-2.1.1-sources.com.extjs.gxt.ui.client.widget.toolbar.LiveToolItem Maven / Gradle / Ivy

There is a newer version: 2.3.1-gwt22
Show newest version
/*
 * Ext GWT - Ext for GWT
 * Copyright(c) 2007-2009, Ext JS, LLC.
 * [email protected]
 * 
 * http://extjs.com/license
 */
package com.extjs.gxt.ui.client.widget.toolbar;

import com.extjs.gxt.ui.client.GXT;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.LiveGridEvent;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.LiveGridView;

/**
 * A specialized tool item for >LiveGridView that shows the current
 * location and total records.
 * 
 * @see LiveGridView
 */
public class LiveToolItem extends LabelToolItem {

  private LiveGridView gridView;
  private Listener> listener;

  /**
   * Binds the tool item to the specified grid, must be called.
   * 
   * @param grid the grid
   */
  public void bindGrid(Grid grid) {
    if (gridView != null) {
      gridView.removeListener(Events.LiveGridViewUpdate, listener);
    }
    assert grid.getView() instanceof LiveGridView : "the GridView needs to be an instance of LiveGridView";
    if (listener == null) {
      listener = new Listener>() {
        public void handleEvent(LiveGridEvent be) {
          onUpdate(be);
        }
      };
    }
    gridView = (LiveGridView) grid.getView();
    gridView.addListener(Events.LiveGridViewUpdate, listener);
  }

  protected void onUpdate(LiveGridEvent be) {
    int pageSize = be.getPageSize();
    int viewIndex = be.getViewIndex();
    int totalCount = be.getTotalCount();
    int i = pageSize + viewIndex;
    if (i > totalCount) {
      i = totalCount;
    }
    setLabel(GXT.MESSAGES.pagingToolBar_displayMsg((totalCount == 0 ? 0 : viewIndex + 1), i, (int) totalCount));
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy