blob: 2ece0142f51dc6a93c5418ba7c0ef1960cd0407a (
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
|
/*
* Copyright (c) 2004 - 2012 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.cdo.CDOState;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.net4j.util.container.IContainer;
import org.eclipse.net4j.util.ui.dnd.DNDDropAdapter;
import org.eclipse.emf.ecore.EObject;
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 java.util.ArrayList;
/**
* @author Victor Roldan Betancort
*/
public class CDOObjectDropAdapter extends DNDDropAdapter<TreeSelection>
{
public static final Transfer[] TRANSFERS = new Transfer[] { org.eclipse.emf.edit.ui.dnd.LocalTransfer.getInstance() };
protected CDOObjectDropAdapter(StructuredViewer viewer)
{
super(TRANSFERS, 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 (isWatchable(obj))
{
elementsToAdd.add(CDOUtil.getCDOObject((EObject)obj));
}
}
objectContainer.addAllElements(elementsToAdd);
return true;
}
return false;
}
@Override
protected boolean validateTarget(Object target, int operation)
{
return true;
}
public static void support(StructuredViewer viewer)
{
int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
viewer.addDropSupport(dndOperations, TRANSFERS, new CDOObjectDropAdapter(viewer));
}
public static boolean isWatchable(Object obj)
{
// Only CLEAN and DIRTY CDOObjects are watchable
if (obj instanceof EObject)
{
CDOObject cdoObject = CDOUtil.getCDOObject((EObject)obj);
if (cdoObject != null)
{
return cdoObject.cdoState() == CDOState.CLEAN || cdoObject.cdoState() == CDOState.DIRTY;
}
}
return false;
}
}
|