Drag&drop issue when exchanging an Object via DragBoard [message #1195188] |
Mon, 18 November 2013 17:11  |
Eclipse User |
|
|
|
I'm setting up a drag&drop communication between TreeView and a Pane containing few fields.
At first, I'm trying to exchange a String: this works just fine.
Then, I'm trying to exchange an Object, and this is where things break apart.
I'm not really sure if this is specific to E(fx)clipse or applicable to JavaFX in general...
Here are details:
I'm setting up an EventHandler on the sending side this way:
private EventHandler<MouseEvent> getMouseDragHandler(final ResourceTreeCell cell) {
return new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if(cell.getItem().getType()==ArgoObjectType.DEVICE) {
Dragboard db = cell.startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
content.put(DataFormats.RESOURCE_DEVICE, cell.getItem());
db.setContent(content);
}
event.consume();
}
};
The receiving side gets setup like this:
private void setDragAndDropHandlers(Pane pane) {
pane.setOnDragOver(
new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent event) {
if(event.getGestureSource()!=this && event.getDragboard().hasContent(DataFormats.RESOURCE_DEVICE)) {
event.acceptTransferModes(TransferMode.COPY);
}
event.consume();
}
}
);
pane.setOnDragDropped(
new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent event) {
boolean success = false;
if(event.getDragboard().hasContent(DataFormats.RESOURCE_DEVICE)) {
Object ooo = event.getDragboard().getContent(DataFormats.RESOURCE_DEVICE);
ArgoObject source = (ArgoObject) event.getDragboard().getContent(DataFormats.RESOURCE_DEVICE);
success = true;
}
event.setDropCompleted(success);
event.consume();
}
}
);
}
and here is a shared DataFormat object:
public static final DataFormat RESOURCE_DEVICE = new DataFormat("com.videonext.argo.resource.device");
I'm getting next exception on receiving side: java.lang.ClassCastException: java.nio.HeapByteBuffer cannot be cast to com.videonext.pleiades.argo.data.model.ArgoObject
"ooo" has java.nio.HeapByteBuffer class, so obviously it throws an exception on the very next line.
ArgoObject is implementing Serializable as it is supposed to do.
|
|
|
|
|
|
|
Re: Drag&drop issue when exchanging an Object via DragBoard [message #1462311 is a reply to message #1199369] |
Wed, 05 November 2014 07:48  |
Eclipse User |
|
|
|
For what it's worth, I think this is an issue with JavaFX and OSGi not playing nice together
JavaFX gets a ClassNotFoundException when trying to deserialize the object, and returns a ByteBuffer instead. JavaFX expects the class to be on the classpath, but in an OSGi environment the class (ArgoObject in your case) is not visible to JavaFX.
I'm not sure what the best solution is. You could serialize the object yourself and put a string in the dragboard, or you could get the ByteBuffer object and finish the deserialization once you are back inside an OSGi context where the ArgoObject class is visible.
|
|
|
Powered by
FUDForum. Page generated in 0.03521 seconds