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
.view
.nameviewersupport
;
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
.actions
.ui
.OpenTaxonEditorAction
;
36 public class ChangeSynonymToTaxonUiAction
extends UndoableAction
{
37 private static final Logger logger
= Logger
38 .getLogger(ChangeSynonymToTaxonUiAction
.class);
40 private static String text
= "Make synonym this taxon's accepted taxon";
41 private static ImageDescriptor image
= TaxEditorPlugin
.getDefault()
42 .getImageDescriptor(ITaxEditorConstants
.SWAP_SYNONYM_AND_TAXON_ICON
);
44 private NameComposite composite
;
46 private Synonym synonym
;
48 public ChangeSynonymToTaxonUiAction(Synonym synonym
, Taxon taxon
) {
51 this.synonym
= synonym
;
56 protected IStatus
executeOperation() {
57 Action action
= new SwapSynonymAndTaxonAction(synonym
, taxon
);
58 action
.addPropertyChangeListener(new IPropertyChangeListener() {
60 public void propertyChange(PropertyChangeEvent event
) {
61 if (event
.getProperty().equals(ITaxEditorConstants
.TAXON
)) {
63 if (event
.getNewValue() instanceof Taxon
) {
64 Taxon newTaxon
= (Taxon
) event
.getNewValue();
66 // Close editor for existing taxon
67 IEditorPart oldEditor
;
69 oldEditor
= UiUtil
.getEditorByTaxon(taxon
);
70 UiUtil
.closeEditor(oldEditor
, true);
71 } catch (PartInitException e
) {
72 // TODO Auto-generated catch block
76 // Remove old taxon from tree
77 TaxEditorPlugin
.getDefault().removeSessionTaxon(taxon
);
79 // Add new taxon to tree
80 TaxEditorPlugin
.getDefault().addSessionTaxon(newTaxon
);
82 // Open editor for new taxon
83 new OpenTaxonEditorAction(newTaxon
).run();
85 // Remove old taxon from recent names list
86 TaxEditorPlugin
.getDefault()
87 .getObservableRecentNamesList().remove(taxon
);
94 return Status
.OK_STATUS
;
98 protected IStatus
redoOperation() {
99 return Status
.OK_STATUS
;
103 protected IStatus
undoOperation() {
104 return Status
.OK_STATUS
;