Project

General

Profile

Download (3 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.e4.ui.workbench.modeling.EPartService;
20
import org.eclipse.jface.dialogs.ErrorDialog;
21
import org.eclipse.jface.viewers.IStructuredSelection;
22
import org.eclipse.swt.widgets.Shell;
23

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

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

    
34
    protected String label;
35
    protected EPartService partService;
36

    
37
    public RemotingCdmHandlerE4(String label) {
38
        this.label = label;
39
    }
40

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

    
61
    public void postOperation(IStatus status) {
62

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

    
73
        onComplete();
74
    }
75

    
76
    public abstract IStatus allowOperations(IStructuredSelection selection,
77
            Shell shell,
78
            MPart activePart,
79
            MHandledMenuItem menuItem);
80

    
81
    public abstract AbstractOperation prepareOperation(IStructuredSelection selection,
82
            Shell shell,
83
            MPart activePart,
84
            MHandledMenuItem menuItem);
85

    
86
    public abstract void onComplete();
87

    
88
    protected abstract Object getTrigger();
89

    
90
}
    (1-1/1)