Subversion Repositories eFlore/Applications.coel

Compare Revisions

Ignore whitespace Rev 1286 → Rev 1287

/branches/v1.0-syrah/src/org/tela_botanica/client/composants/pagination/ProxyValeur.java
New file
0,0 → 1,73
package org.tela_botanica.client.composants.pagination;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
 
import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.ValeurListe;
import org.tela_botanica.client.modeles.ValeurListeAsyncDao;
import org.tela_botanica.client.util.Debug;
 
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.data.BasePagingLoadConfig;
import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
import com.extjs.gxt.ui.client.data.DataReader;
import com.extjs.gxt.ui.client.data.MemoryProxy;
import com.extjs.gxt.ui.client.data.ModelData;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.user.client.rpc.AsyncCallback;
 
public class ProxyValeur<D> extends Proxy {
private String nomListe = "";
public ProxyValeur(String nomListe) {
super();
this.nomListe = nomListe;
}
@Override
public void load(TransformateurJSONaModelData reader, Object loadConfig, AsyncCallback callback, String recherche) {
this.reader = reader;
this.callback = callback;
this.loadConfig = loadConfig;
 
BasePagingLoadConfig lc = (BasePagingLoadConfig)loadConfig;
mediateur.obtenirListeValeurEtRafraichir(this, nomListe, true, recherche, lc.getOffset(), lc.getLimit());
}
 
 
@Override
@SuppressWarnings("unchecked")
public void rafraichir(Object nouvellesDonnees) {
try
{
data = nouvellesDonnees;
D d = null;
 
if (reader != null)
{
d = (D) reader.read(loadConfig, data);
}
else
{
d = (D) data;
if (d instanceof List)
{
d = (D) new ArrayList((List) d);
}
}
 
callback.onSuccess(d);
}
catch (Exception e)
{
callback.onFailure(e);
}
}
 
}
/branches/v1.0-syrah/src/org/tela_botanica/client/composants/pagination/ChargeurListe.java
New file
0,0 → 1,62
package org.tela_botanica.client.composants.pagination;
 
import com.extjs.gxt.ui.client.data.BasePagingLoader;
import com.extjs.gxt.ui.client.data.LoadEvent;
import com.extjs.gxt.ui.client.data.PagingLoadResult;
import com.google.gwt.user.client.rpc.AsyncCallback;
 
public class ChargeurListe<D extends PagingLoadResult<?>> extends BasePagingLoader<D> {
 
private String recherche = "";
 
@SuppressWarnings("unchecked")
public ChargeurListe(Proxy proxy, TransformateurJSONaModelData reader) {
super(proxy, reader);
}
public boolean load(Object loadConfig, String recherche) {
if (fireEvent(BeforeLoad, new LoadEvent(this, loadConfig))) {
lastConfig = loadConfig;
 
this.recherche = recherche;
loadData(loadConfig, recherche);
return true;
}
else return false;
}
public boolean load(Object loadConfig) {
if (fireEvent(BeforeLoad, new LoadEvent(this, loadConfig))) {
lastConfig = loadConfig;
loadData(loadConfig, recherche);
return true;
}
return false;
}
public void load(int offset, int limit) {
this.offset = offset;
this.limit = limit;
load();
}
public boolean load() {
Object config = (reuseConfig && lastConfig != null) ? lastConfig : newLoadConfig();
config = prepareLoadConfig(config);
return load(config);
}
@SuppressWarnings("unchecked")
protected void loadData(final Object config, String recherche) {
AsyncCallback<D> callback = new AsyncCallback<D>() {
public void onFailure(Throwable caught) {
onLoadFailure(config, caught);
}
public void onSuccess(D result) {
onLoadSuccess(config, result);
}
};
((Proxy)proxy).load((TransformateurJSONaModelData)reader, config, callback, recherche);
}
}
/branches/v1.0-syrah/src/org/tela_botanica/client/composants/pagination/Proxy.java
New file
0,0 → 1,55
package org.tela_botanica.client.composants.pagination;
 
import java.util.ArrayList;
import java.util.List;
 
import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.util.Debug;
 
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.data.BasePagingLoadConfig;
import com.extjs.gxt.ui.client.data.DataReader;
import com.extjs.gxt.ui.client.data.MemoryProxy;
import com.google.gwt.user.client.rpc.AsyncCallback;
 
public abstract class Proxy<D> extends MemoryProxy<D> implements Rafraichissable {
 
protected Mediateur mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);
protected DataReader<D> reader = null;
protected Object loadConfig = null;
protected AsyncCallback<D> callback = null;
protected static Object data;
public Proxy() {
super(data);
}
 
