1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.operation;
|
11
|
|
12
|
import org.eclipse.core.commands.AbstractHandler;
|
13
|
import org.eclipse.core.commands.ExecutionEvent;
|
14
|
import org.eclipse.core.commands.ExecutionException;
|
15
|
import org.eclipse.core.commands.operations.AbstractOperation;
|
16
|
import org.eclipse.core.runtime.IStatus;
|
17
|
import org.eclipse.jface.dialogs.ErrorDialog;
|
18
|
|
19
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
20
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
21
|
|
22
|
/**
|
23
|
* @author cmathew
|
24
|
* @date 16 Jun 2015
|
25
|
*
|
26
|
*/
|
27
|
public abstract class RemotingCdmHandler extends AbstractHandler {
|
28
|
|
29
|
private final String label;
|
30
|
|
31
|
public RemotingCdmHandler(String label) {
|
32
|
this.label = label;
|
33
|
}
|
34
|
|
35
|
/* (non-Javadoc)
|
36
|
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
37
|
*/
|
38
|
@Override
|
39
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
40
|
IStatus allowStatus = allowOperations(event);
|
41
|
if(allowStatus.isOK()) {
|
42
|
AbstractOperation op = prepareOperation(event);
|
43
|
if(op != null) {
|
44
|
AbstractUtility.executeOperation(op, this);
|
45
|
}
|
46
|
} else if(allowStatus.getSeverity() == IStatus.ERROR ||
|
47
|
allowStatus.getSeverity() == IStatus.WARNING ||
|
48
|
allowStatus.getSeverity() == IStatus.INFO) {
|
49
|
MessagingUtils.warningDialog("Can not perform " + label, event.getTrigger(), allowStatus);
|
50
|
}
|
51
|
return null;
|
52
|
}
|
53
|
|
54
|
public void postOperation(IStatus status) {
|
55
|
|
56
|
switch(status.getSeverity()) {
|
57
|
case IStatus.WARNING:
|
58
|
ErrorDialog.openError(null, "Operation successful but with warnings", null, status);
|
59
|
break;
|
60
|
case IStatus.ERROR:
|
61
|
ErrorDialog.openError(null, "Error executing operation", null, status);
|
62
|
break;
|
63
|
default:
|
64
|
}
|
65
|
|
66
|
onComplete();
|
67
|
}
|
68
|
|
69
|
public abstract IStatus allowOperations(ExecutionEvent event);
|
70
|
|
71
|
public abstract AbstractOperation prepareOperation(ExecutionEvent event);
|
72
|
|
73
|
public abstract void onComplete();
|
74
|
|
75
|
}
|