Project

General

Profile

Download (3.96 KB) Statistics
| Branch: | Tag: | Revision:
1 3be6ef3e n.hoffmann
/**
2
* Copyright (C) 2007 EDIT
3 0a534d09 Patric Plitzner
* European Distributed Institute of Taxonomy
4 3be6ef3e n.hoffmann
* http://www.e-taxonomy.eu
5 0a534d09 Patric Plitzner
*
6 3be6ef3e n.hoffmann
* 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 35861667 n.hoffmann
package eu.etaxonomy.taxeditor.editor.name.operation;
11 3be6ef3e n.hoffmann
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 db5e366d n.hoffmann
import eu.etaxonomy.cdm.api.service.ITaxonService;
21 3be6ef3e n.hoffmann
import eu.etaxonomy.cdm.model.taxon.Synonym;
22 bdd1bcf5 Andreas Müller
import eu.etaxonomy.cdm.model.taxon.SynonymType;
23 3be6ef3e n.hoffmann
import eu.etaxonomy.cdm.model.taxon.Taxon;
24
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
25 343457b6 Patric Plitzner
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
26 35861667 n.hoffmann
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
27 3be6ef3e n.hoffmann
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
 * @version 1.0
36
 */
37 343457b6 Patric Plitzner
public class ChangeSynonymToMisapplicationOperation extends AbstractPostTaxonOperation {
38 3be6ef3e n.hoffmann
39 0a534d09 Patric Plitzner
	private final Synonym synonym;
40 3be6ef3e n.hoffmann
	private Taxon misapplication;
41 bdd1bcf5 Andreas Müller
	private Set<SynonymType> synonymTypes;
42 3be6ef3e n.hoffmann
43
	/**
44
	 * <p>Constructor for ChangeSynonymToMisapplicationOperation.</p>
45
	 *
46
	 * @param label a {@link java.lang.String} object.
47
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
48
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
49
	 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
50 35861667 n.hoffmann
	 * @param editor a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
51 3be6ef3e n.hoffmann
	 */
52
	public ChangeSynonymToMisapplicationOperation(String label,
53
			IUndoContext undoContext, Taxon taxon, Synonym synonym, IPostOperationEnabled editor) {
54
		super(label, undoContext, taxon, editor);
55 0a534d09 Patric Plitzner
56 3be6ef3e n.hoffmann
		this.synonym = synonym;
57
	}
58
59
	/** {@inheritDoc} */
60
	@Override
61
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
62
			throws ExecutionException {
63 0a534d09 Patric Plitzner
64 c918301b Katja Luther
    	/*// get name from synonym
65 3be6ef3e n.hoffmann
		TaxonNameBase<?, ?> synonymName = synonym.getName();
66
67
		// make misapplied name with synonym name
68
		misapplication = Taxon.NewInstance(synonymName, null);
69 db5e366d n.hoffmann
		CdmStore.getService(ITaxonService.class).saveOrUpdate(misapplication);
70 3be6ef3e n.hoffmann
		monitor.worked(20);
71 0a534d09 Patric Plitzner
72 bdd1bcf5 Andreas Müller
		// store SynonymType for later undo operations
73 0a534d09 Patric Plitzner
		synonymTypes = synonym.getRelationType(element);
74
75
		// remove synonym from taxon
76
		element.removeSynonym(synonym);
77 3be6ef3e n.hoffmann
		monitor.worked(40);
78 0a534d09 Patric Plitzner
79 3be6ef3e n.hoffmann
		// add misapplied name to taxon
80
		// TODO add microcitation for misapplied name to property sheet (if microcitation is indeed needed?!)
81 c918301b Katja Luther
		element.addMisappliedName(misapplication, null, null);*/
82 782f133b Cherian Mathew
		misapplication =
83
		        (Taxon) CdmStore.getService(ITaxonService.class).changeSynonymToRelatedTaxon(synonym.getUuid(),
84
		                element.getUuid(),
85
		                TaxonRelationshipType.MISAPPLIED_NAME_FOR(),
86
		                null,
87
		                null).getCdmEntity();
88 3be6ef3e n.hoffmann
		// redraw editor if exists
89
		return postExecute(misapplication);
90
	}
91
92
	/** {@inheritDoc} */
93
	@Override
94
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
95
			throws ExecutionException {
96
		// add misapplied name to taxon
97
		// TODO add citation for misapplied name to property sheet
98 0a534d09 Patric Plitzner
		element.addMisappliedName(misapplication, null, null);
99
100 3be6ef3e n.hoffmann
		// remove synonym from taxon
101 0a534d09 Patric Plitzner
		element.removeSynonym(synonym);
102
103 3be6ef3e n.hoffmann
		// redraw editor if exists
104
		return postExecute(null);
105
	}
106
107
	/** {@inheritDoc} */
108
	@Override
109
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
110
			throws ExecutionException {
111 0a534d09 Patric Plitzner
112 3be6ef3e n.hoffmann
		// remove misapplied name from taxon
113 0a534d09 Patric Plitzner
		element.removeTaxon(misapplication, TaxonRelationshipType.MISAPPLIED_NAME_FOR());
114
115 3be6ef3e n.hoffmann
		// add synonym to taxon
116 bdd1bcf5 Andreas Müller
		for (SynonymType synonymType : synonymTypes){
117 0a534d09 Patric Plitzner
			element.addSynonym(synonym, synonymType);
118 3be6ef3e n.hoffmann
		}
119 0a534d09 Patric Plitzner
120 3be6ef3e n.hoffmann
		// redraw editor if exists
121
		return postExecute(null);
122
	}
123
}