Project

General

Profile

Download (3.39 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.EModelService;
22
import org.eclipse.e4.ui.workbench.modeling.EPartService;
23
import org.eclipse.jface.dialogs.ErrorDialog;
24
import org.eclipse.jface.viewers.IStructuredSelection;
25
import org.eclipse.swt.widgets.Shell;
26

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

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

    
37
    protected String label;
38
    protected EPartService partService;
39
	protected MApplication application;
40
	protected EModelService modelService;
41

    
42
    public RemotingCdmHandlerE4(String label) {
43
        this.label = label;
44
    }
45

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

    
68
    public void postOperation(IStatus status) {
69

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

    
80
        onComplete();
81
    }
82

    
83
    public abstract IStatus allowOperations(IStructuredSelection selection,
84
            Shell shell,
85
            MPart activePart,
86
            MHandledMenuItem menuItem);
87

    
88
    public abstract AbstractOperation prepareOperation(IStructuredSelection selection,
89
            Shell shell,
90
            MPart activePart,
91
            MHandledMenuItem menuItem);
92

    
93
    public abstract void onComplete();
94

    
95
    protected abstract Object getTrigger();
96

    
97
}
    (1-1/1)