Subversion Repositories eFlore/Applications.cel

Rev

Rev 62 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 62 Rev 63
1
package org.tela_botanica.client.vues;
1
package org.tela_botanica.client.vues;
2
 
2
 
3
import java.util.Iterator;
3
import java.util.Iterator;
4
 
4
 
5
import org.tela_botanica.client.image.ImageMediateur;
5
import org.tela_botanica.client.image.ImageMediateur;
6
import org.tela_botanica.client.interfaces.Rafraichissable;
6
import org.tela_botanica.client.interfaces.Rafraichissable;
7
import org.tela_botanica.client.modeles.ListeObservation;
7
import org.tela_botanica.client.modeles.ListeObservation;
8
import org.tela_botanica.client.modeles.Observation;
8
import org.tela_botanica.client.modeles.Observation;
9
 
9
 
10
import com.google.gwt.user.client.Window;
10
import com.google.gwt.user.client.Window;
11
import com.google.gwt.user.client.ui.MouseListenerAdapter;
11
import com.google.gwt.user.client.ui.MouseListenerAdapter;
12
import com.gwtext.client.data.SimpleStore;
12
import com.gwtext.client.data.SimpleStore;
13
import com.gwtext.client.data.Store;
13
import com.gwtext.client.data.Store;
14
import com.gwtext.client.dd.DragSource;
14
import com.gwtext.client.dd.DragSource;
15
import com.gwtext.client.dd.DropTarget;
15
import com.gwtext.client.dd.DropTarget;
16
import com.gwtext.client.dd.DropTargetConfig;
16
import com.gwtext.client.dd.DropTargetConfig;
17
import com.gwtext.client.widgets.Component;
17
import com.gwtext.client.widgets.Component;
18
import com.gwtext.client.widgets.event.ComponentListenerAdapter;
18
import com.gwtext.client.widgets.event.ComponentListenerAdapter;
19
import com.gwtext.client.widgets.event.ContainerListener;
19
import com.gwtext.client.widgets.event.ContainerListener;
20
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
20
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
21
import com.gwtext.client.widgets.event.PanelListenerAdapter;
21
import com.gwtext.client.widgets.event.PanelListenerAdapter;
22
import com.gwtext.client.widgets.grid.ColumnConfig;
22
import com.gwtext.client.widgets.grid.ColumnConfig;
23
import com.gwtext.client.widgets.grid.ColumnModel;
23
import com.gwtext.client.widgets.grid.ColumnModel;
24
import com.gwtext.client.widgets.grid.GridDragData;
24
import com.gwtext.client.widgets.grid.GridDragData;
25
import com.gwtext.client.widgets.grid.GridPanel;
25
import com.gwtext.client.widgets.grid.GridPanel;
26
import com.gwtext.client.widgets.grid.event.GridListener;
26
import com.gwtext.client.widgets.grid.event.GridListener;
27
import com.gwtext.client.widgets.grid.event.GridListenerAdapter;
27
import com.gwtext.client.widgets.grid.event.GridListenerAdapter;
28
import com.gwtext.client.core.EventObject;
28
import com.gwtext.client.core.EventObject;
29
import com.gwtext.client.dd.DragData;
29
import com.gwtext.client.dd.DragData;
30
 
30
 
31
/**
31
/**
32
 * Fausse liste d'observation pour tester le drag n' drop et l'insertion
32
 * liste d'observation pour l'association d'images aux observations
33
 * Est vouée à devenir une véritable liste avec de vraie données
-
 
34
 * @author aurelien
33
 * @author aurelien
35
 *
34
 *
36
 */
35
 */
