Did some code cleanup. Removed obsolete and deprecated classes.
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / 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.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.taxon.Taxon;
19 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
20 import eu.etaxonomy.taxeditor.store.StoreUtil;
21
22 /**
23 * @author p.ciardelli
24 * @created 26.01.2009
25 * @version 1.0
26 * @author n.hoffmann
27 */
28 public class CreateConceptRelationOperation extends AbstractPostOperation {
29
30 private Taxon concept;
31 private TaxonRelationshipType taxonRelationshipType;
32
33 public CreateConceptRelationOperation(String label,
34 IUndoContext undoContext, Taxon taxon, Taxon concept, TaxonRelationshipType taxonRelationshipType
35 , IPostOperationEnabled postOperationEnabled) {
36 super(label, undoContext, taxon, postOperationEnabled);
37 this.concept = concept;
38 this.taxonRelationshipType = taxonRelationshipType;
39 }
40
41 /* (non-Javadoc)
42 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
43 */
44 @Override
45 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
46 throws ExecutionException {
47
48 // Start the main progress monitor.
49 IProgressMonitor newMonitor = StoreUtil.startMainMonitor(monitor,"Creating Concept Relationship", 2);
50
51 // Do one step
52 newMonitor.worked(1);
53
54 try {
55 // Operation steps
56
57 // add concept to taxon
58 concept.addTaxonRelation(taxon, taxonRelationshipType, null, null);
59 StoreUtil.isCanceled(newMonitor, 1);
60 }
61 finally {
62
63 // Stop the progress monitor.
64 newMonitor.done();
65 }
66
67 // redraw editor if exists
68 return postExecute(concept);
69 }
70
71 /* (non-Javadoc)
72 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
73 */
74 @Override
75 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
76 throws ExecutionException {
77 return execute(monitor, info);
78 }
79
80 /* (non-Javadoc)
81 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
82 */
83 @Override
84 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
85 throws ExecutionException {
86
87 taxon.removeTaxon(concept, taxonRelationshipType);
88
89 // redraw editor if exists
90 return postExecute(null);
91 }
92 }