2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.operations
.description
;
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
;
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
;
30 public class AddElementOperation
extends AbstractEditorOperation
{
31 private static final Logger logger
= Logger
32 .getLogger(AddElementOperation
.class);
34 private TaxonDescription description
;
35 private Feature feature
;
36 private TextData element
;
38 public AddElementOperation(String label
, IUndoContext undoContext
,
39 Taxon taxon
, TaxonDescription description
, Feature feature
) {
40 super(label
, undoContext
, taxon
);
42 this.description
= description
;
43 this.feature
= feature
;
47 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
50 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
51 throws ExecutionException
{
53 element
= TextData
.NewInstance(feature
);
54 description
.addElement(element
);
56 // Redraw editor if exists
57 return redrawOpenEditor();
61 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
64 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
65 throws ExecutionException
{
67 description
.addElement(element
);
69 // Redraw editor if exists
70 return redrawOpenEditor();
74 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
77 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
78 throws ExecutionException
{
80 description
.removeElement(element
);
82 // Redraw editor if exists
83 return redrawOpenEditor();