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
.actions
.ui
.OpenTaxonEditorAction
;
29 import eu
.etaxonomy
.taxeditor
.controller
.EditorController
;
30 import eu
.etaxonomy
.taxeditor
.controller
.GlobalController
;
31 import eu
.etaxonomy
.taxeditor
.model
.CdmSessionDataRepository
;
32 import eu
.etaxonomy
.taxeditor
.navigation
.RecentNamesView
;
33 import eu
.etaxonomy
.taxeditor
.operations
.AbstractEditorOperation
;
40 public class MakeSynonymAcceptedOperation
extends AbstractEditorOperation
{
41 private static final Logger logger
= Logger
42 .getLogger(MakeSynonymAcceptedOperation
.class);
43 private Synonym synonym
;
44 private Taxon parentTaxon
;
46 public MakeSynonymAcceptedOperation(String text
, IUndoContext undoContext
,
47 Taxon taxon
, Synonym synonym
) {
48 super(text
, undoContext
, taxon
);
50 this.synonym
= synonym
;
54 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
57 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
58 throws ExecutionException
{
60 // If taxon editor is dirty force user to save before proceeding, then close editor
62 IEditorPart oldEditor
= EditorController
.getEditorByTaxon(taxon
);
63 if (oldEditor
.isDirty()) {
64 if (!MessageDialog
.openConfirm(GlobalController
.getShell(), "Save before proceeding",
65 "All changes must be saved before proceeding with this action.\n\n" +
66 "Press \"OK\" to save and continue, or \"Cancel\" to cancel this action.")) {
67 return Status
.CANCEL_STATUS
;
69 oldEditor
.doSave(null);
70 EditorController
.close(taxon
, true);
72 } catch (PartInitException e
) {
73 logger
.error("Error while trying to save and close old editor.", e
);
74 MessageDialog
.openError(GlobalController
.getShell(), "Error", "Error saving and closing taxon");
75 return Status
.CANCEL_STATUS
;
78 // Create new taxon for synonym to be swapped into
79 TaxonNameBase synonymName
= synonym
.getName();
80 Taxon newAcceptedTaxon
= Taxon
.NewInstance(synonymName
, synonym
.getSec());
82 // Get taxon service and call its swap method
83 ITaxonService taxonService
= TaxEditorPlugin
.getDefault().getApplicationController().getTaxonService();
84 // TODO prompt user for citation
85 // TODO bug, anahit. new accepted taxon is not removed from synonymy
86 taxonService
.makeTaxonSynonym(taxon
, newAcceptedTaxon
, null, null, null);
88 // Remove old taxon from tree
89 CdmSessionDataRepository
.getDefault().removeTaxon(taxon
);
91 // Add new taxon to tree
92 CdmSessionDataRepository
.getDefault().addTaxon(newAcceptedTaxon
);
94 // Open editor for new accepted taxon
95 EditorController
.open(newAcceptedTaxon
);
97 // Remove old taxon from recent names list
98 RecentNamesView
.addRecentName(taxon
);
100 return Status
.OK_STATUS
;
104 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
107 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
108 throws ExecutionException
{
109 logger
.warn(this.getLabel() + ": Redo not yet implemented.");
114 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
117 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
118 throws ExecutionException
{
119 logger
.warn(this.getLabel() + ": Undo not yet implemented.");