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

com.extjs.gxt.ui.client.data.BaseTreeLoader Maven / Gradle / Ivy

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

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.event.BaseEvent;
import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * Default implementation of the TreeLoader interface.
 * 
 * 
*
Events:
* *
BeforeLoad : LoadEvent(loader, config)
*
Fires before a load operation. Listeners can cancel the action by * calling {@link BaseEvent#setCancelled(boolean)}.
*
    *
  • loader : this
  • *
  • config : the load config
  • *
*
* *
Load : LoadEvent(loader, config, result)
*
Fires after the button is selected.
*
    *
  • loader : this
  • *
  • config : the load config
  • *
  • result : the load result
  • *
*
* *
LoadException : LoadEvent(loader, config, result)
*
Fires after the button is selected.
*
    *
  • loader : this
  • *
  • config : the load config
  • *
  • result : the load result
  • *
*
*
* * @param the model data type */ public class BaseTreeLoader extends BaseLoader> implements TreeLoader { protected List children = new ArrayList(); /** * Creates a new tree loader instance. * * @param proxy the data reader */ @SuppressWarnings({"unchecked", "rawtypes"}) public BaseTreeLoader(DataProxy proxy) { super(proxy); } /** * Creates a new tree loader instance. * * @param reader the data reader */ @SuppressWarnings({"unchecked", "rawtypes"}) public BaseTreeLoader(DataReader reader) { super(reader); } /** * Creates a new tree loader instance. * * @param proxy the data proxy * @param reader the data reader */ @SuppressWarnings({"unchecked", "rawtypes"}) public BaseTreeLoader(DataProxy proxy, DataReader reader) { super(proxy, reader); } public boolean loadChildren(M parent) { children.add(parent); return load(parent); } public boolean hasChildren(M parent) { if (parent instanceof TreeModel) { return !((TreeModel) parent).isLeaf(); } return false; } @Override protected void loadData(Object config, AsyncCallback> callback) { try { List data = (List) reader.read(config, config); callback.onSuccess(data); } catch (Exception e) { callback.onFailure(e); } } @Override @SuppressWarnings("unchecked") protected void onLoadFailure(Object loadConfig, Throwable t) { TreeLoadEvent evt = new TreeLoadEvent(this, (M) loadConfig, t); if (loadConfig != null && children.contains(loadConfig)) { evt.parent = (M) loadConfig; children.remove(loadConfig); } fireEvent(LoadException, evt); } @Override @SuppressWarnings("unchecked") protected void onLoadSuccess(Object loadConfig, List result) { TreeLoadEvent evt = new TreeLoadEvent(this, (M) loadConfig, result); if (loadConfig != null && children.contains(loadConfig)) { evt.parent = (M) loadConfig; children.remove(loadConfig); } fireEvent(Load, evt); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy