Stefan,
I am attempting to use this in a application UI.
Is there any way to get the dropped component and the component it was dropped into in one call? I need to trigger an event that saves the change to my database when the drop occurs.
Stefan,
I am attempting to use this in a application UI.
Is there any way to get the dropped component and the component it was dropped into in one call? I need to trigger an event that saves the change to my database when the drop occurs.
What I was looking for was something like this:
DropTargetExtension<DropTargetComponent, DraggedComponent> droptarget...
...
droptarget.addDropListener(e -> {
DropTargetComponent t = e.getComponent();
DraggedComponent d = e.getDraggedComponent();
});
I think I found where I went wrong, I was following the code sample on the home page of this extension as a gospel of how to use it.
Nope, using this still doesn’t work:
public class T1ProfileCircuit extends VerticalLayout implements HasStyle {
public T1ProfileCircuit(CircuitDBO circuit){
super();
DragSourceExtension.extend(this);
this.circuit = circuit;
addClassName("circuit");
setSpacing(false);
setPadding(false);
}
}
public class T1ProfileChannelCell extends Div implements HasStyle, DropListener<T1ProfileCircuit> {
...
public T1ProfileChannelCell(Integer t1ProfileId, Integer index, T1ChannelDBO channel, T1ProfileCircuit circuit, Boolean disabled){
super();
addClassName("channel-cell");
DropTargetExtension.extend(this);
}
...
@Override
public void onDrop(DropEvent<T1ProfileCircuit> dropEvent) {
if(channel != null){
clearChannel();
}
channel.setCircuitId(dropEvent.getComponent().getCircuit().getId());
channel.setT1ProfileId(t1ProfileId);
channel.add();
contextMenu.setTarget(this);
// add(circuit);
circuit.setInList(false);
}
Setting a breakpoint in T1ProfileChannelCell.onDrop() shows that it isn’t getting called.
Hi Mike, sorry, that it took me long to answer. I’m currently in heave project load and due to private reason time is short. So I cannot promise that I will have a look in near future. If you have some idea what could be fixed in the source code, feel free to make a fork of it and fix or enhance the parts as needed for your usecase :)
Have you figured out on how to solve this? I was thinking of doing the same thing, but I can’t seem to get the source/target to work. Also iterating at the components it doesn’t seem to update the “getChildren” method (meaning that each component has no children at the server…
I had to set a variable outside of the drag, and then when an item began the process of being dragged, I assigned it to that variable. I then used that variable and cleared it after the drop occurred.
private T1ProfileCircuit currentlyBeingDragged = null;
...
protected class T1ProfileChannelSidebar { ...
public T1ProfileChannelSidebar(){ ...
dropTargetExtension.addDropListener(e -> {
// Handle Drop into sidebar
if (currentlyBeingDragged.getContainer() != null) {
currentlyBeingDragged.getContainer().clearChannel();
remove(currentlyBeingDragged);
}
});
}
}
protected class T1ProfileCircuit extends ... {
...
public T1ProfileCircuit(CircuitDBO circuit) {
DragSourceExtension<T1ProfileCircuit> dragSourceExtension = DragSourceExtension.extend(this);
dragSourceExtension.addDragStartListener(e -> currentlyBeingDragged = this);
...
}
}
On other words, I got something to work, but it wasn’t as clean as I would’ve liked it to be.
because of this limitation, I had to move all of my classes related to this form into subclasses so that they could reference this variable, as statics were off of the table.
I’ve manage to do it roughly doing the same thing, giving an ID to each component and afterwards identifying which went where, but yes its a dirty hack not a -clean- solution!!!
Just uploaded v1.1.0, where you can obtain the current active drag source in the different drop extension event listeners. I hope, that this mostly will fix your issues.
If further issues come up, please use the github issue tracker, it’s easier for me to follow it up there :)
BR,
Stefan