2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.dnd
;
11 import java
.util
.Collection
;
12 import java
.util
.Iterator
;
14 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
15 import org
.eclipse
.swt
.dnd
.DropTargetEvent
;
16 import org
.eclipse
.swt
.dnd
.DropTargetListener
;
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
;
27 * Drop listener for the {@link CdmAuthorityComposite}.
30 * @created Mar 28, 2013
33 public class CdmAuthorityTableDropTargetListener
implements DropTargetListener
{
35 private CdmAuthorityCompositeViewer viewer
;
38 public CdmAuthorityTableDropTargetListener(CdmAuthorityCompositeViewer viewer
) {
43 public void dragEnter(DropTargetEvent event
) {
47 public void dragLeave(DropTargetEvent arg0
) {
51 public void dragOperationChanged(DropTargetEvent arg0
) {
55 public void dragOver(DropTargetEvent arg0
) {
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());
67 else if(data
instanceof Object
[]) {
68 for(int i
=0;i
<((Object
[])data
).length
;i
++){
69 addAuthority(((Object
[])data
)[i
]);
72 else if(data
instanceof Collection
) {
73 ((Collection
) data
).forEach(d
->addAuthority(d
));
78 viewer
.getControl().setFocus();
81 private void addAuthority(Object authority
){
82 if(CdmBase
.class.isAssignableFrom(authority
.getClass()) ) {
83 viewer
.addCdmAuthority((CdmBase
)authority
);
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
);
97 public void dropAccept(DropTargetEvent arg0
) {