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.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
;
12 import java
.util
.ArrayList
;
13 import java
.util
.Collection
;
15 import org
.eclipse
.jface
.viewers
.Viewer
;
16 import org
.eclipse
.jface
.viewers
.ViewerDropAdapter
;
17 import org
.eclipse
.swt
.dnd
.DND
;
18 import org
.eclipse
.swt
.dnd
.TransferData
;
20 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
21 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
22 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
23 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.MoveDescriptionElementsOperation
;
24 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
25 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
29 * @created Feb 8, 2011
32 public class DescriptionElementDropAdapter
extends ViewerDropAdapter
{
37 public DescriptionElementDropAdapter(Viewer viewer
) {
42 * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
45 public boolean performDrop(Object data
) {
46 TaxonDescription target
= (TaxonDescription
) getCurrentTarget();
47 Object
[] droppedElements
= (Object
[]) data
;
49 Collection
<DescriptionElementBase
> descriptionElements
= new ArrayList
<DescriptionElementBase
>();
51 boolean isCopy
= getCurrentOperation() == DND
.DROP_COPY ?
true : false;
53 // cannot drop a feature node onto itself
54 if (droppedElements
!= null){
55 for (Object droppedElement
: droppedElements
) {
56 if (droppedElement
== null){
57 MessagingUtils
.warningDialog("Operation not supported yet", this, "We are currently unable to drag and drop a newly created element. Please save the editor to make this work.");
60 if(! (droppedElement
instanceof DescriptionElementBase
)){
63 DescriptionElementBase descriptionElement
= (DescriptionElementBase
) droppedElement
;
65 if (descriptionElement
.getInDescription().equals(target
)) {
69 descriptionElements
.add(descriptionElement
);
73 AbstractPostOperation operation
= new MoveDescriptionElementsOperation("Move Descriptions", EditorUtil
.getUndoContext(), target
, descriptionElements
, isCopy
, null);
75 EditorUtil
.executeOperation(operation
);
78 MessagingUtils
.warningDialog("Operation not supported yet", this, "We are unable to drag and drop empty descriptions");
85 * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
88 public boolean validateDrop(Object target
, int operation
,
89 TransferData transferData
) {
90 boolean transferDataIsSupported
= DescriptionElementTransfer
.getInstance().isSupportedType(
92 return target
instanceof TaxonDescription
&& transferDataIsSupported
;