Correct usage of Clipboard and LocalManifest value map

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Correct usage of Clipboard and LocalManifest value map

Karel Hübl

Hi all,

 

I would like to ask, what is the correct usage (or intent) of LocalManifest value map (accessed by getValue / putValue methods).

 

We used LocalManifest value map to store references to POJO representing TreeView items participating in Cut and Paste.

 

When we put LocalManifest to Clipboard using Clipboard.setContent, then we expected to get it back later using Clipboard.getContent().

 

However this works only for the first time. Next, when we create new LocalManifest instance and put it to Clipboard we never get it back.

 

To test this behaviour call this testing method multiple times from UI for severalt times:

 

      public void copyToClipboard() throws Exception {

            System.out.println(Clipboard.getContent()+": "+Clipboard.getContent().getValue("A"));

            LocalManifest manifest=new LocalManifest();

            manifest.putValue("A", new Object());

            Clipboard.setContent(manifest);               

      }

 

You should get output similar to this:

 

org.apache.pivot.wtk.RemoteManifest@61d94155: null

org.apache.pivot.wtk.LocalManifest@3b5e37ac: java.lang.Object@26991ba7

org.apache.pivot.wtk.RemoteManifest@77315619: null

org.apache.pivot.wtk.RemoteManifest@7b875faa: null

org.apache.pivot.wtk.RemoteManifest@7499d141: null

org.apache.pivot.wtk.RemoteManifest@1e793e35: null

 

After some debugging, we realized that reason for this is implementation of org.apache.pivot.wtk.Clipboard.setContent method. The inner ClipboardOwner class clears the LocalManifest stored in Clipboard.content static variable. The problém is, that the call to lostOwnerhip notification method is not called directly from AWT Clipboard.setContents method, but queued to AWT Event queue.

 

So the ClipboardOwner from previous call to org.apache.pivot.wtk.Clipboard.setContent method, clears the new Clipboard.content field immediately since it is executed later from AWT event queue.

 

We now do not use clipboard to store POJO objects which are part of cut and paste and everything is OK.

 

This is not problem for text, image and files, because of propagation to AWT clipboard.

 

But now I am just curious. Is this a bug or feature?

 

Regards Karel

 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Correct usage of Clipboard and LocalManifest value map

Roger and Beth Whitcomb
Hi Karel,
    Offhand I'd say it's a bug, since it basically is a result of the queued callback.  Perhaps you could write up a JIRA issue and then we can take a look at what might be the best way to handle it.  Also, if you have any thoughts as to how it could be fixed it would help (since you've already spent some time looking into it).

Thanks,
~Roger

On 11/7/13 11:33 AM, Karel Hübl wrote:

Hi all,

 

I would like to ask, what is the correct usage (or intent) of LocalManifest value map (accessed by getValue / putValue methods).

 

We used LocalManifest value map to store references to POJO representing TreeView items participating in Cut and Paste.

 

When we put LocalManifest to Clipboard using Clipboard.setContent, then we expected to get it back later using Clipboard.getContent().

 

However this works only for the first time. Next, when we create new LocalManifest instance and put it to Clipboard we never get it back.

 

To test this behaviour call this testing method multiple times from UI for severalt times:

 

      public void copyToClipboard() throws Exception {

            System.out.println(Clipboard.getContent()+": "+Clipboard.getContent().getValue("A"));

            LocalManifest manifest=new LocalManifest();

            manifest.putValue("A", new Object());

            Clipboard.setContent(manifest);               

      }

 

You should get output similar to this:

 

org.apache.pivot.wtk.RemoteManifest@61d94155: null

org.apache.pivot.wtk.LocalManifest@3b5e37ac: java.lang.Object@26991ba7

org.apache.pivot.wtk.RemoteManifest@77315619: null

org.apache.pivot.wtk.RemoteManifest@7b875faa: null

org.apache.pivot.wtk.RemoteManifest@7499d141: null

org.apache.pivot.wtk.RemoteManifest@1e793e35: null

 

After some debugging, we realized that reason for this is implementation of org.apache.pivot.wtk.Clipboard.setContent method. The inner ClipboardOwner class clears the LocalManifest stored in Clipboard.content static variable. The problém is, that the call to lostOwnerhip notification method is not called directly from AWT Clipboard.setContents method, but queued to AWT Event queue.

 

So the ClipboardOwner from previous call to org.apache.pivot.wtk.Clipboard.setContent method, clears the new Clipboard.content field immediately since it is executed later from AWT event queue.

 

We now do not use clipboard to store POJO objects which are part of cut and paste and everything is OK.

 

This is not problem for text, image and files, because of propagation to AWT clipboard.

 

But now I am just curious. Is this a bug or feature?

 

Regards Karel

 


Loading...