3 * Copyright (C) 2014 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.derivate
;
12 import org
.eclipse
.jface
.viewers
.TreeNode
;
13 import org
.eclipse
.jface
.viewers
.Viewer
;
14 import org
.eclipse
.jface
.viewers
.ViewerDropAdapter
;
15 import org
.eclipse
.swt
.dnd
.DropTargetEvent
;
16 import org
.eclipse
.swt
.dnd
.TransferData
;
17 import org
.eclipse
.swt
.widgets
.TreeItem
;
19 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEvent
;
20 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEventType
;
21 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
22 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
29 public class DerivateDropListener
extends ViewerDropAdapter
{
34 protected DerivateDropListener(Viewer viewer
) {
39 * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
42 public boolean performDrop(Object data
) {
44 // TermBase target = (TermBase) getCurrentTarget();//can be vocab
45 // //DefinedTermBase[] droppedElements = (DefinedTermBase[]) data;
46 // Object[] droppedTerms = (Object[]) data;
47 // Collection<DefinedTermBase> sourceTerms = new ArrayList<DefinedTermBase>(); //Arrays.asList(droppedElements)
49 // for (Object droppedTerm : droppedTerms) {
51 // DefinedTermBase term = (DefinedTermBase) droppedTerm;
52 // sourceTerms.add(term);
56 // AbstractPostOperation operation = new MoveDefinedTermOperation("Move Descriptions", StoreUtil.getUndoContext(), target, sourceTerms, editor);
57 // //TODO: implement execute
58 // AbstractUtility.executeOperation(operation);
59 Object target
= getCurrentTarget();
60 if(target
instanceof TreeNode
){
61 Object targetDerivate
= ((TreeNode
) target
).getValue();
62 if(data
instanceof Object
[]){
63 Object
[] droppedElements
= (Object
[])data
;
64 for (Object droppedElement
:droppedElements
) {
66 if(droppedElement
instanceof DerivedUnit
&& targetDerivate
instanceof SpecimenOrObservationBase
<?
>){
67 SpecimenOrObservationBase
<?
> originSpecimen
= (SpecimenOrObservationBase
<?
>)targetDerivate
;
68 DerivedUnit derivedSpecimen
= (DerivedUnit
)droppedElement
;
69 originSpecimen
.addDerivationEvent(DerivationEvent
.NewSimpleInstance(originSpecimen
, derivedSpecimen
, DerivationEventType
.GATHERING_IN_SITU()));
70 System
.out
.println("Add Derivate: " + droppedElement
.getClass().getSimpleName() + " to " + targetDerivate
.getClass().getSimpleName());
72 System
.out
.println("Drop: " + droppedElement
.getClass().getSimpleName() + " to " + targetDerivate
.getClass().getSimpleName());
81 * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
84 public boolean validateDrop(Object target
, int operation
, TransferData transferType
) {
85 if(SpecimenOrObservationTransfer
.getInstance().isSupportedType(transferType
)
86 && target
instanceof TreeNode
){
87 Object value
= ((TreeNode
) target
).getValue();
88 return checkDropTarget(value
);
94 * @see org.eclipse.jface.viewers.ViewerDropAdapter#dragOver(org.eclipse.swt.dnd.DropTargetEvent)
97 public void dragOver(DropTargetEvent event
) {
98 Object draggedDerivate
= getCurrentTarget();
100 Object targetItem
= event
.item
;
101 // System.out.println(event);
102 if(targetItem
instanceof TreeItem
){
103 TreeItem treeItem
= (TreeItem
)targetItem
;
104 // System.out.println(treeItem.getData());
105 // System.out.println("Drag over: " + draggedDerivate.getClass().getSimpleName() + " to " + targetItem.getClass().getSimpleName());
107 super.dragOver(event
);
116 private boolean checkDropTarget(Object value
) {
117 // TODO Auto-generated method stub