Project

General

Profile

Download (2.82 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.operation.e4;
10

    
11
import javax.inject.Named;
12

    
13
import org.eclipse.core.commands.operations.AbstractOperation;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.e4.core.di.annotations.Execute;
16
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
17
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
18
import org.eclipse.e4.ui.services.IServiceConstants;
19
import org.eclipse.jface.dialogs.ErrorDialog;
20
import org.eclipse.jface.viewers.TreeSelection;
21
import org.eclipse.swt.widgets.Shell;
22

    
23
import eu.etaxonomy.taxeditor.model.AbstractUtility;
24
import eu.etaxonomy.taxeditor.model.MessagingUtils;
25

    
26
/**
27
 * @author cmathew
28
 * @date 16 Jun 2015
29
 *
30
 */
31
public abstract class RemotingCdmHandlerE4 {
32

    
33
    private final String label;
34

    
35
    public RemotingCdmHandlerE4(String label) {
36
        this.label = label;
37
    }
38

    
39
    @Execute
40
    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection,
41
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
42
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
43
            MHandledMenuItem menuItem) {
44
        IStatus allowStatus = allowOperations(selection, shell, activePart, menuItem);
45
        if(allowStatus.isOK()) {
46
            AbstractOperation op = prepareOperation(selection, shell, activePart, menuItem);
47
            if(op != null) {
48
                AbstractUtility.executeOperation(op, this);
49
            }
50
        } else if(allowStatus.getSeverity() == IStatus.ERROR ||
51
                allowStatus.getSeverity() == IStatus.WARNING ||
52
                allowStatus.getSeverity() == IStatus.INFO) {
53
            MessagingUtils.warningDialog("Can not perform " + label, getTrigger(), allowStatus);
54
        }
55
        return;
56
    }
57

    
58
    public void postOperation(IStatus status) {
59

    
60
        switch(status.getSeverity()) {
61
        case IStatus.WARNING:
62
            ErrorDialog.openError(null, "Operation successful but with warnings", null, status);
63
            break;
64
        case IStatus.ERROR:
65
            ErrorDialog.openError(null, "Error executing operation", null, status);
66
            break;
67
        default:
68
        }
69

    
70
        onComplete();
71
    }
72

    
73
    public abstract IStatus allowOperations(TreeSelection selection,
74
            Shell shell,
75
            MPart activePart,
76
            MHandledMenuItem menuItem);
77

    
78
    public abstract AbstractOperation prepareOperation(TreeSelection selection,
79
            Shell shell,
80
            MPart activePart,
81
            MHandledMenuItem menuItem);
82

    
83
    public abstract void onComplete();
84

    
85
    protected abstract Object getTrigger();
86

    
87
}
    (1-1/1)