ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / operation / RemotingCdmHandler.java
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.AbstractUtility;
19 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 AbstractOperation op = prepareOperation(event);
42 if(op != null) {
43 AbstractUtility.executeOperation(op, this);
44 }
45 } else if(allowStatus.getSeverity() == IStatus.ERROR ||
46 allowStatus.getSeverity() == IStatus.WARNING ||
47 allowStatus.getSeverity() == IStatus.INFO) {
48 MessagingUtils.warningDialog("Can not perform " + label, event.getTrigger(), allowStatus);
49 }
50 return null;
51 }
52
53 public void postOperation(IStatus status) {
54
55 switch(status.getSeverity()) {
56 case IStatus.WARNING:
57 ErrorDialog.openError(null, "Operation successful but with warnings", null, status);
58 break;
59 case IStatus.ERROR:
60 ErrorDialog.openError(null, "Error executing operation", null, status);
61 break;
62 default:
63 }
64
65 onComplete();
66 }
67
68 public abstract IStatus allowOperations(ExecutionEvent event);
69
70 public abstract AbstractOperation prepareOperation(ExecutionEvent event);
71
72 public abstract void onComplete();
73
74 }