Class ContentProviders
java.lang.Object
org.eclipse.swt.dnd.ContentProviders
Manages GdkContentProviders
and the (de)serializers they rely on
As the process only has a single collection of
serializers/deserializers/content providers the life-cycle of this class is
that of the process, which means this class is a singleton.
The challenge of handling content providers in GTK4 is that it is all based
around serializing/deserializing GValue and registering GTypes as being
transferable. However we want to keep the Java objects in the Java space
until we are ready to transfer them.
Therefore, we register GTypes associated with each
Transfer, those
GTypes are boxed GTypes which box a simple long value. That long value we use
as an index to connect back to Java object.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThere are multiple clipboards in GTK, each with its own current contents (providers). -
Field Summary
FieldsModifier and TypeFieldDescriptionThe types registered withregisterType(String)on GTK4.This the data that has been deserialized and associates source id (which is a number greater than those inContentProviders.CLIPBOARD_DATAso they can be differentied) It is expected that the map is normally empty and only has data while a gdk_clipboard_read_value_async (or similar) is active.private Callbackprivate CallbackThe types registered withregisterType(String)on GTK4.private static ContentProvidersThe life-time of the serializers in GTK4 (Gdk) are the life-time of the process so we use a singleton to store the mapping data that is needed.private longAll transfer IDs registered with the GTK serializers Key is the transfer obtained withtransferKey(Transfer)Value is the Gtype of of the transferAll transfers registered with the GTK serializers Key is the transfer obtained withtransferKey(Transfer)private intNext index to use forregisterType(String) -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate ObjectWhen calling gdk_clipboard_read_value_async and related functions, if the clipboard is owned locally it returns the instance that was placed on the clipboard and avoid the serialization and deserialization.longcreateContentProviders(Object[] data, Transfer[] transfers, ContentProviders.CLIPBOARD_DATA id) Create a set of content providers (GdkContentProviders) for the given SWT Transfer Types and data, assigned to the given clipboard.private voidgdkContentDeserializeFunc(long pDeserializer) Use the gtype + mime_type of the deserializer to identify which Transfer to complete the transfer with.private voidgdkContentSerializeFunc(long pSerializer) Convert the Java object to data with transfer.javaToNative and then write all the data to the output stream.longGet the GType for the given transfer, andregisterTransfer(Transfer)if needed The gtype can then be used to request data from GTK with methods such as gdk_clipboard_read_value_asyncstatic ContentProvidersgetObject(long gvalue) Return the Java object associated with the given GValueprivate TransfergetTransfer(long gtype) Return the transfer associated with the given gtype Return null on error (unknown gtype)private intReturn the type for the given mime type Returns 0 on error (unknown mime_type).private voidregisterTransfer(Transfer transfer) Register the transfer in the GTK land if not registered already.intregisterType(String formatName) Called byTransfer.registerType(String)onlyprivate StringtransferKey(Transfer transfer) Create a string key for the transfer that can be used as a key for Map and as a GType
-
Field Details
-
instance
The life-time of the serializers in GTK4 (Gdk) are the life-time of the process so we use a singleton to store the mapping data that is needed. -
ID_TO_CONTENTTYPE
The types registered withregisterType(String)on GTK4. Using TreeMap to make the maps sorted to ease debugging. Map of Transfer.id type -> Transfer's type name. -
CONTENTTYPE_TO_ID
The types registered withregisterType(String)on GTK4. Using TreeMap to make the maps sorted to ease debugging. Map of Transfer's type name -> Transfer.id type -
typeIndex
private int typeIndexNext index to use forregisterType(String) -
deserializedData
This the data that has been deserialized and associates source id (which is a number greater than those inContentProviders.CLIPBOARD_DATAso they can be differentied) It is expected that the map is normally empty and only has data while a gdk_clipboard_read_value_async (or similar) is active. Map of sourceId -> associated data -
nextDeserializedDataId
private long nextDeserializedDataId -
gdkContentSerializeFunc
-
gdkContentDeserializeFunc
-
registeredTransfers
All transfers registered with the GTK serializers Key is the transfer obtained withtransferKey(Transfer) -
registeredTransferGtypes
All transfer IDs registered with the GTK serializers Key is the transfer obtained withtransferKey(Transfer)Value is the Gtype of of the transfer
-
-
Constructor Details
-
ContentProviders
private ContentProviders()
-
-
Method Details
-
getInstance
-
registerType
Called byTransfer.registerType(String)only -
createContentProviders
public long createContentProviders(Object[] data, Transfer[] transfers, ContentProviders.CLIPBOARD_DATA id) Create a set of content providers (GdkContentProviders) for the given SWT Transfer Types and data, assigned to the given clipboard.- Returns:
- the content providers. The data is owned by the called function.
-
gdkContentSerializeFunc
private void gdkContentSerializeFunc(long pSerializer) Convert the Java object to data with transfer.javaToNative and then write all the data to the output stream. Use the gvalue of the serializer to identify which Transfer and object to complete the transfer with. Referenced by CallbackgdkContentSerializeFunc -
gdkContentDeserializeFunc
private void gdkContentDeserializeFunc(long pDeserializer) Use the gtype + mime_type of the deserializer to identify which Transfer to complete the transfer with. Read all the data from the source (clipboard or drag source) into this memory stream and then, on success, convert the data to Java object with transfer.nativeToJava. Then place the converted object deserializedData and associate the gvalue with the deserializedData by using nextDeserializedDataId Referenced by CallbackgdkContentSerializeFunc -
getTypeId
-
getTransfer
Return the transfer associated with the given gtype Return null on error (unknown gtype) -
transferKey
-
registerTransfer
Register the transfer in the GTK land if not registered already. See class comment for overall design and connection between different parts. -
getGType
Get the GType for the given transfer, andregisterTransfer(Transfer)if needed The gtype can then be used to request data from GTK with methods such as gdk_clipboard_read_value_async -
getObject
Return the Java object associated with the given GValue -
clone
When calling gdk_clipboard_read_value_async and related functions, if the clipboard is owned locally it returns the instance that was placed on the clipboard and avoid the serialization and deserialization. This presents a problem for SWT because SWT has always returned a copy (javaToNative/nativeToJava) of the object between the setContents and the getContents. For some objects, like String it may be ok to return the same instance since String is immutable, but for others, such as ImageData or custom types a copy definitely needs to be made to preserve the pre-existing behavior. However, to maintain compatibility with the pre-existing implementations for even String type Transfers that have returned a copy, we copy String types too in this implementation.
-