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
.SpecimenDescription
;
23 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
24 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
25 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
26 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
27 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
28 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.e4
.FactualDataPartE4
;
29 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.MoveDescriptionElementsOperation
;
30 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
31 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
32 import eu
.etaxonomy
.taxeditor
.ui
.EditViewerDropAdapter
;
36 * @created Feb 8, 2011
39 public class DescriptionElementDropAdapter
extends EditViewerDropAdapter
{
41 private static final String OPERATION_NOT_SUPPORTED_YET
= Messages
.DescriptionElementDropAdapter_NOT_SUPPORTED
;
48 public DescriptionElementDropAdapter(Viewer viewer
) {
53 * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
56 public boolean performDrop(Object data
) {
57 DescriptionBase target
= (DescriptionBase
) getCurrentTarget();
58 Object
[] droppedElements
= (Object
[]) data
;
60 Collection
<DescriptionElementBase
> descriptionElements
= new ArrayList
<DescriptionElementBase
>();
62 boolean isCopy
= getCurrentOperation() == DND
.DROP_COPY ?
true : false;
63 DescriptionBase
<?
> description
= null;
64 // cannot drop a feature node onto itself
65 if (droppedElements
!= null){
66 for (Object droppedElement
: droppedElements
) {
67 if (droppedElement
== null){
68 MessagingUtils
.warningDialog(OPERATION_NOT_SUPPORTED_YET
, this, Messages
.DescriptionElementDropAdapter_NOT_SUPPORTED_NEW_ELEMENT
);
71 if(! (droppedElement
instanceof DescriptionElementBase
)){
74 DescriptionElementBase descriptionElement
= (DescriptionElementBase
) droppedElement
;
76 if (descriptionElement
.getInDescription().equals(target
)) {
79 for (Object element
: target
.getElements()){
80 if (element
instanceof DescriptionElementBase
){
81 if( !((DescriptionElementBase
)element
).isPersited()){
82 MessagingUtils
.warningDialog(OPERATION_NOT_SUPPORTED_YET
, this, Messages
.DescriptionElementDropAdapter_NOT_SUPPORTED_NEW_ELEMENT_IN_DESCRIPTION
);
88 for (Object element
: descriptionElement
.getInDescription().getElements()){
89 if (element
instanceof DescriptionElementBase
){
90 if( !((DescriptionElementBase
)element
).isPersited()){
91 MessagingUtils
.warningDialog(OPERATION_NOT_SUPPORTED_YET
, this, Messages
.DescriptionElementDropAdapter_NOT_SUPPORTED_NEW_ELEMENT_IN_DESCRIPTION
);
97 description
= descriptionElement
.getInDescription();
98 description
.removeElement(descriptionElement
);
99 target
.addElement(descriptionElement
);
101 if (description
.getElements().isEmpty() ){
102 if (description
instanceof TaxonDescription
){
103 ((TaxonDescription
)description
).getTaxon().removeDescription((TaxonDescription
)description
, false);
104 }else if (description
instanceof TaxonNameDescription
){
105 ((TaxonNameDescription
)description
).getTaxonName().removeDescription((TaxonNameDescription
)description
);
106 } else if (description
instanceof SpecimenDescription
){
107 ((SpecimenDescription
)description
).getDescribedSpecimenOrObservation().removeDescription(description
);
110 descriptionElements
.add(descriptionElement
);
113 TaxonNameEditorE4 editor
= null;
114 Object activePart
= EditorUtil
.getActivePart();
115 if (activePart
instanceof FactualDataPartE4
){
116 MPart selectionProvidingPart
=((FactualDataPartE4
)activePart
).getSelectionProvidingPart();
117 Object obj
= selectionProvidingPart
.getObject();
118 if (obj
instanceof TaxonNameEditorE4
){
119 editor
= (TaxonNameEditorE4
) obj
;
122 AbstractPostTaxonOperation operation
= new MoveDescriptionElementsOperation(Messages
.DescriptionElementDropAdapter_MOVE_DESC
, EditorUtil
.getUndoContext(), target
, description
, descriptionElements
, isCopy
, null, sync
);
124 editor
.getEditorInput().addOperation(operation
);
126 // EditorUtil.executeOperation(operation, sync);
129 MessagingUtils
.warningDialog(OPERATION_NOT_SUPPORTED_YET
, this, Messages
.DescriptionElementDropAdapter_NOT_SUPPORTED_EMPTY_ELEMENT
);
136 * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
139 public boolean validateDrop(Object target
, int operation
,
140 TransferData transferData
) {
141 boolean transferDataIsSupported
= DescriptionElementTransfer
.getInstance().isSupportedType(
143 return target
instanceof DescriptionBase
&& transferDataIsSupported
;