Project

General

Profile

Download (3.3 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.model.description.DescriptionBase;
19
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
20
import eu.etaxonomy.taxeditor.model.MessagingUtils;
21
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
22
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
23
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
24

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

    
34
	private final DescriptionElementBase element;
35
	private DescriptionBase description = null;
36

    
37
	/**
38
	 * <p>Constructor for DeleteDescriptionElementOperation.</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 element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
43
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
44
	 */
45
	public DeleteDescriptionElementOperation(String label, IUndoContext undoContext,
46
			DescriptionElementBase element, IPostOperationEnabled postOperationEnabled,
47
			ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
48
		super(label, undoContext, postOperationEnabled, cdmEntitySessionEnabled);
49

    
50
		this.element = element;
51
	}
52

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

    
61
		description = element.getInDescription();
62

    
63
		monitor.worked(20);
64

    
65
		// Remove element from description
66
		if (description == null) {
67
			MessagingUtils.error(this.getClass(), "Couldn't find element's description!", null);
68
		} else {
69
			description.removeElement(element);
70
		}
71
		monitor.worked(40);
72

    
73
        // Redraw editor if exists
74
		return postExecute(description);
75
	}
76

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

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

    
95
		description.addElement(element);
96

    
97
		return postExecute(element);
98
	}
99
}
(5-5/10)