4,6 → 4,8 |
import java.util.LinkedList; |
|
import org.tela_botanica.client.Mediateur; |
import org.tela_botanica.client.i18n.Constantes; |
import org.tela_botanica.client.i18n.ErrorMessages; |
import org.tela_botanica.client.images.Images; |
import org.tela_botanica.client.interfaces.ListePaginable; |
import org.tela_botanica.client.interfaces.Rafraichissable; |
25,12 → 27,15 |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar; |
import com.google.gwt.event.dom.client.KeyCodes; |
import com.google.gwt.i18n.client.Dictionary; |
import com.google.gwt.user.client.Window; |
|
public class BarrePaginationVue extends ToolBar implements Rafraichissable { |
|
private Mediateur mediateur = null; |
private Constantes i18nC = null; |
private ErrorMessages i18nM = null; |
public int valeur = 0; |
|
private ListePaginable listePaginable = null; |
|
private Button prevPage, suivPage, premierePage, dernierePage, rafraichir; |
|
private int pageCourante, nbElement = 0; |
46,10 → 51,9 |
private boolean filtreActive = false; |
private String termeRecherche = ""; |
|
LinkedList<Integer> intervallePages = new LinkedList<Integer>(); |
private LinkedList<Integer> intervallePages = new LinkedList<Integer>(); |
private ListStore storeIntervalle = new ListStore() ; |
|
ListStore storeIntervalle = new ListStore() ; |
|
private String labelElement; |
private int taillePageDefaut = 50; |
|
61,9 → 65,6 |
this.listePaginable = listePaginable; |
} |
|
private Mediateur mediateur; |
|
public int valeur = 0; |
/*************************************************************************** |
* constructeur sans argument (privé car ne doit pas être utilisé) |
*/ |
78,12 → 79,13 |
* @param im |
* le médiateur à associer à la barre |
*/ |
public BarrePaginationVue(ListePaginable listePaginable, Mediateur mediateur) { |
|
public BarrePaginationVue(ListePaginable listePaginableCourante, Mediateur mediateurCourant) { |
super(); |
|
this.listePaginable = listePaginable; |
this.mediateur = mediateur; |
listePaginable = listePaginableCourante; |
mediateur = mediateurCourant; |
i18nC = Mediateur.i18nC; |
i18nM = Mediateur.i18nM; |
|
intervallePages.add(10); |
intervallePages.add(20); |
101,7 → 103,7 |
|
add(new SeparatorToolItem()); |
|
page = new Text(mediateur.i18nC.page()); |
page = new Text(i18nC.page()); |
page.setStyleAttribute("padding", "0 5px 0 5px"); |
add(page); |
|
110,7 → 112,7 |
champPage.setWidth(30); |
add(champPage); |
|
surTotalPage = new Text(mediateur.i18nC.sur() + " " + pageTotale); |
surTotalPage = new Text(i18nC.sur() + " " + pageTotale); |
surTotalPage.setStyleAttribute("padding-left", "5px"); |
add(surTotalPage); |
|
135,7 → 137,7 |
//Séparation |
add(new SeparatorToolItem()); |
|
afficherNbElem = new Text(mediateur.i18nC.afficher()); |
afficherNbElem = new Text(i18nC.afficher()); |
afficherNbElem.setStyleAttribute("padding", "0 5px 0 5px"); |
add(afficherNbElem); |
|
144,9 → 146,9 |
setIntervallesPages(); |
add(selecteurTaillePage); |
|
labelElement = mediateur.i18nC.elements(); |
labelElement = i18nC.elements(); |
|
nbElemParPage = new Text(labelElement + " " + mediateur.i18nC.parPage()); |
nbElemParPage = new Text(labelElement+" "+i18nC.parPage()); |
nbElemParPage.setStyleAttribute("padding-left", "5px"); |
add(nbElemParPage); |
|
168,32 → 170,23 |
|
add(new FillToolItem()); |
|
intervalleElements = new Text(mediateur.i18nM.elementsAffiches(UtilString.ucFirst(labelElement), pageCourante * taillePage, |
(pageCourante + 1) * taillePage, nbElement)); |
intervalleElements = new Text(i18nM.elementsAffiches(UtilString.ucFirst(labelElement), |
pageCourante * taillePage, (pageCourante + 1) * taillePage, nbElement)); |
add(intervalleElements); |
|
// on ajoute les différents listeners |
ajouterListeners(); |
|
|
} |
|
|
|
|
|
|
/** |
* Texte nommant les elements pagines (Images, Observation, truc, machin etc...). |
* @param label |
*/ |
|
public void setLabelElement(String label) { |
this.labelElement = label; |
nbElemParPage.setText(labelElement + " par page "); |
intervalleElements.setText(mediateur.i18nM.elementsAffiches(UtilString.ucFirst(labelElement), pageCourante * taillePage, |
(pageCourante + 1) * taillePage, nbElement)); |
|
intervalleElements.setText(i18nM.elementsAffiches(UtilString.ucFirst(labelElement), |
pageCourante * taillePage, (pageCourante + 1) * taillePage, nbElement)); |
} |
|
public void setTaillePageParDefaut(int taille) { |
201,9 → 194,7 |
selecteurTaillePage.setRawValue(""+taillePageDefaut); |
} |
|
public void setIntervallesPages() |
{ |
|
public void setIntervallesPages() { |
if (!intervallePages.contains(taillePage)) { |
intervallePages.add(taillePage); |
} |
240,9 → 231,7 |
*/ |
@SuppressWarnings("unchecked") |
private void ajouterListeners() { |
|
premierePage.addSelectionListener(new SelectionListener<ButtonEvent>() { |
|
public void componentSelected(ButtonEvent ce) { |
pageCourante = 0; |
rafraichirNumeroPage(); |
252,7 → 241,6 |
|
// boutons suivants et précédents |
prevPage.addSelectionListener(new SelectionListener<ButtonEvent>() { |
|
public void componentSelected(ButtonEvent ce) { |
// si la page courante n'est pas la première |
if (pageCourante > 0) { |
268,9 → 256,7 |
}); |
|
suivPage.addSelectionListener(new SelectionListener<ButtonEvent>() { |
|
public void componentSelected(ButtonEvent ce) { |
|
// si la page courante n'est pas la dernière |
if (pageCourante < pageTotale - 1) { |
// on incrémente la page courante de 1 |
284,7 → 270,6 |
}); |
|
dernierePage.addSelectionListener(new SelectionListener<ButtonEvent>() { |
|
public void componentSelected(ButtonEvent ce) { |
pageCourante = pageTotale; |
rafraichirNumeroPage(); |
293,7 → 278,6 |
}); |
|
rafraichir.addSelectionListener(new SelectionListener<ButtonEvent>() { |
|
public void componentSelected(ButtonEvent ce) { |
listePaginable.changerNumeroPage(pageCourante); |
} |
300,7 → 284,6 |
}); |
|
annulerFiltre.addSelectionListener(new SelectionListener<ButtonEvent>() { |
|
public void componentSelected(ButtonEvent ce) { |
filtre.setValue(""); |
termeRecherche = ""; |
314,7 → 297,6 |
filtre.addKeyListener(new KeyListener(){ |
public void componentKeyUp(ComponentEvent ce) { |
if (ce.getKeyCode() == KeyCodes.KEY_ENTER) { |
|
termeRecherche = filtre.getValue(); |
if (termeRecherche == null || termeRecherche.equals("")) { |
filtreActive = false; |
332,9 → 314,7 |
}); |
|
champPage.addKeyListener(new KeyListener() { |
|
public void componentKeyUp(ComponentEvent ce) { |
|
// on teste si la touche entrée a été pressée |
if (ce.getKeyCode() == KeyCodes.KEY_ENTER) { |
int nouvellePage = pageCourante; |
361,7 → 341,6 |
// notifie le médiateur |
changerPageCourante(nouvellePage - 1); |
listePaginable.changerNumeroPage(pageCourante); |
|
} else { |
// sinon on reaffiche l'ancien numero de page sans rien |
// changer |
370,21 → 349,12 |
} |
} |
} |
|
|
/* public void onFocus(Field field) { |
|
champPage.focus(); |
}*/ |
|
}); |
|
// pour éviter de se compliquer la vie, on filtre tous les charactères |
// non numériques |
champPage.addKeyListener(new KeyListener() { |
|
public void componentKeyDown(ComponentEvent ce) { |
|
// si c'est un numerique |
/* |
FIXME |
406,16 → 376,11 |
ce.stopEvent(); |
} |
} |
|
}); |
|
// listener pour la selection dans la combobox |
selecteurTaillePage.addSelectionChangedListener( |
|
new SelectionChangedListener() { |
|
selecteurTaillePage.addSelectionChangedListener(new SelectionChangedListener() { |
public void selectionChanged(SelectionChangedEvent e) { |
|
SimpleComboBox comboBox = (SimpleComboBox) e.getSource(); |
String nouvelleTaillePageString = comboBox.getRawValue(); |
int nouvelleTaillePage = Integer.parseInt(nouvelleTaillePageString); |
424,7 → 389,6 |
|
rafraichirNumeroPage(); |
} |
|
}); |
} |
|
433,11 → 397,9 |
* d'éléments à partir des variables de classes |
*/ |
public void rafraichirNumeroPage() { |
|
if (filtreActive == true) { |
intervalleElements.setText("<b><i>Recherche active : </i></b>" + termeRecherche); |
} else { |
|
surTotalPage.setText(" sur " + pageTotale); |
|
if (nbElement == 0) { |
444,7 → 406,7 |
champPage.setValue("" + (0)); |
// on met simplement à jour l'intervalle qui contient toujours le |
// même nombre d'éléments |
intervalleElements.setText(mediateur.i18nM.elementsAffiches(UtilString.ucFirst(labelElement), 0,0,0)); |
intervalleElements.setText(i18nM.elementsAffiches(UtilString.ucFirst(labelElement), 0,0,0)); |
} else { |
champPage.setValue("" + (pageCourante + 1)); |
|
452,13 → 414,13 |
if (pageCourante + 1 != pageTotale) { |
// sauf pour la dernière page qui contient souvent moins |
// d'élements que le nombre d'élements par page |
intervalleElements.setText(mediateur.i18nM.elementsAffiches(UtilString.ucFirst(labelElement), pageCourante * taillePage, |
intervalleElements.setText(i18nM.elementsAffiches(UtilString.ucFirst(labelElement), pageCourante * taillePage, |
(pageCourante + 1) * taillePage, nbElement)); |
} else { |
|
// on met simplement à jour l'intervalle qui contient toujours |
// le même nombre d'éléments |
intervalleElements.setText(mediateur.i18nM.elementsAffiches(UtilString.ucFirst(labelElement), pageCourante * taillePage, |
intervalleElements.setText(i18nM.elementsAffiches(UtilString.ucFirst(labelElement), pageCourante * taillePage, |
nbElement, nbElement)); |
} |
} |
508,7 → 470,6 |
* la nouvelle taille de page |
*/ |
public void selectionnerTaillePage(int nouvelleTaillePage) { |
|
selecteurTaillePage.setRawValue("" + nouvelleTaillePage); |
} |
|
516,7 → 477,6 |
public void rafraichir(Object nouvelleDonnees) { |
// si on reçoit un tableau de int |
if (nouvelleDonnees instanceof int[]) { |
|
int[] page = (int[]) nouvelleDonnees; |
// le premier élement est le nombre de pages totales |
pageTotale = page[0]; |
545,5 → 505,4 |
|
layout(); |
} |
|
} |
} |