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
;
18 import org
.eclipse
.core
.runtime
.Status
;
19 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
20 import org
.eclipse
.ui
.IEditorPart
;
21 import org
.eclipse
.ui
.PartInitException
;
23 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
24 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
27 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
28 import eu
.etaxonomy
.taxeditor
.UiUtil
;
29 import eu
.etaxonomy
.taxeditor
.actions
.ui
.OpenTaxonEditorAction
;
30 import eu
.etaxonomy
.taxeditor
.model
.CdmSessionDataRepository
;
31 import eu
.etaxonomy
.taxeditor
.navigation
.RecentNamesView
;
32 import eu
.etaxonomy
.taxeditor
.operations
.AbstractEditorOperation
;
39 public class MakeSynonymAcceptedOperation
extends AbstractEditorOperation
{
40 private static final Logger logger
= Logger
41 .getLogger(MakeSynonymAcceptedOperation
.class);
42 private Synonym synonym
;
43 private Taxon parentTaxon
;
45 public MakeSynonymAcceptedOperation(String text
, IUndoContext undoContext
,
46 Taxon taxon
, Synonym synonym
) {
47 super(text
, undoContext
, taxon
);
49 this.synonym
= synonym
;
53 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
56 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
57 throws ExecutionException
{
59 // If taxon editor is dirty force user to save before proceeding, then close editor
61 IEditorPart oldEditor
= UiUtil
.getEditorByTaxon(taxon
);
62 if (oldEditor
.isDirty()) {
63 if (!MessageDialog
.openConfirm(UiUtil
.getShell(), "Save before proceeding",
64 "All changes must be saved before proceeding with this action.\n\n" +
65 "Press \"OK\" to save and continue, or \"Cancel\" to cancel this action.")) {
66 return Status
.CANCEL_STATUS
;
68 oldEditor
.doSave(null);
69 UiUtil
.closeEditor(oldEditor
, true);
71 } catch (PartInitException e
) {
73 MessageDialog
.openError(UiUtil
.getShell(), "Error", "Error saving and closing taxon");
74 return Status
.CANCEL_STATUS
;
77 // Create new taxon for synonym to be swapped into
78 TaxonNameBase synonymName
= synonym
.getName();
79 Taxon newAcceptedTaxon
= Taxon
.NewInstance(synonymName
, synonym
.getSec());
81 // Get taxon service and call its swap method
82 ITaxonService taxonService
= TaxEditorPlugin
.getDefault().getApplicationController().getTaxonService();
83 // TODO prompt user for citation
84 // TODO bug, anahit. new accepted taxon is not removed from synonymy
85 taxonService
.makeTaxonSynonym(taxon
, newAcceptedTaxon
, null, null, null);
87 // Remove old taxon from tree
88 CdmSessionDataRepository
.getDefault().removeTaxon(taxon
);
90 // Add new taxon to tree
91 CdmSessionDataRepository
.getDefault().addTaxon(newAcceptedTaxon
);
93 // Open editor for new accepted taxon
95 UiUtil
.openTaxonEditor(newAcceptedTaxon
);
96 } catch (PartInitException e
) {
99 // Remove old taxon from recent names list
100 RecentNamesView
.addRecentName(taxon
);
102 return Status
.OK_STATUS
;
106 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
109 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
110 throws ExecutionException
{
111 logger
.warn(this.getLabel() + ": Redo not yet implemented.");
116 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
119 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
120 throws ExecutionException
{
121 logger
.warn(this.getLabel() + ": Undo not yet implemented.");