ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / key / polytomous / operation / DeleteOperation.java
1 /**
2 * Copyright (C) 2007 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
10 package eu.etaxonomy.taxeditor.navigation.key.polytomous.operation;
11
12 import org.eclipse.core.commands.ExecutionException;
13 import org.eclipse.core.commands.operations.IUndoContext;
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.jface.dialogs.MessageDialog;
18
19 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
20 import eu.etaxonomy.cdm.api.service.DeleteResult;
21 import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
22 import eu.etaxonomy.cdm.model.description.PolytomousKey;
23 import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
24 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
25 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
26 import eu.etaxonomy.taxeditor.store.CdmStore;
27
28 /**
29 * @author n.hoffmann
30 * @created Dec 2, 2010
31 * @version 1.0
32 */
33 public class DeleteOperation extends AbstractPersistentPostOperation {
34
35 private final PolytomousKey key;
36 private final ICdmEntitySessionEnabled cdmEntitySessionEnabled;
37
38
39 /**
40 * @param label
41 * @param undoContext
42 * @param postOperationEnabled
43 */
44 public DeleteOperation(String label, IUndoContext undoContext,
45 PolytomousKey key,
46 IPostOperationEnabled postOperationEnabled,
47 IConversationEnabled conversationEnabled,
48 ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
49 super(label, undoContext, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
50 this.key = key;
51 this.cdmEntitySessionEnabled = cdmEntitySessionEnabled;
52 }
53
54 @Override
55 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
56 throws ExecutionException {
57 bind();
58
59 DeleteResult result = CdmStore.getService(IPolytomousKeyService.class).delete(key);
60
61 if (result.isError() && !result.getExceptions().isEmpty()){
62 MessageDialog.openError(null, "Delete failed", result.getExceptions().iterator().next().getMessage());
63
64 }else if(result.isAbort()){
65 MessageDialog.openWarning(null, "Delete abort", "The object could not be deleted, maybe there was no object selected.");
66 }
67
68 return postExecute(null);
69 }
70
71 @Override
72 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
73 throws ExecutionException {
74 return null;
75 }
76
77 @Override
78 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
79 throws ExecutionException {
80 return null;
81 }
82
83 }