blob: 5add2f08ef66e2b7bb3162357d233d1db069837d (
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
|
/*******************************************************************************
* Copyright (c) 2004 - 2006 University Of British Columbia 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:
* University Of British Columbia - initial API and implementation
*******************************************************************************/
package org.eclipse.mylar.internal.tasks.ui.views;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.mylar.context.core.ContextCorePlugin;
import org.eclipse.mylar.internal.tasks.ui.actions.CopyDetailsAction;
import org.eclipse.mylar.tasks.core.ITask;
import org.eclipse.mylar.tasks.core.ITaskListElement;
import org.eclipse.mylar.tasks.ui.TaskTransfer;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DragSourceListener;
import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.dnd.TextTransfer;
/**
* @author Mik Kersten
*/
class TaskListDragSourceListener implements DragSourceListener {
static final String DELIM = ", ";
private final TaskListView view;
// static final String ID_DATA_TASK_DRAG = "task-drag";
/**
* @param view
*/
public TaskListDragSourceListener(TaskListView view) {
this.view = view;
}
public void dragStart(DragSourceEvent event) {
if (((StructuredSelection) this.view.getViewer().getSelection()).isEmpty()) {
event.doit = false;
}
}
public void dragSetData(DragSourceEvent event) {
StructuredSelection selection = (StructuredSelection) this.view.getViewer().getSelection();
ITaskListElement selectedElement = null;
if (((IStructuredSelection) selection).getFirstElement() instanceof ITaskListElement) {
selectedElement = (ITaskListElement)((IStructuredSelection) selection).getFirstElement();
}
if (TaskTransfer.getInstance().isSupportedType(event.dataType)) {
List<ITask> tasks = new ArrayList<ITask>();
for (Iterator<?> iter = selection.iterator(); iter.hasNext();) {
ITaskListElement element = (ITaskListElement) iter.next();
if (element instanceof ITask) {
tasks.add((ITask)element);
}
}
event.data = tasks.toArray();
} else if (FileTransfer.getInstance().isSupportedType(event.dataType)) {
File file = ContextCorePlugin.getContextManager().getFileForContext(selectedElement.getHandleIdentifier());
if (file != null) {
event.data = new String[] { file.getAbsolutePath() };
}
} else if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
event.data = CopyDetailsAction.getTextForTask(selectedElement);
}
}
public void dragFinished(DragSourceEvent event) {
// don't care if the drag is done
}
}
|