Moving editor sources back into trunk
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / store / operations / ChangeConceptRelationshipTypeOperation.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 java.util.HashSet;
13 import java.util.Set;
14
15 import org.apache.log4j.Logger;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.core.commands.operations.IUndoContext;
18 import org.eclipse.core.runtime.IAdaptable;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.IStatus;
21
22 import eu.etaxonomy.cdm.model.taxon.Taxon;
23 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
24 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
25 import eu.etaxonomy.taxeditor.store.model.TaxonUtil;
26
27 /**
28 * @author n.hoffmann
29 * @created 03.02.2009
30 * @version 1.0
31 */
32 public class ChangeConceptRelationshipTypeOperation extends AbstractPostOperation {
33
34
35 private static final Logger logger = Logger
36 .getLogger(ChangeConceptRelationshipTypeOperation.class);
37
38 private Taxon relatedTaxon;
39
40 private TaxonRelationship taxonRelationship;
41
42 private TaxonRelationshipType oldRelationshipType;
43
44 private TaxonRelationshipType newRelationshipType;
45
46 public ChangeConceptRelationshipTypeOperation(String label,
47 IUndoContext undoContext, Taxon taxon, Taxon relatedTaxon, TaxonRelationshipType type, IPostOperationEnabled postOperationEnabled) {
48 super(label, undoContext, taxon, postOperationEnabled);
49 this.relatedTaxon = relatedTaxon;
50
51 this.taxonRelationship = TaxonUtil.getRelationshipBetweenTwoTaxa(relatedTaxon, taxon);
52 this.oldRelationshipType = taxonRelationship.getType();
53 this.newRelationshipType = type;
54 }
55
56 /* (non-Javadoc)
57 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
58 */
59 @Override
60 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
61 throws ExecutionException {
62 // Remove relatedTaxon and old relationship
63 // FIXME since taxon relationships come in a set, which relationships are we going to delete here?
64 taxon.removeTaxon(relatedTaxon, oldRelationshipType);
65 // Add new relationship
66 // TODO add microcitation for misapplied name to property sheet
67 relatedTaxon.addTaxonRelation(taxon, newRelationshipType, null, null);
68
69
70 return postExecute(relatedTaxon);
71 }
72
73 /* (non-Javadoc)
74 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
75 */
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 @Override
86 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
87 throws ExecutionException {
88 // see FIXME in execute()
89 logger.warn("Not implemented yet. See developer documentation for details");
90 return null;
91 }
92 }