pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Karel Hübl <karel.h...@gemsystem.cz>
Subject Correct usage of Clipboard and LocalManifest value map
Date Thu, 07 Nov 2013 19:33:44 GMT
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

 


Mime
View raw message