1 |
package org.tela_botanica.client.vues.collection;
|
1 |
package org.tela_botanica.client.vues.collection;
|
2 |
|
2 |
|
3 |
import java.util.ArrayList;
|
3 |
import java.util.ArrayList;
|
4 |
import java.util.Iterator;
|
4 |
import java.util.Iterator;
|
5 |
import java.util.List;
|
5 |
import java.util.List;
|
6 |
|
6 |
|
7 |
import org.tela_botanica.client.Mediateur;
|
7 |
import org.tela_botanica.client.Mediateur;
|
8 |
import org.tela_botanica.client.RegistreId;
|
8 |
import org.tela_botanica.client.RegistreId;
|
- |
|
9 |
import org.tela_botanica.client.composants.ChampFiltreRecherche;
|
9 |
import org.tela_botanica.client.composants.InfoLogger;
|
10 |
import org.tela_botanica.client.composants.InfoLogger;
|
10 |
import org.tela_botanica.client.i18n.Constantes;
|
11 |
import org.tela_botanica.client.i18n.Constantes;
|
11 |
import org.tela_botanica.client.images.Images;
|
12 |
import org.tela_botanica.client.images.Images;
|
12 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
13 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
13 |
import org.tela_botanica.client.modeles.Information;
|
14 |
import org.tela_botanica.client.modeles.Information;
|
14 |
import org.tela_botanica.client.modeles.Utilisateur;
|
15 |
import org.tela_botanica.client.modeles.Utilisateur;
|
15 |
import org.tela_botanica.client.modeles.collection.Collection;
|
16 |
import org.tela_botanica.client.modeles.collection.Collection;
|
16 |
import org.tela_botanica.client.modeles.collection.CollectionListe;
|
17 |
import org.tela_botanica.client.modeles.collection.CollectionListe;
|
17 |
import org.tela_botanica.client.modeles.personne.Personne;
|
18 |
import org.tela_botanica.client.modeles.personne.Personne;
|
18 |
import org.tela_botanica.client.modeles.publication.Publication;
|
19 |
import org.tela_botanica.client.modeles.publication.Publication;
|
19 |
import org.tela_botanica.client.modeles.structure.StructureListe;
|
20 |
import org.tela_botanica.client.modeles.structure.StructureListe;
|
20 |
import org.tela_botanica.client.util.Debug;
|
21 |
import org.tela_botanica.client.util.Debug;
|
21 |
import org.tela_botanica.client.vues.BarrePaginationVue;
|
22 |
import org.tela_botanica.client.vues.BarrePaginationVue;
|
22 |
|
23 |
|
23 |
import com.extjs.gxt.ui.client.Registry;
|
24 |
import com.extjs.gxt.ui.client.Registry;
|
24 |
import com.extjs.gxt.ui.client.Style.SortDir;
|
25 |
import com.extjs.gxt.ui.client.Style.SortDir;
|
25 |
import com.extjs.gxt.ui.client.event.BaseEvent;
|
26 |
import com.extjs.gxt.ui.client.event.BaseEvent;
|
26 |
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
27 |
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
27 |
import com.extjs.gxt.ui.client.event.Events;
|
28 |
import com.extjs.gxt.ui.client.event.Events;
|
28 |
import com.extjs.gxt.ui.client.event.Listener;
|
29 |
import com.extjs.gxt.ui.client.event.Listener;
|
29 |
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
|
30 |
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
|
30 |
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
31 |
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
31 |
import com.extjs.gxt.ui.client.event.SelectionListener;
|
32 |
import com.extjs.gxt.ui.client.event.SelectionListener;
|
32 |
import com.extjs.gxt.ui.client.store.ListStore;
|
33 |
import com.extjs.gxt.ui.client.store.ListStore;
|
33 |
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
34 |
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
34 |
import com.extjs.gxt.ui.client.widget.button.Button;
|
35 |
import com.extjs.gxt.ui.client.widget.button.Button;
|
35 |
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
36 |
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
36 |
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
37 |
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
37 |
import com.extjs.gxt.ui.client.widget.grid.Grid;
|
38 |
import com.extjs.gxt.ui.client.widget.grid.Grid;
|
38 |
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
|
39 |
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
|
39 |
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
40 |
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
40 |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
41 |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
41 |
|
42 |
|
42 |
public class CollectionListeVue extends ContentPanel implements Rafraichissable {
|
43 |
public class CollectionListeVue extends ContentPanel implements Rafraichissable {
|
43 |
|
44 |
|
44 |
private Mediateur mediateur = null;
|
45 |
private Mediateur mediateur = null;
|
45 |
private Constantes i18nC = null;
|
46 |
private Constantes i18nC = null;
|
46 |
|
47 |
|
47 |
private Grid<Collection> grille = null;
|
48 |
private Grid<Collection> grille = null;
|
48 |
private ListStore<Collection> store = null;
|
49 |
private ListStore<Collection> store = null;
|
49 |
|
50 |
|
50 |
private Button modifier;
|
51 |
private Button modifier;
|
51 |
private Button supprimer;
|
52 |
private Button supprimer;
|
52 |
private Button ajouter;
|
53 |
private Button ajouter;
|
53 |
private BarrePaginationVue pagination = null;
|
54 |
private BarrePaginationVue pagination = null;
|
- |
|
55 |
private ChampFiltreRecherche champFiltreRecherche = null;
|
54 |
|
56 |
|
55 |
private int indexElementSelectionne = 0;
|
57 |
private int indexElementSelectionne = 0;
|
56 |
private Collection collectionSelectionnee = null;
|
58 |
private Collection collectionSelectionnee = null;
|
57 |
|
59 |
|
58 |
public CollectionListeVue(Mediateur mediateurCourant) {
|
60 |
public CollectionListeVue(Mediateur mediateurCourant) {
|
59 |
mediateur = mediateurCourant;
|
61 |
mediateur = mediateurCourant;
|
60 |
i18nC = Mediateur.i18nC;
|
62 |
i18nC = Mediateur.i18nC;
|
61 |
|
63 |
|
62 |
setLayout(new FitLayout());
|
64 |
setLayout(new FitLayout());
|
63 |
setHeading(i18nC.collectionListeTitre());
|
65 |
setHeading(i18nC.collectionListeTitre());
|
64 |
|
66 |
|
65 |
ToolBar toolBar = new ToolBar();
|
67 |
ToolBar toolBar = new ToolBar();
|
66 |
ajouter = new Button(i18nC.ajouter());
|
68 |
ajouter = new Button(i18nC.ajouter());
|
67 |
ajouter.setIcon(Images.ICONES.ajouter());
|
69 |
ajouter.setIcon(Images.ICONES.ajouter());
|
68 |
ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
70 |
ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
69 |
public void componentSelected(ButtonEvent ce) {
|
71 |
public void componentSelected(ButtonEvent ce) {
|
70 |
mediateur.clicAjouterCollection();
|
72 |
mediateur.clicAjouterCollection();
|
71 |
}
|
73 |
}
|
72 |
});
|
74 |
});
|
73 |
ajouter.setToolTip(i18nC.indicationCreerUneFiche()+" "+i18nC.collectionSingulier());
|
75 |
ajouter.setToolTip(i18nC.indicationCreerUneFiche()+" "+i18nC.collectionSingulier());
|
74 |
toolBar.add(ajouter);
|
76 |
toolBar.add(ajouter);
|
75 |
|
77 |
|
76 |
modifier = new Button(i18nC.modifier());
|
78 |
modifier = new Button(i18nC.modifier());
|
77 |
modifier.setIcon(Images.ICONES.formModifier());
|
79 |
modifier.setIcon(Images.ICONES.formModifier());
|
78 |
modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
80 |
modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
79 |
public void componentSelected(ButtonEvent ce) {
|
81 |
public void componentSelected(ButtonEvent ce) {
|
80 |
mediateur.clicModifierCollection(grille.getSelectionModel().getSelectedItems());
|
82 |
mediateur.clicModifierCollection(grille.getSelectionModel().getSelectedItems());
|
81 |
}
|
83 |
}
|
82 |
});
|
84 |
});
|
83 |
modifier.setToolTip(i18nC.indicationModifierUneFiche());
|
85 |
modifier.setToolTip(i18nC.indicationModifierUneFiche());
|
84 |
toolBar.add(modifier);
|
86 |
toolBar.add(modifier);
|
85 |
|
87 |
|
86 |
supprimer = new Button(i18nC.supprimer());
|
88 |
supprimer = new Button(i18nC.supprimer());
|
87 |
supprimer.setIcon(Images.ICONES.supprimer());
|
89 |
supprimer.setIcon(Images.ICONES.supprimer());
|
88 |
supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
90 |
supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
89 |
public void componentSelected(ButtonEvent ce) {
|
91 |
public void componentSelected(ButtonEvent ce) {
|
90 |
clicSupprimerCollection(grille.getSelectionModel().getSelectedItems());
|
92 |
clicSupprimerCollection(grille.getSelectionModel().getSelectedItems());
|
91 |
}
|
93 |
}
|
92 |
});
|
94 |
});
|
93 |
supprimer.setToolTip(i18nC.indicationSupprimerUneFiche());
|
95 |
supprimer.setToolTip(i18nC.indicationSupprimerUneFiche());
|
94 |
toolBar.add(supprimer);
|
96 |
toolBar.add(supprimer);
|
95 |
|
97 |
|
96 |
setTopComponent(toolBar);
|
98 |
setTopComponent(toolBar);
|
97 |
|
99 |
|
98 |
List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
|
100 |
List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
|
99 |
colonnes.add(new ColumnConfig("nom", i18nC.personneNom(), 300));
|
101 |
colonnes.add(new ColumnConfig("nom", i18nC.personneNom(), 300));
|
100 |
colonnes.add(new ColumnConfig("_structure_nom_", i18nC.structure(), 200));
|
102 |
colonnes.add(new ColumnConfig("_structure_nom_", i18nC.structure(), 200));
|
101 |
colonnes.add(new ColumnConfig("_structure_ville_", i18nC.ville(), 150));
|
103 |
colonnes.add(new ColumnConfig("_structure_ville_", i18nC.ville(), 150));
|
102 |
colonnes.get(1).setHidden(true);
|
104 |
colonnes.get(1).setHidden(true);
|
103 |
ColumnModel modeleDeColonne = new ColumnModel(colonnes);
|
105 |
ColumnModel modeleDeColonne = new ColumnModel(colonnes);
|
104 |
|
106 |
|
105 |
GridSelectionModel<Collection> modeleDeSelection = new GridSelectionModel<Collection>();
|
107 |
GridSelectionModel<Collection> modeleDeSelection = new GridSelectionModel<Collection>();
|
106 |
modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Collection>() {
|
108 |
modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Collection>() {
|
107 |
public void selectionChanged(SelectionChangedEvent<Collection> event) {
|
109 |
public void selectionChanged(SelectionChangedEvent<Collection> event) {
|
108 |
collectionSelectionnee = (Collection) event.getSelectedItem();
|
110 |
collectionSelectionnee = (Collection) event.getSelectedItem();
|
109 |
indexElementSelectionne = store.indexOf(collectionSelectionnee);
|
111 |
indexElementSelectionne = store.indexOf(collectionSelectionnee);
|
110 |
clicListe(collectionSelectionnee);
|
112 |
clicListe(collectionSelectionnee);
|
111 |
}
|
113 |
}
|
112 |
});
|
114 |
});
|
113 |
|
115 |
|
114 |
store = new ListStore<Collection>();
|
116 |
store = new ListStore<Collection>();
|
115 |
store.sort("nom", SortDir.ASC);
|
117 |
store.sort("nom", SortDir.ASC);
|
116 |
|
118 |
|
117 |
grille = new Grid<Collection>(store, modeleDeColonne);
|
119 |
grille = new Grid<Collection>(store, modeleDeColonne);
|
118 |
grille.setWidth("100%");
|
120 |
grille.setWidth("100%");
|
119 |
grille.setAutoExpandColumn("nom");
|
121 |
grille.setAutoExpandColumn("nom");
|
120 |
grille.getView().setAutoFill(true);
|
122 |
grille.getView().setAutoFill(true);
|
121 |
grille.getView().setForceFit(true);
|
123 |
grille.getView().setForceFit(true);
|
122 |
grille.setSelectionModel(modeleDeSelection);
|
124 |
grille.setSelectionModel(modeleDeSelection);
|
123 |
grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
|
125 |
grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
|
124 |
public void handleEvent(BaseEvent be) {
|
126 |
public void handleEvent(BaseEvent be) {
|
125 |
grille.getSelectionModel().select(0, false);
|
127 |
grille.getSelectionModel().select(0, false);
|
126 |
}
|
128 |
}
|
127 |
});
|
129 |
});
|
128 |
grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>() {
|
130 |
grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>() {
|
129 |
public void handleEvent(BaseEvent be) {
|
131 |
public void handleEvent(BaseEvent be) {
|
130 |
modifier.fireEvent(Events.Select);
|
132 |
modifier.fireEvent(Events.Select);
|
131 |
}
|
133 |
}
|
132 |
});
|
134 |
});
|
133 |
add(grille);
|
135 |
add(grille);
|
- |
|
136 |
|
- |
|
137 |
CollectionListe collectionListe = new CollectionListe();
|
134 |
|
138 |
champFiltreRecherche = new ChampFiltreRecherche(mediateur, toolBar, collectionListe);
|
135 |
// Définition de la barre de pagination
|
139 |
// Définition de la barre de pagination
|
136 |
pagination = new BarrePaginationVue(new CollectionListe(), mediateur);
|
140 |
pagination = new BarrePaginationVue(collectionListe, mediateur);
|
137 |
setBottomComponent(pagination);
|
141 |
setBottomComponent(pagination);
|
138 |
}
|
142 |
}
|
139 |
|
143 |
|
140 |
private void clicListe(Collection collection) {
|
144 |
private void clicListe(Collection collection) {
|
141 |
if (collection != null && store.getCount() > 0) {
|
145 |
if (collection != null && store.getCount() > 0) {
|
142 |
mediateur.clicListeCollection(collection);
|
146 |
mediateur.clicListeCollection(collection);
|
143 |
}
|
147 |
}
|
144 |
}
|
148 |
}
|
145 |
|
149 |
|
146 |
private void clicSupprimerCollection(List<Collection> collectionsASupprimer) {
|
150 |
private void clicSupprimerCollection(List<Collection> collectionsASupprimer) {
|
147 |
if (store.getCount() > 0) {
|
151 |
if (store.getCount() > 0) {
|
148 |
mediateur.clicSupprimerCollection(this, collectionsASupprimer);
|
152 |
mediateur.clicSupprimerCollection(this, collectionsASupprimer);
|
149 |
}
|
153 |
}
|
150 |
}
|
154 |
}
|
151 |
|
155 |
|
152 |
private void gererEtatActivationBouton() {
|
156 |
private void gererEtatActivationBouton() {
|
153 |
int nbreElementDuMagazin = store.getCount();
|
157 |
int nbreElementDuMagazin = store.getCount();
|
154 |
ajouter.enable();
|
158 |
ajouter.enable();
|
155 |
if (nbreElementDuMagazin == 0) {
|
159 |
if (nbreElementDuMagazin == 0) {
|
156 |
supprimer.disable();
|
160 |
supprimer.disable();
|
157 |
modifier.disable();
|
161 |
modifier.disable();
|
158 |
} else if (nbreElementDuMagazin > 0) {
|
162 |
} else if (nbreElementDuMagazin > 0) {
|
159 |
modifier.enable();
|
163 |
modifier.enable();
|
160 |
if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
|
164 |
if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
|
161 |
supprimer.enable();
|
165 |
supprimer.enable();
|
162 |
}
|
166 |
}
|
163 |
}
|
167 |
}
|
164 |
}
|
168 |
}
|
165 |
|
169 |
|
166 |
public void rafraichir(Object nouvellesDonnees) {
|
170 |
public void rafraichir(Object nouvellesDonnees) {
|
167 |
|
171 |
|
168 |
if (nouvellesDonnees instanceof CollectionListe) {
|
172 |
if (nouvellesDonnees instanceof CollectionListe) {
|
169 |
CollectionListe collections = (CollectionListe) nouvellesDonnees;
|
173 |
CollectionListe collections = (CollectionListe) nouvellesDonnees;
|
170 |
|
174 |
|
171 |
pagination.setlistePaginable(collections);
|
175 |
pagination.setlistePaginable(collections);
|
172 |
int[] pt = collections.getPageTable();
|
176 |
int[] pt = collections.getPageTable();
|
173 |
pagination.rafraichir(collections.getPageTable());
|
177 |
pagination.rafraichir(collections.getPageTable());
|
- |
|
178 |
champFiltreRecherche.setListePaginable(collections);
|
174 |
|
179 |
|
175 |
if (collections != null) {
|
180 |
if (collections != null) {
|
176 |
List<Collection> liste = collections.toList();
|
181 |
List<Collection> liste = collections.toList();
|
177 |
store.removeAll();
|
182 |
store.removeAll();
|
178 |
store.add(liste);
|
183 |
store.add(liste);
|
179 |
|
184 |
|
180 |
mediateur.actualiserPanneauCentral();
|
185 |
mediateur.actualiserPanneauCentral();
|
181 |
}
|
186 |
}
|
182 |
} else if (nouvellesDonnees instanceof Information) {
|
187 |
} else if (nouvellesDonnees instanceof Information) {
|
183 |
Information info = (Information) nouvellesDonnees;
|
188 |
Information info = (Information) nouvellesDonnees;
|
184 |
if (info.getType().equals("maj_utilisateur")) {
|
189 |
if (info.getType().equals("maj_utilisateur")) {
|
185 |
gererEtatActivationBouton();
|
190 |
gererEtatActivationBouton();
|
186 |
} else if (info.getType().equals("modif_collection")) {
|
191 |
} else if (info.getType().equals("modif_collection")) {
|
187 |
if(collectionSelectionnee != null) {
|
192 |
if(collectionSelectionnee != null) {
|
188 |
store.remove(indexElementSelectionne);
|
193 |
store.remove(indexElementSelectionne);
|
189 |
collectionSelectionnee = null;
|
194 |
collectionSelectionnee = null;
|
190 |
}
|
195 |
}
|
191 |
Collection collecModifiee = (Collection)info.getDonnee(0);
|
196 |
Collection collecModifiee = (Collection)info.getDonnee(0);
|
192 |
// au cas ou le bouton appliquer aurait été cliqué avant de valider
|
197 |
// au cas ou le bouton appliquer aurait été cliqué avant de valider
|
193 |
store.remove(collecModifiee);
|
198 |
store.remove(collecModifiee);
|
194 |
store.insert(collecModifiee, indexElementSelectionne);
|
199 |
store.insert(collecModifiee, indexElementSelectionne);
|
195 |
grille.repaint();
|
200 |
grille.repaint();
|
196 |
grille.getSelectionModel().select(indexElementSelectionne, true);
|
201 |
grille.getSelectionModel().select(indexElementSelectionne, true);
|
197 |
clicListe(collecModifiee);
|
202 |
clicListe(collecModifiee);
|
198 |
} else if (info.getType().equals("suppression_collection")) {
|
203 |
} else if (info.getType().equals("suppression_collection")) {
|
199 |
// Affichage d'un message d'information
|
204 |
// Affichage d'un message d'information
|
200 |
InfoLogger.display(i18nC.suppressionCollection(), info.toString().replaceAll("\n", "<br />"));
|
205 |
InfoLogger.display(i18nC.suppressionCollection(), info.toString().replaceAll("\n", "<br />"));
|
201 |
|
206 |
|
202 |
supprimerCollectionsSelectionnees();
|
207 |
supprimerCollectionsSelectionnees();
|
203 |
|
208 |
|
204 |
gererEtatActivationBouton();
|
209 |
gererEtatActivationBouton();
|
205 |
}
|
210 |
}
|
206 |
} else {
|
211 |
} else {
|
207 |
Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));
|
212 |
Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));
|
208 |
}
|
213 |
}
|
209 |
layout();
|
214 |
layout();
|
210 |
}
|
215 |
}
|
211 |
|
216 |
|
212 |
private void supprimerCollectionsSelectionnees() {
|
217 |
private void supprimerCollectionsSelectionnees() {
|
213 |
List<Collection> collectionsSelectionnees = grille.getSelectionModel().getSelectedItems();
|
218 |
List<Collection> collectionsSelectionnees = grille.getSelectionModel().getSelectedItems();
|
214 |
Iterator<Collection> it = collectionsSelectionnees.iterator();
|
219 |
Iterator<Collection> it = collectionsSelectionnees.iterator();
|
215 |
while (it.hasNext()) {
|
220 |
while (it.hasNext()) {
|
216 |
grille.getStore().remove(it.next());
|
221 |
grille.getStore().remove(it.next());
|
217 |
}
|
222 |
}
|
218 |
layout(true);
|
223 |
layout(true);
|
219 |
}
|
224 |
}
|
220 |
}
|
225 |
}
|