Project

General

Profile

Download (3.25 KB) Statistics
| Branch: | Tag: | Revision:
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

    
10
package eu.etaxonomy.taxeditor.editor.view.descriptive;
11

    
12
import java.util.ArrayList;
13
import java.util.Collection;
14

    
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.DescriptionElementBase;
20
import eu.etaxonomy.cdm.model.description.TaxonDescription;
21
import eu.etaxonomy.taxeditor.editor.EditorUtil;
22
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
23
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.MoveDescriptionElementsOperation;
24
import eu.etaxonomy.taxeditor.model.MessagingUtils;
25
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
26
import eu.etaxonomy.taxeditor.ui.EditViewerDropAdapter;
27

    
28
/**
29
 * @author n.hoffmann
30
 * @created Feb 8, 2011
31
 * @version 1.0
32
 */
33
public class DescriptionElementDropAdapter extends EditViewerDropAdapter {
34

    
35
    private static final String OPERATION_NOT_SUPPORTED_YET = Messages.DescriptionElementDropAdapter_NOT_SUPPORTED;
36

    
37
    /**
38
	 * @param viewer
39
	 */
40
	public DescriptionElementDropAdapter(Viewer viewer) {
41
		super(viewer);
42
	}
43

    
44
	/* (non-Javadoc)
45
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
46
	 */
47
	@Override
48
	public boolean performDrop(Object data) {
49
		TaxonDescription target = (TaxonDescription) getCurrentTarget();
50
		Object[] droppedElements = (Object[]) data;
51

    
52
		Collection<DescriptionElementBase> descriptionElements = new ArrayList<DescriptionElementBase>();
53

    
54
		boolean isCopy = getCurrentOperation() == DND.DROP_COPY ? true : false;
55

    
56
		// cannot drop a feature node onto itself
57
		if (droppedElements != null){
58
			for (Object droppedElement : droppedElements) {
59
				if (droppedElement == null){
60
					MessagingUtils.warningDialog(OPERATION_NOT_SUPPORTED_YET, this, Messages.DescriptionElementDropAdapter_NOT_SUPPORTED_NEW_ELEMENT);
61
					return false;
62
				}
63
				if(! (droppedElement instanceof DescriptionElementBase)){
64
					return false;
65
				}else{
66
					DescriptionElementBase descriptionElement = (DescriptionElementBase) droppedElement;
67

    
68
					if (descriptionElement.getInDescription().equals(target)) {
69
						return false;
70
					}
71

    
72
					descriptionElements.add(descriptionElement);
73
				}
74
			}
75

    
76
			AbstractPostOperation operation = new MoveDescriptionElementsOperation(Messages.DescriptionElementDropAdapter_MOVE_DESC, EditorUtil.getUndoContext(), target, descriptionElements, isCopy, null);
77

    
78
			EditorUtil.executeOperation(operation, sync);
79
			return true;
80
		}
81
		MessagingUtils.warningDialog(OPERATION_NOT_SUPPORTED_YET, this, Messages.DescriptionElementDropAdapter_NOT_SUPPORTED_EMPTY_ELEMENT);
82

    
83
		return false;
84

    
85
	}
86

    
87
	/* (non-Javadoc)
88
	 * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
89
	 */
90
	@Override
91
	public boolean validateDrop(Object target, int operation,
92
			TransferData transferData) {
93
		boolean transferDataIsSupported = DescriptionElementTransfer.getInstance().isSupportedType(
94
				transferData);
95
		return target instanceof TaxonDescription && transferDataIsSupported;
96
	}
97

    
98
}
(2-2/7)