performed javacscript:fix and worked on documentation
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / 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.operations;
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.cdm.model.taxon.TaxonRelationshipType;
23 import eu.etaxonomy.taxeditor.store.StoreUtil;
24
25 /**
26 * <p>ChangeConceptRelationshipTypeOperation class.</p>
27 *
28 * @author n.hoffmann
29 * @created 03.02.2009
30 * @version 1.0
31 */
32 public class ChangeConceptRelationshipTypeOperation extends AbstractPostOperation {
33
34 private Taxon relatedTaxon;
35
36 private TaxonRelationship taxonRelationship;
37
38 private TaxonRelationshipType oldRelationshipType;
39
40 private TaxonRelationshipType newRelationshipType;
41
42 /**
43 * <p>Constructor for ChangeConceptRelationshipTypeOperation.</p>
44 *
45 * @param label a {@link java.lang.String} object.
46 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
47 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
48 * @param relatedTaxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
49 * @param type a {@link eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType} object.
50 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operations.IPostOperationEnabled} object.
51 */
52 public ChangeConceptRelationshipTypeOperation(String label,
53 IUndoContext undoContext, Taxon taxon, Taxon relatedTaxon, TaxonRelationshipType type, IPostOperationEnabled postOperationEnabled) {
54 super(label, undoContext, taxon, postOperationEnabled);
55 this.relatedTaxon = relatedTaxon;
56
57 Set<TaxonRelationship> taxonRelationships = taxon.getTaxonRelations(relatedTaxon);
58
59 if(taxonRelationships.size() > 1){
60 StoreUtil.warningDialog("Multiple relations between taxa", this, "There are multiple relations between the " +
61 "accepted and the related taxon. This case is not handled by the software yet");
62 return;
63 }
64
65 this.taxonRelationship = taxonRelationships.iterator().next();
66 this.oldRelationshipType = taxonRelationship.getType();
67 this.newRelationshipType = type;
68 }
69
70 /* (non-Javadoc)
71 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
72 */
73 /** {@inheritDoc} */
74 @Override
75 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
76 throws ExecutionException {
77
78 // Remove relatedTaxon and old relationship
79 // FIXME since taxon relationships come in a set, which relationships are we going to delete here?
80 taxon.removeTaxon(relatedTaxon, oldRelationshipType);
81 monitor.worked(20);
82
83 // Add new relationship
84 // TODO add microcitation for misapplied name to property sheet
85 relatedTaxon.addTaxonRelation(taxon, newRelationshipType, null, null);
86 monitor.worked(40);
87
88 return postExecute(relatedTaxon);
89 }
90
91 /* (non-Javadoc)
92 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
93 */
94 /** {@inheritDoc} */
95 @Override
96 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
97 throws ExecutionException {
98 return execute(monitor, info);
99 }
100
101 /* (non-Javadoc)
102 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
103 */
104 /** {@inheritDoc} */
105 @Override
106 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
107 throws ExecutionException {
108 // see FIXME in execute()
109 StoreUtil.warn(this.getClass(), "Not implemented yet. See developer documentation for details");
110 return null;
111 }
112 }