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
;
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
.DescriptionElementBase
;
20 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
28 public class DeleteDescriptionElementOperation
extends AbstractPostOperation
{
29 private static final Logger logger
= Logger
30 .getLogger(DeleteDescriptionElementOperation
.class);
32 private DescriptionElementBase element
;
33 private TaxonDescription description
= null;
35 public DeleteDescriptionElementOperation(String label
, IUndoContext undoContext
,
36 Taxon taxon
, DescriptionElementBase element
, IPostOperationEnabled postOperationEnabled
) {
37 super(label
, undoContext
, taxon
, postOperationEnabled
);
39 this.element
= element
;
43 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
46 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
47 throws ExecutionException
{
49 // Find description to which element belongs
50 for (TaxonDescription descr
: taxon
.getDescriptions()) {
51 for (DescriptionElementBase elem
: descr
.getElements()) {
52 if (elem
.equals(element
)) {
59 // Remove element from description
60 if (description
== null) {
61 logger
.error("Couldn't find element's description!");
63 description
.removeElement(element
);
66 // Redraw editor if exists
67 return postExecute(null);
71 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
74 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
75 throws ExecutionException
{
76 return execute(monitor
, info
);
80 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
83 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
84 throws ExecutionException
{
86 description
.addElement(element
);
88 return postExecute(element
);