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
.actions
.ui
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.core
.runtime
.IStatus
;
14 import org
.eclipse
.core
.runtime
.Status
;
15 import org
.eclipse
.jface
.action
.Action
;
16 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
17 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
18 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
19 import org
.eclipse
.ui
.IEditorPart
;
20 import org
.eclipse
.ui
.PartInitException
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
24 import eu
.etaxonomy
.taxeditor
.ITaxEditorConstants
;
25 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
26 import eu
.etaxonomy
.taxeditor
.UiUtil
;
27 import eu
.etaxonomy
.taxeditor
.actions
.UndoableAction
;
28 import eu
.etaxonomy
.taxeditor
.actions
.cdm
.SwapSynonymAndTaxonAction
;
29 import eu
.etaxonomy
.taxeditor
.editor
.name
.NameComposite
;
30 import eu
.etaxonomy
.taxeditor
.model
.CdmSessionDataRepository
;
31 import eu
.etaxonomy
.taxeditor
.navigation
.RecentNamesView
;
38 public class ChangeSynonymToTaxonUiAction
extends UndoableAction
{
39 private static final Logger logger
= Logger
40 .getLogger(ChangeSynonymToTaxonUiAction
.class);
42 private static String text
= "Make synonym this taxon's accepted taxon";
43 private static ImageDescriptor image
= TaxEditorPlugin
.getDefault()
44 .getImageDescriptor(ITaxEditorConstants
.SWAP_SYNONYM_AND_TAXON_ICON
);
46 private NameComposite composite
;
48 private Synonym synonym
;
50 public ChangeSynonymToTaxonUiAction(Synonym synonym
, Taxon taxon
) {
53 this.synonym
= synonym
;
58 protected IStatus
executeOperation() {
59 Action action
= new SwapSynonymAndTaxonAction(synonym
, taxon
);
60 action
.addPropertyChangeListener(new IPropertyChangeListener() {
61 public void propertyChange(PropertyChangeEvent event
) {
62 if (event
.getProperty().equals(ITaxEditorConstants
.TAXON
)) {
64 if (event
.getNewValue() instanceof Taxon
) {
65 Taxon newTaxon
= (Taxon
) event
.getNewValue();
67 // Close editor for existing taxon
68 IEditorPart oldEditor
;
70 oldEditor
= UiUtil
.getEditorByTaxon(taxon
);
71 UiUtil
.closeEditor(oldEditor
, true);
72 } catch (PartInitException e
) {
73 // TODO Auto-generated catch block
77 // Remove old taxon from tree
78 CdmSessionDataRepository
.getDefault().removeTaxon(taxon
);
80 // Add new taxon to tree
81 CdmSessionDataRepository
.getDefault().addTaxon(newTaxon
);
83 // Open editor for new taxon
84 new OpenTaxonEditorAction(newTaxon
).run();
86 // Remove old taxon from recent names list
87 RecentNamesView
.addRecentName(taxon
);
94 return Status
.OK_STATUS
;
98 protected IStatus
redoOperation() {
99 return Status
.OK_STATUS
;
103 protected IStatus
undoOperation() {
104 return Status
.OK_STATUS
;