Project

General

Profile

Download (4.23 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.TaxonName;
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.editor.l10n.Messages;
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
    protected static final String CHANGE_CONCEPT_TO_SYNONYM_OPERATION_MULTI_REPS_MESSAGE = Messages.ChangeConceptToSynonymOperation_MULTI_REPS_MESSAGE;
46
    protected static final String CHANGE_CONCEPT_TO_SYNONYM_OPERATION_MULTI_REPS = Messages.ChangeConceptToSynonymOperation_MULTI_REPS;
47

    
48
    private Taxon concept;
49

    
50
	private HomotypicalGroup homotypicalGroup;
51

    
52
	private TaxonRelationship taxonRelationship;
53
	private TaxonRelationshipType oldRelationshipType;
54

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

    
70
		Set<TaxonRelationship> taxonRelationships = taxon.getTaxonRelations(concept);
71

    
72
		if(taxonRelationships.size() > 1){
73
			MessagingUtils.warningDialog(CHANGE_CONCEPT_TO_SYNONYM_OPERATION_MULTI_REPS, this, CHANGE_CONCEPT_TO_SYNONYM_OPERATION_MULTI_REPS_MESSAGE);
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
	/** {@inheritDoc} */
85
	@Override
86
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
87
			throws ExecutionException {
88

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

    
103

    
104
		return postExecute(synonym);
105
	}
106

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

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