Rev 1029 | Blame | Last modification | View Log | RSS feed
package org.tela_botanica.cel.client.vues.observation.listeobservation;
import org.tela_botanica.cel.client.modeles.Observation;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.DefaultSelectionEventManager;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.MultiSelectionModel;
import com.google.gwt.view.client.ProvidesKey;
import com.google.gwt.view.client.SelectionChangeEvent.HasSelectionChangedHandlers;
import com.google.gwt.view.client.SelectionModel;
public class ListeObservationVue extends Composite implements ListeObservationPresenteur.Vue {
interface MyUiBinder extends UiBinder<Widget, ListeObservationVue> {
}
private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
@UiField(provided = true)
CellTable<Observation> tableauObservation;
@UiField(provided = true)
FlowPanel panneauPagination, panneauBarreOutils;
Column<Observation, String> transmis, nomSaisi, nomRetenu, lieu, date ,ordre;
SelectionModel<Observation> modeleSelection;
ListDataProvider<Observation> listeObservation;
private static final ProvidesKey<Observation> CLE_OBS = new ProvidesKey<Observation>() {
public Object getKey(Observation obs) {
return obs == null ? null : obs.getId();
}
};
public ListeObservationVue() {
tableauObservation = new CellTable<Observation>();
// en attendant qu'il y a quelque chose à y mettre
panneauPagination = new FlowPanel();
panneauBarreOutils = new FlowPanel();
initialiserTable();
initWidget(uiBinder.createAndBindUi(this));
}
private void initialiserTable() {
modeleSelection = new MultiSelectionModel<Observation>(CLE_OBS);
tableauObservation.setSelectionModel(modeleSelection, DefaultSelectionEventManager.<Observation> createDefaultManager());
initialiserColonnes();
listeObservation = new ListDataProvider<Observation>();
listeObservation.addDataDisplay(tableauObservation);
}
private void initialiserColonnes() {
transmis = new Column<Observation, String>(
new TextCell()) {
@Override
public String getValue(Observation obs) {
return obs.getTransmission();
}
};
transmis.setSortable(true);
ajouterColonne(transmis, "Transmis", 10);
nomSaisi = new Column<Observation, String>(
new TextCell()) {
@Override
public String getValue(Observation obs) {
return obs.getNomSaisi();
}
};
nomSaisi.setSortable(true);
ajouterColonne(nomSaisi, "Nom saisi", 20);
nomRetenu = new Column<Observation, String>(
new TextCell()) {
@Override
public String getValue(Observation obs) {
return obs.getNomRetenu();
}
};
nomRetenu.setSortable(true);
ajouterColonne(nomRetenu, "Nom retenu", 20);
lieu = new Column<Observation, String>(
new TextCell()) {
@Override
public String getValue(Observation obs) {
return obs.getLocaliteAvecIdFormatee()+" "+obs.getLieuDit();
}
};
lieu.setSortable(true);
ajouterColonne(lieu, "Lieu", 20);
date = new Column<Observation, String>(
new TextCell()) {
@Override
public String getValue(Observation obs) {
return obs.getDateReleve();
}
};
date.setSortable(true);
ajouterColonne(date, "Date", 20);
ordre = new Column<Observation, String>(
new TextCell()) {
@Override
public String getValue(Observation obs) {
return obs.getOrdre();
}
};
ordre.setSortable(true);
ajouterColonne(ordre, "Ordre", 10);
}
private void ajouterColonne(Column<Observation, String> colonne, String nomColonne, int largeur) {
tableauObservation.addColumn(colonne, nomColonne);
tableauObservation.setColumnWidth(colonne, largeur, Unit.PCT);
}
@Override
public void ajouterAuParent(HasWidgets parent) {
parent.add(this);
}
}