1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.dnd;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
import java.util.Iterator;
|
13
|
|
14
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
15
|
import org.eclipse.swt.dnd.DropTargetEvent;
|
16
|
import org.eclipse.swt.dnd.DropTargetListener;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
19
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
20
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
21
|
import eu.etaxonomy.taxeditor.ui.group.grantedauthority.CdmAuthorityComposite;
|
22
|
import eu.etaxonomy.taxeditor.ui.group.grantedauthority.CdmAuthorityCompositeViewer;
|
23
|
|
24
|
/**
|
25
|
* Drop listener for the {@link CdmAuthorityComposite}.
|
26
|
*
|
27
|
* @author cmathew
|
28
|
* @created Mar 28, 2013
|
29
|
*
|
30
|
*/
|
31
|
public class CdmAuthorityTableDropTargetListener implements DropTargetListener {
|
32
|
|
33
|
private CdmAuthorityCompositeViewer viewer;
|
34
|
|
35
|
|
36
|
public CdmAuthorityTableDropTargetListener(CdmAuthorityCompositeViewer viewer) {
|
37
|
this.viewer = viewer;
|
38
|
}
|
39
|
|
40
|
@Override
|
41
|
public void dragEnter(DropTargetEvent event) {
|
42
|
}
|
43
|
|
44
|
@Override
|
45
|
public void dragLeave(DropTargetEvent arg0) {
|
46
|
}
|
47
|
|
48
|
@Override
|
49
|
public void dragOperationChanged(DropTargetEvent arg0) {
|
50
|
}
|
51
|
|
52
|
@Override
|
53
|
public void dragOver(DropTargetEvent arg0) {
|
54
|
}
|
55
|
|
56
|
@Override
|
57
|
public void drop(DropTargetEvent dtevent) {
|
58
|
Object data = dtevent.data;
|
59
|
if (data instanceof IStructuredSelection) {
|
60
|
Iterator<?> selectionIterator = ((IStructuredSelection) dtevent.data).iterator();
|
61
|
while (selectionIterator.hasNext()){
|
62
|
addAuthority(selectionIterator.next());
|
63
|
}
|
64
|
}
|
65
|
else if(data instanceof Object[]) {
|
66
|
for(int i=0;i<((Object[])data).length;i++){
|
67
|
addAuthority(((Object[])data)[i]);
|
68
|
}
|
69
|
}
|
70
|
else if(data instanceof Collection) {
|
71
|
((Collection) data).forEach(d->addAuthority(d));
|
72
|
}
|
73
|
else{
|
74
|
addAuthority(data);
|
75
|
}
|
76
|
viewer.getControl().setFocus();
|
77
|
}
|
78
|
|
79
|
private void addAuthority(Object authority){
|
80
|
if(CdmBase.class.isAssignableFrom(authority.getClass()) ) {
|
81
|
viewer.addCdmAuthority((CdmBase)authority);
|
82
|
}
|
83
|
else if(authority instanceof UuidAndTitleCache){
|
84
|
UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache) authority;
|
85
|
CdmBase cdmBase = CdmStore.getCommonService().find(uuidAndTitleCache.getType(), uuidAndTitleCache.getUuid());
|
86
|
viewer.addCdmAuthority(cdmBase);
|
87
|
}
|
88
|
}
|
89
|
|
90
|
@Override
|
91
|
public void dropAccept(DropTargetEvent arg0) {
|
92
|
}
|
93
|
|
94
|
}
|