Project

General

Profile

Download (3.72 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2015 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
package eu.etaxonomy.taxeditor.navigation.key.polytomous.e4.handler;
10

    
11
import java.util.List;
12
import java.util.UUID;
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.IEditorInput;
20
import org.eclipse.ui.IEditorReference;
21
import org.eclipse.ui.IWorkbenchPage;
22
import org.eclipse.ui.PartInitException;
23
import org.eclipse.ui.handlers.HandlerUtil;
24

    
25
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorInput;
26
import eu.etaxonomy.taxeditor.model.MessagingUtils;
27
import eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewLabels;
28
import eu.etaxonomy.taxeditor.navigation.key.polytomous.operation.RemotingDeletePolytomousKeyOperation;
29
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
30
import eu.etaxonomy.taxeditor.util.OperationsUtil;
31

    
32
/**
33
 * @author cmathew
34
 * @date 25 Jun 2015
35
 *
36
 */
37
public class RemotingDeletePolytomousKeyHandlerE4 extends RemotingCdmHandler {
38

    
39
    List<UUID> keysToDelete;
40
    /**
41
     * @param label
42
     */
43
    public RemotingDeletePolytomousKeyHandlerE4() {
44
        super(PolytomousKeyViewLabels.DELETE_POLYTOMOUS_KEY_LABEL);
45
    }
46

    
47
    /* (non-Javadoc)
48
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
49
     */
50
    @Override
51
    public IStatus allowOperations(ExecutionEvent event) {
52
        IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
53

    
54
        keysToDelete = OperationsUtil.convertToUuidList(selection.toList());
55

    
56
        if(keysToDelete.isEmpty()){
57
           return Status.CANCEL_STATUS;
58
        }
59

    
60
        boolean confirmation = MessagingUtils.confirmDialog(DeleteHandler.CONFIRM, DeleteHandler.CONFIRM_MESSAGE);
61

    
62
        if(!confirmation) {
63
            return Status.CANCEL_STATUS;
64
        }
65
        closeObsoleteEditor(event);
66
        return Status.OK_STATUS;
67
    }
68

    
69
    /* (non-Javadoc)
70
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
71
     */
72
    @Override
73
    public AbstractOperation prepareOperation(ExecutionEvent event) {
74
        return new RemotingDeletePolytomousKeyOperation(event.getTrigger(),
75
                false,
76
                keysToDelete);
77
    }
78

    
79
    /* (non-Javadoc)
80
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
81
     */
82
    @Override
83
    public void onComplete() {
84
        // TODO Auto-generated method stub
85

    
86
    }
87
    protected boolean closeObsoleteEditor(ExecutionEvent event){
88
        boolean result = true;
89
        IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
90

    
91
        for (IEditorReference ref : activePage.getEditorReferences()) {
92
            try {
93
                IEditorInput input = ref.getEditorInput();
94
                if (input instanceof PolytomousKeyEditorInput) {
95
                    UUID uuidForKey = ((PolytomousKeyEditorInput) input).getKey().getUuid();
96
                    for (UUID keyUuid :keysToDelete) {
97
                        if( uuidForKey.equals(keyUuid)){
98
                            result &= activePage.closeEditor(ref.getEditor(false), false);
99
                        }
100
                    }
101

    
102
                }
103
            } catch (PartInitException e) {
104
                continue;
105
            }
106
        }
107
        return result;
108
    }
109

    
110
}
(4-4/6)