Project

General

Profile

Download (2.62 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.SpecimenDescription;
20
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
21
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
22
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
23
import eu.etaxonomy.taxeditor.store.CdmStore;
24

    
25
/**
26
 *
27
 * @author pplitzner
28
 * @date Jan 15, 2015
29
 *
30
 */
31
public class DeleteSpecimenDescriptionOperation extends AbstractPostOperation<SpecimenOrObservationBase<?>> {
32

    
33
	private final SpecimenDescription description;
34

    
35
	public DeleteSpecimenDescriptionOperation(String label, IUndoContext undoContext,
36
	        SpecimenDescription description, IPostOperationEnabled postOperationEnabled) {
37
		super(label, undoContext, description.getDescribedSpecimenOrObservation(), postOperationEnabled);
38
		this.description = description;
39
	}
40

    
41
	/* (non-Javadoc)
42
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
43
	 */
44
	/** {@inheritDoc} */
45
	@Override
46
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
47
			throws ExecutionException {
48

    
49
		monitor.worked(20);
50
		element.removeDescription(description);
51
		monitor.worked(40);
52
		CdmStore.getService(IDescriptionService.class).delete(description);
53

    
54
		return postExecute(description);
55
	}
56

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

    
67
	/* (non-Javadoc)
68
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
69
	 */
70
	/** {@inheritDoc} */
71
	@Override
72
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
73
			throws ExecutionException {
74

    
75
	    element.addDescription(description);
76

    
77
		return postExecute(null);
78
	}
79
}
(6-6/10)