blob: 0d3de85bcb2f787de709ecd7abb4315a377453c2 (
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*******************************************************************************
* Copyright (c) 2011 Wind River Systems, Inc. and others. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.tcf.te.tcf.filesystem.ui.internal.operations;
import java.util.List;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.widgets.Display;
import org.eclipse.tcf.te.tcf.filesystem.core.internal.operations.OpClipboard;
import org.eclipse.tcf.te.tcf.filesystem.core.model.FSTreeNode;
import org.eclipse.ui.PlatformUI;
/**
* The clip board to which copy or cut files/folders.
*/
public class FsClipboard extends OpClipboard {
// The system clipboard.
private Clipboard clipboard;
/**
* Create a clip board instance.
*/
public FsClipboard() {
super();
clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
}
/**
* Cut the specified files/folders to the clip board.
*
* @param files The file/folder nodes.
*/
@Override
public void cutFiles(List<FSTreeNode> files) {
super.cutFiles(files);
clearSystemClipboard();
}
/**
* Copy the specified files/folders to the clip board.
*
* @param files The file/folder nodes.
*/
@Override
public void copyFiles(List<FSTreeNode> files) {
super.copyFiles(files);
clearSystemClipboard();
}
/**
* Clear the clip board.
*/
@Override
public void clear() {
super.clear();
clearSystemClipboard();
}
/**
* Make sure the system clip board is cleared in a UI thread.
*/
void clearSystemClipboard() {
if (Display.getCurrent() != null) {
clipboard.clearContents();
}
else {
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable(){
@Override
public void run() {
clearSystemClipboard();
}});
}
}
/**
* Dispose the clipboard.
*/
@Override
public void dispose() {
if(Display.getCurrent() != null) {
if (!clipboard.isDisposed()) {
try {
clipboard.dispose();
}
catch (SWTException e) {
}
}
}
else {
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable(){
@Override
public void run() {
dispose();
}});
}
}
/**
* Get the system clipboard.
*
* @return The system clipboard.
*/
public Clipboard getSystemClipboard() {
return clipboard;
}
}
|