1 |
840d4d5d
|
n.hoffmann
|
// $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 |
41e2f693
|
Cherian Mathew
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
26 |
840d4d5d
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
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 |
953c844d
|
a.theys
|
public DescriptionElementDropAdapter(Viewer viewer) {
|
39 |
840d4d5d
|
n.hoffmann
|
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 |
41e2f693
|
Cherian Mathew
|
MessagingUtils.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 |
840d4d5d
|
n.hoffmann
|
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 |
c1c463d7
|
Katja Luther
|
|
78 |
840d4d5d
|
n.hoffmann
|
return true;
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
/* (non-Javadoc)
|
82 |
|
|
* @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
|
83 |
|
|
*/
|
84 |
|
|
@Override
|
85 |
|
|
public boolean validateDrop(Object target, int operation,
|
86 |
|
|
TransferData transferData) {
|
87 |
|
|
boolean transferDataIsSupported = DescriptionElementTransfer.getInstance().isSupportedType(
|
88 |
|
|
transferData);
|
89 |
fee5e282
|
n.hoffmann
|
System.out.println(target);
|
90 |
840d4d5d
|
n.hoffmann
|
return target instanceof TaxonDescription && transferDataIsSupported;
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
}
|