3 |
aperonnet |
1 |
package org.tela_botanica.client.vues;
|
|
|
2 |
|
|
|
3 |
import org.tela_botanica.client.image.ImageMediateur;
|
|
|
4 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
|
|
5 |
|
|
|
6 |
import com.gwtext.client.data.SimpleStore;
|
|
|
7 |
import com.gwtext.client.data.Store;
|
|
|
8 |
import com.gwtext.client.dd.DragSource;
|
|
|
9 |
import com.gwtext.client.dd.DropTarget;
|
|
|
10 |
import com.gwtext.client.dd.DropTargetConfig;
|
|
|
11 |
import com.gwtext.client.widgets.Component;
|
|
|
12 |
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
|
|
|
13 |
import com.gwtext.client.widgets.grid.ColumnConfig;
|
|
|
14 |
import com.gwtext.client.widgets.grid.ColumnModel;
|
|
|
15 |
import com.gwtext.client.widgets.grid.GridDragData;
|
|
|
16 |
import com.gwtext.client.widgets.grid.GridPanel;
|
|
|
17 |
import com.gwtext.client.core.EventObject;
|
|
|
18 |
import com.gwtext.client.dd.DragData;
|
|
|
19 |
|
|
|
20 |
public class MiniListeObservationVue extends GridPanel implements Rafraichissable {
|
|
|
21 |
|
|
|
22 |
private ImageMediateur iMediateur = null ;
|
|
|
23 |
|
|
|
24 |
private boolean estInstancie = false ;
|
|
|
25 |
|
|
|
26 |
public MiniListeObservationVue(ImageMediateur im)
|
|
|
27 |
{
|
|
|
28 |
iMediateur = im ;
|
|
|
29 |
|
|
|
30 |
this.setId("x-view-mini-obs") ;
|
|
|
31 |
final Store store = new SimpleStore(new String[]{"plante"}, getObs());
|
|
|
32 |
ColumnConfig[] columns = {
|
|
|
33 |
//new ColumnConfig("Numero", "num_obs", 45, true),
|
|
|
34 |
new ColumnConfig("Taxon", "plante", 45, true) } ;
|
|
|
35 |
|
|
|
36 |
ColumnModel columnModel = new ColumnModel(columns);
|
|
|
37 |
setTitle("Observations");
|
|
|
38 |
setColumnModel(columnModel);
|
|
|
39 |
setHeight(390);
|
|
|
40 |
setWidth(200);
|
|
|
41 |
//Enable drag and drop
|
|
|
42 |
this.setEnableDragDrop(true);
|
|
|
43 |
//You need to set the same group for both grids
|
|
|
44 |
this.setDdGroup("DragGroupName");
|
|
|
45 |
store.load();
|
|
|
46 |
setStore(store) ;
|
|
|
47 |
|
|
|
48 |
configDragAndDrop() ;
|
|
|
49 |
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
public void ajouterListeners()
|
|
|
54 |
{
|
|
|
55 |
|
|
|
56 |
this.addListener(new ContainerListenerAdapter() {
|
|
|
57 |
|
|
|
58 |
public void onHide(Component component) {
|
|
|
59 |
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
// lors du premier rendu on demande les données qui sont déjà
|
|
|
63 |
// contenues dans la galerie qui est le premier élément affiché
|
|
|
64 |
|
|
|
65 |
public void onRender(Component component) {
|
|
|
66 |
|
|
|
67 |
if (!estInstancie) {
|
|
|
68 |
|
|
|
69 |
//configDragAndDrop() ;
|
|
|
70 |
//estInstancie = true ;
|
|
|
71 |
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
public void onShow(Component component) {
|
|
|
76 |
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
});
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
public void configDragAndDrop()
|
|
|
83 |
{
|
|
|
84 |
// on choisit le texte qui sera affiché lors d'un drag 'n drop
|
|
|
85 |
setDragDropText("Faites glisser la selection d'observations sur une image pour les lier") ;
|
|
|
86 |
|
|
|
87 |
//On active le drag 'n drop
|
|
|
88 |
this.setEnableDragDrop(true);
|
|
|
89 |
|
|
|
90 |
// on fabrique la nouvelle configuration
|
|
|
91 |
// les éléments sur lesquels on fait du drag 'n drop doivent tous avoir le même ddGroup
|
|
|
92 |
this.setDdGroup("DragGroupName");
|
|
|
93 |
DropTargetConfig dtc = new DropTargetConfig();
|
|
|
94 |
dtc.setdDdGroup("DragGroupName");
|
|
|
95 |
|
|
|
96 |
//La drop target permet de gérer l'évenement onDrop sur l'élement courant
|
|
|
97 |
@SuppressWarnings("unused")
|
|
|
98 |
DropTarget tg = new DropTarget(this, dtc)
|
|
|
99 |
{
|
|
|
100 |
public boolean notifyDrop(DragSource source, EventObject e, DragData data){
|
|
|
101 |
|
|
|
102 |
// si on reçoit des données provenant d'une grille
|
|
|
103 |
if(data instanceof GridDragData)
|
|
|
104 |
{
|
|
|
105 |
// on la convertit
|
|
|
106 |
GridDragData gdd = (GridDragData)data ;
|
|
|
107 |
// et on vérifie que les données ne viennent pas de l'élément courant
|
|
|
108 |
if(gdd.getGrid().getId().equals("x-view-mini-obs"))
|
|
|
109 |
{
|
|
|
110 |
return false ;
|
|
|
111 |
}
|
|
|
112 |
else
|
|
|
113 |
{
|
|
|
114 |
// on appelle le médiateur
|
|
|
115 |
return iMediateur.lierImagesDD(source, e, data) ;
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
return false ;
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
public String notifyOver(DragSource source, EventObject e, DragData data){
|
|
|
122 |
return "x-dd-drop-ok";
|
|
|
123 |
}
|
|
|
124 |
};
|
|
|
125 |
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
public void rafraichir(Object nouvelleDonnees,
|
|
|
129 |
boolean repandreRaffraichissement) {
|
|
|
130 |
// TODO Auto-generated method stub
|
|
|
131 |
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
private Object[][] getObs() {
|
|
|
135 |
return new Object[][]{
|
|
|
136 |
new Object[]{"Plante1"} ,
|
|
|
137 |
new Object[]{"Plante2"},
|
|
|
138 |
new Object[]{"Plante3"},
|
|
|
139 |
new Object[]{"Plante4"},
|
|
|
140 |
new Object[]{"Plante5"}
|
|
|
141 |
} ;
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
}
|