3 * Copyright (C) 2007 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.
11 package eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
;
13 import java
.util
.ArrayList
;
14 import java
.util
.Collection
;
16 import org
.eclipse
.jface
.viewers
.Viewer
;
17 import org
.eclipse
.jface
.viewers
.ViewerDropAdapter
;
18 import org
.eclipse
.swt
.dnd
.DND
;
19 import org
.eclipse
.swt
.dnd
.TransferData
;
21 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
22 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
23 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
24 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.MoveDescriptionElementsOperation
;
25 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
26 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
30 * @created Feb 8, 2011
33 public class DescriptionElementDropAdapter
extends ViewerDropAdapter
{
38 public DescriptionElementDropAdapter(Viewer viewer
) {
43 * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
46 public boolean performDrop(Object data
) {
47 TaxonDescription target
= (TaxonDescription
) getCurrentTarget();
48 Object
[] droppedElements
= (Object
[]) data
;
50 Collection
<DescriptionElementBase
> descriptionElements
= new ArrayList
<DescriptionElementBase
>();
52 boolean isCopy
= getCurrentOperation() == DND
.DROP_COPY ?
true : false;
54 // cannot drop a feature node onto itself
55 if (droppedElements
!= null){
56 for (Object droppedElement
: droppedElements
) {
57 if (droppedElement
== null){
58 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.");
61 if(! (droppedElement
instanceof DescriptionElementBase
)){
64 DescriptionElementBase descriptionElement
= (DescriptionElementBase
) droppedElement
;
66 if (descriptionElement
.getInDescription().equals(target
)) {
70 descriptionElements
.add(descriptionElement
);
74 AbstractPostOperation operation
= new MoveDescriptionElementsOperation("Move Descriptions", EditorUtil
.getUndoContext(), target
, descriptionElements
, isCopy
, null);
76 EditorUtil
.executeOperation(operation
);
79 MessagingUtils
.warningDialog("Operation not supported yet", this, "We are unable to drag and drop empty descriptions");
86 * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
89 public boolean validateDrop(Object target
, int operation
,
90 TransferData transferData
) {
91 boolean transferDataIsSupported
= DescriptionElementTransfer
.getInstance().isSupportedType(
93 return target
instanceof TaxonDescription
&& transferDataIsSupported
;