Issues with serialization in a TransferHandler

In implementing a drag and drop functionality, I am trying to get a reference to the source component transferred to the drop site. For my initial attempts, I was doing my own serialization of the data and the component using native Java serialization. However, the native serializer refuses to serialize MyComponent as it thinks it has parts that are unserializable. Obviously, ignition thinks different as it is able to serialize the component for downloading to the client and designer.

Looking thro’ the javadocs I came across the class SerializableTransferable which I concluded was exactly what I needed.
This is how I am using it.

[code] @Override
protected Transferable createTransferable(JComponent c) {
//return new StringSelection(exportString©);

    TransferObject transferObj = new TransferObject(c);
    return new SerializableTransferable(transferObj, TransferObject.class);
}[/code]

Here is an outline of the TransferObject definition. When I uncomment the references to MyComponent, I get a serialization error.

[code]public class TransferObject implements Serializable {
//private final MyComponent mycomponent;
private int[] rowIndices;
private Dataset rowData;

TransferObject(JComponent c) {
    //mycomponent = (MyComponent) c.getParent();
    extractDataAndIndices(c);
}

public MyComponent getComponent() {
    //return mycomponent;
    return null;
}

public int[] getRowIndices() {
    return rowIndices;
}

public Dataset getRowData() {
    return rowData;
}

… etc
[/code]
While SerializableTransferable cleans up my code considerably, it has the same issue as my own attempt at serialization. Any thoughts on how I can overcome this problem?

This typically means that one of your fields is typed to contain a non-serializable object, or it is a simple Object type that doesn’t implement Serializable. Also, you should know that IA uses an opaque alternate serialization method on project resources, which may explain your confusion. I vaguely recall looking at it at one point, but it made my head hurt. /-:

Yea, I started marking some of the fields on myComponent as transient, hoping that that would allow it to be serialized. That started all kinds of confusion for the Designer when I started it up and launched the window with test examples of myComponent. Not sure, if I have to delete the existing components on the form and add them again, or if marking these components as transient hoses the operation of the component. Given that I have a temporary issue with component initialization when the designer installed them on a window, I didn’t want to delete the existing components just yet.

This is all kinds of fun. Does ignition moving to a HTML5 based client architecture make it such that it is obsolete in a year?

[quote=“JimBranKelly”]This is all kinds of fun. Does ignition moving to a HTML5 based client architecture make it such that it is obsolete in a year?[/quote]If they can re-implement the entire client architecture in HTML5 in a year I’ll be totally blown away. Unless Carl and Colby and especially Steve himself say so, I wouldn’t hold my breath. /-:
Also, I’m not sure browser security models are ready for some of the local operations available to java and used by some extension modules. At least not without platform-dependent hooks. Which kind of defeats Ignition’s current cross platform advantage.

The Swing-based Vision module and client aren’t going anywhere for a long time, so whether this knowledge is obsolete once we have a web-based offering as well is up to you.

One issue that I did not find obvious is that within Ignition when serializing a JComponent or derivative, the variable holding it needs, it seems, to be declared static. The following worked fine in my Java Swing test application when “mycomponent” was not declared static. It does not work in Ignition until I declare it static. I’m inclined to suppose that it is something to do with thread safety.

[code] private static class TransferObjectRev3 implements Serializable {
private static JComponent mycomponent;
private int[] rowIndices;
private Dataset rowData;

    TransferObjectRev3(JComponent c) {
        mycomponent = (JComponent) c.getParent().getParent();
        extractDataAndIndices(c);
    }

    public JComponent getComponent() {
        return mycomponent;
    }

… etc
[/code]