Project

General

Profile

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

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

    
40
	private final Synonym synonym;
41
	private Taxon misapplication;
42
	private Set<SynonymRelationshipType> synonymTypes;
43

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

    
57
		this.synonym = synonym;
58
	}
59

    
60
	/** {@inheritDoc} */
61
	@Override
62
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
63
			throws ExecutionException {
64

    
65
    	// get name from synonym
66
		TaxonNameBase<?, ?> synonymName = synonym.getName();
67

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

    
73
		// store synonymRelationshipType for later undo operations
74
		synonymTypes = synonym.getRelationType(element);
75

    
76
		// remove synonym from taxon
77
		element.removeSynonym(synonym);
78
		monitor.worked(40);
79

    
80
		// add misapplied name to taxon
81
		// TODO add microcitation for misapplied name to property sheet (if microcitation is indeed needed?!)
82
		element.addMisappliedName(misapplication, null, null);
83

    
84
		// redraw editor if exists
85
		return postExecute(misapplication);
86
	}
87

    
88
	/** {@inheritDoc} */
89
	@Override
90
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
91
			throws ExecutionException {
92
		// add misapplied name to taxon
93
		// TODO add citation for misapplied name to property sheet
94
		element.addMisappliedName(misapplication, null, null);
95

    
96
		// remove synonym from taxon
97
		element.removeSynonym(synonym);
98

    
99
		// redraw editor if exists
100
		return postExecute(null);
101
	}
102

    
103
	/** {@inheritDoc} */
104
	@Override
105
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
106
			throws ExecutionException {
107

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

    
111
		// add synonym to taxon
112
		for (SynonymRelationshipType synonymType : synonymTypes){
113
			element.addSynonym(synonym, synonymType);
114
		}
115

    
116
		// redraw editor if exists
117
		return postExecute(null);
118
	}
119
}
(9-9/19)