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