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 |
}
|
907 |
jpm |
321 |
publicationLiee.set("_etat_", aDonnee.ETAT_AJOUTE);
|
910 |
jpm |
322 |
|
1513 |
jpm |
323 |
grille.getGrille().stopEditing();
|
1896 |
aurelien |
324 |
grille.getGrille().getStore().insert(publicationLiee, index);
|
1513 |
jpm |
325 |
grille.getGrille().startEditing(index, 0);
|
|
|
326 |
grille.getGrille().getSelectionModel().select(index, false);
|
719 |
jp_milcent |
327 |
}
|
|
|
328 |
}
|
|
|
329 |
|
1638 |
aurelien |
330 |
private void supprimerDansGrille(CollectionAPublication publicationLiee, ModelData publicationLieeModele) {
|
907 |
jpm |
331 |
if (publicationLiee != null) {
|
719 |
jp_milcent |
332 |
// Ajout de la personne supprimée à la liste
|
907 |
jpm |
333 |
if ((publicationLiee.get("_etat_").equals("") || !publicationLiee.get("_etat_").equals(aDonnee.ETAT_AJOUTE))
|
|
|
334 |
&& publicationLiee.getId() != null
|
|
|
335 |
&& !publicationLiee.getId().equals("")) {
|
|
|
336 |
publicationsSupprimees.put("id"+idGenere++, publicationLiee);
|
719 |
jp_milcent |
337 |
}
|
|
|
338 |
|
|
|
339 |
// Suppression de l'enregistrement de la grille
|
1638 |
aurelien |
340 |
grille.getStore().remove(publicationLieeModele);
|
719 |
jp_milcent |
341 |
}
|
|
|
342 |
}
|
1513 |
jpm |
343 |
|
|
|
344 |
private GrillePaginable<ModelData> creerGrille() {
|
|
|
345 |
|
|
|
346 |
GrillePaginable<ModelData> grillePublications = null;
|
|
|
347 |
|
|
|
348 |
// ModelType
|
|
|
349 |
ModelType modelTypeCollectionAPublication = new ModelType();
|
|
|
350 |
modelTypeCollectionAPublication.setRoot("collectionsAPublication");
|
|
|
351 |
modelTypeCollectionAPublication.setTotalName("nbElements");
|
|
|
352 |
modelTypeCollectionAPublication.addField("ccapu_id_collection");
|
|
|
353 |
modelTypeCollectionAPublication.addField("ccapu_id_publication");
|
1800 |
aurelien |
354 |
modelTypeCollectionAPublication.addField("ccapu_source");
|
1513 |
jpm |
355 |
modelTypeCollectionAPublication.addField("ccapu_mark_licence");
|
|
|
356 |
modelTypeCollectionAPublication.addField("cpu_id_publication");
|
|
|
357 |
modelTypeCollectionAPublication.addField("cpu_fmt_auteur");
|
|
|
358 |
modelTypeCollectionAPublication.addField("cpu_titre");
|
|
|
359 |
modelTypeCollectionAPublication.addField("cpu_collection");
|
|
|
360 |
modelTypeCollectionAPublication.addField("cpu_ce_truk_editeur");
|
|
|
361 |
modelTypeCollectionAPublication.addField("cpu_date_parution");
|
|
|
362 |
modelTypeCollectionAPublication.addField("cpu_fascicule");
|
|
|
363 |
modelTypeCollectionAPublication.addField("cpu_truk_pages");
|
|
|
364 |
modelTypeCollectionAPublication.addField("cpu_indication_nvt");
|
|
|
365 |
|
|
|
366 |
// Proxy
|
|
|
367 |
ProxyCollectionAPublication<ModelData> proxyCollectionAPublication = new ProxyCollectionAPublication<ModelData>(null, collection.getId());
|
719 |
jp_milcent |
368 |
|
1513 |
jpm |
369 |
// Colonnes
|
|
|
370 |
List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
|
799 |
jpm |
371 |
RowNumberer numeroPlugin = new RowNumberer();
|
1680 |
raphael |
372 |
numeroPlugin.setHeaderHtml("#");
|
799 |
jpm |
373 |
XTemplate infoTpl = XTemplate.create("<p>"+
|
1513 |
jpm |
374 |
"<span style='font-weight:bold;'>"+i18nC.publicationAuteurs()+" :</span> {cpu_fmt_auteur}<br />"+
|
|
|
375 |
"<span style='font-weight:bold;'>"+i18nC.publicationTitre()+" :</span> {cpu_titre}<br />"+
|
|
|
376 |
"<span style='font-weight:bold;'>"+i18nC.publicationRevueCollection()+" :</span> {cpu_collection}<br />"+
|
799 |
jpm |
377 |
"<span style='font-weight:bold;'>"+i18nC.publicationEditeur()+" :</span> {_editeur_}"+
|
|
|
378 |
"</p>");
|
|
|
379 |
RowExpander expansionPlugin = new RowExpander();
|
|
|
380 |
expansionPlugin.setTemplate(infoTpl);
|
|
|
381 |
colonnes.add(expansionPlugin);
|
1800 |
aurelien |
382 |
|
1803 |
aurelien |
383 |
ColumnConfig sourceColonne = new ColumnConfig("ccapu_source", i18nC.collectionPublicationSource(), 60);
|
1800 |
aurelien |
384 |
sourceColonne.setRenderer(new GridCellRenderer<ModelData>() {
|
|
|
385 |
@Override
|
|
|
386 |
public Object render(ModelData model, String property,
|
|
|
387 |
ColumnData config, int rowIndex, int colIndex,
|
|
|
388 |
ListStore<ModelData> store, Grid<ModelData> grid) {
|
|
|
389 |
|
|
|
390 |
CheckBox cbSource = new CheckBox();
|
|
|
391 |
boolean source = model.get("ccapu_source") != null && model.get("ccapu_source").equals("1");
|
1896 |
aurelien |
392 |
|
|
|
393 |
Publication publiFromCache = Publication.publisSaisiesModifieesCache.get((new CollectionAPublication(model, false)).getPublication().getId());
|
|
|
394 |
if(publiFromCache != null) {
|
|
|
395 |
source = publiFromCache.get("ccapu_source") != null && publiFromCache.get("ccapu_source").equals("1");
|
|
|
396 |
}
|
|
|
397 |
|
1800 |
aurelien |
398 |
cbSource.setValue(source);
|
|
|
399 |
|
|
|
400 |
final Integer ligne = rowIndex;
|
|
|
401 |
final ModelData ceModele = model;
|
|
|
402 |
|
|
|
403 |
cbSource.addListener(Events.Change, new Listener<BaseEvent>() {
|
|
|
404 |
@Override
|
|
|
405 |
public void handleEvent(BaseEvent be) {
|
|
|
406 |
String estSource = ((CheckBox)be.getSource()).getValue() ? "1" : "0";
|
|
|
407 |
ceModele.set("ccapu_source", estSource);
|
|
|
408 |
if (!(ceModele.get("_etat_") != null && ceModele.get("_etat_").equals(aDonnee.ETAT_AJOUTE))) {
|
|
|
409 |
ceModele.set("_etat_", aDonnee.ETAT_MODIFIE);
|
|
|
410 |
}
|
|
|
411 |
grille.getStore().commitChanges();
|
|
|
412 |
}
|
|
|
413 |
});
|
|
|
414 |
return cbSource;
|
|
|
415 |
}
|
|
|
416 |
});
|
|
|
417 |
colonnes.add(sourceColonne);
|
|
|
418 |
|
799 |
jpm |
419 |
colonnes.add(numeroPlugin);
|
1803 |
aurelien |
420 |
colonnes.add(new ColumnConfig("cpu_fmt_auteur", i18nC.publicationAuteurs(), 135));
|
1800 |
aurelien |
421 |
colonnes.add(new ColumnConfig("cpu_titre", i18nC.publicationTitre(), 135));
|
1803 |
aurelien |
422 |
colonnes.add(new ColumnConfig("cpu_collection", i18nC.publicationRevueCollection(), 100));
|
910 |
jpm |
423 |
colonnes.add(creerColonneEditeur());
|
|
|
424 |
colonnes.add(creerColonneAnneePublication());
|
1513 |
jpm |
425 |
colonnes.add(new ColumnConfig("cpu_indication_nvt", i18nC.publicationNvt(), 75));
|
1803 |
aurelien |
426 |
colonnes.add(new ColumnConfig("cpu_fascicule", i18nC.publicationFascicule(), 70));
|
1513 |
jpm |
427 |
colonnes.add(new ColumnConfig("cpu_truk_pages", i18nC.publicationPage(), 50));
|
719 |
jp_milcent |
428 |
|
1513 |
jpm |
429 |
HashMap<String, String> virtualFields = new HashMap<String, String>();
|
|
|
430 |
virtualFields.put("_editeur_", "cpu_ce_truk_editeur");
|
|
|
431 |
virtualFields.put("_annee_", "cpu_date_parution");
|
|
|
432 |
virtualFields.put("_etat_", "");
|
719 |
jp_milcent |
433 |
|
1513 |
jpm |
434 |
// Modele de selection
|
|
|
435 |
GridSelectionModel<ModelData> modeleDeSelection = new GridSelectionModel<ModelData>();
|
719 |
jp_milcent |
436 |
ColumnModel modeleDeColonnes = new ColumnModel(colonnes);
|
823 |
jpm |
437 |
modeleDeColonnes.getColumn(0).setWidget(Images.ICONES.information().createImage(), "Info");
|
719 |
jp_milcent |
438 |
|
1513 |
jpm |
439 |
// Grille
|
|
|
440 |
grillePublications = new GrillePaginable<ModelData>(modelTypeCollectionAPublication, virtualFields, proxyCollectionAPublication, colonnes, modeleDeColonnes);
|
|
|
441 |
grillePublications.getGrille().setBorders(true);
|
|
|
442 |
grillePublications.getGrille().setSelectionModel(modeleDeSelection);
|
|
|
443 |
grillePublications.getGrille().addPlugin(expansionPlugin);
|
|
|
444 |
grillePublications.getGrille().addPlugin(numeroPlugin);
|
|
|
445 |
grillePublications.getGrille().getView().setForceFit(true);
|
|
|
446 |
grillePublications.getGrille().setAutoExpandColumn("titre");
|
|
|
447 |
grillePublications.getGrille().setStripeRows(true);
|
|
|
448 |
grillePublications.getGrille().setTrackMouseOver(true);
|
719 |
jp_milcent |
449 |
|
1513 |
jpm |
450 |
// Rajouter des écouteurs
|
|
|
451 |
grillePublications.getStore().addListener(Store.Add, new Listener<StoreEvent<ModelData>>() {
|
|
|
452 |
public void handleEvent(StoreEvent<ModelData> ce) {
|
|
|
453 |
actualiserEtatBoutonsBarreOutils();
|
|
|
454 |
}
|
|
|
455 |
});
|
|
|
456 |
grillePublications.getStore().addListener(Store.Remove, new Listener<StoreEvent<ModelData>>() {
|
|
|
457 |
public void handleEvent(StoreEvent<ModelData> ce) {
|
|
|
458 |
actualiserEtatBoutonsBarreOutils();
|
|
|
459 |
}
|
|
|
460 |
});
|
|
|
461 |
|
719 |
jp_milcent |
462 |
return grillePublications;
|
|
|
463 |
}
|
910 |
jpm |
464 |
|
|
|
465 |
private ColumnConfig creerColonneEditeur() {
|
1513 |
jpm |
466 |
GridCellRenderer<ModelData> editeurRendu = new GridCellRenderer<ModelData>() {
|
|
|
467 |
public String render(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {
|
|
|
468 |
String editeur = (new CollectionAPublication(model, false)).getPublication().getNomEditeur();
|
1896 |
aurelien |
469 |
// Des fois l'éditeur est vide, là intervient le caché fabriqué dans publication
|
1899 |
aurelien |
470 |
if(editeur.isEmpty() && Publication.publisSaisiesModifieesCache.containsKey((new CollectionAPublication(model, false)).getPublication().getId())) {
|
1896 |
aurelien |
471 |
editeur = Publication.publisSaisiesModifieesCache.get((new CollectionAPublication(model, false)).getPublication().getId()).getNomEditeur();
|
|
|
472 |
}
|
910 |
jpm |
473 |
model.set("_editeur_", editeur);
|
|
|
474 |
return editeur;
|
|
|
475 |
}
|
|
|
476 |
};
|
1803 |
aurelien |
477 |
ColumnConfig editeurColonne = new ColumnConfig("_editeur_", Mediateur.i18nC.publicationEditeur(), 130);
|
910 |
jpm |
478 |
editeurColonne.setRenderer(editeurRendu);
|
|
|
479 |
return editeurColonne;
|
|
|
480 |
}
|
|
|
481 |
|
|
|
482 |
private ColumnConfig creerColonneAnneePublication() {
|
1513 |
jpm |
483 |
GridCellRenderer<ModelData> datePublicationRendu = new GridCellRenderer<ModelData>() {
|
|
|
484 |
public String render(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {
|
|
|
485 |
String annee = (new CollectionAPublication(model, false)).getPublication().getAnneeParution();
|
1896 |
aurelien |
486 |
if(annee.isEmpty()) {
|
|
|
487 |
annee = Publication.publisSaisiesModifieesCache.get((new CollectionAPublication(model, false)).getPublication().getId()).getAnneeParution();
|
|
|
488 |
}
|
910 |
jpm |
489 |
model.set("_annee_", annee);
|
|
|
490 |
return annee;
|
|
|
491 |
}
|
|
|
492 |
};
|
1803 |
aurelien |
493 |
ColumnConfig datePublicationColonne = new ColumnConfig("_annee_", Mediateur.i18nC.publicationDateParution(), 40);
|
910 |
jpm |
494 |
datePublicationColonne.setRenderer(datePublicationRendu);
|
|
|
495 |
return datePublicationColonne;
|
|
|
496 |
}
|
799 |
jpm |
497 |
|
719 |
jp_milcent |
498 |
public void actualiserEtatBoutonsBarreOutils() {
|
|
|
499 |
// Activation des boutons si la grille contient un élément
|
|
|
500 |
if (grille.getStore().getCount() > 0) {
|
|
|
501 |
publicationsBoutonSupprimer.enable();
|
|
|
502 |
publicationsBoutonModifier.enable();
|
|
|
503 |
}
|
|
|
504 |
// Désactivation des boutons si la grille ne contient plus d'élément
|
|
|
505 |
if (grille.getStore().getCount() == 0) {
|
|
|
506 |
publicationsBoutonSupprimer.disable();
|
|
|
507 |
publicationsBoutonModifier.disable();
|
|
|
508 |
}
|
|
|
509 |
}
|
|
|
510 |
|
|
|
511 |
public void rafraichir(Object nouvellesDonnees) {
|
|
|
512 |
if (nouvellesDonnees instanceof Information) {
|
|
|
513 |
Information info = (Information) nouvellesDonnees;
|
|
|
514 |
rafraichirInformation(info);
|
|
|
515 |
} else {
|
|
|
516 |
GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
|
|
|
517 |
}
|
|
|
518 |
}
|
|
|
519 |
|
|
|
520 |
public void rafraichirInformation(Information info) {
|
|
|
521 |
if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
|
|
|
522 |
GWT.log("MESSAGES:\n"+info.getMessages().toString(), null);
|
|
|
523 |
}
|
|
|
524 |
String type = info.getType();
|
|
|
525 |
if (type.equals("liste_collection_a_publication")) {
|
|
|
526 |
if (info.getDonnee(0) != null) {
|
|
|
527 |
initialiser();
|
907 |
jpm |
528 |
collection.setPublicationsLiees((CollectionAPublicationListe) info.getDonnee(0));
|
719 |
jp_milcent |
529 |
peupler();
|
|
|
530 |
}
|
1098 |
jpm |
531 |
} else if (info.getType().equals("ajout_collection")) {
|
|
|
532 |
if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {
|
|
|
533 |
String collectionId = (String) info.getDonnee(0);
|
|
|
534 |
|
|
|
535 |
// Suite à la récupération de l'id de la collection nouvellement ajoutée nous ajoutons les publications liées
|
|
|
536 |
// En mode AJOUT, il ne peut que y avoir des publications liées ajoutées
|
|
|
537 |
mediateur.ajouterCollectionAPublication(this, collectionId, publicationsAjoutees);
|
|
|
538 |
}
|
786 |
jpm |
539 |
} else if (type.equals("publication_modifiee")) {
|
1513 |
jpm |
540 |
if (info.getDonnee(0) != null) {
|
|
|
541 |
Publication publication = (Publication) info.getDonnee(0);
|
|
|
542 |
ModelData publicationDansGrille = null;
|
1896 |
aurelien |
543 |
publicationDansGrille = grille.getStore().findModel("cpu_id_publication", publication.getId());
|
|
|
544 |
publication.set("ccapu_source", publicationDansGrille.get("ccapu_source"));
|
|
|
545 |
int index = grille.getStore().indexOf(publicationDansGrille);
|
799 |
jpm |
546 |
grille.getStore().remove(publicationDansGrille);
|
907 |
jpm |
547 |
ajouterDansGrille(publication, index);
|
786 |
jpm |
548 |
}
|
1513 |
jpm |
549 |
} else if (type.equals("publication_ajoutee")) {
|
799 |
jpm |
550 |
if (info.getDonnee(0) != null) {
|
|
|
551 |
Publication publication = (Publication) info.getDonnee(0);
|
907 |
jpm |
552 |
ajouterDansGrille(publication);
|
799 |
jpm |
553 |
}
|
907 |
jpm |
554 |
} else if (type.equals("suppression_collection_a_publication")) {
|
1239 |
cyprien |
555 |
InfoLogger.display("Suppression des publications liées à la collection", info.toString());
|
907 |
jpm |
556 |
} else if (type.equals("ajout_collection_a_publication")) {
|
1239 |
cyprien |
557 |
InfoLogger.display("Ajout des publications liées à la collection", info.toString());
|
786 |
jpm |
558 |
} else {
|
|
|
559 |
GWT.log(Mediateur.i18nM.erreurRafraichir(info.getClass(), this.getClass()), null);
|
719 |
jp_milcent |
560 |
}
|
|
|
561 |
}
|
|
|
562 |
|
883 |
jpm |
563 |
public void peupler() {
|
907 |
jpm |
564 |
grille.getStore().removeAll();
|
|
|
565 |
grille.getStore().add(collection.getPublicationsLiees().toList());
|
719 |
jp_milcent |
566 |
layout();
|
1239 |
cyprien |
567 |
InfoLogger.display(i18nC.chargementPublication(), i18nC.ok());
|
719 |
jp_milcent |
568 |
}
|
|
|
569 |
|
907 |
jpm |
570 |
public void collecter() {
|
|
|
571 |
if (etreAccede()) {
|
910 |
jpm |
572 |
int nbrePublication = grille.getStore().getCount();
|
|
|
573 |
for (int i = 0; i < nbrePublication; i++) {
|
1513 |
jpm |
574 |
ModelData publicationLiee = grille.getStore().getAt(i);
|
|
|
575 |
CollectionAPublication cap = new CollectionAPublication(grille.getStore().getAt(i), false);
|
907 |
jpm |
576 |
if (publicationLiee.get("_etat_") != null) {
|
|
|
577 |
if (publicationLiee.get("_etat_").equals(aDonnee.ETAT_MODIFIE)) {
|
1800 |
aurelien |
578 |
publicationsModifiees.put(cap.getIdPublication(), cap);
|
907 |
jpm |
579 |
}
|
|
|
580 |
if (publicationLiee.get("_etat_").equals(aDonnee.ETAT_AJOUTE)) {
|
1513 |
jpm |
581 |
publicationsAjoutees.put("id"+idGenere++, cap);
|
907 |
jpm |
582 |
}
|
|
|
583 |
// Initialisation de la grille
|
|
|
584 |
publicationLiee.set("_etat_", "");
|
|
|
585 |
}
|
|
|
586 |
}
|
|
|
587 |
grille.getStore().commitChanges();
|
|
|
588 |
}
|
|
|
589 |
}
|
|
|
590 |
|
|
|
591 |
public void soumettre() {
|
|
|
592 |
if (mode.equals(Formulaire.MODE_MODIFIER)) {
|
1800 |
aurelien |
593 |
if (publicationsAjoutees.size() == 0 && publicationsSupprimees.size() == 0 && publicationsModifiees.size() == 0) {
|
1630 |
aurelien |
594 |
//InfoLogger.display("Modification des publications liées", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");
|
907 |
jpm |
595 |
} else {
|
1800 |
aurelien |
596 |
//Window.alert(publicationsAjoutees.size()+" | "+publicationsSupprimees.size()+" | "+publicationsModifiees.size());
|
|
|
597 |
publicationsSontModifiees = true;
|
907 |
jpm |
598 |
// Ajout des relations CollectionAPublication
|
|
|
599 |
if (publicationsAjoutees.size() != 0) {
|
|
|
600 |
mediateur.ajouterCollectionAPublication(this, collection.getId(), publicationsAjoutees);
|
|
|
601 |
}
|
1800 |
aurelien |
602 |
|
|
|
603 |
// Modification des relations CollectionAPublication
|
|
|
604 |
if (publicationsModifiees.size() != 0) {
|
|
|
605 |
mediateur.modifierCollectionAPublication(this, publicationsModifiees);
|
|
|
606 |
}
|
|
|
607 |
|
907 |
jpm |
608 |
// Suppression des relations CollectionAPublication
|
|
|
609 |
if (publicationsSupprimees.size() != 0) {
|
|
|
610 |
mediateur.supprimerCollectionAPublication(this, publicationsSupprimees);
|
|
|
611 |
}
|
|
|
612 |
}
|
|
|
613 |
}
|
|
|
614 |
}
|
719 |
jp_milcent |
615 |
}
|