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
.store
.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
.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
;
25 * Change the homotypical group of a given synonym.
31 public class ChangeHomotypicGroupOperation
extends AbstractPostOperation
{
33 @SuppressWarnings("unused")
34 private static final Logger logger
= Logger
35 .getLogger(ChangeHomotypicGroupOperation
.class);
38 * The synonym to be moved.
40 private Synonym synonym
;
42 * The former homotypical group the synonym belonged to
44 private HomotypicalGroup oldHomotypicalGroup
;
46 * The homotypical group the synonym is to be moved to
48 private HomotypicalGroup newHomotypicalGroup
;
50 public ChangeHomotypicGroupOperation(String label
, IUndoContext undoContext
,
51 Taxon taxon
, Synonym synonym
, HomotypicalGroup newHomotypicalGroup
, IPostOperationEnabled editor
) {
52 super(label
, undoContext
, taxon
, editor
);
54 this.synonym
= synonym
;
56 throw new IllegalArgumentException(
57 "A null synonym was provided.");
60 this.oldHomotypicalGroup
= synonym
.getHomotypicGroup();
61 this.newHomotypicalGroup
= newHomotypicalGroup
;
65 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
68 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
69 throws ExecutionException
{
72 TaxonNameBase
<?
, ?
> synonymName
= this.synonym
.getName();
74 // TODO pass in homotypical group's taxon in case we are dragging from one editor to another
77 oldHomotypicalGroup
.removeTypifiedName(synonymName
);
78 newHomotypicalGroup
.addTypifiedName(synonymName
);
80 // Redraw editor if it exists
81 return postExecute(synonym
);
85 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
88 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
89 throws ExecutionException
{
90 return execute(monitor
, info
);
94 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
97 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
98 throws ExecutionException
{
101 TaxonNameBase
<?
, ?
> synonymName
= this.synonym
.getName();
102 if(synonymName
== null){
106 // TODO pass in homotypical group's taxon in case we are dragging from one editor to another
109 newHomotypicalGroup
.removeTypifiedName(synonymName
);
110 oldHomotypicalGroup
.addTypifiedName(synonymName
);
112 // Redraw editor if it exists
113 return postExecute(synonym
);