Project

General

Profile

Download (3.22 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.di.UISynchronize;
17
import org.eclipse.e4.ui.model.application.MApplication;
18
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
19
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
20
import org.eclipse.e4.ui.services.IServiceConstants;
21
import org.eclipse.e4.ui.workbench.modeling.EPartService;
22
import org.eclipse.jface.dialogs.ErrorDialog;
23
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.swt.widgets.Shell;
25

    
26
import eu.etaxonomy.taxeditor.model.AbstractUtility;
27
import eu.etaxonomy.taxeditor.model.MessagingUtils;
28

    
29
/**
30
 * @author cmathew
31
 * @date 16 Jun 2015
32
 *
33
 */
34
public abstract class RemotingCdmHandlerE4 {
35

    
36
    protected String label;
37
    protected EPartService partService;
38
	protected MApplication application;
39

    
40
    public RemotingCdmHandlerE4(String label) {
41
        this.label = label;
42
    }
43

    
44
    @Execute
45
    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
46
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
47
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
48
            MHandledMenuItem menuItem, EPartService partService, UISynchronize sync, MApplication application) {
49
        this.partService = partService;
50
        this.application = application;
51
        IStatus allowStatus = allowOperations(selection, shell, activePart, menuItem);
52
        if(allowStatus.isOK()) {
53
            AbstractOperation op = prepareOperation(selection, shell, activePart, menuItem);
54
            if(op != null) {
55
                AbstractUtility.executeOperation(op, this, sync);
56
            }
57
        } else if(allowStatus.getSeverity() == IStatus.ERROR ||
58
                allowStatus.getSeverity() == IStatus.WARNING ||
59
                allowStatus.getSeverity() == IStatus.INFO) {
60
            MessagingUtils.warningDialog("Can not perform " + label, getTrigger(), allowStatus);
61
        }
62
        return;
63
    }
64

    
65
    public void postOperation(IStatus status) {
66

    
67
        switch(status.getSeverity()) {
68
        case IStatus.WARNING:
69
            ErrorDialog.openError(null, "Operation successful but with warnings", null, status);
70
            break;
71
        case IStatus.ERROR:
72
            ErrorDialog.openError(null, "Error executing operation", null, status);
73
            break;
74
        default:
75
        }
76

    
77
        onComplete();
78
    }
79

    
80
    public abstract IStatus allowOperations(IStructuredSelection selection,
81
            Shell shell,
82
            MPart activePart,
83
            MHandledMenuItem menuItem);
84

    
85
    public abstract AbstractOperation prepareOperation(IStructuredSelection selection,
86
            Shell shell,
87
            MPart activePart,
88
            MHandledMenuItem menuItem);
89

    
90
    public abstract void onComplete();
91

    
92
    protected abstract Object getTrigger();
93

    
94
}
    (1-1/1)