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.Inject;
|
12
|
import javax.inject.Named;
|
13
|
|
14
|
import org.eclipse.core.commands.operations.AbstractOperation;
|
15
|
import org.eclipse.core.runtime.IStatus;
|
16
|
import org.eclipse.e4.core.di.annotations.Execute;
|
17
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
18
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
19
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
20
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
21
|
import org.eclipse.jface.dialogs.ErrorDialog;
|
22
|
import org.eclipse.jface.viewers.TreeSelection;
|
23
|
import org.eclipse.swt.widgets.Shell;
|
24
|
|
25
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
26
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
27
|
|
28
|
/**
|
29
|
* @author cmathew
|
30
|
* @date 16 Jun 2015
|
31
|
*
|
32
|
*/
|
33
|
public abstract class RemotingCdmHandlerE4 {
|
34
|
|
35
|
private final String label;
|
36
|
@Inject
|
37
|
protected EPartService partService;
|
38
|
|
39
|
public RemotingCdmHandlerE4(String label) {
|
40
|
this.label = label;
|
41
|
}
|
42
|
|
43
|
@Execute
|
44
|
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection,
|
45
|
@Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
|
46
|
@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
47
|
MHandledMenuItem menuItem) {
|
48
|
IStatus allowStatus = allowOperations(selection, shell, activePart, menuItem);
|
49
|
if(allowStatus.isOK()) {
|
50
|
AbstractOperation op = prepareOperation(selection, shell, activePart, menuItem);
|
51
|
if(op != null) {
|
52
|
AbstractUtility.executeOperation(op, this);
|
53
|
}
|
54
|
} else if(allowStatus.getSeverity() == IStatus.ERROR ||
|
55
|
allowStatus.getSeverity() == IStatus.WARNING ||
|
56
|
allowStatus.getSeverity() == IStatus.INFO) {
|
57
|
MessagingUtils.warningDialog("Can not perform " + label, getTrigger(), allowStatus);
|
58
|
}
|
59
|
return;
|
60
|
}
|
61
|
|
62
|
public void postOperation(IStatus status) {
|
63
|
|
64
|
switch(status.getSeverity()) {
|
65
|
case IStatus.WARNING:
|
66
|
ErrorDialog.openError(null, "Operation successful but with warnings", null, status);
|
67
|
break;
|
68
|
case IStatus.ERROR:
|
69
|
ErrorDialog.openError(null, "Error executing operation", null, status);
|
70
|
break;
|
71
|
default:
|
72
|
}
|
73
|
|
74
|
onComplete();
|
75
|
}
|
76
|
|
77
|
public abstract IStatus allowOperations(TreeSelection selection,
|
78
|
Shell shell,
|
79
|
MPart activePart,
|
80
|
MHandledMenuItem menuItem);
|
81
|
|
82
|
public abstract AbstractOperation prepareOperation(TreeSelection selection,
|
83
|
Shell shell,
|
84
|
MPart activePart,
|
85
|
MHandledMenuItem menuItem);
|
86
|
|
87
|
public abstract void onComplete();
|
88
|
|
89
|
protected abstract Object getTrigger();
|
90
|
|
91
|
}
|