public abstract void load(TransformateurJSONaModelData<D> reader, Object loadConfig, AsyncCallback<D> callback, String recherche);
 
@Override
@SuppressWarnings("unchecked")
public void rafraichir(Object nouvellesDonnees) {
try {
data = nouvellesDonnees;
D d = null;
if (reader != null) {
d = reader.read(loadConfig, data);
} else {
d = (D) data;
if (d instanceof List) {
d = (D) new ArrayList((List) d);
}
}
callback.onSuccess(d);
} catch (Exception e) {
callback.onFailure(e);
}
}
 
}
/branches/v1.0-syrah/src/org/tela_botanica/client/composants/pagination/TransformateurJSONaModelData.java
New file
0,0 → 1,133
package org.tela_botanica.client.composants.pagination;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import org.tela_botanica.client.modeles.ValeurListe;
import org.tela_botanica.client.util.Debug;
 
import com.extjs.gxt.ui.client.data.BasePagingLoadConfig;
import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
import com.extjs.gxt.ui.client.data.DataField;
import com.extjs.gxt.ui.client.data.DataReader;
import com.extjs.gxt.ui.client.data.JsonPagingLoadResultReader;
import com.extjs.gxt.ui.client.data.JsonReader;
import com.extjs.gxt.ui.client.data.ListLoadResult;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.PagingLoadResult;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
 
public class TransformateurJSONaModelData<D> extends JsonPagingLoadResultReader<D> {
 
private ModelType modelType = null;
public TransformateurJSONaModelData(ModelType modelType) {
super(modelType);
this.modelType = modelType;
}
 
@SuppressWarnings("unchecked")
@Override
protected Object createReturnData(Object loadConfig, List<ModelData> records, int totalCount) {
ListLoadResult<?> result = (ListLoadResult<?>) super.createReturnData(loadConfig, records, totalCount);
 
if (result instanceof PagingLoadResult) {
PagingLoadResult<?> r = (PagingLoadResult<?>) result;
r.setTotalLength(totalCount);
 
if (loadConfig instanceof PagingLoadConfig) {
PagingLoadConfig config = (PagingLoadConfig) loadConfig;
r.setOffset(config.getOffset());
}
}
return result;
 
}
 
@Override
protected BasePagingLoadResult<ModelData> newLoadResult(Object loadConfig, List<ModelData> models) {
return new BasePagingLoadResult<ModelData>(models);
}
 
@SuppressWarnings("unchecked")
public D read(Object loadConfig, Object data) {
JSONObject jsonRoot = null;
if (data instanceof JSONObject) {
jsonRoot = (JSONObject) data;
}
JSONArray root = (JSONArray) jsonRoot.get(modelType.getRoot());
int size = root.size();
ArrayList<ModelData> models = new ArrayList<ModelData>();
for (int i = 0; i < size; i++) {
JSONObject obj = (JSONObject) root.get(i);
ModelData model = newModelInstance();
for (int j = 0; j < modelType.getFieldCount(); j++) {
DataField field = modelType.getField(j);
String name = field.getName();
Class type = field.getType();
String map = field.getMap() != null ? field.getMap() : field.getName();
JSONValue value = obj.get(map);
if (value == null) continue;
if (value.isArray() != null) {
// nothing
} else if (value.isBoolean() != null) {
model.set(name, value.isBoolean().booleanValue());
} else if (value.isNumber() != null) {
if (type != null) {
Double d = value.isNumber().doubleValue();
if (type.equals(Integer.class)) {
model.set(name, d.intValue());
} else if (type.equals(Long.class)) {
model.set(name, d.longValue());
} else if (type.equals(Float.class)) {
model.set(name, d.floatValue());
} else {
model.set(name, d);
}
} else {
model.set(name, value.isNumber().doubleValue());
}
} else if (value.isObject() != null) {
// nothing
} else if (value.isString() != null) {
String s = value.isString().stringValue();
if (type != null) {
if (type.equals(Date.class)) {
if ("timestamp".equals(field.getFormat())) {
Date d = new Date(Long.parseLong(s) * 1000);
model.set(name, d);
} else {
DateTimeFormat format = DateTimeFormat.getFormat(field.getFormat());
Date d = format.parse(s);
model.set(name, d);
}
}
} else {
model.set(name, s);
}
} else if (value.isNull() != null) {
model.set(name, null);
}
}
models.add(model);
}
int totalCount = models.size();
if (modelType.getTotalName() != null) {
totalCount = getTotalCount(jsonRoot);
}
return (D) createReturnData(loadConfig, models, totalCount);
}
 
}