Remove/Refactor System.out statements
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / descriptive / DescriptionElementDropAdapter.java
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.model.MessagingUtils;
26 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 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 if (droppedElements != null){
56 for (Object droppedElement : droppedElements) {
57 if (droppedElement == null){
58 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.");
59 return false;
60 }
61 if(! (droppedElement instanceof DescriptionElementBase)){
62 return false;
63 }else{
64 DescriptionElementBase descriptionElement = (DescriptionElementBase) droppedElement;
65
66 if (descriptionElement.getInDescription().equals(target)) {
67 return false;
68 }
69
70 descriptionElements.add(descriptionElement);
71 }
72 }
73
74 AbstractPostOperation operation = new MoveDescriptionElementsOperation("Move Descriptions", EditorUtil.getUndoContext(), target, descriptionElements, isCopy, null);
75
76 EditorUtil.executeOperation(operation);
77 return true;
78 }
79 MessagingUtils.warningDialog("Operation not supported yet", this, "We are unable to drag and drop empty descriptions");
80
81 return false;
82
83 }
84
85 /* (non-Javadoc)
86 * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
87 */
88 @Override
89 public boolean validateDrop(Object target, int operation,
90 TransferData transferData) {
91 boolean transferDataIsSupported = DescriptionElementTransfer.getInstance().isSupportedType(
92 transferData);
93 return target instanceof TaxonDescription && transferDataIsSupported;
94 }
95
96 }