60 |
jpm |
1 |
package org.tela_botanica.client.vues;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.List;
|
|
|
5 |
|
69 |
jpm |
6 |
import org.tela_botanica.client.ComposantClass;
|
60 |
jpm |
7 |
import org.tela_botanica.client.Mediateur;
|
|
|
8 |
import org.tela_botanica.client.RegistreId;
|
422 |
jp_milcent |
9 |
import org.tela_botanica.client.i18n.Constantes;
|
60 |
jpm |
10 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
133 |
jpm |
11 |
import org.tela_botanica.client.modeles.Information;
|
60 |
jpm |
12 |
import org.tela_botanica.client.modeles.Structure;
|
69 |
jpm |
13 |
import org.tela_botanica.client.modeles.StructureListe;
|
156 |
jp_milcent |
14 |
import org.tela_botanica.client.modeles.Utilisateur;
|
60 |
jpm |
15 |
|
|
|
16 |
import com.extjs.gxt.ui.client.Registry;
|
|
|
17 |
import com.extjs.gxt.ui.client.Style.SelectionMode;
|
210 |
jp_milcent |
18 |
import com.extjs.gxt.ui.client.Style.SortDir;
|
60 |
jpm |
19 |
import com.extjs.gxt.ui.client.binder.TableBinder;
|
69 |
jpm |
20 |
import com.extjs.gxt.ui.client.event.ComponentEvent;
|
60 |
jpm |
21 |
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
|
|
|
22 |
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
69 |
jpm |
23 |
import com.extjs.gxt.ui.client.event.SelectionListener;
|
60 |
jpm |
24 |
import com.extjs.gxt.ui.client.store.ListStore;
|
|
|
25 |
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
133 |
jpm |
26 |
import com.extjs.gxt.ui.client.widget.Info;
|
60 |
jpm |
27 |
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
|
|
28 |
import com.extjs.gxt.ui.client.widget.table.Table;
|
|
|
29 |
import com.extjs.gxt.ui.client.widget.table.TableColumn;
|
|
|
30 |
import com.extjs.gxt.ui.client.widget.table.TableColumnModel;
|
155 |
jpm |
31 |
import com.extjs.gxt.ui.client.widget.table.TableItem;
|
60 |
jpm |
32 |
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
|
|
|
33 |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
133 |
jpm |
34 |
import com.google.gwt.core.client.GWT;
|
60 |
jpm |
35 |
|
442 |
jp_milcent |
36 |
public class StructureListeVue extends ContentPanel implements Rafraichissable {
|
60 |
jpm |
37 |
|
373 |
jp_milcent |
38 |
private Mediateur mediateur = null ;
|
422 |
jp_milcent |
39 |
private Constantes i18nC = null ;
|
448 |
jp_milcent |
40 |
|
60 |
jpm |
41 |
private Table table = null;
|
|
|
42 |
private ListStore<Structure> store = null;
|
|
|
43 |
private TableBinder<Structure> binder = null;
|
448 |
jp_milcent |
44 |
|
155 |
jpm |
45 |
private TextToolItem modifier;
|
|
|
46 |
private TextToolItem supprimer;
|
|
|
47 |
private TextToolItem ajouter;
|
60 |
jpm |
48 |
|
442 |
jp_milcent |
49 |
public StructureListeVue(Mediateur mediateurCourant) {
|
373 |
jp_milcent |
50 |
mediateur = mediateurCourant;
|
422 |
jp_milcent |
51 |
i18nC = mediateur.i18nC;
|
373 |
jp_milcent |
52 |
|
277 |
jp_milcent |
53 |
Utilisateur utilisateur = (Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT);
|
60 |
jpm |
54 |
|
|
|
55 |
ToolBar toolBar = new ToolBar();
|
422 |
jp_milcent |
56 |
ajouter = new TextToolItem(i18nC.ajouter());
|
69 |
jpm |
57 |
ajouter.setIconStyle(ComposantClass.ICONE_AJOUTER);
|
|
|
58 |
ajouter.addSelectionListener(new SelectionListener<ComponentEvent>() {
|
|
|
59 |
public void componentSelected(ComponentEvent ce) {
|
156 |
jp_milcent |
60 |
mediateur.clicAjouterStructure();
|
133 |
jpm |
61 |
}
|
69 |
jpm |
62 |
});
|
60 |
jpm |
63 |
toolBar.add(ajouter);
|
|
|
64 |
|
422 |
jp_milcent |
65 |
modifier = new TextToolItem(i18nC.modifier());
|
69 |
jpm |
66 |
modifier.setIconStyle(ComposantClass.ICONE_MODIFIER);
|
156 |
jp_milcent |
67 |
modifier.addSelectionListener(new SelectionListener<ComponentEvent>() {
|
|
|
68 |
public void componentSelected(ComponentEvent ce) {
|
|
|
69 |
mediateur.clicModifierStructure(binder.getSelection());
|
|
|
70 |
}
|
|
|
71 |
});
|
60 |
jpm |
72 |
toolBar.add(modifier);
|
|
|
73 |
|
422 |
jp_milcent |
74 |
supprimer = new TextToolItem(i18nC.supprimer());
|
69 |
jpm |
75 |
supprimer.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
|
133 |
jpm |
76 |
supprimer.addSelectionListener(new SelectionListener<ComponentEvent>() {
|
|
|
77 |
public void componentSelected(ComponentEvent ce) {
|
448 |
jp_milcent |
78 |
clicSupprimerStructure(binder.getSelection());
|
133 |
jpm |
79 |
}
|
|
|
80 |
});
|
156 |
jp_milcent |
81 |
if (!utilisateur.isIdentifie()) {
|
|
|
82 |
supprimer.disable();
|
|
|
83 |
}
|
60 |
jpm |
84 |
toolBar.add(supprimer);
|
|
|
85 |
|
|
|
86 |
setTopComponent(toolBar);
|
|
|
87 |
|
|
|
88 |
List<TableColumn> columns = new ArrayList<TableColumn>();
|
422 |
jp_milcent |
89 |
columns.add(new TableColumn("ville", i18nC.ville(), .3f));
|
|
|
90 |
columns.add(new TableColumn("nom", i18nC.nom(), .7f));
|
60 |
jpm |
91 |
|
|
|
92 |
TableColumnModel cm = new TableColumnModel(columns);
|
|
|
93 |
table = new Table(cm);
|
|
|
94 |
table.setSelectionMode(SelectionMode.MULTI);
|
|
|
95 |
table.setBorders(false);
|
210 |
jp_milcent |
96 |
table.setStripeRows(true);
|
60 |
jpm |
97 |
add(table);
|
210 |
jp_milcent |
98 |
|
60 |
jpm |
99 |
store = new ListStore<Structure>();
|
210 |
jp_milcent |
100 |
store.sort("ville", SortDir.ASC);
|
|
|
101 |
|
60 |
jpm |
102 |
binder = new TableBinder<Structure>(table, store);
|
|
|
103 |
binder.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
|
|
|
104 |
public void selectionChanged(SelectionChangedEvent<Structure> event) {
|
|
|
105 |
Structure m = (Structure) event.getSelectedItem();
|
|
|
106 |
clicListe(m);
|
|
|
107 |
}
|
|
|
108 |
});
|
|
|
109 |
|
|
|
110 |
setLayout(new FitLayout());
|
|
|
111 |
}
|
|
|
112 |
|
379 |
jp_milcent |
113 |
private void clicListe(Structure structure) {
|
|
|
114 |
if (store.getCount() > 0) {
|
|
|
115 |
mediateur.clicListeStructure(structure);
|
|
|
116 |
}
|
60 |
jpm |
117 |
}
|
448 |
jp_milcent |
118 |
|
|
|
119 |
private void clicSupprimerStructure(List<Structure> structuresASupprimer) {
|
|
|
120 |
if (store.getCount() > 0) {
|
|
|
121 |
mediateur.clicSupprimerStructure(this, structuresASupprimer);
|
|
|
122 |
}
|
|
|
123 |
}
|
60 |
jpm |
124 |
|
|
|
125 |
public void rafraichir(Object nouvelleDonnees) {
|
69 |
jpm |
126 |
if (nouvelleDonnees instanceof StructureListe) {
|
379 |
jp_milcent |
127 |
StructureListe structures = (StructureListe) nouvelleDonnees;
|
422 |
jp_milcent |
128 |
setHeading(i18nC.titreStructureListe());
|
60 |
jpm |
129 |
|
379 |
jp_milcent |
130 |
List<Structure> liste = (List<Structure>) structures.toList();
|
60 |
jpm |
131 |
store.removeAll();
|
368 |
jp_milcent |
132 |
store.add(liste);
|
278 |
jp_milcent |
133 |
|
379 |
jp_milcent |
134 |
mediateur.actualiserPanneauCentral();
|
|
|
135 |
|
|
|
136 |
if (store.getCount() > 0) {
|
362 |
jp_milcent |
137 |
table.getSelectionModel().select(0);
|
60 |
jpm |
138 |
}
|
133 |
jpm |
139 |
} else if (nouvelleDonnees instanceof Information) {
|
|
|
140 |
Information info = (Information) nouvelleDonnees;
|
|
|
141 |
if (info.getType().equals("suppression_structure")) {
|
155 |
jpm |
142 |
// Affichage d'un message d'information
|
|
|
143 |
//GWT.log(info.toString(), null);
|
422 |
jp_milcent |
144 |
Info.display(i18nC.suppressionStructure(), info.toString().replaceAll("\n", "<br />"));
|
155 |
jpm |
145 |
|
|
|
146 |
// Suppression des structures sélectionnées
|
|
|
147 |
List<TableItem> selectionStructure = table.getSelectedItems();
|
|
|
148 |
final int taille = selectionStructure.size();
|
|
|
149 |
for (int i = 0; i < taille; i++) {
|
|
|
150 |
//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null);
|
|
|
151 |
table.remove(selectionStructure.get(i));
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
// Désactivation des boutons si la liste est vide
|
|
|
155 |
if (table.getItemCount() == 0) {
|
|
|
156 |
supprimer.disable();
|
|
|
157 |
modifier.disable();
|
|
|
158 |
}
|
156 |
jp_milcent |
159 |
} else if (info.getType().equals("maj_utilisateur")) {
|
277 |
jp_milcent |
160 |
if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
|
156 |
jp_milcent |
161 |
if (table.getItemCount() != 0) {
|
|
|
162 |
supprimer.enable();
|
|
|
163 |
}
|
|
|
164 |
} else {
|
|
|
165 |
supprimer.disable();
|
|
|
166 |
}
|
133 |
jpm |
167 |
}
|
156 |
jp_milcent |
168 |
} else {
|
278 |
jp_milcent |
169 |
GWT.log("Pas de correspondance dans la méthode rafraichir() de la classe "+this.getClass(), null);
|
60 |
jpm |
170 |
}
|
156 |
jp_milcent |
171 |
layout();
|
60 |
jpm |
172 |
}
|
|
|
173 |
}
|