Skip to content

Instantly share code, notes, and snippets.

@gbougeard
Created May 1, 2012 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbougeard/2568258 to your computer and use it in GitHub Desktop.
Save gbougeard/2568258 to your computer and use it in GitHub Desktop.
public void onDrop(DragDropEvent event) {
// Puisque l'on a associé une datasource à nos éléments droppable
// alors event.getData() contient un objet Java et en l'occurrence puisque la datasource
// en question était la DataGrid, elle-même associée à lstTarget étant une ArrayList<CanvasFormationItem>
// on a donc accès à un objet de type CanvasFormationItem
// Attention, c'est l'objet draggé, donc l'objet source.
CanvasFormationItem item = (CanvasFormationItem) event.getData();
// Pour avoir accès à l'objet où on a droppé, ce n'est pas encore possible
// du coup on feinte :D
// on recupère l'ID de l'élément DOM sur lequel on a droppé
String idCoord = event.getDropId();
// et on récupère l'index de la grille (j'avoue c'est pas super classe)
idCoord = idCoord.substring(idCoord.indexOf("trgField")); // cf trgField dans la JSF
idCoord = idCoord.substring(idCoord.indexOf(':') + 1, idCoord.lastIndexOf(':'));
Integer coord = Integer.parseInt(idCoord) + 1; // les id autos commencent à 0 alors que les index de notre grille comment à 1
// Maintenant on met à jour les coords des FormationItem et CanvasFormationItem incriminés
FamFormationItem fi = item.getFamFormationItem();
for (CanvasFormationItem cfi : lstTarget) {
if (cfi.getStrIdx().equals(String.format("%d", coord))) {
// on swappe les formationItem
FormationItem fiTemp = cfi.getFormationItem();
Integer oldCoord = null;
if (fi != null) {
oldCoord = fi.getCoord();
}
cfi.setFormationItem(fi);
item.setFormationItem(fiTemp);
cfi.getFormationItem().setCoord(coord);
if (oldCoord != null && item.getFormationItem() != null) {
item.getFormationItem().setCoord(oldCoord);
}
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment