Project

General

Profile

Download (4.46 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.SynonymRelationship;
25
import eu.etaxonomy.cdm.model.taxon.Taxon;
26
import eu.etaxonomy.cdm.model.taxon.Synonym;
27
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
28
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
29
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
30
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
31
import eu.etaxonomy.taxeditor.store.CdmStore;
32
import eu.etaxonomy.taxeditor.store.StoreUtil;
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
			StoreUtil.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 = CdmStore.getService(ITaxonService.class).changeRelatedTaxonToSynonym(concept, element, taxonRelationship.getType(), null);
97
		} catch (DataChangeNoRollbackException e) {
98
			// TODO Auto-generated catch block
99
			e.printStackTrace();
100
		}
101
		
102
	
103
		return postExecute(synonym);
104
	}
105

    
106
	/* (non-Javadoc)
107
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
108
	 */
109
	/** {@inheritDoc} */
110
	@Override
111
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
112
			throws ExecutionException {
113
		// TODO redo for change misapplied name ...
114
		return null;
115
	}
116

    
117
	/* (non-Javadoc)
118
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
119
	 */
120
	/** {@inheritDoc} */
121
	@Override
122
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
123
			throws ExecutionException {
124
		// TODO undo for change misapplied name ...
125
		return null;
126
	}
127
}
(2-2/18)