1633 |
aurelien |
1 |
package org.tela_botanica.client.composants;
|
|
|
2 |
|
|
|
3 |
import org.tela_botanica.client.Mediateur;
|
|
|
4 |
import org.tela_botanica.client.images.Images;
|
|
|
5 |
import org.tela_botanica.client.interfaces.ListePaginable;
|
|
|
6 |
|
|
|
7 |
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
|
|
8 |
import com.extjs.gxt.ui.client.event.ComponentEvent;
|
|
|
9 |
import com.extjs.gxt.ui.client.event.KeyListener;
|
|
|
10 |
import com.extjs.gxt.ui.client.event.SelectionListener;
|
|
|
11 |
import com.extjs.gxt.ui.client.widget.Text;
|
|
|
12 |
import com.extjs.gxt.ui.client.widget.button.Button;
|
|
|
13 |
import com.extjs.gxt.ui.client.widget.form.TextField;
|
|
|
14 |
import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem;
|
|
|
15 |
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
|
|
|
16 |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
|
|
17 |
import com.google.gwt.event.dom.client.KeyCodes;
|
|
|
18 |
|
|
|
19 |
public class ChampFiltreRecherche {
|
|
|
20 |
|
|
|
21 |
private ListePaginable listePaginable;
|
|
|
22 |
private Mediateur mediateur;
|
|
|
23 |
private ToolBar parent;
|
|
|
24 |
private TextField<String> filtre;
|
|
|
25 |
private Button annulerFiltre;
|
|
|
26 |
private boolean filtreActive = false;
|
|
|
27 |
private String termeRecherche = "";
|
|
|
28 |
private Text labelFiltre;
|
|
|
29 |
|
|
|
30 |
public ChampFiltreRecherche(Mediateur mediateur, ToolBar parent, ListePaginable listePaginable) {
|
|
|
31 |
//Séparation
|
|
|
32 |
this.mediateur = mediateur;
|
|
|
33 |
this.parent = parent;
|
|
|
34 |
this.listePaginable = listePaginable;
|
|
|
35 |
parent.add(new SeparatorToolItem());
|
|
|
36 |
|
1637 |
aurelien |
37 |
labelFiltre = new Text("Recherche : ");
|
1633 |
aurelien |
38 |
labelFiltre.setStyleAttribute("padding-right", "5px");
|
|
|
39 |
parent.add(labelFiltre);
|
|
|
40 |
|
|
|
41 |
filtre = new TextField<String>();
|
|
|
42 |
filtre.setWidth(150);
|
|
|
43 |
parent.add(filtre);
|
|
|
44 |
|
|
|
45 |
annulerFiltre = new Button();
|
|
|
46 |
annulerFiltre.setIcon(Images.ICONES.annuler());
|
|
|
47 |
annulerFiltre.setVisible(false);
|
|
|
48 |
parent.add(annulerFiltre);
|
|
|
49 |
|
|
|
50 |
parent.add(new FillToolItem());
|
|
|
51 |
ajouterListeners();
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
private void ajouterListeners() {
|
|
|
55 |
annulerFiltre.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
56 |
public void componentSelected(ButtonEvent ce) {
|
|
|
57 |
filtre.setValue("");
|
|
|
58 |
termeRecherche = "";
|
|
|
59 |
filtreActive = false;
|
|
|
60 |
listePaginable.filtrerParNom("");
|
|
|
61 |
labelFiltre.setStyleAttribute("font-weight", "normal");
|
|
|
62 |
changerEtat();
|
|
|
63 |
}
|
|
|
64 |
});
|
|
|
65 |
|
|
|
66 |
filtre.addKeyListener(new KeyListener(){
|
|
|
67 |
public void componentKeyUp(ComponentEvent ce) {
|
|
|
68 |
if (ce.getKeyCode() == KeyCodes.KEY_ENTER) {
|
|
|
69 |
termeRecherche = filtre.getValue();
|
|
|
70 |
if (termeRecherche == null || termeRecherche.equals("")) {
|
|
|
71 |
filtreActive = false;
|
|
|
72 |
labelFiltre.setStyleAttribute("font-weight", "normal");
|
|
|
73 |
termeRecherche= "";
|
|
|
74 |
listePaginable.filtrerParNom("");
|
|
|
75 |
changerEtat();
|
|
|
76 |
} else {
|
|
|
77 |
listePaginable.filtrerParNom(termeRecherche);
|
|
|
78 |
labelFiltre.setStyleAttribute("font-weight", "bold");
|
|
|
79 |
filtreActive = true;
|
|
|
80 |
changerEtat();
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
});
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
private void changerEtat() {
|
|
|
88 |
if (filtreActive == true) {
|
|
|
89 |
annulerFiltre.setVisible(true);
|
|
|
90 |
} else {
|
|
|
91 |
annulerFiltre.setVisible(false);
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
public void setListePaginable(ListePaginable listePaginable) {
|
|
|
96 |
this.listePaginable = listePaginable;
|
|
|
97 |
}
|
1687 |
raphael |
98 |
|
|
|
99 |
public String getFiltreValue() {
|
|
|
100 |
return filtre.getValue();
|
|
|
101 |
}
|
1633 |
aurelien |
102 |
}
|