Project

General

Profile

Download (4.15 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
 */
41
public class ChangeConceptToSynonymOperation extends
42
		AbstractPostTaxonOperation {
43

    
44
    protected static final String CHANGE_CONCEPT_TO_SYNONYM_OPERATION_MULTI_REPS_MESSAGE = Messages.ChangeConceptToSynonymOperation_MULTI_REPS_MESSAGE;
45
    protected static final String CHANGE_CONCEPT_TO_SYNONYM_OPERATION_MULTI_REPS = Messages.ChangeConceptToSynonymOperation_MULTI_REPS;
46

    
47
    private Taxon concept;
48

    
49
	private HomotypicalGroup homotypicalGroup;
50

    
51
	private TaxonRelationship taxonRelationship;
52
	private TaxonRelationshipType oldRelationshipType;
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(CHANGE_CONCEPT_TO_SYNONYM_OPERATION_MULTI_REPS, this, CHANGE_CONCEPT_TO_SYNONYM_OPERATION_MULTI_REPS_MESSAGE);
73
			return;
74
		}
75

    
76
		this.taxonRelationship = taxonRelationships.iterator().next();
77
		this.oldRelationshipType = taxonRelationship.getType();
78

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

    
83
	@Override
84
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
85
			throws ExecutionException {
86

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

    
101

    
102
		return postExecute(synonym);
103
	}
104

    
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
	@Override
113
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
114
			throws ExecutionException {
115
		// TODO undo for change misapplied name ...
116
		return null;
117
	}
118
}
(2-2/15)