Page 1 of 1

AuthorDnDListener - Can't get my objet

Posted: Wed Jun 13, 2012 12:08 pm
by sebastienlavandier
Hi,

In my application, I make a drag and drop action of a swing objet to an xml document, with a AuthorDnDListener which is in a framework and a java.awt.datatransfer.Transferable with a TransferHandler which are in a plugin.
That works !

But now I want to make some tests/update on the xml document during the DnD actions, and I don't want do that in the TransferHandler /exportDone() function. I want do all my test/update during the Dnd Action in the same place, most specially in the AuthorDnDListener/authorDrop function.

public boolean authorDrop(Transferable transferable, DropTargetDropEvent dropTargetDropEvent)

But in this function I can't cast the transferable to my transferableObjet, I don't understand why, and this one works in the TransferHandler /exportDone() function.

protected void exportDone(JComponent c, java.awt.datatransfer.Transferable transferable, int action)

Tool tool = (Tool) transferable.getTransferData(ToolTransferable.TOOL_DATAFLAVOR);

The exception message is :
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: com._4dconcept.docAdvance.authorNeo.plugin.views.tools.SpareTool cannot be cast to com._4dconcept.docAdvance.authorNeo.plugin.views.tools.SpareTool

Do you have an idea ? or an example ?
Thanks in advance.

Re: AuthorDnDListener - Can't get my objet

Posted: Wed Jun 13, 2012 5:34 pm
by Radu
Hi Sebastien,

You have a custom view contributed by a plugin and you somehow drag and drop content from it to the Author page, correct?

So you probably have a JAR library containing the com._4dconcept.docAdvance.authorNeo.plugin.views.tools.SpareTool class which you have added both to the plugin.xml and to the framework's Classpath list, right?

Oxygen creates separate Java class loaders for each loaded plugin and framework.

The object is created on the plugin's class loader and when it gets dropped the callback is made in the framework's class loader where the object cannot be cast to the class because it was created on a different class loader.

Your options would be:

1) Call the object's methods using Java Reflection on the framework's side.
2) If the "SpareTool" object would be serializable it could probably be possible to serialize it to a byte array output stream and then to de-serialize it in the framework class loader.

We'll see if we can make improvements to allow in certain cases a plugin and a framework to share a class loader.

Regards,
Radu

Re: AuthorDnDListener - Can't get my objet

Posted: Thu Jun 14, 2012 11:59 am
by nithril
Hello Radu,

I work with Sebastien.

Your description of our issues is right.

On one side we have a plugin with a custom view. User can d&d content from the view to the author.
On the other side we have a framework which handle the d&d and transform the content of the d&d according to the xml schema.
The content is a class shared between the plugin and the framework what causes the class cast.

On a developer point of view, I think the separation between plugin and framework is not always suitable because plugin (ie. view) and framework is tightly coupled.

Regards,

Nicolas

Re: AuthorDnDListener - Can't get my objet

Posted: Thu Jun 14, 2012 12:26 pm
by Radu
Hi Nicolas,
On a developer point of view, I think the separation between plugin and framework is not always suitable because plugin (ie. view) and framework is tightly coupled.
I agree with this and you are not the only ones having such problems.
We'll try to make some improvements in this area after Oxygen 14.0 is released.
Maybe even come up with the concept of a plugin which is also a framework.

Would any of the workaround I gave be suitable for you?

Regards,
Radu

Re: AuthorDnDListener - Can't get my objet

Posted: Thu Jun 14, 2012 12:32 pm
by sebastienlavandier
Hi,
I tested both solutions (retrospection / Serialisation). Both works well !
Thanks again.
Bye