Project

General

Profile

Download (2.07 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
 * Copyright (C) 2014 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.view.derivate;
11

    
12
import org.eclipse.jface.util.LocalSelectionTransfer;
13
import org.eclipse.jface.viewers.ISelection;
14
import org.eclipse.swt.dnd.DragSourceAdapter;
15
import org.eclipse.swt.dnd.DragSourceEvent;
16

    
17
import eu.etaxonomy.taxeditor.editor.EditorUtil;
18
import eu.etaxonomy.taxeditor.model.AbstractUtility;
19

    
20
/**
21
 * @author pplitzner
22
 * @date 18.03.2014
23
 *
24
 */
25
public class DerivateDragListener extends DragSourceAdapter{
26

    
27
    private final DerivateView derivateView;
28

    
29
    /**
30
     * @param derivateView
31
     */
32
    public DerivateDragListener(DerivateView derivateView) {
33
        this.derivateView = derivateView;
34
    }
35

    
36
    /* (non-Javadoc)
37
     * @see org.eclipse.swt.dnd.DragSourceAdapter#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
38
     */
39
    @Override
40
    public void dragSetData(DragSourceEvent event) {
41
        if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) {
42
            DerivateViewSelection derivateViewSelection = new DerivateViewSelection(derivateView.getViewer().getSelection(), derivateView);
43
            LocalSelectionTransfer.getTransfer().setSelection(derivateViewSelection);
44
        }
45
    }
46

    
47
    /* (non-Javadoc)
48
     * @see org.eclipse.swt.dnd.DragSourceAdapter#dragStart(org.eclipse.swt.dnd.DragSourceEvent)
49
     */
50
    @Override
51
    public void dragStart(DragSourceEvent event) {
52
        if(derivateView.isDirty()){
53
            event.doit = false;
54
            AbstractUtility.warningDialog("View has unsaved changes", this, "You need to save before performing this action");
55
            return;
56
        }
57
        ISelection selection = derivateView.getViewer().getSelection();
58
        if(EditorUtil.getTreeNodeOfSelection(selection)!=null){
59
            event.doit = true;
60
        }
61
        else{
62
            event.doit = false;
63
        }
64
    }
65
}
(2-2/6)