1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.editor.view.descriptive;
|
12
|
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.Collection;
|
15
|
|
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;
|
20
|
|
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.operation.AbstractPostOperation;
|
26
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
27
|
|
28
|
/**
|
29
|
* @author n.hoffmann
|
30
|
* @created Feb 8, 2011
|
31
|
* @version 1.0
|
32
|
*/
|
33
|
public class DescriptionElementDropAdapter extends ViewerDropAdapter {
|
34
|
|
35
|
/**
|
36
|
* @param viewer
|
37
|
*/
|
38
|
public DescriptionElementDropAdapter(Viewer viewer) {
|
39
|
super(viewer);
|
40
|
}
|
41
|
|
42
|
/* (non-Javadoc)
|
43
|
* @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
|
44
|
*/
|
45
|
@Override
|
46
|
public boolean performDrop(Object data) {
|
47
|
TaxonDescription target = (TaxonDescription) getCurrentTarget();
|
48
|
Object[] droppedElements = (Object[]) data;
|
49
|
|
50
|
Collection<DescriptionElementBase> descriptionElements = new ArrayList<DescriptionElementBase>();
|
51
|
|
52
|
boolean isCopy = getCurrentOperation() == DND.DROP_COPY ? true : false;
|
53
|
|
54
|
// cannot drop a feature node onto itself
|
55
|
for (Object droppedElement : droppedElements) {
|
56
|
if (droppedElement == null){
|
57
|
StoreUtil.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.");
|
58
|
return false;
|
59
|
}
|
60
|
if(! (droppedElement instanceof DescriptionElementBase)){
|
61
|
return false;
|
62
|
}else{
|
63
|
DescriptionElementBase descriptionElement = (DescriptionElementBase) droppedElement;
|
64
|
|
65
|
if (descriptionElement.getInDescription().equals(target)) {
|
66
|
return false;
|
67
|
}
|
68
|
|
69
|
descriptionElements.add(descriptionElement);
|
70
|
}
|
71
|
}
|
72
|
|
73
|
AbstractPostOperation operation = new MoveDescriptionElementsOperation("Move Descriptions", EditorUtil.getUndoContext(), target, descriptionElements, isCopy, null);
|
74
|
|
75
|
EditorUtil.executeOperation(operation);
|
76
|
|
77
|
return true;
|
78
|
}
|
79
|
|
80
|
/* (non-Javadoc)
|
81
|
* @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
|
82
|
*/
|
83
|
@Override
|
84
|
public boolean validateDrop(Object target, int operation,
|
85
|
TransferData transferData) {
|
86
|
boolean transferDataIsSupported = DescriptionElementTransfer.getInstance().isSupportedType(
|
87
|
transferData);
|
88
|
System.out.println(target);
|
89
|
return target instanceof TaxonDescription && transferDataIsSupported;
|
90
|
}
|
91
|
|
92
|
}
|