7c8b588be75036e4012655907dba6e5ff7cb158b
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / key / polytomous / operation / DeleteOperation.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 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
11 package eu.etaxonomy.taxeditor.navigation.key.polytomous.operation;
12
13 import org.eclipse.core.commands.ExecutionException;
14 import org.eclipse.core.commands.operations.IUndoContext;
15 import org.eclipse.core.runtime.IAdaptable;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.jface.dialogs.MessageDialog;
19
20 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
21 import eu.etaxonomy.cdm.api.service.DeleteResult;
22 import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
23 import eu.etaxonomy.cdm.model.description.PolytomousKey;
24 import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
25 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
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 PolytomousKey key;
36
37 /**
38 * @param label
39 * @param undoContext
40 * @param postOperationEnabled
41 */
42 public DeleteOperation(String label, IUndoContext undoContext,
43 PolytomousKey key,
44 IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled) {
45 super(label, undoContext, postOperationEnabled, conversationEnabled);
46 this.key = key;
47 }
48
49 /* (non-Javadoc)
50 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
51 */
52 @Override
53 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
54 throws ExecutionException {
55 bind();
56
57 DeleteResult result = CdmStore.getService(IPolytomousKeyService.class).delete(key);
58 if (result.isError()){
59 MessageDialog.openError(null, "Delete failed", result.getExceptions().get(0).getMessage());
60
61 }else if(result.isAbort()){
62 MessageDialog.openWarning(null, "Delete abort", "The object could not be deleted, maybe there was no object selected.");
63 }
64
65 return postExecute(null);
66 }
67
68 /* (non-Javadoc)
69 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
70 */
71 @Override
72 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
73 throws ExecutionException {
74 return null;
75 }
76
77 /* (non-Javadoc)
78 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
79 */
80 @Override
81 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
82 throws ExecutionException {
83 return null;
84 }
85
86 }