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
115
116
117
118
119
120
121
122
|
/*******************************************************************************
* 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.internal.operations;
import java.util.List;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.tcf.te.tcf.filesystem.model.FSTreeNode;
import org.eclipse.tcf.te.ui.utils.PropertyChangeProvider;
import org.eclipse.ui.PlatformUI;
/**
* The clip board to which copy or cut files/folders.
*/
public class FSClipboard extends PropertyChangeProvider {
// The constants to define the current operation type of the clip board.
public static final int NONE = -1;
public static final int CUT = 0;
public static final int COPY = 1;
// The operation type, CUT, COPY or NONE.
private int operation;
// The currently selected files/folders.
private List<FSTreeNode> files;
// The system clipboard.
private Clipboard clipboard;
/**
* Create a clip board instance.
*/
public FSClipboard() {
operation = NONE;
clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay());
}
/**
* If the clip board is empty.
*
* @return true if the operation is NONE and no files are selected.
*/
public boolean isEmpty() {
return operation == NONE && (files == null || files.isEmpty());
}
/**
* Return the current operation type.
*
* @return The operation of the current clip board content.
*/
public int getOperation() {
return operation;
}
/**
* Get the currently selected files/folders to operated.
*
* @return The file/folder list using their location URLs.
*/
public List<FSTreeNode> getFiles() {
return files;
}
/**
* Cut the specified files/folders to the clip board.
*
* @param files The file/folder nodes.
*/
public void cutFiles(List<FSTreeNode> files) {
operation = CUT;
this.files = files;
clipboard.clearContents();
PropertyChangeEvent event = new PropertyChangeEvent(this, "cut", null, null); //$NON-NLS-1$
firePropertyChange(event);
}
/**
* Copy the specified files/folders to the clip board.
*
* @param files The file/folder nodes.
*/
public void copyFiles(List<FSTreeNode> files) {
operation = COPY;
this.files = files;
clipboard.clearContents();
PropertyChangeEvent event = new PropertyChangeEvent(this, "copy", null, null); //$NON-NLS-1$
firePropertyChange(event);
}
/**
* Clear the clip board.
*/
public void clear() {
operation = NONE;
this.files = null;
clipboard.clearContents();
PropertyChangeEvent event = new PropertyChangeEvent(this, "clear", null, null); //$NON-NLS-1$
firePropertyChange(event);
}
/**
* Dispose the clipboard.
*/
public void dispose() {
if (!clipboard.isDisposed()) clipboard.dispose();
}
/**
* Get the system clipboard.
*
* @return The system clipboard.
*/
public Clipboard getSystemClipboard() {
return clipboard;
}
}
|