blob: 7babdf848be23695824ecf19e29f878e52688903 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/*******************************************************************************
* Copyright (c) 2007, 2008 Dakshinamurthy Karra, IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Dakshinamurthy Karra (Jalian Systems) - Templates View - https://bugs.eclipse.org/bugs/show_bug.cgi?id=69581
*******************************************************************************/
package org.eclipse.ui.texteditor.templates;
import org.eclipse.swt.dnd.ByteArrayTransfer;
import org.eclipse.swt.dnd.TransferData;
import org.eclipse.jface.text.templates.persistence.TemplatePersistenceData;
/**
* Transfer type used for clipboard and drag and drop operations for templates.
* The templates are transfered as {@link TemplatePersistenceData}.
* <p>
* FIXME: only works inside the same workspace.
* </p>
*
* @see AbstractTemplatesPage
* @since 3.4
*/
class TemplatesTransfer extends ByteArrayTransfer {
private static final TemplatesTransfer INSTANCE= new TemplatesTransfer();
private static final String TYPE_NAME= "template-transfer-format:" + System.currentTimeMillis() + ":" + INSTANCE.hashCode(); //$NON-NLS-1$ //$NON-NLS-2$
private static final int TYPE_ID= registerType(TYPE_NAME);
private TemplatePersistenceData[] fObject ;
/**
* Returns the singleton instance of this <code>TemplateTransfer</code> class.
*
* @return the singleton template transfer instance
*/
public static TemplatesTransfer getInstance() {
return INSTANCE;
}
@Override
protected int[] getTypeIds() {
return new int[] { TYPE_ID };
}
@Override
protected String[] getTypeNames() {
return new String[] { TYPE_NAME };
}
@Override
protected void javaToNative(Object object, TransferData transferData) {
if (object == null || !(object instanceof TemplatePersistenceData[]) || !isSupportedType(transferData)) {
fObject= null ;
return;
}
fObject= (TemplatePersistenceData[]) object ;
super.javaToNative(TYPE_NAME.getBytes(), transferData);
}
@Override
protected Object nativeToJava(TransferData transferData) {
Object result= super.nativeToJava(transferData);
if (!(result instanceof byte[]) || !TYPE_NAME.equals(new String((byte[]) result)))
return null ;
return fObject ;
}
}
|