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.api.service.ITermService;
|
19
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
20
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
21
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
22
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
23
|
import eu.etaxonomy.taxeditor.ui.group.grantedauthority.CdmAuthorityComposite;
|
24
|
import eu.etaxonomy.taxeditor.ui.group.grantedauthority.CdmAuthorityCompositeViewer;
|
25
|
|
26
|
/**
|
27
|
* Drop listener for the {@link CdmAuthorityComposite}.
|
28
|
*
|
29
|
* @author cmathew
|
30
|
* @created Mar 28, 2013
|
31
|
*
|
32
|
*/
|
33
|
public class CdmAuthorityTableDropTargetListener implements DropTargetListener {
|
34
|
|
35
|
private CdmAuthorityCompositeViewer viewer;
|
36
|
|
37
|
|
38
|
public CdmAuthorityTableDropTargetListener(CdmAuthorityCompositeViewer viewer) {
|
39
|
this.viewer = viewer;
|
40
|
}
|
41
|
|
42
|
@Override
|
43
|
public void dragEnter(DropTargetEvent event) {
|
44
|
}
|
45
|
|
46
|
@Override
|
47
|
public void dragLeave(DropTargetEvent arg0) {
|
48
|
}
|
49
|
|
50
|
@Override
|
51
|
public void dragOperationChanged(DropTargetEvent arg0) {
|
52
|
}
|
53
|
|
54
|
@Override
|
55
|
public void dragOver(DropTargetEvent arg0) {
|
56
|
}
|
57
|
|
58
|
@Override
|
59
|
public void drop(DropTargetEvent dtevent) {
|
60
|
Object data = dtevent.data;
|
61
|
if (data instanceof IStructuredSelection) {
|
62
|
Iterator<?> selectionIterator = ((IStructuredSelection) dtevent.data).iterator();
|
63
|
while (selectionIterator.hasNext()){
|
64
|
addAuthority(selectionIterator.next());
|
65
|
}
|
66
|
}
|
67
|
else if(data instanceof Object[]) {
|
68
|
for(int i=0;i<((Object[])data).length;i++){
|
69
|
addAuthority(((Object[])data)[i]);
|
70
|
}
|
71
|
}
|
72
|
else if(data instanceof Collection) {
|
73
|
((Collection) data).forEach(d->addAuthority(d));
|
74
|
}
|
75
|
else{
|
76
|
addAuthority(data);
|
77
|
}
|
78
|
viewer.getControl().setFocus();
|
79
|
}
|
80
|
|
81
|
private void addAuthority(Object authority){
|
82
|
if(CdmBase.class.isAssignableFrom(authority.getClass()) ) {
|
83
|
viewer.addCdmAuthority((CdmBase)authority);
|
84
|
}
|
85
|
else if(authority instanceof UuidAndTitleCache){
|
86
|
UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache) authority;
|
87
|
CdmBase cdmBase = CdmStore.getCommonService().find(uuidAndTitleCache.getType(), uuidAndTitleCache.getUuid());
|
88
|
viewer.addCdmAuthority(cdmBase);
|
89
|
}else if (authority instanceof TermDto){
|
90
|
TermDto uuidAndTitleCache = (TermDto) authority;
|
91
|
CdmBase cdmBase = CdmStore.getService(ITermService.class).find(uuidAndTitleCache.getUuid());
|
92
|
viewer.addCdmAuthority(cdmBase);
|
93
|
}
|
94
|
}
|
95
|
|
96
|
@Override
|
97
|
public void dropAccept(DropTargetEvent arg0) {
|
98
|
}
|
99
|
|
100
|
}
|