Project

General

Profile

Download (2.25 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;
10

    
11
import org.eclipse.core.commands.AbstractHandler;
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.core.commands.ExecutionException;
14
import org.eclipse.core.commands.operations.AbstractOperation;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.jface.dialogs.ErrorDialog;
17

    
18
import eu.etaxonomy.taxeditor.model.MessagingUtils;
19

    
20
/**
21
 * @author cmathew
22
 * @date 16 Jun 2015
23
 *
24
 */
25
public abstract class RemotingCdmHandler extends AbstractHandler {
26

    
27
    private final String label;
28

    
29
    public RemotingCdmHandler(String label) {
30
        this.label = label;
31
    }
32

    
33
    /* (non-Javadoc)
34
     * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
35
     */
36
    @Override
37
    public Object execute(ExecutionEvent event) throws ExecutionException {
38
        IStatus allowStatus = allowOperations(event);
39
        if(allowStatus.isOK()) {
40
            AbstractOperation op = prepareOperation(event);
41
            if(op != null) {
42
//                AbstractUtility.executeOperation(op, this);
43
            }
44
        } else if(allowStatus.getSeverity() == IStatus.ERROR ||
45
                allowStatus.getSeverity() == IStatus.WARNING ||
46
                allowStatus.getSeverity() == IStatus.INFO) {
47
            MessagingUtils.warningDialog("Can not perform " + label, event.getTrigger(), allowStatus);
48
        }
49
        return null;
50
    }
51

    
52
    public void postOperation(IStatus status) {
53

    
54
        switch(status.getSeverity()) {
55
        case IStatus.WARNING:
56
            ErrorDialog.openError(null, "Operation successful but with warnings", null, status);
57
            break;
58
        case IStatus.ERROR:
59
            ErrorDialog.openError(null, "Error executing operation", null, status);
60
            break;
61
        default:
62
        }
63

    
64
        onComplete();
65
    }
66

    
67
    public abstract IStatus allowOperations(ExecutionEvent event);
68

    
69
    public abstract AbstractOperation prepareOperation(ExecutionEvent event);
70

    
71
    public abstract void onComplete();
72

    
73
}
(10-10/12)