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.
9 package eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Collection
;
14 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
15 import org
.eclipse
.jface
.viewers
.Viewer
;
16 import org
.eclipse
.swt
.dnd
.DND
;
17 import org
.eclipse
.swt
.dnd
.TransferData
;
19 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
20 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
21 import eu
.etaxonomy
.cdm
.model
.description
.IndividualsAssociation
;
22 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
23 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
24 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonEditor
;
25 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.e4
.FactualDataPartE4
;
26 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.operation
.MoveDescriptionElementsOperation
;
27 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
28 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostTaxonOperation
;
29 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
30 import eu
.etaxonomy
.taxeditor
.ui
.EditViewerDropAdapter
;
34 * @created Feb 8, 2011
36 public class DescriptionElementDropAdapter
extends EditViewerDropAdapter
{
38 private static final String OPERATION_NOT_SUPPORTED_YET
= Messages
.DescriptionElementDropAdapter_NOT_SUPPORTED
;
40 public DescriptionElementDropAdapter(Viewer viewer
) {
45 public boolean performDrop(Object data
) {
46 DescriptionBase target
= (DescriptionBase
) getCurrentTarget();
47 Object
[] droppedElements
= (Object
[]) data
;
49 Collection
<DescriptionElementBase
> descriptionElements
= new ArrayList
<DescriptionElementBase
>();
51 boolean isCopy
= getCurrentOperation() == DND
.DROP_COPY ?
true : false;
52 DescriptionBase
<?
> description
= null;
53 boolean containsSpecimen
= 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, Messages
.DescriptionElementDropAdapter_NOT_SUPPORTED_NEW_ELEMENT
);
61 if(! (droppedElement
instanceof DescriptionElementBase
)){
64 DescriptionElementBase descriptionElement
= (DescriptionElementBase
) droppedElement
;
66 if (descriptionElement
.getInDescription().equals(target
)) {
69 for (Object element
: target
.getElements()){
70 if (element
instanceof DescriptionElementBase
){
71 if( !((DescriptionElementBase
)element
).isPersisted()){
72 MessagingUtils
.warningDialog(OPERATION_NOT_SUPPORTED_YET
, this, Messages
.DescriptionElementDropAdapter_NOT_SUPPORTED_NEW_ELEMENT_IN_DESCRIPTION
);
78 for (Object element
: descriptionElement
.getInDescription().getElements()){
79 if (element
instanceof DescriptionElementBase
){
80 if( !((DescriptionElementBase
)element
).isPersisted()){
81 MessagingUtils
.warningDialog(OPERATION_NOT_SUPPORTED_YET
, this, Messages
.DescriptionElementDropAdapter_NOT_SUPPORTED_NEW_ELEMENT_IN_DESCRIPTION
);
87 description
= descriptionElement
.getInDescription();
88 description
.removeElement(descriptionElement
);
89 target
.addElement(descriptionElement
);
90 if (descriptionElement
instanceof IndividualsAssociation
&& PreferencesUtil
.getBooleanValue("AskForNewCurrentDetermination")) {
91 if (((IndividualsAssociation
)descriptionElement
).getAssociatedSpecimenOrObservation() != null && !((IndividualsAssociation
)descriptionElement
).getAssociatedSpecimenOrObservation().getDeterminations().isEmpty()) {
92 containsSpecimen
= true;
95 descriptionElements
.add(descriptionElement
);
98 TaxonEditor editor
= null;
99 Object activePart
= EditorUtil
.getActivePart();
100 if (activePart
instanceof FactualDataPartE4
){
101 MPart selectionProvidingPart
=((FactualDataPartE4
)activePart
).getSelectionProvidingPart();
102 Object obj
= selectionProvidingPart
.getObject();
103 if (obj
instanceof TaxonEditor
){
104 editor
= (TaxonEditor
) obj
;
109 AbstractPostTaxonOperation operation
= new MoveDescriptionElementsOperation(Messages
.DescriptionElementDropAdapter_MOVE_DESC
, EditorUtil
.getUndoContext(), target
, description
, descriptionElements
, isCopy
, null, sync
, false, containsSpecimen
);
111 editor
.getEditorInput().addOperation(operation
);
113 // EditorUtil.executeOperation(operation, sync);
116 MessagingUtils
.warningDialog(OPERATION_NOT_SUPPORTED_YET
, this, Messages
.DescriptionElementDropAdapter_NOT_SUPPORTED_EMPTY_ELEMENT
);
123 public boolean validateDrop(Object target
, int operation
,
124 TransferData transferData
) {
125 boolean transferDataIsSupported
= true;
126 if (target
instanceof DescriptionBase
){
127 if((((DescriptionBase
)target
).isComputed() || ((DescriptionBase
)target
).isCloneForSource())&& PreferencesUtil
.isComputedDesciptionHandlingDisabled()){
128 transferDataIsSupported
= false;
131 transferDataIsSupported
= DescriptionElementTransfer
.getInstance().isSupportedType(
132 transferData
) && transferDataIsSupported
;
133 return target
instanceof DescriptionBase
&& transferDataIsSupported
;