Adding SWT DragSource support without breaking NatTable DragMode? [message #1360962] |
Sat, 17 May 2014 01:53 |
Rob Sigel Messages: 4 Registered: April 2014 |
Junior Member |
|
|
I recently tried adding SWT DragSource support to the NatTable using a custom DragSourceListener which is populated by callbacks to a ...nattable.selection.RowSelectionProvider. I then called NatTable#addDragSupport() to connect things in what appears to be the "official" way. (At least it's the way things are set up in the _781_DragAndDropExample.)
This mostly worked, and I was able to drag data to other SWT and JFace widgets without problems.
Unfortunately, this also appears to break almost all other NatTable operations based upon Drag-and-drop, including column reordering and column resizing.
The only in-NatTable DnD operation that still appears to work as expected is selecting multiple rows. (I'm using a RowSelectionModel.)
If I comment out the call to NatTable#addDragSupport() then the in-NatTable DnD operations all work correctly again. (But my own DnD to other widgets does not work, of course.)
Am I doing something wrong, or is there a bug in how the tiny DragSourceListener wrapper instantiated in addDragSupport() interacts with the rest of the NatTable DnD system?
Would it make more sense for the wrapper to switch the NatTable mode as a final step in dragFinished(), instead of as the first step in dragStart()?
When I tried first tried resizing a column width in the _781_DragAndDropExample, that threw an exception and hung the application, requiring a hard kill.
Altering the DragAndDropSupport inner class in _781_DragAndDropExample so dragStart verifies there's data to be dragged will fix the hang:
public void dragStart(DragSourceEvent event) {
if (this.selectionLayer.getSelectionModel().getSelectedRowCount() == 0) {
event.doit = false;
}
}
This will also allow everyone else to test the column header drags that are causing me problems.
In my own code, I tried adding a DragSource and listener directly to the NatTable instance myself, without calling NatTable#addDragSupport(), to avoid the unwanted wrapper behavior. In this case, the column header DnD behavior worked as expected, and I was still able to perform my own DnD from table rows to other widgets, but the NatTable was left in some intermediate drag mode state, and had apparently not detected the dragFinished/mouseUp (which happened in another widget). My symptom of this was how the cell/row table selection was still being extended to follow the mouse cursor, even though I was no longer dragging. I had to perform a mouse click in the table body to reset the selection. (This is not seen in _781_DragAndDropExample because that selectionmodel is configured to only allow single row selection. Allowing the _781_DragAndDropExample to use multiple row selection, and manually adding the DragSource instead of using NatTable#addDragSupport() will again show the same behavior I've seen in my own code.)
This again makes me wonder if the anonymous inner wrapper within NatTable#addDragSupport() should switch the NatTable mode as a final step in dragFinished(), instead of as the first step in dragStart().
(I need to mention that my table is readonly -- I'm not allowing cell editors in my table, so I can't say how those would be interacting with external DnD support.)
Is there a way for me to make this all work without modifying the NatTable source? Has anyone else already done this? I'm starting to dig deeper into the source to see how the UIBindingRegistry, the IDragModes, etc. all interact. I'm hoping to figure out a way to create and register a custom IDragMode that can limit itself to the table body and cleanly populate an SWT DragSource (using the SelectionModel) without breaking other DragModes, but a thorough explanation or a working example would make life easier.
Thanks in advance for any help!
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03384 seconds