- adapted sub classes of AbstractPostOperation
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / concept / operation / DeleteConceptRelationOperation.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.editor.view.concept.operation;
11
12 import java.util.Set;
13
14 import org.eclipse.core.commands.ExecutionException;
15 import org.eclipse.core.commands.operations.IUndoContext;
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.IStatus;
19
20 import eu.etaxonomy.cdm.model.taxon.Taxon;
21 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
22 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
23 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
24
25 /**
26 * Deletes given relations between two taxa.
27 *
28 * @author p.ciardelli
29 * @author n.hoffmann
30 * @created 29.01.2009
31 * @version 1.0
32 */
33 public class DeleteConceptRelationOperation extends AbstractPostTaxonOperation {
34
35 private final Set<TaxonRelationship> taxonRelationships;
36
37
38 /**
39 * @param name
40 * @param undoContext
41 * @param relation
42 * @param postOperationEnabled
43 */
44 public DeleteConceptRelationOperation(String label,
45 IUndoContext undoContext, Taxon taxon, Set<TaxonRelationship> relations,
46 IPostOperationEnabled postOperationEnabled) {
47 super(label, undoContext, taxon, postOperationEnabled);
48
49 taxonRelationships = relations;
50 }
51
52 /* (non-Javadoc)
53 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
54 */
55 /** {@inheritDoc} */
56 @Override
57 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
58 throws ExecutionException {
59
60 monitor.worked(20);
61
62 // Remove relation from taxon
63 for(TaxonRelationship relationship : taxonRelationships){
64 element.removeTaxonRelation(relationship);
65 monitor.worked(10);
66 }
67 monitor.worked(10);
68
69 return postExecute(element);
70 }
71
72 /* (non-Javadoc)
73 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
74 */
75 /** {@inheritDoc} */
76 @Override
77 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
78 throws ExecutionException {
79 return execute(monitor, info);
80 }
81
82 /* (non-Javadoc)
83 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
84 */
85 /** {@inheritDoc} */
86 @Override
87 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
88 throws ExecutionException {
89
90 for(TaxonRelationship relationship : taxonRelationships){
91 element.addTaxonRelation(relationship);
92 monitor.worked(10);
93 }
94
95 return postExecute(element);
96 }
97 }