Project

General

Profile

Download (3.89 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.model.taxon.Synonym;
22
import eu.etaxonomy.cdm.model.taxon.SynonymType;
23
import eu.etaxonomy.cdm.model.taxon.Taxon;
24
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
25
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
26
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28

    
29
/**
30
 * <p>ChangeSynonymToMisapplicationOperation class.</p>
31
 *
32
 * @author p.ciardelli
33
 * @author n.hoffmann
34
 * @created 14.01.2009
35
 */
36
public class ChangeSynonymToMisapplicationOperation extends AbstractPostTaxonOperation {
37

    
38
	private final Synonym synonym;
39
	private Taxon misapplication;
40
	private Set<SynonymType> synonymTypes;
41

    
42
	/**
43
	 * <p>Constructor for ChangeSynonymToMisapplicationOperation.</p>
44
	 *
45
	 * @param label a {@link java.lang.String} object.
46
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
47
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
48
	 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
49
	 * @param editor a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
50
	 */
51
	public ChangeSynonymToMisapplicationOperation(String label,
52
			IUndoContext undoContext, Taxon taxon, Synonym synonym, IPostOperationEnabled editor) {
53
		super(label, undoContext, taxon, editor);
54

    
55
		this.synonym = synonym;
56
	}
57

    
58
	@Override
59
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
60
			throws ExecutionException {
61

    
62
    	/*// get name from synonym
63
		TaxonNameBase<?, ?> synonymName = synonym.getName();
64

    
65
		// make misapplied name with synonym name
66
		misapplication = Taxon.NewInstance(synonymName, null);
67
		CdmStore.getService(ITaxonService.class).saveOrUpdate(misapplication);
68
		monitor.worked(20);
69

    
70
		// store SynonymType for later undo operations
71
		synonymTypes = synonym.getRelationType(element);
72

    
73
		// remove synonym from taxon
74
		element.removeSynonym(synonym);
75
		monitor.worked(40);
76

    
77
		// add misapplied name to taxon
78
		// TODO add microcitation for misapplied name to property sheet (if microcitation is indeed needed?!)
79
		element.addMisappliedName(misapplication, null, null);*/
80

    
81

    
82
		misapplication =
83
		        (Taxon) CdmStore.getService(ITaxonService.class).changeSynonymToRelatedTaxon(synonym.getUuid(),
84
		                element.getUuid(),
85
		                TaxonRelationshipType.MISAPPLIED_NAME_FOR(),
86
		                null,
87
		                null).getCdmEntity();
88
		// redraw editor if exists
89
		return postExecute(misapplication);
90
	}
91

    
92
	@Override
93
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
94
			throws ExecutionException {
95
		// add misapplied name to taxon
96
		// TODO add citation for misapplied name to property sheet
97
		element.addMisappliedName(misapplication, null, null);
98

    
99
		// remove synonym from taxon
100
		element.removeSynonym(synonym);
101

    
102
		// redraw editor if exists
103
		return postExecute(misapplication);
104
	}
105

    
106
	@Override
107
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
108
			throws ExecutionException {
109

    
110
		// remove misapplied name from taxon
111
		element.removeTaxon(misapplication, TaxonRelationshipType.MISAPPLIED_NAME_FOR());
112

    
113
		// add synonym to taxon
114
		for (SynonymType synonymType : synonymTypes){
115
			element.addSynonym(synonym, synonymType);
116
		}
117

    
118
		// redraw editor if exists
119
		return postExecute(null);
120
	}
121
}
(8-8/15)