New file |
0,0 → 1,144 |
package org.tela_botanica.client.vues; |
|
import org.tela_botanica.client.image.ImageMediateur; |
import org.tela_botanica.client.interfaces.Rafraichissable; |
|
import com.gwtext.client.data.SimpleStore; |
import com.gwtext.client.data.Store; |
import com.gwtext.client.dd.DragSource; |
import com.gwtext.client.dd.DropTarget; |
import com.gwtext.client.dd.DropTargetConfig; |
import com.gwtext.client.widgets.Component; |
import com.gwtext.client.widgets.event.ContainerListenerAdapter; |
import com.gwtext.client.widgets.grid.ColumnConfig; |
import com.gwtext.client.widgets.grid.ColumnModel; |
import com.gwtext.client.widgets.grid.GridDragData; |
import com.gwtext.client.widgets.grid.GridPanel; |
import com.gwtext.client.core.EventObject; |
import com.gwtext.client.dd.DragData; |
|
public class MiniListeObservationVue extends GridPanel implements Rafraichissable { |
|
private ImageMediateur iMediateur = null ; |
|
private boolean estInstancie = false ; |
|
public MiniListeObservationVue(ImageMediateur im) |
{ |
iMediateur = im ; |
|
this.setId("x-view-mini-obs") ; |
final Store store = new SimpleStore(new String[]{"plante"}, getObs()); |
ColumnConfig[] columns = { |
//new ColumnConfig("Numero", "num_obs", 45, true), |
new ColumnConfig("Taxon", "plante", 45, true) } ; |
|
ColumnModel columnModel = new ColumnModel(columns); |
setTitle("Observations"); |
setColumnModel(columnModel); |
setHeight(390); |
setWidth(200); |
//Enable drag and drop |
this.setEnableDragDrop(true); |
//You need to set the same group for both grids |
this.setDdGroup("DragGroupName"); |
store.load(); |
setStore(store) ; |
|
configDragAndDrop() ; |
|
} |
|
|
public void ajouterListeners() |
{ |
|
this.addListener(new ContainerListenerAdapter() { |
|
public void onHide(Component component) { |
|
} |
|
// lors du premier rendu on demande les données qui sont déjà |
// contenues dans la galerie qui est le premier élément affiché |
|
public void onRender(Component component) { |
|
if (!estInstancie) { |
|
//configDragAndDrop() ; |
//estInstancie = true ; |
|
} |
} |
|
public void onShow(Component component) { |
|
} |
|
}); |
} |
|
public void configDragAndDrop() |
{ |
// on choisit le texte qui sera affiché lors d'un drag 'n drop |
setDragDropText("Faites glisser la selection d'observations sur une image pour les lier") ; |
|
//On active le drag 'n drop |
this.setEnableDragDrop(true); |
|
// on fabrique la nouvelle configuration |
// les éléments sur lesquels on fait du drag 'n drop doivent tous avoir le même ddGroup |
this.setDdGroup("DragGroupName"); |
DropTargetConfig dtc = new DropTargetConfig(); |
dtc.setdDdGroup("DragGroupName"); |
|
//La drop target permet de gérer l'évenement onDrop sur l'élement courant |
@SuppressWarnings("unused") |
DropTarget tg = new DropTarget(this, dtc) |
{ |
public boolean notifyDrop(DragSource source, EventObject e, DragData data){ |
|
// si on reçoit des données provenant d'une grille |
if(data instanceof GridDragData) |
{ |
// on la convertit |
GridDragData gdd = (GridDragData)data ; |
// et on vérifie que les données ne viennent pas de l'élément courant |
if(gdd.getGrid().getId().equals("x-view-mini-obs")) |
{ |
return false ; |
} |
else |
{ |
// on appelle le médiateur |
return iMediateur.lierImagesDD(source, e, data) ; |
} |
} |
return false ; |
} |
|
public String notifyOver(DragSource source, EventObject e, DragData data){ |
return "x-dd-drop-ok"; |
} |
}; |
|
} |
|
public void rafraichir(Object nouvelleDonnees, |
boolean repandreRaffraichissement) { |
// TODO Auto-generated method stub |
|
} |
|
private Object[][] getObs() { |
return new Object[][]{ |
new Object[]{"Plante1"} , |
new Object[]{"Plante2"}, |
new Object[]{"Plante3"}, |
new Object[]{"Plante4"}, |
new Object[]{"Plante5"} |
} ; |
} |
|
} |