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
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
16 import org
.eclipse
.jface
.viewers
.Viewer
;
17 import org
.eclipse
.swt
.dnd
.DND
;
18 import org
.eclipse
.swt
.dnd
.TransferData
;
20 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
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
.l10n
.Messages
;
25 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
26 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.e4
.FactualDataPartE4
;
27 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.MoveDescriptionElementsOperation
;
28 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
29 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
30 import eu
.etaxonomy
.taxeditor
.ui
.EditViewerDropAdapter
;
34 * @created Feb 8, 2011
37 public class DescriptionElementDropAdapter
extends EditViewerDropAdapter
{
39 private static final String OPERATION_NOT_SUPPORTED_YET
= Messages
.DescriptionElementDropAdapter_NOT_SUPPORTED
;
46 public DescriptionElementDropAdapter(Viewer viewer
) {
51 * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
54 public boolean performDrop(Object data
) {
55 TaxonDescription target
= (TaxonDescription
) getCurrentTarget();
56 Object
[] droppedElements
= (Object
[]) data
;
58 Collection
<DescriptionElementBase
> descriptionElements
= new ArrayList
<DescriptionElementBase
>();
60 boolean isCopy
= getCurrentOperation() == DND
.DROP_COPY ?
true : false;
62 // cannot drop a feature node onto itself
63 if (droppedElements
!= null){
64 for (Object droppedElement
: droppedElements
) {
65 if (droppedElement
== null){
66 MessagingUtils
.warningDialog(OPERATION_NOT_SUPPORTED_YET
, this, Messages
.DescriptionElementDropAdapter_NOT_SUPPORTED_NEW_ELEMENT
);
69 if(! (droppedElement
instanceof DescriptionElementBase
)){
72 DescriptionElementBase descriptionElement
= (DescriptionElementBase
) droppedElement
;
74 if (descriptionElement
.getInDescription().equals(target
)) {
77 DescriptionBase
<?
> description
= descriptionElement
.getInDescription();
78 description
.removeElement(descriptionElement
);
79 target
.addElement(descriptionElement
);
81 if (description
.getElements().isEmpty()){
82 ((TaxonDescription
)description
).getTaxon().removeDescription((TaxonDescription
)description
, false);
84 descriptionElements
.add(descriptionElement
);
87 TaxonNameEditorE4 editor
= null;
88 Object activePart
= EditorUtil
.getActivePart();
89 if (activePart
instanceof FactualDataPartE4
){
90 MPart selectionProvidingPart
=(MPart
) ((FactualDataPartE4
)activePart
).getSelectionProvidingPart();
91 Object obj
= selectionProvidingPart
.getObject();
92 if (obj
instanceof TaxonNameEditorE4
){
93 editor
= (TaxonNameEditorE4
) obj
;
96 AbstractPostTaxonOperation operation
= new MoveDescriptionElementsOperation(Messages
.DescriptionElementDropAdapter_MOVE_DESC
, EditorUtil
.getUndoContext(), target
, descriptionElements
, isCopy
, null, sync
);
98 editor
.getEditorInput().addOperation(operation
);
100 // EditorUtil.executeOperation(operation, sync);
103 MessagingUtils
.warningDialog(OPERATION_NOT_SUPPORTED_YET
, this, Messages
.DescriptionElementDropAdapter_NOT_SUPPORTED_EMPTY_ELEMENT
);
110 * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
113 public boolean validateDrop(Object target
, int operation
,
114 TransferData transferData
) {
115 boolean transferDataIsSupported
= DescriptionElementTransfer
.getInstance().isSupportedType(
117 return target
instanceof TaxonDescription
&& transferDataIsSupported
;