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
|
/*******************************************************************************
* Copyright (c) 2011, 2015 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.dnd;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.dnd.TransferData;
import org.eclipse.swt.widgets.Display;
import org.eclipse.tcf.te.tcf.filesystem.core.interfaces.runtime.IFSTreeNode;
import org.eclipse.tcf.te.ui.views.interfaces.IUIConstants;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.navigator.CommonDropAdapter;
import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
import org.eclipse.ui.navigator.CommonNavigator;
/**
* The drop assistant used by Target Explorer to extend its DnD support to IFSTreeNode elements.
*/
public class FSDropAdapterAssistant extends CommonDropAdapterAssistant {
// The common dnd operation
CommonDnD dnd;
/**
* Create an instance.
*/
public FSDropAdapterAssistant() {
dnd = new CommonDnD();
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
*/
@Override
public IStatus validateDrop(Object target, int operation, TransferData transferType) {
boolean valid = false;
if (target instanceof IFSTreeNode) {
if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) {
int op = dnd.validateLocalSelectionDrop(target, operation, transferType);
valid = op != 0;
if (valid && op != operation) {
getCommonDropAdapter().overrideOperation(op);
}
}
else if(FileTransfer.getInstance().isSupportedType(transferType)) {
valid = dnd.validateFilesDrop(target, operation, transferType);
}
}
return valid ? Status.OK_STATUS : Status.CANCEL_STATUS;
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#isSupportedType(org.eclipse.swt.dnd.TransferData)
*/
@Override
public boolean isSupportedType(TransferData aTransferType) {
if(FileTransfer.getInstance().isSupportedType(aTransferType))
return true;
return super.isSupportedType(aTransferType);
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(org.eclipse.ui.navigator.CommonDropAdapter, org.eclipse.swt.dnd.DropTargetEvent, java.lang.Object)
*/
@Override
public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget) {
boolean sucess = false;
TransferData transferType = aDropTargetEvent.currentDataType;
if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) {
IStructuredSelection selection = (IStructuredSelection) aDropTargetEvent.data;
int operations = aDropAdapter.getCurrentOperation();
IFSTreeNode target = (IFSTreeNode) aTarget;
sucess = dnd.dropLocalSelection(target, operations, selection);
}
else if(FileTransfer.getInstance().isSupportedType(transferType)) {
String[] files = (String[]) aDropTargetEvent.data;
int operations = aDropAdapter.getCurrentOperation();
IFSTreeNode target = (IFSTreeNode) aTarget;
sucess = dnd.dropFiles(getCommonViewer(), files, operations, target);
}
return sucess ? Status.OK_STATUS : Status.CANCEL_STATUS;
}
/**
* Get the tree viewer of Target Explorer view.
*
* @return The tree viewer of Target Explorer view or null if the view is not found.
*/
private TreeViewer getCommonViewer() {
Assert.isNotNull(Display.getCurrent());
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
Assert.isNotNull(window);
IViewReference[] references = window.getActivePage().getViewReferences();
for(IViewReference reference : references) {
if(reference.getId().equals(IUIConstants.ID_EXPLORER)) {
CommonNavigator navigator = (CommonNavigator) reference.getPart(true);
return navigator.getCommonViewer();
}
}
return null;
}
}
|