Project

General

Profile

Download (3.19 KB) Statistics
| Branch: | Tag: | Revision:
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.editor.view.descriptive.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

    
18
import eu.etaxonomy.cdm.api.service.IDescriptionService;
19
import eu.etaxonomy.cdm.model.description.TaxonDescription;
20
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
21
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
22
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
23
import eu.etaxonomy.taxeditor.store.CdmStore;
24

    
25
/**
26
 * <p>DeleteTaxonDescriptionOperation class.</p>
27
 *
28
 * @author p.ciardelli
29
 * @author n.hoffmann
30
 * @created 05.02.2009
31
 * @version 1.0
32
 */
33
public class DeleteTaxonDescriptionOperation extends AbstractPostTaxonOperation {
34

    
35
	private final TaxonDescription description;
36

    
37
	/**
38
	 * <p>Constructor for DeleteTaxonDescriptionOperation.</p>
39
	 *
40
	 * @param label a {@link java.lang.String} object.
41
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
42
	 * @param description a {@link eu.etaxonomy.cdm.model.description.TaxonDescription} object.
43
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
44
	 */
45
	public DeleteTaxonDescriptionOperation(String label,
46
	        IUndoContext undoContext,
47
			TaxonDescription description,
48
			IPostOperationEnabled postOperationEnabled,
49
			ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
50
		super(label, undoContext, postOperationEnabled, cdmEntitySessionEnabled);
51

    
52
		this.description = description;
53
		element = description.getTaxon();
54
	}
55

    
56
	/* (non-Javadoc)
57
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
58
	 */
59
	/** {@inheritDoc} */
60
	@Override
61
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
62
			throws ExecutionException {
63

    
64
		monitor.worked(20);
65
		if (description != null){
66
		    element.removeDescription(description);
67
		    CdmStore.getService(IDescriptionService.class).deleteDescription(description.getUuid());
68
			return postExecute(description);
69
		}
70
		return null;
71

    
72
	}
73

    
74
	/* (non-Javadoc)
75
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
76
	 */
77
	/** {@inheritDoc} */
78
	@Override
79
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
80
			throws ExecutionException {
81
		return execute(monitor, info);
82
	}
83

    
84
	/* (non-Javadoc)
85
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
86
	 */
87
	/** {@inheritDoc} */
88
	@Override
89
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
90
			throws ExecutionException {
91

    
92
	    element.addDescription(description);
93

    
94
		return postExecute(null);
95
	}
96
}
(7-7/10)