Nothing works.
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / operations / name / CreateMisappliedNameOperation.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
19 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
20 import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
21 import eu.etaxonomy.cdm.model.taxon.Taxon;
22 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
23 import eu.etaxonomy.taxeditor.editor.name.CdmParserController;
24 import eu.etaxonomy.taxeditor.operations.AbstractEditorOperation;
25
26 /**
27 * @author p.ciardelli
28 * @created 21.01.2009
29 * @version 1.0
30 */
31 public class CreateMisappliedNameOperation extends AbstractEditorOperation {
32 private static final Logger logger = Logger
33 .getLogger(CreateMisappliedNameOperation.class);
34
35 private Taxon misapplication;
36
37 public CreateMisappliedNameOperation(String label, IUndoContext undoContext,
38 Taxon taxon) {
39 super(label, undoContext, taxon);
40 }
41
42 /* (non-Javadoc)
43 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
44 */
45 @Override
46 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
47 throws ExecutionException {
48
49 // Create empty new name
50 TaxonNameBase misapplicationName =
51 CdmParserController.parseFullReference("", null, null);
52
53 // make misapplication name with misapplication name
54 misapplication = Taxon.NewInstance(misapplicationName, null);
55
56 // add misapplied name to taxon
57 // TODO add microcitation for misapplied name to property sheet
58 taxon.addMisappliedName(misapplication, null, null);
59
60 // redraw editor if exists
61 return redrawOpenEditor();
62 }
63
64 /* (non-Javadoc)
65 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
66 */
67 @Override
68 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
69 throws ExecutionException {
70 return execute(monitor, info);
71 }
72
73 /* (non-Javadoc)
74 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
75 */
76 @Override
77 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
78 throws ExecutionException {
79
80 // Remove misapplied name from taxon
81 taxon.removeTaxon(misapplication, TaxonRelationshipType.MISAPPLIED_NAME_FOR());
82
83 // Redraw editor if exists
84 return redrawOpenEditor();
85 }
86 }