Massive refactoring of the methodology in former class UiUtils
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / operations / name / ChangeSynonymToTaxonOperation.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.taxeditor.operations.name;
11
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.ui.PartInitException;
19
20 import eu.etaxonomy.cdm.model.taxon.Synonym;
21 import eu.etaxonomy.cdm.model.taxon.Taxon;
22 import eu.etaxonomy.taxeditor.controller.EditorController;
23 import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository;
24 import eu.etaxonomy.taxeditor.operations.AbstractEditorOperation;
25
26 /**
27 * @author p.ciardelli
28 * @created 15.01.2009
29 * @version 1.0
30 */
31 public class ChangeSynonymToTaxonOperation extends AbstractEditorOperation {
32 private static final Logger logger = Logger
33 .getLogger(ChangeSynonymToTaxonOperation.class);
34 private Synonym synonym;
35
36 public ChangeSynonymToTaxonOperation(String text, IUndoContext undoContext,
37 Taxon taxon, Synonym synonym) {
38 super(text, undoContext, taxon);
39
40 this.synonym = synonym;
41 }
42
43 /* (non-Javadoc)
44 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
45 */
46 @Override
47 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
48 throws ExecutionException {
49
50 // Remove synonym from taxon
51 taxon.removeSynonym(synonym);
52
53 // Create new taxon with synonym name
54 Taxon newTaxon = Taxon.NewInstance(synonym.getName(), synonym.getSec());
55
56 // Add new taxon to session data repository
57 taxon.setTaxonomicParent(null, null, null);
58 CdmSessionDataRepository.getDefault().addTaxon(newTaxon);
59
60 // Open editor for new taxon
61 EditorController.open(newTaxon);
62
63
64 return redrawOpenEditor();
65 }
66
67 /* (non-Javadoc)
68 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
69 */
70 @Override
71 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
72 throws ExecutionException {
73 // TODO Auto-generated method stub
74 return null;
75 }
76
77 /* (non-Javadoc)
78 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
79 */
80 @Override
81 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
82 throws ExecutionException {
83 // TODO Auto-generated method stub
84 return null;
85 }
86 }