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
;
18 import org
.eclipse
.core
.runtime
.Status
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
28 public class ChangeTaxonToSynonymOperation
extends AbstractPostOperation
{
30 private static final Logger logger
= Logger
31 .getLogger(ChangeTaxonToSynonymOperation
.class);
33 private Taxon destinationTaxon
;
35 public ChangeTaxonToSynonymOperation(String label
,
36 IUndoContext undoContext
, Taxon taxon
) {
37 super(label
, undoContext
, taxon
);
41 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
42 throws ExecutionException
{
44 // FIXME this is old code: reimplement
45 // IEditorPart editor = null;
48 // // Prompt user "Would you like to save?" before showing dialog
49 // // "Cancel" cancels action - "No" does not
50 // editor = EditorController.getEditorByTaxon(taxon);
51 // if (editor.isDirty()) {
52 // if (!MessageDialog.openConfirm(GlobalController.getShell(), "Save before proceeding",
53 // "All changes must be saved before proceeding with this action.\n\n" +
54 // "Press \"OK\" to save and continue, or \"Cancel\" to cancel this action.")) {
55 // return Status.CANCEL_STATUS;
57 // editor.doSave(null);
59 //// if (UiUtil.getActivePage().saveEditor(oldEditor, true) == false) {
62 // } catch (PartInitException e1) {
63 // e1.printStackTrace();
66 // // Get destination taxon from dialog
67 // Shell shell = GlobalController.getShell();
68 // SelectTaxonDialog dialog = new SelectTaxonDialog(shell, SelectTaxonDialog.TAXON_TO_SYNONYM);
69 // destinationTaxon = dialog.open(taxon);
71 // // Abort action if user cancelled dialog without choosing a taxon
72 // if (destinationTaxon == null) {
73 // return Status.CANCEL_STATUS;
77 // return makeTaxonSynonym(taxon, destinationTaxon) ? Status.OK_STATUS : Status.CANCEL_STATUS;
78 return Status
.CANCEL_STATUS
;
81 // FIXME this is old code: reimplement
82 // private boolean makeTaxonSynonym(Taxon taxon, Taxon destinationTaxon){
83 // // Move taxon in CDM to new destinationTaxon
84 // TaxonNameBase synonymName = taxon.getName();
85 // SynonymRelationshipType synonymType;
86 // if (CdmUtil.isNameHomotypic(synonymName, destinationTaxon)) {
87 // synonymType = SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF();
89 // synonymType = SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF();
91 // CdmUtil.makeTaxonSynonym(taxon, destinationTaxon, synonymType,
94 // // TODO move any children, descriptions, synonyms
95 // for (TaxonDescription description: taxon.getDescriptions()) {
96 // destinationTaxon.addDescription(description);
97 // taxon.removeDescription(description);
100 // for (TaxonRelationship fromRelation : taxon.getRelationsFromThisTaxon()) {
101 // fromRelation.setFromTaxon(destinationTaxon);
104 // for (TaxonRelationship toRelation : taxon.getRelationsToThisTaxon()) {
105 // toRelation.setToTaxon(destinationTaxon);
108 // CdmSessionDataRepository.getDefault().removeTaxon(taxon);
110 // // Close open editor for oldTaxon without forcing save.
111 // // User has already saved or declined to do so above.
112 // EditorController.close(taxon, false);
113 // CdmSessionDataRepository.getDefault().saveTaxon(destinationTaxon);
114 // // Open editor for destinationTaxon
115 // EditorController.open(destinationTaxon);
121 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
122 throws ExecutionException
{
123 // return makeTaxonSynonym(taxon, destinationTaxon) ? Status.OK_STATUS : Status.CANCEL_STATUS;
124 return Status
.CANCEL_STATUS
;
128 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
129 throws ExecutionException
{
130 // TODO implement undo
131 logger
.warn("Not yet implemented.");
132 return Status
.CANCEL_STATUS
;