8744410156e8faf0c1182b8758c19fc982a8d25e
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / editor / definedterm / DefinedTermDropAdapter.java
1 // $Id$
2 /**
3 * Copyright (C) 2009 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 package eu.etaxonomy.taxeditor.editor.definedterm;
11
12 import java.util.ArrayList;
13 import java.util.Collection;
14
15 import org.eclipse.jface.viewers.ViewerDropAdapter;
16 import org.eclipse.swt.dnd.TransferData;
17
18 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
19 import eu.etaxonomy.cdm.model.common.TermBase;
20 import eu.etaxonomy.taxeditor.editor.definedterm.operation.MoveDefinedTermOperation;
21 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
22 import eu.etaxonomy.taxeditor.store.StoreUtil;
23
24 /**
25 * @author l.morris
26 * @date 10 Jan 2012
27 *
28 */
29 public class DefinedTermDropAdapter extends ViewerDropAdapter {
30
31 private DefinedTermEditor editor;
32 /**
33 * @param viewer
34 */
35 protected DefinedTermDropAdapter(DefinedTermEditor editor) {
36 super(editor.getViewer());
37 this.editor = editor;
38 }
39
40 /* (non-Javadoc)
41 * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
42 */
43 @Override
44 public boolean performDrop(Object data) {
45
46 TermBase target = (TermBase) getCurrentTarget();//can be vocab
47 //DefinedTermBase[] droppedElements = (DefinedTermBase[]) data;
48 Object[] droppedTerms = (Object[]) data;
49 Collection<DefinedTermBase> sourceTerms = new ArrayList<DefinedTermBase>(); //Arrays.asList(droppedElements)
50
51 for (Object droppedTerm : droppedTerms) {
52
53 DefinedTermBase term = (DefinedTermBase) droppedTerm;
54 sourceTerms.add(term);
55
56 }
57
58 AbstractPostOperation operation = new MoveDefinedTermOperation("Move Descriptions", StoreUtil.getUndoContext(), target, sourceTerms, editor);
59 //TODO: implement execute
60 StoreUtil.executeOperation(operation);
61
62 return true;
63 }
64
65 /* (non-Javadoc)
66 * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
67 */
68 @Override
69 public boolean validateDrop(Object target, int operation,
70 TransferData transferType) {
71 boolean transferDataIsSupported = TermTransfer.getInstance().isSupportedType(transferType);
72 System.out.println(target);
73 // maybe don't need this - they will be all TermBase anyway
74 return target instanceof TermBase && transferDataIsSupported;
75 }
76
77 }