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