37
public class MiniListeObservationVue extends GridPanel implements Rafraichissable {
36
public class MiniListeObservationVue extends GridPanel implements Rafraichissable {
38
 
37
 
39
	/**
38
	/**
40
	 * Le médiateur associé à la vue
39
	 * Le médiateur associé à la vue
41
	 */
40
	 */
42
	private ImageMediateur iMediateur = null ;
41
	private ImageMediateur iMediateur = null ;
43
	
42
	
44
	/**
43
	/**
45
	 * Booléen d'instanciation
44
	 * Booléen d'instanciation
46
	 */
45
	 */
47
	private boolean estInstancie = false ;
46
	private boolean estInstancie = false ;
48
	
47
	
49
	/**
48
	/**
50
	 * Le modèle de colonnes
49
	 * Le modèle de colonnes
51
	 */
50
	 */
52
	private ColumnModel colModel = null ;
51
	private ColumnModel colModel = null ;
53
	
52
	
54
	private SimpleStore store = null ;
53
	private SimpleStore store = null ;
55
	
54
	
56
	/**
55
	/**
57
	 * Constructeur avec arguments
56
	 * Constructeur avec arguments
58
	 * @param im le médiateur à associer à la vue
57
	 * @param im le médiateur à associer à la vue
59
	 */
58
	 */
60
	public MiniListeObservationVue(ImageMediateur im)
59
	public MiniListeObservationVue(ImageMediateur im)
61
	{
60
	{
62
		iMediateur = im ;
61
		iMediateur = im ;
63
		
62
		
64
		this.setId("x-view-mini-obs") ;
63
		this.setId("x-view-mini-obs") ;
65
		
64
		
66
		// on crée un store simple contenant un petit set de données et deux colonnes
65
		// on crée un store simple contenant un petit set de données et deux colonnes
67
		store = new SimpleStore(new String[]{"id_obs","plante","date"}, getObs());  
66
		store = new SimpleStore(new String[]{"id_obs","plante","date"}, getObs());  
68
		ColumnConfig[] columns = {  
67
		ColumnConfig[] columns = {  
69
		new ColumnConfig("Numero", "id_obs", 50, true),   
68
		new ColumnConfig("Numero", "id_obs", 50, true),   
70
		new ColumnConfig("Taxon", "plante", 145, true), 
69
		new ColumnConfig("Taxon", "plante", 145, true), 
71
		new ColumnConfig("Date", "date", 68, true) } ;
70
		new ColumnConfig("Date", "date", 68, true) } ;
72
		   
71
		   
73
        ColumnModel columnModel = new ColumnModel(columns);
72
        ColumnModel columnModel = new ColumnModel(columns);
74
         
73
         
75
        colModel = columnModel ;
74
        colModel = columnModel ;
76
         
75
         
77
        setTitle("Observations");  
76
        setTitle("Observations");  
78
        // on associe le modèle de colonnes
77
        // on associe le modèle de colonnes
79
        setColumnModel(columnModel);  
78
        setColumnModel(columnModel);  
80
        setAutoScroll(true) ;
79
        setAutoScroll(true) ;
81
        setHeight("100%") ;
80
        setHeight("100%") ;
82
		setAutoWidth(true) ; 
81
		setAutoWidth(true) ; 
83
        // on autorise le drag 'n drop pour un certain groupe
82
        // on autorise le drag 'n drop pour un certain groupe
84
 		this.setEnableDragDrop(true);
83
 		this.setEnableDragDrop(true);
85
 		this.setDdGroup("DragGroupName");
84
 		this.setDdGroup("DragGroupName");
86
        store.load();       
85
        store.load();       
87
		setStore(store) ;
86
		setStore(store) ;
88
		
87
		
89
		setAutoScroll(true) ;
88
		setAutoScroll(true) ;
90
		// on configure le drag 'n drop
89
		// on configure le drag 'n drop
91
		configDragAndDrop() ;
90
		configDragAndDrop() ;
92
		
91
		
93
		this.addListener(new ComponentListenerAdapter() {
92
		this.addListener(new ComponentListenerAdapter() {
94
			
93
			
95
			public void onRender(Component c) {
94
			public void onRender(Component c) {
96
				
95
				
97
				obtenirMiniListeObservations() ;
96
				obtenirMiniListeObservations() ;
98
				
97
				
99
			}
98
			}
100
			
99
			
101
		}) ;
100
		}) ;
102
		
101
		
103
		this.addGridListener(new GridListenerAdapter() {
102
		this.addGridListener(new GridListenerAdapter() {
104
 
103
 
105
			@Override
104
			@Override
106
			public void onContextMenu(EventObject e) {
105
			public void onContextMenu(EventObject e) {
107
				
106
				
108
				e.stopEvent() ;
107
				e.stopEvent() ;
109
				MenuLiaisonVue mlv = new MenuLiaisonVue(iMediateur) ;
108
				MenuLiaisonVue mlv = new MenuLiaisonVue(iMediateur) ;
110
				mlv.showAt(e.getXY()) ;
109
				mlv.showAt(e.getXY()) ;
111
				
110
				
112
			}
111
			}
113
			
112
			
114
		}) ;
113
		}) ;
115
		                  
114
		                  
116
	}
115
	}
117
	
116
	
118
	/**
117
	/**
119
	 * Configure le drag 'n drop pour la liste
118
	 * Configure le drag 'n drop pour la liste
120
	 */
119
	 */
121
	private void configDragAndDrop()
120
	private void configDragAndDrop()
122
	{
121
	{
123
		// on choisit le texte qui sera affiché lors d'un drag 'n drop
122
		// on choisit le texte qui sera affiché lors d'un drag 'n drop
124
		setDragDropText("Faites glisser la selection d'observations sur une image pour les lier") ;
123
		setDragDropText("Faites glisser la selection d'observations sur une image pour les lier") ;
125
		
124
		
126
		//On active le drag 'n drop
125
		//On active le drag 'n drop
127
		this.setEnableDragDrop(true);
126
		this.setEnableDragDrop(true);
128
 
127
 
129
		// on fabrique la nouvelle configuration
128
		// on fabrique la nouvelle configuration
130
		// les éléments sur lesquels on fait du drag 'n drop doivent tous avoir le même ddGroup
129
		// les éléments sur lesquels on fait du drag 'n drop doivent tous avoir le même ddGroup
131
		this.setDdGroup("DragGroupName");
130
		this.setDdGroup("DragGroupName");
132
		DropTargetConfig dtc = new DropTargetConfig();
131
		DropTargetConfig dtc = new DropTargetConfig();
133
		dtc.setdDdGroup("DragGroupName");
132
		dtc.setdDdGroup("DragGroupName");
134
 
133
 
135
		//La drop target permet de gérer l'évenement onDrop sur l'élement courant
134
		//La drop target permet de gérer l'évenement onDrop sur l'élement courant
136
		@SuppressWarnings("unused")
135
		@SuppressWarnings("unused")
137
		DropTarget tg = new DropTarget(this, dtc)
136
		DropTarget tg = new DropTarget(this, dtc)
138
		{
137
		{
139
			public boolean notifyDrop(DragSource source, EventObject e, DragData data){	
138
			public boolean notifyDrop(DragSource source, EventObject e, DragData data){	
140
				
139
				
141
				// si on reçoit des données provenant d'une grille
140
				// si on reçoit des données provenant d'une grille
142
				if(data instanceof GridDragData)
141
				if(data instanceof GridDragData)
143
		    	  {
142
		    	  {
144
					// on la convertit 
143
					// on la convertit 
145
		    		  	GridDragData gdd = (GridDragData)data ;
144
		    		  	GridDragData gdd = (GridDragData)data ;
146
		    		  	// et on vérifie que les données ne viennent pas de l'élément courant
145
		    		  	// et on vérifie que les données ne viennent pas de l'élément courant
147
		    		  	if(gdd.getGrid().getId().equals("x-view-mini-obs"))
146
		    		  	if(gdd.getGrid().getId().equals("x-view-mini-obs"))
148
		    		  	{
147
		    		  	{
149
		    		  		return false ;
148
		    		  		return false ;
150
		    		  	}
149
		    		  	}
151
		    		  	else
150
		    		  	else
152
		    		  	{
151
		    		  	{
153
		    		  		// on appelle le médiateur
152
		    		  		// on appelle le médiateur
154
		    		  		return iMediateur.lierImagesDD(source, e, data) ;   
153
		    		  		return iMediateur.lierImagesDD(source, e, data) ;   
155
		    		  	}
154
		    		  	}
156
		    	  }
155
		    	  }
157
				return false ;
156
				return false ;
158
			}
157
			}
159
			
158
			
160
			public String notifyOver(DragSource source, EventObject e, DragData data){
159
			public String notifyOver(DragSource source, EventObject e, DragData data){
161
			    return "x-dd-drop-ok";
160
			    return "x-dd-drop-ok";
162
			}
161
			}
163
		};
162
		};
164
        
163
        
165
	}
164
	}
166
	
165
	
167
	/**
166
	/**
168
	 * Méthode héritée de l'interface rafraichissable
167
	 * Méthode héritée de l'interface rafraichissable
169
	 */
168
	 */
170
	public void rafraichir(Object nouvelleDonnees,
169
	public void rafraichir(Object nouvelleDonnees,
171
			boolean repandreRaffraichissement) {
170
			boolean repandreRaffraichissement) {
172
		
171
		
173
		if(nouvelleDonnees instanceof ListeObservation)
172
		if(nouvelleDonnees instanceof ListeObservation)
174
		{
173
		{
175
			ListeObservation data = (ListeObservation)nouvelleDonnees ;
-
 
176
			String[][] listeObs = new String[data.size()][3] ;
-
 
177
			int i = 0 ;
174
			if(this.getView() != null)
178
			
-
 
179
			for (Iterator it = data.keySet().iterator(); it.hasNext();) 
-
 
180
			{
175
			{
-
 
176
				ListeObservation data = (ListeObservation)nouvelleDonnees ;
-
 
177
				String[][] listeObs = new String[data.size()][3] ;
-
 
178
				int i = 0 ;
181
				
179
				
-
 
180
				for (Iterator it = data.keySet().iterator(); it.hasNext();) 
-
 
181
				{
-
 
182
					
182
				Observation obs=(Observation) data.get(it.next());
183
					Observation obs=(Observation) data.get(it.next());
183
				
184
					
184
				listeObs[i][0] = obs.getNumeroOrdre();
185
					listeObs[i][0] = obs.getNumeroOrdre();
185
				listeObs[i][1] = obs.getNomSaisi();
186
					listeObs[i][1] = obs.getNomSaisi();
186
				listeObs[i][2] = obs.getDate() ;
187
					listeObs[i][2] = obs.getDate() ;
187
			
188
				
188
				i++ ;
189
					i++ ;
-
 
190
				}
-
 
191
	
-
 
192
				store = new SimpleStore(new String[]{"id_obs","plante","date"}, listeObs);  	
-
 
193
				store.load();       
-
 
194
				this.reconfigure(store, colModel) ;
-
 
195
			}
-
 
196
			else
-
 
197
			{
-
 
198
				addListener(new ContainerListenerAdapter() {
-
 
199
					
-
 
200
					public void onShow(Component c)
-
 
201
					{
-
 
202
						obtenirMiniListeObservations() ;
-
 
203
					}
-
 
204
					
-
 
205
				}) ;
189
			}
206
			}
190
 
-
 
191
			store = new SimpleStore(new String[]{"id_obs","plante","date"}, listeObs);  	
-
 
192
			store.load();       
-
 
193
			this.reconfigure(store, colModel) ;
-
 
194
	
207
	
195
		}
208
		}
196
		
209
		
197
	}
210
	}
198
	
211
	
199
	private void obtenirMiniListeObservations()
212
	private void obtenirMiniListeObservations()
200
	{
213
	{
201
		iMediateur.obtenirMiniListeObservations(this) ;
214
		iMediateur.obtenirMiniListeObservations(this) ;
202
	}
215
	}
203
	
216
	
204
	/**
217
	/**
205
	 * Renvoie le faux set de données pour le store
218
	 * Renvoie le faux set de données pour le store
206
	 * @return un tableau à deux colonnes int - String
219
	 * @return un tableau à deux colonnes int - String
207
	 */
220
	 */
208
	private Object[][] getObs() {  
221
	private Object[][] getObs() {  
209
	         return new Object[][]{  
222
	         return new Object[][]{  
210
		              
223
		              
211
	         } ;
224
	         } ;
212
	 }
225
	 }
213
	
226
	
214
	public Store getStore()
227
	public Store getStore()
215
	{
228
	{
216
		return store ;
229
		return store ;
217
	}
230
	}
218
	
231
	
219
	
232
	
220
 
233
 
221
}
234
}