Project

General

Profile

Download (2.6 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2015 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.navigation.key.polytomous.handler;
11

    
12
import java.util.List;
13

    
14
import org.eclipse.core.commands.ExecutionEvent;
15
import org.eclipse.core.commands.operations.AbstractOperation;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.Status;
18
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.ui.handlers.HandlerUtil;
20

    
21
import eu.etaxonomy.cdm.model.description.PolytomousKey;
22
import eu.etaxonomy.taxeditor.model.MessagingUtils;
23
import eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewLabels;
24
import eu.etaxonomy.taxeditor.navigation.key.polytomous.operation.RemotingPolytomousKeyDeleteOperation;
25
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
26

    
27
/**
28
 * @author cmathew
29
 * @date 25 Jun 2015
30
 *
31
 */
32
public class RemotingPolytomousKeyDeleteHandler extends RemotingCdmHandler {
33

    
34
    List<PolytomousKey> keysToDelete;
35
    /**
36
     * @param label
37
     */
38
    public RemotingPolytomousKeyDeleteHandler() {
39
        super(PolytomousKeyViewLabels.DELETE_POLYTOMOUS_KEY_LABEL);
40
    }
41

    
42
    /* (non-Javadoc)
43
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
44
     */
45
    @Override
46
    public IStatus allowOperations(ExecutionEvent event) {
47
        IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
48

    
49
        keysToDelete = selection.toList();
50

    
51
        if(keysToDelete.isEmpty()){
52
           return Status.CANCEL_STATUS;
53
        }
54

    
55
        boolean confirmation = MessagingUtils.confirmDialog("Confirm deletaion", "Do you want to delete the selected key" + (keysToDelete.size() == 1 ? "" : "s") + "?");
56

    
57
        if(!confirmation) {
58
            return Status.CANCEL_STATUS;
59
        }
60
        return Status.OK_STATUS;
61
    }
62

    
63
    /* (non-Javadoc)
64
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
65
     */
66
    @Override
67
    public AbstractOperation prepareOperation(ExecutionEvent event) {
68
        return new RemotingPolytomousKeyDeleteOperation(event.getTrigger(),
69
                false,
70
                keysToDelete);
71
    }
72

    
73
    /* (non-Javadoc)
74
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
75
     */
76
    @Override
77
    public void onComplete() {
78
        // TODO Auto-generated method stub
79

    
80
    }
81

    
82
}
(6-6/6)