Project

General

Profile

Download (3.97 KB) Statistics
| Branch: | Tag: | Revision:
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.Taxon;
26
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
27
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
28
import eu.etaxonomy.taxeditor.model.MessagingUtils;
29
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
30
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
31
import eu.etaxonomy.taxeditor.store.CdmStore;
32

    
33
/**
34
 * <p>ChangeConceptToSynonymOperation class.</p>
35
 *
36
 * @author p.ciardelli
37
 * @author n.hoffmann
38
 * @created 15.01.2009
39
 * @version 1.0
40
 */
41
public class ChangeConceptToSynonymOperation extends
42
		AbstractPostTaxonOperation {
43

    
44
	private Taxon concept;
45

    
46
	private HomotypicalGroup homotypicalGroup;
47

    
48
	private TaxonRelationship taxonRelationship;
49
	private TaxonRelationshipType oldRelationshipType;
50

    
51
	/**
52
	 * <p>Constructor for ChangeConceptToSynonymOperation.</p>
53
	 *
54
	 * @param label a {@link java.lang.String} object.
55
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
56
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
57
	 * @param concept a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
58
	 * @param homotypicalGroup a {@link eu.etaxonomy.cdm.model.name.HomotypicalGroup} object.
59
	 * @param editor a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
60
	 */
61
	public ChangeConceptToSynonymOperation(String label,
62
			IUndoContext undoContext, Taxon taxon, Taxon concept, HomotypicalGroup homotypicalGroup,
63
			IPostOperationEnabled editor) {
64
		super(label, undoContext, taxon, editor);
65

    
66
		Set<TaxonRelationship> taxonRelationships = taxon.getTaxonRelations(concept);
67

    
68
		if(taxonRelationships.size() > 1){
69
			MessagingUtils.warningDialog("Multiple relations between taxa", this, "There are multiple relations between the " +
70
					"accepted and the related taxon. This case is not handled by the software yet");
71
			return;
72
		}
73

    
74
		this.taxonRelationship = taxonRelationships.iterator().next();
75
		this.oldRelationshipType = taxonRelationship.getType();
76

    
77
		this.concept = concept;
78
		this.homotypicalGroup = homotypicalGroup != null ? homotypicalGroup : HomotypicalGroup.NewInstance();
79
	}
80

    
81
	/** {@inheritDoc} */
82
	@Override
83
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
84
			throws ExecutionException {
85

    
86
		// Create new synonym using concept name
87
		TaxonNameBase<?, ?> synonymName = concept.getName();
88
		Synonym synonym = null;
89
		try {
90
			synonym =
91
			        (Synonym) CdmStore.getService(ITaxonService.class).changeRelatedTaxonToSynonym(concept.getUuid(),
92
			                element.getUuid(),
93
			                taxonRelationship.getType(),
94
			                null).getCdmEntity();
95
		} catch (DataChangeNoRollbackException e) {
96
			// TODO Auto-generated catch block
97
			e.printStackTrace();
98
		}
99

    
100

    
101
		return postExecute(synonym);
102
	}
103

    
104
	/** {@inheritDoc} */
105
	@Override
106
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
107
			throws ExecutionException {
108
		// TODO redo for change misapplied name ...
109
		return null;
110
	}
111

    
112
	/** {@inheritDoc} */
113
	@Override
114
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
115
			throws ExecutionException {
116
		// TODO undo for change misapplied name ...
117
		return null;
118
	}
119
}
(2-2/19)