Merge branch 'develop' into remoting-4.0
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / operation / ChangeConceptToSynonymOperation.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.name.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.api.service.ITaxonService;
21 import eu.etaxonomy.cdm.api.service.exception.DataChangeNoRollbackException;
22 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
23 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
24 import eu.etaxonomy.cdm.model.taxon.Synonym;
25 import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
26 import eu.etaxonomy.cdm.model.taxon.Taxon;
27 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
28 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
29 import eu.etaxonomy.taxeditor.model.MessagingUtils;
30 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
31 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
32 import eu.etaxonomy.taxeditor.store.CdmStore;
33
34 /**
35 * <p>ChangeConceptToSynonymOperation class.</p>
36 *
37 * @author p.ciardelli
38 * @author n.hoffmann
39 * @created 15.01.2009
40 * @version 1.0
41 */
42 public class ChangeConceptToSynonymOperation extends
43 AbstractPostTaxonOperation {
44
45 private Taxon concept;
46
47 private HomotypicalGroup homotypicalGroup;
48
49 private TaxonRelationship taxonRelationship;
50 private TaxonRelationshipType oldRelationshipType;
51
52 private SynonymRelationship newSynonymRelationship;
53
54 /**
55 * <p>Constructor for ChangeConceptToSynonymOperation.</p>
56 *
57 * @param label a {@link java.lang.String} object.
58 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
59 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
60 * @param concept a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
61 * @param homotypicalGroup a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object.
62 * @param editor a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
63 */
64 public ChangeConceptToSynonymOperation(String label,
65 IUndoContext undoContext, Taxon taxon, Taxon concept, HomotypicalGroup homotypicalGroup,
66 IPostOperationEnabled editor) {
67 super(label, undoContext, taxon, editor);
68
69 Set<TaxonRelationship> taxonRelationships = taxon.getTaxonRelations(concept);
70
71 if(taxonRelationships.size() > 1){
72 MessagingUtils.warningDialog("Multiple relations between taxa", this, "There are multiple relations between the " +
73 "accepted and the related taxon. This case is not handled by the software yet");
74 return;
75 }
76
77 this.taxonRelationship = taxonRelationships.iterator().next();
78 this.oldRelationshipType = taxonRelationship.getType();
79
80 this.concept = concept;
81 this.homotypicalGroup = homotypicalGroup != null ? homotypicalGroup : HomotypicalGroup.NewInstance();
82 }
83
84 /* (non-Javadoc)
85 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
86 */
87 /** {@inheritDoc} */
88 @Override
89 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
90 throws ExecutionException {
91
92 // Create new synonym using concept name
93 TaxonNameBase<?, ?> synonymName = concept.getName();
94 Synonym synonym = null;
95 try {
96 synonym =
97 (Synonym) CdmStore.getService(ITaxonService.class).changeRelatedTaxonToSynonym(concept.getUuid(),
98 element.getUuid(),
99 taxonRelationship.getType(),
100 null).getCdmEntity();
101 } catch (DataChangeNoRollbackException e) {
102 // TODO Auto-generated catch block
103 e.printStackTrace();
104 }
105
106
107 return postExecute(synonym);
108 }
109
110 /* (non-Javadoc)
111 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
112 */
113 /** {@inheritDoc} */
114 @Override
115 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
116 throws ExecutionException {
117 // TODO redo for change misapplied name ...
118 return null;
119 }
120
121 /* (non-Javadoc)
122 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
123 */
124 /** {@inheritDoc} */
125 @Override
126 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
127 throws ExecutionException {
128 // TODO undo for change misapplied name ...
129 return null;
130 }
131 }