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