1 |
840d4d5d
|
n.hoffmann
|
/**
|
2 |
|
|
* Copyright (C) 2007 EDIT
|
3 |
7d3bda1d
|
Patrick Plitzner
|
* European Distributed Institute of Taxonomy
|
4 |
840d4d5d
|
n.hoffmann
|
* http://www.e-taxonomy.eu
|
5 |
7d3bda1d
|
Patrick Plitzner
|
*
|
6 |
840d4d5d
|
n.hoffmann
|
* 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 |
|
|
|
10 |
|
|
package eu.etaxonomy.taxeditor.editor.view.descriptive;
|
11 |
|
|
|
12 |
|
|
import java.util.ArrayList;
|
13 |
|
|
import java.util.Collection;
|
14 |
|
|
|
15 |
81783422
|
Katja Luther
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
16 |
840d4d5d
|
n.hoffmann
|
import org.eclipse.jface.viewers.Viewer;
|
17 |
|
|
import org.eclipse.swt.dnd.DND;
|
18 |
|
|
import org.eclipse.swt.dnd.TransferData;
|
19 |
|
|
|
20 |
81783422
|
Katja Luther
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
21 |
840d4d5d
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
22 |
|
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
23 |
|
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
24 |
150b624d
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
25 |
81783422
|
Katja Luther
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
26 |
|
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
|
27 |
840d4d5d
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.MoveDescriptionElementsOperation;
|
28 |
41e2f693
|
Cherian Mathew
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
29 |
81783422
|
Katja Luther
|
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
|
30 |
b5b429af
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.ui.EditViewerDropAdapter;
|
31 |
840d4d5d
|
n.hoffmann
|
|
32 |
|
|
/**
|
33 |
|
|
* @author n.hoffmann
|
34 |
|
|
* @created Feb 8, 2011
|
35 |
|
|
* @version 1.0
|
36 |
|
|
*/
|
37 |
b5b429af
|
Patrick Plitzner
|
public class DescriptionElementDropAdapter extends EditViewerDropAdapter {
|
38 |
840d4d5d
|
n.hoffmann
|
|
39 |
150b624d
|
Patrick Plitzner
|
private static final String OPERATION_NOT_SUPPORTED_YET = Messages.DescriptionElementDropAdapter_NOT_SUPPORTED;
|
40 |
|
|
|
41 |
81783422
|
Katja Luther
|
|
42 |
|
|
|
43 |
150b624d
|
Patrick Plitzner
|
/**
|
44 |
840d4d5d
|
n.hoffmann
|
* @param viewer
|
45 |
|
|
*/
|
46 |
953c844d
|
a.theys
|
public DescriptionElementDropAdapter(Viewer viewer) {
|
47 |
840d4d5d
|
n.hoffmann
|
super(viewer);
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
/* (non-Javadoc)
|
51 |
|
|
* @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
|
52 |
|
|
*/
|
53 |
|
|
@Override
|
54 |
|
|
public boolean performDrop(Object data) {
|
55 |
|
|
TaxonDescription target = (TaxonDescription) getCurrentTarget();
|
56 |
|
|
Object[] droppedElements = (Object[]) data;
|
57 |
7d3bda1d
|
Patrick Plitzner
|
|
58 |
840d4d5d
|
n.hoffmann
|
Collection<DescriptionElementBase> descriptionElements = new ArrayList<DescriptionElementBase>();
|
59 |
7d3bda1d
|
Patrick Plitzner
|
|
60 |
840d4d5d
|
n.hoffmann
|
boolean isCopy = getCurrentOperation() == DND.DROP_COPY ? true : false;
|
61 |
c87fb375
|
Katja Luther
|
DescriptionBase<?> description = null;
|
62 |
840d4d5d
|
n.hoffmann
|
// cannot drop a feature node onto itself
|
63 |
d0a4b949
|
Katja Luther
|
if (droppedElements != null){
|
64 |
7d3bda1d
|
Patrick Plitzner
|
for (Object droppedElement : droppedElements) {
|
65 |
d0a4b949
|
Katja Luther
|
if (droppedElement == null){
|
66 |
150b624d
|
Patrick Plitzner
|
MessagingUtils.warningDialog(OPERATION_NOT_SUPPORTED_YET, this, Messages.DescriptionElementDropAdapter_NOT_SUPPORTED_NEW_ELEMENT);
|
67 |
840d4d5d
|
n.hoffmann
|
return false;
|
68 |
|
|
}
|
69 |
d0a4b949
|
Katja Luther
|
if(! (droppedElement instanceof DescriptionElementBase)){
|
70 |
|
|
return false;
|
71 |
|
|
}else{
|
72 |
|
|
DescriptionElementBase descriptionElement = (DescriptionElementBase) droppedElement;
|
73 |
7d3bda1d
|
Patrick Plitzner
|
|
74 |
d0a4b949
|
Katja Luther
|
if (descriptionElement.getInDescription().equals(target)) {
|
75 |
|
|
return false;
|
76 |
|
|
}
|
77 |
c87fb375
|
Katja Luther
|
description = descriptionElement.getInDescription();
|
78 |
81783422
|
Katja Luther
|
description.removeElement(descriptionElement);
|
79 |
|
|
target.addElement(descriptionElement);
|
80 |
7d3bda1d
|
Patrick Plitzner
|
|
81 |
81783422
|
Katja Luther
|
if (description.getElements().isEmpty()){
|
82 |
|
|
((TaxonDescription)description).getTaxon().removeDescription((TaxonDescription)description, false);
|
83 |
|
|
}
|
84 |
d0a4b949
|
Katja Luther
|
descriptionElements.add(descriptionElement);
|
85 |
7d3bda1d
|
Patrick Plitzner
|
}
|
86 |
d0a4b949
|
Katja Luther
|
}
|
87 |
81783422
|
Katja Luther
|
TaxonNameEditorE4 editor = null;
|
88 |
|
|
Object activePart = EditorUtil.getActivePart();
|
89 |
|
|
if (activePart instanceof FactualDataPartE4){
|
90 |
c87fb375
|
Katja Luther
|
MPart selectionProvidingPart =((FactualDataPartE4)activePart).getSelectionProvidingPart();
|
91 |
81783422
|
Katja Luther
|
Object obj = selectionProvidingPart.getObject();
|
92 |
|
|
if (obj instanceof TaxonNameEditorE4){
|
93 |
|
|
editor = (TaxonNameEditorE4) obj;
|
94 |
|
|
}
|
95 |
|
|
}
|
96 |
c87fb375
|
Katja Luther
|
AbstractPostTaxonOperation operation = new MoveDescriptionElementsOperation(Messages.DescriptionElementDropAdapter_MOVE_DESC, EditorUtil.getUndoContext(), target, description, descriptionElements, isCopy, null, sync);
|
97 |
7d3bda1d
|
Patrick Plitzner
|
|
98 |
81783422
|
Katja Luther
|
editor.getEditorInput().addOperation(operation);
|
99 |
|
|
editor.setDirty();
|
100 |
|
|
// EditorUtil.executeOperation(operation, sync);
|
101 |
d0a4b949
|
Katja Luther
|
return true;
|
102 |
840d4d5d
|
n.hoffmann
|
}
|
103 |
150b624d
|
Patrick Plitzner
|
MessagingUtils.warningDialog(OPERATION_NOT_SUPPORTED_YET, this, Messages.DescriptionElementDropAdapter_NOT_SUPPORTED_EMPTY_ELEMENT);
|
104 |
7d3bda1d
|
Patrick Plitzner
|
|
105 |
d0a4b949
|
Katja Luther
|
return false;
|
106 |
7d3bda1d
|
Patrick Plitzner
|
|
107 |
840d4d5d
|
n.hoffmann
|
}
|
108 |
|
|
|
109 |
|
|
/* (non-Javadoc)
|
110 |
|
|
* @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
|
111 |
|
|
*/
|
112 |
|
|
@Override
|
113 |
|
|
public boolean validateDrop(Object target, int operation,
|
114 |
|
|
TransferData transferData) {
|
115 |
|
|
boolean transferDataIsSupported = DescriptionElementTransfer.getInstance().isSupportedType(
|
116 |
|
|
transferData);
|
117 |
|
|
return target instanceof TaxonDescription && transferDataIsSupported;
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
}
|