Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0c0b91c3ec84f0e0b8c73682cd9b10d9de546781 (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
/*******************************************************************************
 * 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.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.ViewerDropAdapter;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.dnd.TransferData;
import org.eclipse.tcf.te.tcf.filesystem.core.interfaces.runtime.IFSTreeNode;

/**
 * The drop target listener for the file tree of Target Explorer.
 */
public class FSDropTargetListener extends ViewerDropAdapter {
	// The tree viewer that the drop listener attached to.
	TreeViewer viewer;
	// The common dnd operation
	CommonDnD dnd;
	/**
	 * Create FSDropTargetListener using the viewer.
	 *
	 * @param viewer The file system tree viewer.
	 */
	public FSDropTargetListener(TreeViewer viewer) {
		super(viewer);
		this.viewer = viewer;
		dnd = new CommonDnD();
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#dragEnter(org.eclipse.swt.dnd.DropTargetEvent)
	 */
	@Override
    public void dragEnter(DropTargetEvent event) {
		if (FileTransfer.getInstance().isSupportedType(event.currentDataType)) {
			// Force the operation of file transfer from external application to DROP_COPY
			event.detail = DND.DROP_COPY;
		}
		super.dragEnter(event);
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
	 */
	@Override
	public boolean validateDrop(Object target, int operation, TransferData transferType) {
		if (target instanceof IFSTreeNode) {
			if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) {
				return dnd.validateLocalSelectionDrop(target, operation, transferType);
			}
			else if (FileTransfer.getInstance().isSupportedType(transferType)) {
				return dnd.validateFilesDrop(target, operation, transferType);
			}
		}
		return false;
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
	 */
	@Override
	public boolean performDrop(Object data) {
		boolean success = false;
		TransferData transferType = getCurrentEvent().currentDataType;
		if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) {
		    IStructuredSelection selection = (IStructuredSelection) data;
		    int operations = getCurrentOperation();
			IFSTreeNode target = (IFSTreeNode) getCurrentTarget();
		    success = dnd.dropLocalSelection(target, operations, selection);
		}
		else if(FileTransfer.getInstance().isSupportedType(transferType)) {
			String[] files = (String[]) data;
		    int operations = getCurrentOperation();
			IFSTreeNode target = (IFSTreeNode) getCurrentTarget();
			success = dnd.dropFiles(viewer, files, operations, target);
		}
		return success;
	}
}

Back to the top