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
.name
;
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
.name
.HomotypicalGroup
;
20 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
23 import eu
.etaxonomy
.taxeditor
.operations
.AbstractEditorOperation
;
26 * Change a the homotypical group for a given synonym.
32 public class ChangeHomotypicGroupOperation
extends AbstractEditorOperation
{
34 @SuppressWarnings("unused")
35 private static final Logger logger
= Logger
36 .getLogger(ChangeHomotypicGroupOperation
.class);
39 * The synonym to be moved.
41 private Synonym synonym
;
43 * The former homotypical group the synonym belonged to
45 private HomotypicalGroup oldHomotypicalGroup
;
47 * The homotypical group the synonym is to be moved to
49 private HomotypicalGroup newHomotypicalGroup
;
51 public ChangeHomotypicGroupOperation(String label
, IUndoContext undoContext
,
52 Taxon taxon
, Synonym synonym
, HomotypicalGroup newHomotypicalGroup
) {
53 super(label
, undoContext
, taxon
);
55 this.synonym
= synonym
;
57 throw new IllegalArgumentException(
58 "A null synonym was provided.");
61 this.oldHomotypicalGroup
= synonym
.getHomotypicGroup();
62 this.newHomotypicalGroup
= newHomotypicalGroup
;
66 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
69 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
70 throws ExecutionException
{
73 TaxonNameBase synonymName
= this.synonym
.getName();
75 // TODO pass in homotypical group's taxon in case we are dragging from one editor to another
78 oldHomotypicalGroup
.removeTypifiedName(synonymName
);
79 newHomotypicalGroup
.addTypifiedName(synonymName
);
81 // Redraw editor if it exists
82 return redrawOpenEditor();
86 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
89 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
90 throws ExecutionException
{
91 return execute(monitor
, info
);
95 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
98 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
99 throws ExecutionException
{
102 TaxonNameBase synonymName
= this.synonym
.getName();
103 if(synonymName
== null){
107 // TODO pass in homotypical group's taxon in case we are dragging from one editor to another
110 newHomotypicalGroup
.removeTypifiedName(synonymName
);
111 oldHomotypicalGroup
.addTypifiedName(synonymName
);
113 // Redraw editor if it exists
114 return redrawOpenEditor();