934 |
jpm |
1 |
package org.tela_botanica.client.vues.collection;
|
719 |
jp_milcent |
2 |
|
|
|
3 |
import java.util.ArrayList;
|
1513 |
jpm |
4 |
import java.util.HashMap;
|
719 |
jp_milcent |
5 |
import java.util.List;
|
|
|
6 |
|
|
|
7 |
import org.tela_botanica.client.Mediateur;
|
1513 |
jpm |
8 |
import org.tela_botanica.client.composants.ChampComboBoxRechercheTempsReelPaginable;
|
|
|
9 |
import org.tela_botanica.client.composants.GrillePaginable;
|
1239 |
cyprien |
10 |
import org.tela_botanica.client.composants.InfoLogger;
|
1513 |
jpm |
11 |
import org.tela_botanica.client.composants.pagination.ProxyCollectionAPublication;
|
|
|
12 |
import org.tela_botanica.client.composants.pagination.ProxyPublications;
|
719 |
jp_milcent |
13 |
import org.tela_botanica.client.images.Images;
|
|
|
14 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
|
|
15 |
import org.tela_botanica.client.modeles.Information;
|
907 |
jpm |
16 |
import org.tela_botanica.client.modeles.aDonnee;
|
935 |
jpm |
17 |
import org.tela_botanica.client.modeles.collection.Collection;
|
|
|
18 |
import org.tela_botanica.client.modeles.collection.CollectionAPublication;
|
|
|
19 |
import org.tela_botanica.client.modeles.collection.CollectionAPublicationListe;
|
|
|
20 |
import org.tela_botanica.client.modeles.publication.Publication;
|
934 |
jpm |
21 |
import org.tela_botanica.client.vues.FenetreForm;
|
|
|
22 |
import org.tela_botanica.client.vues.Formulaire;
|
|
|
23 |
import org.tela_botanica.client.vues.FormulaireBarreValidation;
|
|
|
24 |
import org.tela_botanica.client.vues.FormulaireOnglet;
|
935 |
jpm |
25 |
import org.tela_botanica.client.vues.publication.PublicationForm;
|
719 |
jp_milcent |
26 |
|
799 |
jpm |
27 |
import com.extjs.gxt.ui.client.core.XTemplate;
|
1513 |
jpm |
28 |
import com.extjs.gxt.ui.client.data.ModelData;
|
|
|
29 |
import com.extjs.gxt.ui.client.data.ModelType;
|
775 |
jpm |
30 |
import com.extjs.gxt.ui.client.event.BaseEvent;
|
719 |
jp_milcent |
31 |
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
775 |
jpm |
32 |
import com.extjs.gxt.ui.client.event.Events;
|
719 |
jp_milcent |
33 |
import com.extjs.gxt.ui.client.event.Listener;
|
|
|
34 |
import com.extjs.gxt.ui.client.event.SelectionListener;
|
|
|
35 |
import com.extjs.gxt.ui.client.store.ListStore;
|
|
|
36 |
import com.extjs.gxt.ui.client.store.Store;
|
|
|
37 |
import com.extjs.gxt.ui.client.store.StoreEvent;
|
|
|
38 |
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
862 |
jpm |
39 |
import com.extjs.gxt.ui.client.widget.Text;
|
719 |
jp_milcent |
40 |
import com.extjs.gxt.ui.client.widget.button.Button;
|
775 |
jpm |
41 |
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
|
1513 |
jpm |
42 |
import com.extjs.gxt.ui.client.widget.form.Field;
|
775 |
jpm |
43 |
import com.extjs.gxt.ui.client.widget.form.FormPanel;
|
1513 |
jpm |
44 |
import com.extjs.gxt.ui.client.widget.form.Validator;
|
719 |
jp_milcent |
45 |
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
910 |
jpm |
46 |
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
|
719 |
jp_milcent |
47 |
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
910 |
jpm |
48 |
import com.extjs.gxt.ui.client.widget.grid.Grid;
|
|
|
49 |
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
|
719 |
jp_milcent |
50 |
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
|
799 |
jpm |
51 |
import com.extjs.gxt.ui.client.widget.grid.RowExpander;
|
719 |
jp_milcent |
52 |
import com.extjs.gxt.ui.client.widget.grid.RowNumberer;
|
|
|
53 |
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
|
|
54 |
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
|
|
|
55 |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
|
|
56 |
import com.google.gwt.core.client.GWT;
|
|
|
57 |
|
|
|
58 |
public class CollectionFormPublication extends FormulaireOnglet implements Rafraichissable {
|
883 |
jpm |
59 |
|
1083 |
jpm |
60 |
public static final String ID = "publication";
|
883 |
jpm |
61 |
private Collection collection = null;
|
|
|
62 |
private static int idGenere = 1;
|
|
|
63 |
|
719 |
jp_milcent |
64 |
private ContentPanel panneauPrincipal = null;
|
|
|
65 |
private ToolBar barreOutils = null;
|
1513 |
jpm |
66 |
private GrillePaginable<ModelData> grille;
|
719 |
jp_milcent |
67 |
|
907 |
jpm |
68 |
private CollectionAPublicationListe publicationsAjoutees = null;
|
|
|
69 |
private CollectionAPublicationListe publicationsSupprimees = null;
|
1513 |
jpm |
70 |
private ChampComboBoxRechercheTempsReelPaginable publicationsSaisiesComboBox = null;
|
719 |
jp_milcent |
71 |
private Button publicationsBoutonSupprimer = null;
|
|
|
72 |
private Button publicationsBoutonModifier = null;
|
|
|
73 |
|
781 |
jpm |
74 |
private FenetreForm fenetreFormulaire = null;
|
|
|
75 |
|
719 |
jp_milcent |
76 |
public CollectionFormPublication(Formulaire formulaireCourrant) {
|
1284 |
gduche |
77 |
|
719 |
jp_milcent |
78 |
initialiserOnglet(formulaireCourrant);
|
1083 |
jpm |
79 |
setId(ID);
|
719 |
jp_milcent |
80 |
setText(Mediateur.i18nC.collectionPublication());
|
|
|
81 |
setStyleAttribute("padding", "0");
|
1513 |
jpm |
82 |
|
|
|
83 |
initialiser();
|
|
|
84 |
|
719 |
jp_milcent |
85 |
panneauPrincipal = creerPanneauContenantGrille();
|
1284 |
gduche |
86 |
setLayout(new FitLayout());
|
719 |
jp_milcent |
87 |
barreOutils = creerBarreOutilsGrille();
|
|
|
88 |
panneauPrincipal.setTopComponent(barreOutils);
|
|
|
89 |
grille = creerGrille();
|
1284 |
gduche |
90 |
panneauPrincipal.setLayout(new FitLayout());
|
|
|
91 |
panneauPrincipal.add(grille);
|
|
|
92 |
|
1513 |
jpm |
93 |
add(panneauPrincipal);
|
719 |
jp_milcent |
94 |
}
|
|
|
95 |
|
|
|
96 |
private void initialiser() {
|
|
|
97 |
// Remise à zéro des modification dans la liste des auteurs
|
883 |
jpm |
98 |
idGenere = 1;
|
907 |
jpm |
99 |
publicationsAjoutees = new CollectionAPublicationListe();
|
|
|
100 |
publicationsSupprimees = new CollectionAPublicationListe();
|
719 |
jp_milcent |
101 |
|
883 |
jpm |
102 |
collection = ((CollectionForm) formulaire).collection;
|
719 |
jp_milcent |
103 |
}
|
883 |
jpm |
104 |
|
719 |
jp_milcent |
105 |
private ContentPanel creerPanneauContenantGrille() {
|
|
|
106 |
ContentPanel panneau = new ContentPanel();
|
|
|
107 |
|
1680 |
raphael |
108 |
panneau.setHeadingHtml(i18nC.collectionPublicationTitre());
|
719 |
jp_milcent |
109 |
panneau.setIcon(Images.ICONES.table());
|
|
|
110 |
panneau.setLayout(new FitLayout());
|
|
|
111 |
panneau.setFrame(true);
|
|
|
112 |
|
|
|
113 |
return panneau;
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
private ToolBar creerBarreOutilsGrille() {
|
|
|
117 |
ToolBar barreOutils = new ToolBar();
|
|
|
118 |
|
|
|
119 |
Button ajouterBouton = creerBoutonAjouter();
|
|
|
120 |
barreOutils.add(ajouterBouton);
|
|
|
121 |
|
862 |
jpm |
122 |
barreOutils.add(new Text(" ou "));
|
|
|
123 |
|
|
|
124 |
publicationsSaisiesComboBox = creerComboBoxPublicationsSaisis();
|
|
|
125 |
barreOutils.add(publicationsSaisiesComboBox);
|
|
|
126 |
|
719 |
jp_milcent |
127 |
barreOutils.add(new SeparatorToolItem());
|
|
|
128 |
|
|
|
129 |
publicationsBoutonModifier = creerBoutonModifier();
|
|
|
130 |
barreOutils.add(publicationsBoutonModifier);
|
|
|
131 |
|
|
|
132 |
barreOutils.add(new SeparatorToolItem());
|
|
|
133 |
|
|
|
134 |
publicationsBoutonSupprimer = creerBoutonSupprimer();
|
|
|
135 |
barreOutils.add(publicationsBoutonSupprimer);
|
|
|
136 |
|
|
|
137 |
barreOutils.add(new SeparatorToolItem());
|
|
|
138 |
|
|
|
139 |
Button rafraichirBouton = creerBoutonRafraichir();
|
|
|
140 |
barreOutils.add(rafraichirBouton);
|
|
|
141 |
|
|
|
142 |
return barreOutils;
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
private Button creerBoutonAjouter() {
|
|
|
146 |
Button bouton = new Button(i18nC.ajouter());
|
|
|
147 |
bouton.setIcon(Images.ICONES.vcardAjouter());
|
|
|
148 |
bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
149 |
public void componentSelected(ButtonEvent ce) {
|
1468 |
jpm |
150 |
fenetreFormulaire = creerFenetreModaleAvecFormulairePublication(Formulaire.MODE_AJOUTER);
|
781 |
jpm |
151 |
fenetreFormulaire.show();
|
719 |
jp_milcent |
152 |
}
|
|
|
153 |
});
|
|
|
154 |
return bouton;
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
private Button creerBoutonModifier() {
|
|
|
158 |
Button bouton = new Button(i18nC.modifier());
|
|
|
159 |
bouton.setIcon(Images.ICONES.vcardModifier());
|
|
|
160 |
bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
161 |
public void componentSelected(ButtonEvent ce) {
|
1513 |
jpm |
162 |
ModelData publicationSaisieSelectionnee = grille.getGrille().getSelectionModel().getSelectedItem();
|
719 |
jp_milcent |
163 |
if (publicationSaisieSelectionnee == null) {
|
1239 |
cyprien |
164 |
InfoLogger.display(i18nC.informationTitreGenerique(), i18nC.selectionnerPublication());
|
719 |
jp_milcent |
165 |
} else {
|
1468 |
jpm |
166 |
fenetreFormulaire = creerFenetreModaleAvecFormulairePublication(Formulaire.MODE_MODIFIER);
|
781 |
jpm |
167 |
fenetreFormulaire.show();
|
719 |
jp_milcent |
168 |
}
|
|
|
169 |
}
|
|
|
170 |
});
|
|
|
171 |
return bouton;
|
|
|
172 |
}
|
775 |
jpm |
173 |
|
1468 |
jpm |
174 |
private FenetreForm creerFenetreModaleAvecFormulairePublication(String mode) {
|
781 |
jpm |
175 |
String publicationId = null;
|
|
|
176 |
if (mode.equals(Formulaire.MODE_MODIFIER)) {
|
1513 |
jpm |
177 |
CollectionAPublication publicationSaisiSelectionne = new CollectionAPublication(grille.getGrille().getSelectionModel().getSelectedItem(), false);
|
907 |
jpm |
178 |
publicationId = publicationSaisiSelectionne.getIdPublication();
|
781 |
jpm |
179 |
}
|
|
|
180 |
|
775 |
jpm |
181 |
final FenetreForm fenetre = new FenetreForm("");
|
781 |
jpm |
182 |
final PublicationForm formulaire = creerFormulairePublication(fenetre, publicationId);
|
775 |
jpm |
183 |
fenetre.add(formulaire);
|
|
|
184 |
return fenetre;
|
|
|
185 |
}
|
|
|
186 |
|
781 |
jpm |
187 |
private PublicationForm creerFormulairePublication(final FenetreForm fenetre, final String publicationId) {
|
786 |
jpm |
188 |
PublicationForm formulairePublication = new PublicationForm(mediateur, publicationId, this);
|
775 |
jpm |
189 |
FormPanel panneauFormulaire = formulairePublication.getFormulaire();
|
1680 |
raphael |
190 |
fenetre.setHeadingHtml(panneauFormulaire.getHeadingHtml());
|
775 |
jpm |
191 |
panneauFormulaire.setHeaderVisible(false);
|
|
|
192 |
panneauFormulaire.setTopComponent(null);
|
957 |
jpm |
193 |
|
|
|
194 |
// FIXME : avec GXT-2.1.0 la redéfinition du bottom component ne marche plus. Nous le cachons et en créeons un dans la fenêtre.
|
|
|
195 |
panneauFormulaire.getBottomComponent().hide();
|
775 |
jpm |
196 |
SelectionListener<ButtonEvent> ecouteur = creerEcouteurValidationFormulairePublication(fenetre, formulairePublication);
|
|
|
197 |
final ButtonBar barreValidation = new FormulaireBarreValidation(ecouteur);
|
957 |
jpm |
198 |
fenetre.setBottomComponent(barreValidation);
|
775 |
jpm |
199 |
|
|
|
200 |
return formulairePublication;
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
private SelectionListener<ButtonEvent> creerEcouteurValidationFormulairePublication(final FenetreForm fenetre, final PublicationForm formulaire) {
|
|
|
204 |
SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() {
|
|
|
205 |
public void componentSelected(ButtonEvent ce) {
|
|
|
206 |
String code = ((Button) ce.getComponent()).getData("code");
|
|
|
207 |
if (code.equals(FormulaireBarreValidation.CODE_BOUTON_VALIDER)) {
|
786 |
jpm |
208 |
if (formulaire.soumettreFormulaire()) {
|
|
|
209 |
fenetre.hide();
|
|
|
210 |
}
|
775 |
jpm |
211 |
} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_APPLIQUER)) {
|
782 |
jpm |
212 |
formulaire.soumettreFormulaire();
|
775 |
jpm |
213 |
} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_ANNULER)) {
|
|
|
214 |
fenetre.hide();
|
|
|
215 |
}
|
|
|
216 |
}
|
|
|
217 |
};
|
|
|
218 |
|
|
|
219 |
return ecouteur;
|
|
|
220 |
}
|
781 |
jpm |
221 |
|
719 |
jp_milcent |
222 |
private Button creerBoutonSupprimer() {
|
|
|
223 |
Button bouton = new Button(i18nC.supprimer());
|
|
|
224 |
bouton.setIcon(Images.ICONES.vcardSupprimer());
|
|
|
225 |
bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
226 |
public void componentSelected(ButtonEvent ce) {
|
1638 |
aurelien |
227 |
List<ModelData> listeDonneesSelectionnees = grille.getGrille().getSelectionModel().getSelectedItems();
|
|
|
228 |
for (ModelData donneeSelectionnee : listeDonneesSelectionnees) {
|
|
|
229 |
CollectionAPublication publicationSaisieSelectionnee = new CollectionAPublication(grille.getGrille().getSelectionModel().getSelectedItem(), false);
|
|
|
230 |
supprimerDansGrille(publicationSaisieSelectionnee, donneeSelectionnee);
|
719 |
jp_milcent |
231 |
}
|
|
|
232 |
}
|
|
|
233 |
});
|
|
|
234 |
return bouton;
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
private Button creerBoutonRafraichir() {
|
|
|
238 |
Button bouton = new Button(i18nC.rafraichir());
|
|
|
239 |
bouton.setIcon(Images.ICONES.rafraichir());
|
|
|
240 |
bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
241 |
public void componentSelected(ButtonEvent ce) {
|
883 |
jpm |
242 |
actualiserGrille();
|
1513 |
jpm |
243 |
}
|
719 |
jp_milcent |
244 |
});
|
|
|
245 |
return bouton;
|
|
|
246 |
}
|
|
|
247 |
|
883 |
jpm |
248 |
private void actualiserGrille() {
|
|
|
249 |
if (mode.equals(Formulaire.MODE_MODIFIER)) {
|
1367 |
cyprien |
250 |
mediateur.selectionnerCollectionAPublication(this, collection.getId(), null);
|
883 |
jpm |
251 |
} else {
|
|
|
252 |
grille.getStore().removeAll();
|
|
|
253 |
layout();
|
|
|
254 |
}
|
|
|
255 |
}
|
|
|
256 |
|
1513 |
jpm |
257 |
private ChampComboBoxRechercheTempsReelPaginable creerComboBoxPublicationsSaisis() {
|
719 |
jp_milcent |
258 |
|
1513 |
jpm |
259 |
ModelType modelTypePublications = new ModelType();
|
|
|
260 |
modelTypePublications.setRoot("publications");
|
|
|
261 |
modelTypePublications.setTotalName("nbElements");
|
|
|
262 |
modelTypePublications.addField("ccapu_id_collection");
|
|
|
263 |
modelTypePublications.addField("ccapu_id_publication");
|
|
|
264 |
modelTypePublications.addField("cc_nom");
|
|
|
265 |
modelTypePublications.addField("cc_id_collection");
|
|
|
266 |
modelTypePublications.addField("cpu_id_publication");
|
|
|
267 |
modelTypePublications.addField("cpu_fmt_nom_complet");
|
|
|
268 |
modelTypePublications.addField("cpu_titre");
|
|
|
269 |
modelTypePublications.addField("cpu_nom");
|
|
|
270 |
modelTypePublications.addField("cpu_fmt_auteur");
|
|
|
271 |
modelTypePublications.addField("cpu_indication_nvt");
|
|
|
272 |
modelTypePublications.addField("cpu_truk_pages");
|
|
|
273 |
modelTypePublications.addField("cpu_fascicule");
|
|
|
274 |
modelTypePublications.addField("cpu_date_parution");
|
|
|
275 |
modelTypePublications.addField("cpu_ce_truk_editeur");
|
|
|
276 |
|
|
|
277 |
String displayNamePublications = "cpu_fmt_nom_complet";
|
|
|
278 |
ProxyPublications<ModelData> proxyPublications= new ProxyPublications<ModelData>(null);
|
|
|
279 |
|
|
|
280 |
final ChampComboBoxRechercheTempsReelPaginable publicationsCombo = new ChampComboBoxRechercheTempsReelPaginable(proxyPublications, modelTypePublications, displayNamePublications);
|
|
|
281 |
publicationsCombo.getCombo().setTabIndex(tabIndex++);
|
|
|
282 |
publicationsCombo.getCombo().setForceSelection(true);
|
|
|
283 |
|
|
|
284 |
publicationsCombo.getCombo().setValidator(new Validator() {
|
|
|
285 |
public String validate(Field<?> field, String value) {
|
|
|
286 |
String retour = null;
|
|
|
287 |
if (field.getRawValue().equals("")) {
|
|
|
288 |
field.setValue(null);
|
|
|
289 |
} else if (publicationsCombo.getStore().findModel("cpu_fmt_nom_complet", field.getRawValue()) == null) {
|
|
|
290 |
String contenuBrut = field.getRawValue();
|
|
|
291 |
field.setValue(null);
|
|
|
292 |
field.setRawValue(contenuBrut);
|
|
|
293 |
retour = "Veuillez sélectionner une valeur ou laisser le champ vide";
|
719 |
jp_milcent |
294 |
}
|
1513 |
jpm |
295 |
return retour;
|
719 |
jp_milcent |
296 |
}
|
|
|
297 |
});
|
1513 |
jpm |
298 |
|
|
|
299 |
publicationsCombo.getCombo().addListener(Events.Select, new Listener<BaseEvent>() {
|
775 |
jpm |
300 |
public void handleEvent(BaseEvent be) {
|
1513 |
jpm |
301 |
if (publicationsSaisiesComboBox.getValeur() instanceof ModelData) {
|
|
|
302 |
Publication publicationSaisieSelectionne = new Publication(publicationsSaisiesComboBox.getValeur(), false);
|
862 |
jpm |
303 |
ajouterDansGrille(publicationSaisieSelectionne);
|
1513 |
jpm |
304 |
publicationsSaisiesComboBox.getCombo().setValue(null);
|
775 |
jpm |
305 |
}
|
|
|
306 |
}
|
|
|
307 |
});
|
1513 |
jpm |
308 |
|
|
|
309 |
return publicationsCombo;
|
719 |
jp_milcent |
310 |
}
|
907 |
jpm |
311 |
|
719 |
jp_milcent |
312 |
private void ajouterDansGrille(Publication publication) {
|
907 |
jpm |
313 |
ajouterDansGrille(publication, 0);
|
|
|
314 |
}
|
|
|
315 |
|
|
|
316 |
private void ajouterDansGrille(Publication publication, int index) {
|
1513 |
jpm |
317 |
if (publication != null) {
|
|
|
318 |
CollectionAPublication publicationLiee = new CollectionAPublication(false);
|
907 |
jpm |
319 |
publicationLiee.setPublication(publication);
|
|
|
320 |
publicationLiee.setIdPublication(publication.getId());
|
1513 |
jpm |
321 |
|
907 |
jpm |
322 |
// Gestion de l'id de la collection
|
|
|
323 |
if (mode.equals(Formulaire.MODE_MODIFIER)) {
|
|
|
324 |
publicationLiee.setIdCollection(collection.getId());
|
719 |
jp_milcent |
325 |
}
|
907 |
jpm |
326 |
publicationLiee.set("_etat_", aDonnee.ETAT_AJOUTE);
|
910 |
jpm |
327 |
|
1513 |
jpm |
328 |
grille.getGrille().stopEditing();
|
|
|
329 |
grille.getGrille().getStore().insert(publicationLiee, 0);
|
|
|
330 |
grille.getGrille().startEditing(index, 0);
|
|
|
331 |
grille.getGrille().getSelectionModel().select(index, false);
|
719 |
jp_milcent |
332 |
}
|
|
|
333 |
}
|
|
|
334 |
|
1638 |
aurelien |
335 |
private void supprimerDansGrille(CollectionAPublication publicationLiee, ModelData publicationLieeModele) {
|
907 |
jpm |
336 |
if (publicationLiee != null) {
|
719 |
jp_milcent |
337 |
// Ajout de la personne supprimée à la liste
|
907 |
jpm |
338 |
if ((publicationLiee.get("_etat_").equals("") || !publicationLiee.get("_etat_").equals(aDonnee.ETAT_AJOUTE))
|
|
|
339 |
&& publicationLiee.getId() != null
|
|
|
340 |
&& !publicationLiee.getId().equals("")) {
|
|
|
341 |
publicationsSupprimees.put("id"+idGenere++, publicationLiee);
|
719 |
jp_milcent |
342 |
}
|
|
|
343 |
|
|
|
344 |
// Suppression de l'enregistrement de la grille
|
1638 |
aurelien |
345 |
grille.getStore().remove(publicationLieeModele);
|
719 |
jp_milcent |
346 |
}
|
|
|
347 |
}
|
1513 |
jpm |
348 |
|
|
|
349 |
private GrillePaginable<ModelData> creerGrille() {
|
|
|
350 |
|
|
|
351 |
GrillePaginable<ModelData> grillePublications = null;
|
|
|
352 |
|
|
|
353 |
// ModelType
|
|
|
354 |
ModelType modelTypeCollectionAPublication = new ModelType();
|
|
|
355 |
modelTypeCollectionAPublication.setRoot("collectionsAPublication");
|
|
|
356 |
modelTypeCollectionAPublication.setTotalName("nbElements");
|
|
|
357 |
modelTypeCollectionAPublication.addField("ccapu_id_collection");
|
|
|
358 |
modelTypeCollectionAPublication.addField("ccapu_id_publication");
|
|
|
359 |
modelTypeCollectionAPublication.addField("ccapu_mark_licence");
|
|
|
360 |
modelTypeCollectionAPublication.addField("cpu_id_publication");
|
|
|
361 |
modelTypeCollectionAPublication.addField("cpu_fmt_auteur");
|
|
|
362 |
modelTypeCollectionAPublication.addField("cpu_titre");
|
|
|
363 |
modelTypeCollectionAPublication.addField("cpu_collection");
|
|
|
364 |
modelTypeCollectionAPublication.addField("cpu_ce_truk_editeur");
|
|
|
365 |
modelTypeCollectionAPublication.addField("cpu_date_parution");
|
|
|
366 |
modelTypeCollectionAPublication.addField("cpu_fascicule");
|
|
|
367 |
modelTypeCollectionAPublication.addField("cpu_truk_pages");
|
|
|
368 |
modelTypeCollectionAPublication.addField("cpu_indication_nvt");
|
|
|
369 |
|
|
|
370 |
// Proxy
|
|
|
371 |
ProxyCollectionAPublication<ModelData> proxyCollectionAPublication = new ProxyCollectionAPublication<ModelData>(null, collection.getId());
|
719 |
jp_milcent |
372 |
|
1513 |
jpm |
373 |
// Colonnes
|
|
|
374 |
List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
|
799 |
jpm |
375 |
RowNumberer numeroPlugin = new RowNumberer();
|
1680 |
raphael |
376 |
numeroPlugin.setHeaderHtml("#");
|
799 |
jpm |
377 |
XTemplate infoTpl = XTemplate.create("<p>"+
|
1513 |
jpm |
378 |
"<span style='font-weight:bold;'>"+i18nC.publicationAuteurs()+" :</span> {cpu_fmt_auteur}<br />"+
|
|
|
379 |
"<span style='font-weight:bold;'>"+i18nC.publicationTitre()+" :</span> {cpu_titre}<br />"+
|
|
|
380 |
"<span style='font-weight:bold;'>"+i18nC.publicationRevueCollection()+" :</span> {cpu_collection}<br />"+
|
799 |
jpm |
381 |
"<span style='font-weight:bold;'>"+i18nC.publicationEditeur()+" :</span> {_editeur_}"+
|
|
|
382 |
"</p>");
|
|
|
383 |
RowExpander expansionPlugin = new RowExpander();
|
|
|
384 |
expansionPlugin.setTemplate(infoTpl);
|
|
|
385 |
colonnes.add(expansionPlugin);
|
|
|
386 |
colonnes.add(numeroPlugin);
|
1513 |
jpm |
387 |
colonnes.add(new ColumnConfig("cpu_fmt_auteur", i18nC.publicationAuteurs(), 150));
|
|
|
388 |
colonnes.add(new ColumnConfig("cpu_titre", i18nC.publicationTitre(), 150));
|
|
|
389 |
colonnes.add(new ColumnConfig("cpu_collection", i18nC.publicationRevueCollection(), 75));
|
910 |
jpm |
390 |
colonnes.add(creerColonneEditeur());
|
|
|
391 |
colonnes.add(creerColonneAnneePublication());
|
1513 |
jpm |
392 |
colonnes.add(new ColumnConfig("cpu_indication_nvt", i18nC.publicationNvt(), 75));
|
|
|
393 |
colonnes.add(new ColumnConfig("cpu_fascicule", i18nC.publicationFascicule(), 75));
|
|
|
394 |
colonnes.add(new ColumnConfig("cpu_truk_pages", i18nC.publicationPage(), 50));
|
719 |
jp_milcent |
395 |
|
1513 |
jpm |
396 |
HashMap<String, String> virtualFields = new HashMap<String, String>();
|
|
|
397 |
virtualFields.put("_editeur_", "cpu_ce_truk_editeur");
|
|
|
398 |
virtualFields.put("_annee_", "cpu_date_parution");
|
|
|
399 |
virtualFields.put("_etat_", "");
|
719 |
jp_milcent |
400 |
|
1513 |
jpm |
401 |
// Modele de selection
|
|
|
402 |
GridSelectionModel<ModelData> modeleDeSelection = new GridSelectionModel<ModelData>();
|
719 |
jp_milcent |
403 |
ColumnModel modeleDeColonnes = new ColumnModel(colonnes);
|
823 |
jpm |
404 |
modeleDeColonnes.getColumn(0).setWidget(Images.ICONES.information().createImage(), "Info");
|
719 |
jp_milcent |
405 |
|
1513 |
jpm |
406 |
// Grille
|
|
|
407 |
grillePublications = new GrillePaginable<ModelData>(modelTypeCollectionAPublication, virtualFields, proxyCollectionAPublication, colonnes, modeleDeColonnes);
|
|
|
408 |
grillePublications.getGrille().setBorders(true);
|
|
|
409 |
grillePublications.getGrille().setSelectionModel(modeleDeSelection);
|
|
|
410 |
grillePublications.getGrille().addPlugin(expansionPlugin);
|
|
|
411 |
grillePublications.getGrille().addPlugin(numeroPlugin);
|
|
|
412 |
grillePublications.getGrille().getView().setForceFit(true);
|
|
|
413 |
grillePublications.getGrille().setAutoExpandColumn("titre");
|
|
|
414 |
grillePublications.getGrille().setStripeRows(true);
|
|
|
415 |
grillePublications.getGrille().setTrackMouseOver(true);
|
719 |
jp_milcent |
416 |
|
1513 |
jpm |
417 |
// Rajouter des écouteurs
|
|
|
418 |
grillePublications.getStore().addListener(Store.Add, new Listener<StoreEvent<ModelData>>() {
|
|
|
419 |
public void handleEvent(StoreEvent<ModelData> ce) {
|
|
|
420 |
actualiserEtatBoutonsBarreOutils();
|
|
|
421 |
}
|
|
|
422 |
});
|
|
|
423 |
grillePublications.getStore().addListener(Store.Remove, new Listener<StoreEvent<ModelData>>() {
|
|
|
424 |
public void handleEvent(StoreEvent<ModelData> ce) {
|
|
|
425 |
actualiserEtatBoutonsBarreOutils();
|
|
|
426 |
}
|
|
|
427 |
});
|
|
|
428 |
|
719 |
jp_milcent |
429 |
return grillePublications;
|
|
|
430 |
}
|
910 |
jpm |
431 |
|
|
|
432 |
private ColumnConfig creerColonneEditeur() {
|
1513 |
jpm |
433 |
GridCellRenderer<ModelData> editeurRendu = new GridCellRenderer<ModelData>() {
|
|
|
434 |
public String render(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {
|
|
|
435 |
String editeur = (new CollectionAPublication(model, false)).getPublication().getNomEditeur();
|
910 |
jpm |
436 |
model.set("_editeur_", editeur);
|
|
|
437 |
return editeur;
|
|
|
438 |
}
|
|
|
439 |
};
|
|
|
440 |
ColumnConfig editeurColonne = new ColumnConfig("_editeur_", Mediateur.i18nC.publicationEditeur(), 135);
|
|
|
441 |
editeurColonne.setRenderer(editeurRendu);
|
|
|
442 |
return editeurColonne;
|
|
|
443 |
}
|
|
|
444 |
|
|
|
445 |
private ColumnConfig creerColonneAnneePublication() {
|
1513 |
jpm |
446 |
GridCellRenderer<ModelData> datePublicationRendu = new GridCellRenderer<ModelData>() {
|
|
|
447 |
public String render(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {
|
|
|
448 |
String annee = (new CollectionAPublication(model, false)).getPublication().getAnneeParution();
|
910 |
jpm |
449 |
model.set("_annee_", annee);
|
|
|
450 |
return annee;
|
|
|
451 |
}
|
|
|
452 |
};
|
|
|
453 |
ColumnConfig datePublicationColonne = new ColumnConfig("_annee_", Mediateur.i18nC.publicationDateParution(), 75);
|
|
|
454 |
datePublicationColonne.setRenderer(datePublicationRendu);
|
|
|
455 |
return datePublicationColonne;
|
|
|
456 |
}
|
799 |
jpm |
457 |
|
719 |
jp_milcent |
458 |
public void actualiserEtatBoutonsBarreOutils() {
|
|
|
459 |
// Activation des boutons si la grille contient un élément
|
|
|
460 |
if (grille.getStore().getCount() > 0) {
|
|
|
461 |
publicationsBoutonSupprimer.enable();
|
|
|
462 |
publicationsBoutonModifier.enable();
|
|
|
463 |
}
|
|
|
464 |
// Désactivation des boutons si la grille ne contient plus d'élément
|
|
|
465 |
if (grille.getStore().getCount() == 0) {
|
|
|
466 |
publicationsBoutonSupprimer.disable();
|
|
|
467 |
publicationsBoutonModifier.disable();
|
|
|
468 |
}
|
|
|
469 |
}
|
|
|
470 |
|
|
|
471 |
public void rafraichir(Object nouvellesDonnees) {
|
|
|
472 |
if (nouvellesDonnees instanceof Information) {
|
|
|
473 |
Information info = (Information) nouvellesDonnees;
|
|
|
474 |
rafraichirInformation(info);
|
|
|
475 |
} else {
|
|
|
476 |
GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
|
|
|
477 |
}
|
|
|
478 |
}
|
|
|
479 |
|
|
|
480 |
public void rafraichirInformation(Information info) {
|
|
|
481 |
if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
|
|
|
482 |
GWT.log("MESSAGES:\n"+info.getMessages().toString(), null);
|
|
|
483 |
}
|
|
|
484 |
String type = info.getType();
|
|
|
485 |
if (type.equals("liste_collection_a_publication")) {
|
|
|
486 |
if (info.getDonnee(0) != null) {
|
|
|
487 |
initialiser();
|
907 |
jpm |
488 |
collection.setPublicationsLiees((CollectionAPublicationListe) info.getDonnee(0));
|
719 |
jp_milcent |
489 |
peupler();
|
|
|
490 |
}
|
1098 |
jpm |
491 |
} else if (info.getType().equals("ajout_collection")) {
|
|
|
492 |
if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {
|
|
|
493 |
String collectionId = (String) info.getDonnee(0);
|
|
|
494 |
|
|
|
495 |
// Suite à la récupération de l'id de la collection nouvellement ajoutée nous ajoutons les publications liées
|
|
|
496 |
// En mode AJOUT, il ne peut que y avoir des publications liées ajoutées
|
|
|
497 |
mediateur.ajouterCollectionAPublication(this, collectionId, publicationsAjoutees);
|
|
|
498 |
}
|
786 |
jpm |
499 |
} else if (type.equals("publication_modifiee")) {
|
1513 |
jpm |
500 |
if (info.getDonnee(0) != null) {
|
|
|
501 |
Publication publication = (Publication) info.getDonnee(0);
|
|
|
502 |
ModelData publicationDansGrille = null;
|
|
|
503 |
publicationDansGrille = grille.getStore().findModel("cpu_id_publication", publication.getId());
|
|
|
504 |
int index = grille.getStore().indexOf(publicationDansGrille);
|
799 |
jpm |
505 |
grille.getStore().remove(publicationDansGrille);
|
907 |
jpm |
506 |
ajouterDansGrille(publication, index);
|
786 |
jpm |
507 |
}
|
1513 |
jpm |
508 |
} else if (type.equals("publication_ajoutee")) {
|
799 |
jpm |
509 |
if (info.getDonnee(0) != null) {
|
|
|
510 |
Publication publication = (Publication) info.getDonnee(0);
|
907 |
jpm |
511 |
ajouterDansGrille(publication);
|
799 |
jpm |
512 |
}
|
907 |
jpm |
513 |
} else if (type.equals("suppression_collection_a_publication")) {
|
1239 |
cyprien |
514 |
InfoLogger.display("Suppression des publications liées à la collection", info.toString());
|
907 |
jpm |
515 |
} else if (type.equals("ajout_collection_a_publication")) {
|
1239 |
cyprien |
516 |
InfoLogger.display("Ajout des publications liées à la collection", info.toString());
|
786 |
jpm |
517 |
} else {
|
|
|
518 |
GWT.log(Mediateur.i18nM.erreurRafraichir(info.getClass(), this.getClass()), null);
|
719 |
jp_milcent |
519 |
}
|
|
|
520 |
}
|
|
|
521 |
|
883 |
jpm |
522 |
public void peupler() {
|
907 |
jpm |
523 |
grille.getStore().removeAll();
|
|
|
524 |
grille.getStore().add(collection.getPublicationsLiees().toList());
|
719 |
jp_milcent |
525 |
layout();
|
1239 |
cyprien |
526 |
InfoLogger.display(i18nC.chargementPublication(), i18nC.ok());
|
719 |
jp_milcent |
527 |
}
|
|
|
528 |
|
907 |
jpm |
529 |
public void collecter() {
|
|
|
530 |
if (etreAccede()) {
|
910 |
jpm |
531 |
int nbrePublication = grille.getStore().getCount();
|
|
|
532 |
for (int i = 0; i < nbrePublication; i++) {
|
1513 |
jpm |
533 |
ModelData publicationLiee = grille.getStore().getAt(i);
|
|
|
534 |
CollectionAPublication cap = new CollectionAPublication(grille.getStore().getAt(i), false);
|
907 |
jpm |
535 |
if (publicationLiee.get("_etat_") != null) {
|
|
|
536 |
if (publicationLiee.get("_etat_").equals(aDonnee.ETAT_MODIFIE)) {
|
|
|
537 |
// Comme il est impossible de modifier les relations nous supprimons l'ancien enregistrement et ajoutons un nouveau avec le nouveau id_role
|
1513 |
jpm |
538 |
publicationsSupprimees.put("id"+idGenere++, cap);
|
907 |
jpm |
539 |
|
1513 |
jpm |
540 |
CollectionAPublication relationAAjouter = (CollectionAPublication) cap.cloner(new CollectionAPublication());
|
907 |
jpm |
541 |
publicationsAjoutees.put("id"+idGenere++, relationAAjouter);
|
|
|
542 |
}
|
|
|
543 |
if (publicationLiee.get("_etat_").equals(aDonnee.ETAT_AJOUTE)) {
|
1513 |
jpm |
544 |
publicationsAjoutees.put("id"+idGenere++, cap);
|
907 |
jpm |
545 |
}
|
|
|
546 |
// Initialisation de la grille
|
|
|
547 |
publicationLiee.set("_etat_", "");
|
|
|
548 |
}
|
|
|
549 |
}
|
|
|
550 |
grille.getStore().commitChanges();
|
|
|
551 |
}
|
|
|
552 |
}
|
|
|
553 |
|
|
|
554 |
public void soumettre() {
|
|
|
555 |
if (mode.equals(Formulaire.MODE_MODIFIER)) {
|
|
|
556 |
if (publicationsAjoutees.size() == 0 && publicationsSupprimees.size() == 0) {
|
1630 |
aurelien |
557 |
//InfoLogger.display("Modification des publications liées", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");
|
907 |
jpm |
558 |
} else {
|
|
|
559 |
// Ajout des relations CollectionAPublication
|
|
|
560 |
if (publicationsAjoutees.size() != 0) {
|
|
|
561 |
mediateur.ajouterCollectionAPublication(this, collection.getId(), publicationsAjoutees);
|
|
|
562 |
}
|
|
|
563 |
// Suppression des relations CollectionAPublication
|
|
|
564 |
if (publicationsSupprimees.size() != 0) {
|
|
|
565 |
mediateur.supprimerCollectionAPublication(this, publicationsSupprimees);
|
|
|
566 |
}
|
|
|
567 |
}
|
|
|
568 |
}
|
|
|
569 |
}
|
719 |
jp_milcent |
570 |
}
|