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