2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.operation
.e4
;
11 import javax
.inject
.Named
;
13 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
14 import org
.eclipse
.core
.runtime
.IStatus
;
15 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
16 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
17 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
18 import org
.eclipse
.jface
.dialogs
.ErrorDialog
;
19 import org
.eclipse
.jface
.viewers
.TreeSelection
;
20 import org
.eclipse
.swt
.widgets
.Shell
;
22 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
23 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
30 public abstract class RemotingCdmHandlerE4
{
32 private final String label
;
34 public RemotingCdmHandlerE4(String label
) {
38 public void execute(@Named(IServiceConstants
.ACTIVE_SELECTION
)TreeSelection selection
,
39 @Named(IServiceConstants
.ACTIVE_SHELL
)Shell shell
,
40 @Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
41 MHandledMenuItem menuItem
) {
42 IStatus allowStatus
= allowOperations(selection
, shell
, activePart
, menuItem
);
43 if(allowStatus
.isOK()) {
44 AbstractOperation op
= prepareOperation(selection
, shell
, activePart
, menuItem
);
46 AbstractUtility
.executeOperation(op
, this);
48 } else if(allowStatus
.getSeverity() == IStatus
.ERROR
||
49 allowStatus
.getSeverity() == IStatus
.WARNING
||
50 allowStatus
.getSeverity() == IStatus
.INFO
) {
51 MessagingUtils
.warningDialog("Can not perform " + label
, getTrigger(), allowStatus
);
56 public void postOperation(IStatus status
) {
58 switch(status
.getSeverity()) {
60 ErrorDialog
.openError(null, "Operation successful but with warnings", null, status
);
63 ErrorDialog
.openError(null, "Error executing operation", null, status
);
71 public abstract IStatus
allowOperations(TreeSelection selection
,
74 MHandledMenuItem menuItem
);
76 public abstract AbstractOperation
prepareOperation(TreeSelection selection
,
79 MHandledMenuItem menuItem
);
81 public abstract void onComplete();
83 protected abstract Object
getTrigger();