Project

General

Profile

Download (3.03 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
package eu.etaxonomy.taxeditor.editor.view.descriptive.operation;
10

    
11
import org.eclipse.core.commands.ExecutionException;
12
import org.eclipse.core.commands.operations.IUndoContext;
13
import org.eclipse.core.runtime.IAdaptable;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.IStatus;
16

    
17
import eu.etaxonomy.cdm.api.service.IDescriptionElementService;
18
import eu.etaxonomy.cdm.api.service.IDescriptionService;
19
import eu.etaxonomy.cdm.model.description.DescriptionBase;
20
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
21
import eu.etaxonomy.cdm.model.taxon.Taxon;
22
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
23
import eu.etaxonomy.taxeditor.model.MessagingUtils;
24
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
25
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
26
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28

    
29
/**
30
 * <p>DeleteDescriptionElementOperation class.</p>
31
 *
32
 * @author p.ciardelli
33
 * @created 05.02.2009
34
 */
35
public class DeleteDescriptionElementOperation extends AbstractPostTaxonOperation {
36

    
37
	private final DescriptionElementBase element;
38
	private DescriptionBase<?> description = null;
39

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

    
53
		this.element = element;
54
	}
55

    
56
	@Override
57
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
58
			throws ExecutionException {
59

    
60
		CdmStore.getService(IDescriptionElementService.class).delete(element.getUuid());
61

    
62
		monitor.worked(20);
63

    
64
		// Remove element from description
65
		if (description == null) {
66
			MessagingUtils.error(this.getClass(), Messages.DeleteDescriptionElementOperation_DESC_NOT_FOUND, null);
67
		} else {
68
			description.removeElement(element);
69
		}
70
		monitor.worked(40);
71

    
72
        // Redraw editor if exists
73
		return postExecute(element);
74
	}
75

    
76
	@Override
77
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
78
			throws ExecutionException {
79
		return execute(monitor, info);
80
	}
81

    
82
	@Override
83
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
84
			throws ExecutionException {
85

    
86
		description.addElement(element);
87

    
88
		return postExecute(element);
89
	}
90
}
(6-6/11)