Refactored description editor per #577
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / operations / description / AddElementOperation.java
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.operations.description;
11
12 import org.apache.log4j.Logger;
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
19 import eu.etaxonomy.cdm.model.description.Feature;
20 import eu.etaxonomy.cdm.model.description.TaxonDescription;
21 import eu.etaxonomy.cdm.model.description.TextData;
22 import eu.etaxonomy.cdm.model.taxon.Taxon;
23 import eu.etaxonomy.taxeditor.operations.AbstractEditorOperation;
24
25 /**
26 * @author p.ciardelli
27 * @created 05.02.2009
28 * @version 1.0
29 */
30 public class AddElementOperation extends AbstractEditorOperation {
31 private static final Logger logger = Logger
32 .getLogger(AddElementOperation.class);
33
34 private TaxonDescription description;
35 private Feature feature;
36 private TextData element;
37
38 public AddElementOperation(String label, IUndoContext undoContext,
39 Taxon taxon, TaxonDescription description, Feature feature) {
40 super(label, undoContext, taxon);
41
42 this.description = description;
43 this.feature = feature;
44 }
45
46 /* (non-Javadoc)
47 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
48 */
49 @Override
50 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
51 throws ExecutionException {
52
53 element = TextData.NewInstance(feature);
54 description.addElement(element);
55
56 // Redraw editor if exists
57 return redrawOpenEditor();
58 }
59
60 /* (non-Javadoc)
61 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
62 */
63 @Override
64 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
65 throws ExecutionException {
66
67 description.addElement(element);
68
69 // Redraw editor if exists
70 return redrawOpenEditor();
71 }
72
73 /* (non-Javadoc)
74 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
75 */
76 @Override
77 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
78 throws ExecutionException {
79
80 description.removeElement(element);
81
82 // Redraw editor if exists
83 return redrawOpenEditor();
84 }
85 }