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();
|
1784 |
aurelien |
118 |
|
|
|
119 |
publicationsSaisiesComboBox = creerComboBoxPublicationsSaisis();
|
|
|
120 |
barreOutils.add(publicationsSaisiesComboBox);
|
719 |
jp_milcent |
121 |
|
1784 |
aurelien |
122 |
barreOutils.add(new Text(" ou "));
|
|
|
123 |
|
719 |
jp_milcent |
124 |
Button ajouterBouton = creerBoutonAjouter();
|
|
|
125 |
barreOutils.add(ajouterBouton);
|
|
|
126 |
|
|
|
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 |
|
1784 |
aurelien |
299 |
publicationsCombo.getCombo().setEmptyText("Rechercher et sélectionner une publication existante dans la base");
|
|
|
300 |
|
1513 |
jpm |
301 |
publicationsCombo.getCombo().addListener(Events.Select, new Listener<BaseEvent>() {
|
775 |
jpm |
302 |
public void handleEvent(BaseEvent be) {
|
1513 |
jpm |
303 |
if (publicationsSaisiesComboBox.getValeur() instanceof ModelData) {
|
|
|
304 |
Publication publicationSaisieSelectionne = new Publication(publicationsSaisiesComboBox.getValeur(), false);
|
862 |
jpm |
305 |
ajouterDansGrille(publicationSaisieSelectionne);
|
1513 |
jpm |
306 |
publicationsSaisiesComboBox.getCombo().setValue(null);
|
775 |
jpm |
307 |
}
|
|
|
308 |
}
|
|
|
309 |
});
|
1513 |
jpm |
310 |
|
|
|
311 |
return publicationsCombo;
|
719 |
jp_milcent |
312 |
}
|
907 |
jpm |
313 |
|
719 |
jp_milcent |
314 |
private void ajouterDansGrille(Publication publication) {
|
907 |
jpm |
315 |
ajouterDansGrille(publication, 0);
|
|
|
316 |
}
|
|
|
317 |
|
|
|
318 |
private void ajouterDansGrille(Publication publication, int index) {
|
1513 |
jpm |
319 |
if (publication != null) {
|
|
|
320 |
CollectionAPublication publicationLiee = new CollectionAPublication(false);
|
907 |
jpm |
321 |
publicationLiee.setPublication(publication);
|
|
|
322 |
publicationLiee.setIdPublication(publication.getId());
|
1513 |
jpm |
323 |
|
907 |
jpm |
324 |
// Gestion de l'id de la collection
|
|
|
325 |
if (mode.equals(Formulaire.MODE_MODIFIER)) {
|
|
|
326 |
publicationLiee.setIdCollection(collection.getId());
|
719 |
jp_milcent |
327 |
}
|
907 |
jpm |
328 |
publicationLiee.set("_etat_", aDonnee.ETAT_AJOUTE);
|
910 |
jpm |
329 |
|
1513 |
jpm |
330 |
grille.getGrille().stopEditing();
|
|
|
331 |
grille.getGrille().getStore().insert(publicationLiee, 0);
|
|
|
332 |
grille.getGrille().startEditing(index, 0);
|
|
|
333 |
grille.getGrille().getSelectionModel().select(index, false);
|
719 |
jp_milcent |
334 |
}
|
|
|
335 |
}
|
|
|
336 |
|
1638 |
aurelien |
337 |
private void supprimerDansGrille(CollectionAPublication publicationLiee, ModelData publicationLieeModele) {
|
907 |
jpm |
338 |
if (publicationLiee != null) {
|
719 |
jp_milcent |
339 |
// Ajout de la personne supprimée à la liste
|
907 |
jpm |
340 |
if ((publicationLiee.get("_etat_").equals("") || !publicationLiee.get("_etat_").equals(aDonnee.ETAT_AJOUTE))
|
|
|
341 |
&& publicationLiee.getId() != null
|
|
|
342 |
&& !publicationLiee.getId().equals("")) {
|
|
|
343 |
publicationsSupprimees.put("id"+idGenere++, publicationLiee);
|
719 |
jp_milcent |
344 |
}
|
|
|
345 |
|
|
|
346 |
// Suppression de l'enregistrement de la grille
|
1638 |
aurelien |
347 |
grille.getStore().remove(publicationLieeModele);
|
719 |
jp_milcent |
348 |
}
|
|
|
349 |
}
|
1513 |
jpm |
350 |
|
|
|
351 |
private GrillePaginable<ModelData> creerGrille() {
|
|
|
352 |
|
|
|
353 |
GrillePaginable<ModelData> grillePublications = null;
|
|
|
354 |
|
|
|
355 |
// ModelType
|
|
|
356 |
ModelType modelTypeCollectionAPublication = new ModelType();
|
|
|
357 |
modelTypeCollectionAPublication.setRoot("collectionsAPublication");
|
|
|
358 |
modelTypeCollectionAPublication.setTotalName("nbElements");
|
|
|
359 |
modelTypeCollectionAPublication.addField("ccapu_id_collection");
|
|
|
360 |
modelTypeCollectionAPublication.addField("ccapu_id_publication");
|
|
|
361 |
modelTypeCollectionAPublication.addField("ccapu_mark_licence");
|
|
|
362 |
modelTypeCollectionAPublication.addField("cpu_id_publication");
|
|
|
363 |
modelTypeCollectionAPublication.addField("cpu_fmt_auteur");
|
|
|
364 |
modelTypeCollectionAPublication.addField("cpu_titre");
|
|
|
365 |
modelTypeCollectionAPublication.addField("cpu_collection");
|
|
|
366 |
modelTypeCollectionAPublication.addField("cpu_ce_truk_editeur");
|
|
|
367 |
modelTypeCollectionAPublication.addField("cpu_date_parution");
|
|
|
368 |
modelTypeCollectionAPublication.addField("cpu_fascicule");
|
|
|
369 |
modelTypeCollectionAPublication.addField("cpu_truk_pages");
|
|
|
370 |
modelTypeCollectionAPublication.addField("cpu_indication_nvt");
|
|
|
371 |
|
|
|
372 |
// Proxy
|
|
|
373 |
ProxyCollectionAPublication<ModelData> proxyCollectionAPublication = new ProxyCollectionAPublication<ModelData>(null, collection.getId());
|
719 |
jp_milcent |
374 |
|
1513 |
jpm |
375 |
// Colonnes
|
|
|
376 |
List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
|
799 |
jpm |
377 |
RowNumberer numeroPlugin = new RowNumberer();
|
1680 |
raphael |
378 |
numeroPlugin.setHeaderHtml("#");
|
799 |
jpm |
379 |
XTemplate infoTpl = XTemplate.create("<p>"+
|
1513 |
jpm |
380 |
"<span style='font-weight:bold;'>"+i18nC.publicationAuteurs()+" :</span> {cpu_fmt_auteur}<br />"+
|
|
|
381 |
"<span style='font-weight:bold;'>"+i18nC.publicationTitre()+" :</span> {cpu_titre}<br />"+
|
|
|
382 |
"<span style='font-weight:bold;'>"+i18nC.publicationRevueCollection()+" :</span> {cpu_collection}<br />"+
|
799 |
jpm |
383 |
"<span style='font-weight:bold;'>"+i18nC.publicationEditeur()+" :</span> {_editeur_}"+
|
|
|
384 |
"</p>");
|
|
|
385 |
RowExpander expansionPlugin = new RowExpander();
|
|
|
386 |
expansionPlugin.setTemplate(infoTpl);
|
|
|
387 |
colonnes.add(expansionPlugin);
|
|
|
388 |
colonnes.add(numeroPlugin);
|
1513 |
jpm |
389 |
colonnes.add(new ColumnConfig("cpu_fmt_auteur", i18nC.publicationAuteurs(), 150));
|
|
|
390 |
colonnes.add(new ColumnConfig("cpu_titre", i18nC.publicationTitre(), 150));
|
|
|
391 |
colonnes.add(new ColumnConfig("cpu_collection", i18nC.publicationRevueCollection(), 75));
|
910 |
jpm |
392 |
colonnes.add(creerColonneEditeur());
|
|
|
393 |
colonnes.add(creerColonneAnneePublication());
|
1513 |
jpm |
394 |
colonnes.add(new ColumnConfig("cpu_indication_nvt", i18nC.publicationNvt(), 75));
|
|
|
395 |
colonnes.add(new ColumnConfig("cpu_fascicule", i18nC.publicationFascicule(), 75));
|
|
|
396 |
colonnes.add(new ColumnConfig("cpu_truk_pages", i18nC.publicationPage(), 50));
|
719 |
jp_milcent |
397 |
|
1513 |
jpm |
398 |
HashMap<String, String> virtualFields = new HashMap<String, String>();
|
|
|
399 |
virtualFields.put("_editeur_", "cpu_ce_truk_editeur");
|
|
|
400 |
virtualFields.put("_annee_", "cpu_date_parution");
|
|
|
401 |
virtualFields.put("_etat_", "");
|
719 |
jp_milcent |
402 |
|
1513 |
jpm |
403 |
// Modele de selection
|
|
|
404 |
GridSelectionModel<ModelData> modeleDeSelection = new GridSelectionModel<ModelData>();
|
719 |
jp_milcent |
405 |
ColumnModel modeleDeColonnes = new ColumnModel(colonnes);
|
823 |
jpm |
406 |
modeleDeColonnes.getColumn(0).setWidget(Images.ICONES.information().createImage(), "Info");
|
719 |
jp_milcent |
407 |
|
1513 |
jpm |
408 |
// Grille
|
|
|
409 |
grillePublications = new GrillePaginable<ModelData>(modelTypeCollectionAPublication, virtualFields, proxyCollectionAPublication, colonnes, modeleDeColonnes);
|
|
|
410 |
grillePublications.getGrille().setBorders(true);
|
|
|
411 |
grillePublications.getGrille().setSelectionModel(modeleDeSelection);
|
|
|
412 |
grillePublications.getGrille().addPlugin(expansionPlugin);
|
|
|
413 |
grillePublications.getGrille().addPlugin(numeroPlugin);
|
|
|
414 |
grillePublications.getGrille().getView().setForceFit(true);
|
|
|
415 |
grillePublications.getGrille().setAutoExpandColumn("titre");
|
|
|
416 |
grillePublications.getGrille().setStripeRows(true);
|
|
|
417 |
grillePublications.getGrille().setTrackMouseOver(true);
|
719 |
jp_milcent |
418 |
|
1513 |
jpm |
419 |
// Rajouter des écouteurs
|
|
|
420 |
grillePublications.getStore().addListener(Store.Add, new Listener<StoreEvent<ModelData>>() {
|
|
|
421 |
public void handleEvent(StoreEvent<ModelData> ce) {
|
|
|
422 |
actualiserEtatBoutonsBarreOutils();
|
|
|
423 |
}
|
|
|
424 |
});
|
|
|
425 |
grillePublications.getStore().addListener(Store.Remove, new Listener<StoreEvent<ModelData>>() {
|
|
|
426 |
public void handleEvent(StoreEvent<ModelData> ce) {
|
|
|
427 |
actualiserEtatBoutonsBarreOutils();
|
|
|
428 |
}
|
|
|
429 |
});
|
|
|
430 |
|
719 |
jp_milcent |
431 |
return grillePublications;
|
|
|
432 |
}
|
910 |
jpm |
433 |
|
|
|
434 |
private ColumnConfig creerColonneEditeur() {
|
1513 |
jpm |
435 |
GridCellRenderer<ModelData> editeurRendu = new GridCellRenderer<ModelData>() {
|
|
|
436 |
public String render(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {
|
|
|
437 |
String editeur = (new CollectionAPublication(model, false)).getPublication().getNomEditeur();
|
910 |
jpm |
438 |
model.set("_editeur_", editeur);
|
|
|
439 |
return editeur;
|
|
|
440 |
}
|
|
|
441 |
};
|
|
|
442 |
ColumnConfig editeurColonne = new ColumnConfig("_editeur_", Mediateur.i18nC.publicationEditeur(), 135);
|
|
|
443 |
editeurColonne.setRenderer(editeurRendu);
|
|
|
444 |
return editeurColonne;
|
|
|
445 |
}
|
|
|
446 |
|
|
|
447 |
private ColumnConfig creerColonneAnneePublication() {
|
1513 |
jpm |
448 |
GridCellRenderer<ModelData> datePublicationRendu = new GridCellRenderer<ModelData>() {
|
|
|
449 |
public String render(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {
|
|
|
450 |
String annee = (new CollectionAPublication(model, false)).getPublication().getAnneeParution();
|
910 |
jpm |
451 |
model.set("_annee_", annee);
|
|
|
452 |
return annee;
|
|
|
453 |
}
|
|
|
454 |
};
|
|
|
455 |
ColumnConfig datePublicationColonne = new ColumnConfig("_annee_", Mediateur.i18nC.publicationDateParution(), 75);
|
|
|
456 |
datePublicationColonne.setRenderer(datePublicationRendu);
|
|
|
457 |
return datePublicationColonne;
|
|
|
458 |
}
|
799 |
jpm |
459 |
|
719 |
jp_milcent |
460 |
public void actualiserEtatBoutonsBarreOutils() {
|
|
|
461 |
// Activation des boutons si la grille contient un élément
|
|
|
462 |
if (grille.getStore().getCount() > 0) {
|
|
|
463 |
publicationsBoutonSupprimer.enable();
|
|
|
464 |
publicationsBoutonModifier.enable();
|
|
|
465 |
}
|
|
|
466 |
// Désactivation des boutons si la grille ne contient plus d'élément
|
|
|
467 |
if (grille.getStore().getCount() == 0) {
|
|
|
468 |
publicationsBoutonSupprimer.disable();
|
|
|
469 |
publicationsBoutonModifier.disable();
|
|
|
470 |
}
|
|
|
471 |
}
|
|
|
472 |
|
|
|
473 |
public void rafraichir(Object nouvellesDonnees) {
|
|
|
474 |
if (nouvellesDonnees instanceof Information) {
|
|
|
475 |
Information info = (Information) nouvellesDonnees;
|
|
|
476 |
rafraichirInformation(info);
|
|
|
477 |
} else {
|
|
|
478 |
GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
|
|
|
479 |
}
|
|
|
480 |
}
|
|
|
481 |
|
|
|
482 |
public void rafraichirInformation(Information info) {
|
|
|
483 |
if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
|
|
|
484 |
GWT.log("MESSAGES:\n"+info.getMessages().toString(), null);
|
|
|
485 |
}
|
|
|
486 |
String type = info.getType();
|
|
|
487 |
if (type.equals("liste_collection_a_publication")) {
|
|
|
488 |
if (info.getDonnee(0) != null) {
|
|
|
489 |
initialiser();
|
907 |
jpm |
490 |
collection.setPublicationsLiees((CollectionAPublicationListe) info.getDonnee(0));
|
719 |
jp_milcent |
491 |
peupler();
|
|
|
492 |
}
|
1098 |
jpm |
493 |
} else if (info.getType().equals("ajout_collection")) {
|
|
|
494 |
if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {
|
|
|
495 |
String collectionId = (String) info.getDonnee(0);
|
|
|
496 |
|
|
|
497 |
// Suite à la récupération de l'id de la collection nouvellement ajoutée nous ajoutons les publications liées
|
|
|
498 |
// En mode AJOUT, il ne peut que y avoir des publications liées ajoutées
|
|
|
499 |
mediateur.ajouterCollectionAPublication(this, collectionId, publicationsAjoutees);
|
|
|
500 |
}
|
786 |
jpm |
501 |
} else if (type.equals("publication_modifiee")) {
|
1513 |
jpm |
502 |
if (info.getDonnee(0) != null) {
|
|
|
503 |
Publication publication = (Publication) info.getDonnee(0);
|
|
|
504 |
ModelData publicationDansGrille = null;
|
|
|
505 |
publicationDansGrille = grille.getStore().findModel("cpu_id_publication", publication.getId());
|
|
|
506 |
int index = grille.getStore().indexOf(publicationDansGrille);
|
799 |
jpm |
507 |
grille.getStore().remove(publicationDansGrille);
|
907 |
jpm |
508 |
ajouterDansGrille(publication, index);
|
786 |
jpm |
509 |
}
|
1513 |
jpm |
510 |
} else if (type.equals("publication_ajoutee")) {
|
799 |
jpm |
511 |
if (info.getDonnee(0) != null) {
|
|
|
512 |
Publication publication = (Publication) info.getDonnee(0);
|
907 |
jpm |
513 |
ajouterDansGrille(publication);
|
799 |
jpm |
514 |
}
|
907 |
jpm |
515 |
} else if (type.equals("suppression_collection_a_publication")) {
|
1239 |
cyprien |
516 |
InfoLogger.display("Suppression des publications liées à la collection", info.toString());
|
907 |
jpm |
517 |
} else if (type.equals("ajout_collection_a_publication")) {
|
1239 |
cyprien |
518 |
InfoLogger.display("Ajout des publications liées à la collection", info.toString());
|
786 |
jpm |
519 |
} else {
|
|
|
520 |
GWT.log(Mediateur.i18nM.erreurRafraichir(info.getClass(), this.getClass()), null);
|
719 |
jp_milcent |
521 |
}
|
|
|
522 |
}
|
|
|
523 |
|
883 |
jpm |
524 |
public void peupler() {
|
907 |
jpm |
525 |
grille.getStore().removeAll();
|
|
|
526 |
grille.getStore().add(collection.getPublicationsLiees().toList());
|
719 |
jp_milcent |
527 |
layout();
|
1239 |
cyprien |
528 |
InfoLogger.display(i18nC.chargementPublication(), i18nC.ok());
|
719 |
jp_milcent |
529 |
}
|
|
|
530 |
|
907 |
jpm |
531 |
public void collecter() {
|
|
|
532 |
if (etreAccede()) {
|
910 |
jpm |
533 |
int nbrePublication = grille.getStore().getCount();
|
|
|
534 |
for (int i = 0; i < nbrePublication; i++) {
|
1513 |
jpm |
535 |
ModelData publicationLiee = grille.getStore().getAt(i);
|
|
|
536 |
CollectionAPublication cap = new CollectionAPublication(grille.getStore().getAt(i), false);
|
907 |
jpm |
537 |
if (publicationLiee.get("_etat_") != null) {
|
|
|
538 |
if (publicationLiee.get("_etat_").equals(aDonnee.ETAT_MODIFIE)) {
|
|
|
539 |
// Comme il est impossible de modifier les relations nous supprimons l'ancien enregistrement et ajoutons un nouveau avec le nouveau id_role
|
1513 |
jpm |
540 |
publicationsSupprimees.put("id"+idGenere++, cap);
|
907 |
jpm |
541 |
|
1513 |
jpm |
542 |
CollectionAPublication relationAAjouter = (CollectionAPublication) cap.cloner(new CollectionAPublication());
|
907 |
jpm |
543 |
publicationsAjoutees.put("id"+idGenere++, relationAAjouter);
|
|
|
544 |
}
|
|
|
545 |
if (publicationLiee.get("_etat_").equals(aDonnee.ETAT_AJOUTE)) {
|
1513 |
jpm |
546 |
publicationsAjoutees.put("id"+idGenere++, cap);
|
907 |
jpm |
547 |
}
|
|
|
548 |
// Initialisation de la grille
|
|
|
549 |
publicationLiee.set("_etat_", "");
|
|
|
550 |
}
|
|
|
551 |
}
|
|
|
552 |
grille.getStore().commitChanges();
|
|
|
553 |
}
|
|
|
554 |
}
|
|
|
555 |
|
|
|
556 |
public void soumettre() {
|
|
|
557 |
if (mode.equals(Formulaire.MODE_MODIFIER)) {
|
|
|
558 |
if (publicationsAjoutees.size() == 0 && publicationsSupprimees.size() == 0) {
|
1630 |
aurelien |
559 |
//InfoLogger.display("Modification des publications liées", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");
|
907 |
jpm |
560 |
} else {
|
|
|
561 |
// Ajout des relations CollectionAPublication
|
|
|
562 |
if (publicationsAjoutees.size() != 0) {
|
|
|
563 |
mediateur.ajouterCollectionAPublication(this, collection.getId(), publicationsAjoutees);
|
|
|
564 |
}
|
|
|
565 |
// Suppression des relations CollectionAPublication
|
|
|
566 |
if (publicationsSupprimees.size() != 0) {
|
|
|
567 |
mediateur.supprimerCollectionAPublication(this, publicationsSupprimees);
|
|
|
568 |
}
|
|
|
569 |
}
|
|
|
570 |
}
|
|
|
571 |
}
|
719 |
jp_milcent |
572 |
}
|