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