Project

General

Profile

Download (2.34 KB) Statistics
| Branch: | Tag: | Revision:
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 final 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
	@Override
50
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
51
			throws ExecutionException {
52
		bind();
53

    
54
		DeleteResult result = CdmStore.getService(IPolytomousKeyService.class).delete(key);
55
		if (result.isError() && !result.getExceptions().isEmpty()){
56
			MessageDialog.openError(null, "Delete failed", result.getExceptions().iterator().next().getMessage());
57

    
58
		}else if(result.isAbort()){
59
			MessageDialog.openWarning(null, "Delete abort", "The object could not be deleted, maybe there was no object selected.");
60
		}
61

    
62
		return postExecute(null);
63
	}
64

    
65
	@Override
66
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
67
			throws ExecutionException {
68
		return null;
69
	}
70

    
71
	@Override
72
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
73
			throws ExecutionException {
74
		return null;
75
	}
76

    
77
}
(1-1/2)