1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.editor.view.descriptive;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Collection;
|
13
|
|
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;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
20
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
21
|
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
|
22
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
23
|
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
|
24
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
25
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
26
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonEditor;
|
27
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
|
28
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.MoveDescriptionElementsOperation;
|
29
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
30
|
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
|
31
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
32
|
import eu.etaxonomy.taxeditor.ui.EditViewerDropAdapter;
|
33
|
|
34
|
/**
|
35
|
* @author n.hoffmann
|
36
|
* @created Feb 8, 2011
|
37
|
*/
|
38
|
public class DescriptionElementDropAdapter extends EditViewerDropAdapter {
|
39
|
|
40
|
private static final String OPERATION_NOT_SUPPORTED_YET = Messages.DescriptionElementDropAdapter_NOT_SUPPORTED;
|
41
|
|
42
|
public DescriptionElementDropAdapter(Viewer viewer) {
|
43
|
super(viewer);
|
44
|
}
|
45
|
|
46
|
@Override
|
47
|
public boolean performDrop(Object data) {
|
48
|
DescriptionBase target = (DescriptionBase) getCurrentTarget();
|
49
|
Object[] droppedElements = (Object[]) data;
|
50
|
|
51
|
Collection<DescriptionElementBase> descriptionElements = new ArrayList<DescriptionElementBase>();
|
52
|
|
53
|
boolean isCopy = getCurrentOperation() == DND.DROP_COPY ? true : false;
|
54
|
DescriptionBase<?> description = null;
|
55
|
// cannot drop a feature node onto itself
|
56
|
if (droppedElements != null){
|
57
|
for (Object droppedElement : droppedElements) {
|
58
|
if (droppedElement == null){
|
59
|
MessagingUtils.warningDialog(OPERATION_NOT_SUPPORTED_YET, this, Messages.DescriptionElementDropAdapter_NOT_SUPPORTED_NEW_ELEMENT);
|
60
|
return false;
|
61
|
}
|
62
|
if(! (droppedElement instanceof DescriptionElementBase)){
|
63
|
return false;
|
64
|
}else{
|
65
|
DescriptionElementBase descriptionElement = (DescriptionElementBase) droppedElement;
|
66
|
|
67
|
if (descriptionElement.getInDescription().equals(target)) {
|
68
|
return false;
|
69
|
}
|
70
|
for (Object element : target.getElements()){
|
71
|
if (element instanceof DescriptionElementBase){
|
72
|
if( !((DescriptionElementBase)element).isPersited()){
|
73
|
MessagingUtils.warningDialog(OPERATION_NOT_SUPPORTED_YET, this, Messages.DescriptionElementDropAdapter_NOT_SUPPORTED_NEW_ELEMENT_IN_DESCRIPTION);
|
74
|
return false;
|
75
|
}
|
76
|
|
77
|
}
|
78
|
}
|
79
|
for (Object element : descriptionElement.getInDescription().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);
|
83
|
return false;
|
84
|
}
|
85
|
|
86
|
}
|
87
|
}
|
88
|
description = descriptionElement.getInDescription();
|
89
|
description.removeElement(descriptionElement);
|
90
|
target.addElement(descriptionElement);
|
91
|
|
92
|
descriptionElements.add(descriptionElement);
|
93
|
}
|
94
|
}
|
95
|
TaxonEditor editor = null;
|
96
|
Object activePart = EditorUtil.getActivePart();
|
97
|
if (activePart instanceof FactualDataPartE4){
|
98
|
MPart selectionProvidingPart =((FactualDataPartE4)activePart).getSelectionProvidingPart();
|
99
|
Object obj = selectionProvidingPart.getObject();
|
100
|
if (obj instanceof TaxonEditor){
|
101
|
editor = (TaxonEditor) obj;
|
102
|
}
|
103
|
}
|
104
|
AbstractPostTaxonOperation operation = new MoveDescriptionElementsOperation(Messages.DescriptionElementDropAdapter_MOVE_DESC, EditorUtil.getUndoContext(), target, description, descriptionElements, isCopy, null, sync, false);
|
105
|
|
106
|
editor.getEditorInput().addOperation(operation);
|
107
|
editor.setDirty();
|
108
|
// EditorUtil.executeOperation(operation, sync);
|
109
|
return true;
|
110
|
}
|
111
|
MessagingUtils.warningDialog(OPERATION_NOT_SUPPORTED_YET, this, Messages.DescriptionElementDropAdapter_NOT_SUPPORTED_EMPTY_ELEMENT);
|
112
|
|
113
|
return false;
|
114
|
|
115
|
}
|
116
|
|
117
|
@Override
|
118
|
public boolean validateDrop(Object target, int operation,
|
119
|
TransferData transferData) {
|
120
|
boolean transferDataIsSupported = true;
|
121
|
if (target instanceof DescriptionBase){
|
122
|
if((((DescriptionBase)target).isComputed() || ((DescriptionBase)target).isCloneForSource())&& PreferencesUtil.isComputedDesciptionHandlingDisabled()){
|
123
|
transferDataIsSupported = false;
|
124
|
}
|
125
|
}
|
126
|
transferDataIsSupported = DescriptionElementTransfer.getInstance().isSupportedType(
|
127
|
transferData) && transferDataIsSupported;
|
128
|
return target instanceof DescriptionBase && transferDataIsSupported;
|
129
|
}
|
130
|
}
|