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