Project

General

Profile

Download (2.3 KB) Statistics
| Branch: | Tag: | Revision:
1 6c610cc5 Cherian Mathew
/**
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 ae7e2680 Cherian Mathew
import org.eclipse.core.commands.operations.AbstractOperation;
15 6c610cc5 Cherian Mathew
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.jface.dialogs.ErrorDialog;
17
18 ae7e2680 Cherian Mathew
import eu.etaxonomy.taxeditor.model.AbstractUtility;
19 6c610cc5 Cherian Mathew
import eu.etaxonomy.taxeditor.model.MessagingUtils;
20
21
/**
22
 * @author cmathew
23
 * @date 16 Jun 2015
24
 *
25
 */
26
public abstract class RemotingCdmHandler extends AbstractHandler {
27
28
    private final String label;
29
30
    public RemotingCdmHandler(String label) {
31
        this.label = label;
32
    }
33
34
    /* (non-Javadoc)
35
     * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
36
     */
37
    @Override
38
    public Object execute(ExecutionEvent event) throws ExecutionException {
39
        IStatus allowStatus = allowOperations(event);
40
        if(allowStatus.isOK()) {
41 ae7e2680 Cherian Mathew
            AbstractOperation op = prepareOperation(event);
42
            if(op != null) {
43
                AbstractUtility.executeOperation(op, this);
44
            }
45 83a1a479 Cherian Mathew
        } else if(allowStatus.getSeverity() == IStatus.ERROR ||
46
                allowStatus.getSeverity() == IStatus.WARNING ||
47
                allowStatus.getSeverity() == IStatus.INFO) {
48 6c610cc5 Cherian Mathew
            MessagingUtils.warningDialog("Can not perform " + label, event.getTrigger(), allowStatus);
49
        }
50
        return null;
51
    }
52
53 ae7e2680 Cherian Mathew
    public void postOperation(IStatus status) {
54 83a1a479 Cherian Mathew
55
        switch(status.getSeverity()) {
56
        case IStatus.WARNING:
57 8c8ead8a Cherian Mathew
            ErrorDialog.openError(null, "Operation successful but with warnings", null, status);
58 83a1a479 Cherian Mathew
            break;
59
        case IStatus.ERROR:
60
            ErrorDialog.openError(null, "Error executing operation", null, status);
61
            break;
62
        default:
63 6c610cc5 Cherian Mathew
        }
64 83a1a479 Cherian Mathew
65 ae7e2680 Cherian Mathew
        onComplete();
66 6c610cc5 Cherian Mathew
    }
67
68
    public abstract IStatus allowOperations(ExecutionEvent event);
69
70 ae7e2680 Cherian Mathew
    public abstract AbstractOperation prepareOperation(ExecutionEvent event);
71 6c610cc5 Cherian Mathew
72 ae7e2680 Cherian Mathew
    public abstract void onComplete();
73 6c610cc5 Cherian Mathew
74
}