1202 |
cyprien |
1 |
package org.tela_botanica.client.vues;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.Date;
|
|
|
5 |
import java.util.List;
|
|
|
6 |
|
|
|
7 |
import org.tela_botanica.client.Mediateur;
|
|
|
8 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
|
|
9 |
import org.tela_botanica.client.modeles.Valeur;
|
|
|
10 |
|
|
|
11 |
import com.extjs.gxt.ui.client.Style.SortDir;
|
|
|
12 |
import com.extjs.gxt.ui.client.core.XTemplate;
|
|
|
13 |
import com.extjs.gxt.ui.client.event.BaseEvent;
|
|
|
14 |
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
|
|
15 |
import com.extjs.gxt.ui.client.event.Events;
|
|
|
16 |
import com.extjs.gxt.ui.client.event.Listener;
|
|
|
17 |
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
|
|
|
18 |
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
|
|
19 |
import com.extjs.gxt.ui.client.event.SelectionListener;
|
|
|
20 |
import com.extjs.gxt.ui.client.store.ListStore;
|
|
|
21 |
import com.extjs.gxt.ui.client.widget.Dialog;
|
|
|
22 |
import com.extjs.gxt.ui.client.widget.InfoConfig;
|
|
|
23 |
import com.extjs.gxt.ui.client.widget.button.Button;
|
|
|
24 |
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
|
|
25 |
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
|
|
26 |
import com.extjs.gxt.ui.client.widget.grid.EditorGrid;
|
|
|
27 |
import com.extjs.gxt.ui.client.widget.grid.Grid;
|
|
|
28 |
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
|
|
|
29 |
import com.extjs.gxt.ui.client.widget.grid.RowExpander;
|
|
|
30 |
import com.extjs.gxt.ui.client.widget.grid.RowNumberer;
|
|
|
31 |
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
|
|
32 |
import com.google.gwt.i18n.client.DateTimeFormat;
|
|
|
33 |
import com.google.gwt.i18n.client.Dictionary;
|
|
|
34 |
|
|
|
35 |
public class FenetreJournal extends Dialog implements Rafraichissable{
|
|
|
36 |
|
|
|
37 |
private int id = 0;
|
|
|
38 |
private EditorGrid<Valeur> grille;
|
|
|
39 |
private int nbLogs = Integer.valueOf(((Dictionary) Dictionary.getDictionary("configuration")).get("nbLogs"));
|
|
|
40 |
private ListStore<Valeur> store;
|
|
|
41 |
public FenetreJournal(Mediateur mediateur) {
|
|
|
42 |
|
|
|
43 |
this.setHeading(mediateur.i18nC.titreJournal());
|
|
|
44 |
this.setWidth(500);
|
|
|
45 |
this.setHeight(500);
|
|
|
46 |
setLayout(new FitLayout());
|
|
|
47 |
|
|
|
48 |
// Définition des colomnes de la grille:
|
|
|
49 |
RowNumberer numeroPlugin = new RowNumberer();
|
|
|
50 |
numeroPlugin.setHeader("#");
|
|
|
51 |
|
|
|
52 |
XTemplate infoTpl = XTemplate.create("<p>"+
|
|
|
53 |
"<b>" + mediateur.i18nC.heureMessage() + " : </b>{heure}<br />" +
|
|
|
54 |
"<b>" + mediateur.i18nC.message() + " : </b>{description}<br />" +
|
|
|
55 |
"</p>");
|
|
|
56 |
RowExpander expansionPlugin = new RowExpander();
|
|
|
57 |
expansionPlugin.setTemplate(infoTpl);
|
|
|
58 |
|
|
|
59 |
List<ColumnConfig> lstColumns = new ArrayList<ColumnConfig>();
|
|
|
60 |
lstColumns.add(expansionPlugin);
|
|
|
61 |
lstColumns.add(new ColumnConfig("nom", mediateur.i18nC.publicationTitre(), 200));
|
|
|
62 |
lstColumns.add(new ColumnConfig("description", mediateur.i18nC.message() , 400));
|
|
|
63 |
|
|
|
64 |
ColumnModel modeleColonnes = new ColumnModel(lstColumns);
|
|
|
65 |
|
|
|
66 |
store = new ListStore<Valeur>();
|
|
|
67 |
|
|
|
68 |
grille = new EditorGrid<Valeur>(store, modeleColonnes);
|
|
|
69 |
grille.addPlugin(expansionPlugin);
|
|
|
70 |
|
|
|
71 |
grille.setAutoExpandColumn("description");
|
|
|
72 |
grille.getView().setAutoFill(true);
|
|
|
73 |
grille.getView().setForceFit(true);
|
|
|
74 |
|
|
|
75 |
store.sort("id", SortDir.DESC);
|
|
|
76 |
add(grille);
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
@Override
|
|
|
80 |
public void rafraichir(Object nouvellesDonnees) {
|
|
|
81 |
if (nouvellesDonnees instanceof InfoConfig) {
|
|
|
82 |
InfoConfig info = (InfoConfig) nouvellesDonnees;
|
|
|
83 |
id++;
|
|
|
84 |
Valeur v = new Valeur(String.valueOf(id), info.title, null, info.text);
|
|
|
85 |
v.set("heure", getDate());
|
|
|
86 |
store.add(v);
|
|
|
87 |
|
|
|
88 |
if (store.getModels().size() > nbLogs) {
|
|
|
89 |
store.remove(store.getAt(nbLogs));
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
public String getDate() {
|
|
|
95 |
Date date = new Date();
|
|
|
96 |
return String.valueOf(DateTimeFormat.getFormat("HH:mm:ss").format(date));
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
@Override
|
|
|
101 |
protected void createButtons() {
|
|
|
102 |
//Pas de boutons, merci
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
}
|