Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » Drag&drop issue when exchanging an Object via DragBoard
Drag&drop issue when exchanging an Object via DragBoard [message #1195188] Mon, 18 November 2013 22:11 Go to next message
Andriy Fomenko is currently offline Andriy FomenkoFriend
Messages: 24
Registered: May 2013
Junior Member
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&amp;drop issue when exchanging an Object via DragBoard [message #1195203 is a reply to message #1195188] Mon, 18 November 2013 22:24 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
You better ask a general JavaFX forum. This is pure FX-Code and no
e(fx)clipse special stuff is involved.

Tom

On 18.11.13 23:11, Andriy Fomenko wrote:
> 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&amp;drop issue when exchanging an Object via DragBoard [message #1196507 is a reply to message #1195203] Tue, 19 November 2013 12:59 Go to previous messageGo to next message
Andriy Fomenko is currently offline Andriy FomenkoFriend
Messages: 24
Registered: May 2013
Junior Member
Thank you, Tom.

I've opened a similar thread here: https://forums.oracle.com/thread/2604605

Will post solution here if I get one.
Re: Drag&amp;drop issue when exchanging an Object via DragBoard [message #1199346 is a reply to message #1196507] Wed, 20 November 2013 20:17 Go to previous messageGo to next message
Andriy Fomenko is currently offline Andriy FomenkoFriend
Messages: 24
Registered: May 2013
Junior Member
I've answered my own question in Oracle forum on the link posted above... pretty much RTFM Smile

The essence: when registering a DataFormat, you have to use the fully-qualified class name, not just some arbitrary name Smile
Re: Drag&amp;drop issue when exchanging an Object via DragBoard [message #1199369 is a reply to message #1199346] Wed, 20 November 2013 20:32 Go to previous messageGo to next message
Andriy Fomenko is currently offline Andriy FomenkoFriend
Messages: 24
Registered: May 2013
Junior Member
OPS... spoke too early... please disregard prior post
Re: Drag&amp;drop issue when exchanging an Object via DragBoard [message #1462311 is a reply to message #1199369] Wed, 05 November 2014 12:48 Go to previous message
Robert Fisher is currently offline Robert FisherFriend
Messages: 5
Registered: June 2014
Junior Member
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.

Previous Topic:Building a native executable with Eclipse 4.4 and e(fx)clispe
Next Topic:e(fx)clipse 1.1.0 is released
Goto Forum:
  


Current Time: Thu Mar 28 11:25:48 GMT 2024

Powered by FUDForum. Page generated in 0.01654 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top