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