blob: 34232c7f3b5ac18c6af56fbf76b5af5e530567e8 (
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
|
/**
* Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) 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:
* Victor Roldan Betancort - initial API and implementation
* Eike Stepper - maintenance
*/
package org.eclipse.emf.cdo.internal.ui.dnd;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.internal.cdo.util.FSMUtil;
import org.eclipse.net4j.util.container.IContainer;
import org.eclipse.net4j.util.ui.dnd.DNDDropAdapter;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.dnd.TransferData;
import java.util.ArrayList;
/**
* @author Victor Roldan Betancort
*/
public class CDOObjectDropAdapter extends DNDDropAdapter<TreeSelection>
{
private static final Transfer[] TRANSFERS = new Transfer[] { org.eclipse.emf.edit.ui.dnd.LocalTransfer.getInstance() };
protected CDOObjectDropAdapter(StructuredViewer viewer)
{
super(org.eclipse.emf.edit.ui.dnd.LocalTransfer.getInstance(), viewer);
setExpandEnabled(false);
}
@SuppressWarnings("unchecked")
@Override
protected boolean performDrop(TreeSelection data, Object target)
{
if (target instanceof IContainer.Modifiable<?>)
{
IContainer.Modifiable<CDOObject> objectContainer = (IContainer.Modifiable<CDOObject>)target;
ArrayList<CDOObject> elementsToAdd = new ArrayList<CDOObject>();
for (Object obj : data.toArray())
{
if (FSMUtil.isWatchable(obj))
{
elementsToAdd.add((CDOObject)obj);
}
}
objectContainer.addAllElements(elementsToAdd);
return true;
}
return false;
}
@Override
protected boolean validateTarget(Object target, int operation)
{
return false;
}
@Override
public boolean validateDrop(Object target, int operation, TransferData type)
{
return getTransfer().isSupportedType(type);
}
public static void support(StructuredViewer viewer)
{
int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
viewer.addDropSupport(dndOperations, TRANSFERS, new CDOObjectDropAdapter(viewer));
}
}
|