Re-implemented taxonomic tree using Common Navigator Framework.
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / store / operations / CreateConceptRelationOperation.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.store.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.store.parser.CdmParserUtil;
22
23 /**
24 * @author p.ciardelli
25 * @created 26.01.2009
26 * @version 1.0
27 * @author n.hoffmann
28 */
29 public class CreateConceptRelationOperation extends AbstractPostOperation {
30
31 private Taxon concept;
32 private TaxonRelationshipType taxonRelationshipType;
33
34 public CreateConceptRelationOperation(String label,
35 IUndoContext undoContext, Taxon taxon, TaxonRelationshipType taxonRelationshipType
36 , IPostOperationEnabled postOperationEnabled) {
37 super(label, undoContext, taxon, postOperationEnabled);
38
39 this.taxonRelationshipType = taxonRelationshipType;
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<?, ?> conceptName = CdmParserUtil.parseFullReference("", null, null);
51
52 // make concept name with concept name
53 concept = Taxon.NewInstance(conceptName, null);
54
55 // add misapplied name to taxon
56 // TODO add microcitation for misapplied name to property sheet
57 concept.addTaxonRelation(taxon, taxonRelationshipType, null, null);
58
59 // redraw editor if exists
60 return postExecute(concept);
61 }
62
63 /* (non-Javadoc)
64 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
65 */
66 @Override
67 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
68 throws ExecutionException {
69 return execute(monitor, info);
70 }
71
72 /* (non-Javadoc)
73 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
74 */
75 @Override
76 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
77 throws ExecutionException {
78
79 taxon.removeTaxon(concept, taxonRelationshipType);
80
81 // redraw editor if exists
82 return postExecute(null);
83 }
84 }