Project

General

Profile

Download (4.3 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 org.eclipse.core.commands.ExecutionException;
13
import org.eclipse.core.commands.operations.IUndoContext;
14
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IStatus;
17

    
18
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
19
import eu.etaxonomy.cdm.api.service.ITaxonService;
20
import eu.etaxonomy.cdm.model.taxon.ITreeNode;
21
import eu.etaxonomy.cdm.model.taxon.Synonym;
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
24
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
25
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
26
import eu.etaxonomy.taxeditor.store.CdmStore;
27
import eu.etaxonomy.taxeditor.store.StoreUtil;
28

    
29
/**
30
 * Change the taxonomic parent of a given taxon.
31
 *
32
 * @author n.hoffmann
33
 * @created 16.01.2009
34
 * @version 1.0
35
 */
36
public class ChangeSynonymToAcceptedTaxonOperation extends AbstractPersistentPostOperation {
37
	
38
	private Taxon newTaxon;
39
	private Synonym synonym;
40
	private ITreeNode parentNode;
41

    
42
	private TaxonNode newNode;
43

    
44
	private Synonym[] synonymsInHomotypicalGroup;
45
	
46
	/**
47
	 * <p>Constructor for ChangeSynonymToAcceptedTaxonOperation.</p>
48
	 *
49
	 * @param label a {@link java.lang.String} object.
50
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
51
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
52
	 * @param parentNode a {@link eu.etaxonomy.cdm.model.taxon.ITreeNode} object.
53
	 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
54
	 * @param synonymsInHomotypicalGroup an array of {@link eu.etaxonomy.cdm.model.taxon.Synonym} objects.
55
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
56
	 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
57
	 */
58
	public ChangeSynonymToAcceptedTaxonOperation(String label, IUndoContext undoContext,
59
			Taxon taxon, ITreeNode parentNode, Synonym synonym, Synonym[] synonymsInHomotypicalGroup, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled) {
60
		super(label, undoContext, postOperationEnabled, conversationEnabled);
61

    
62
		this.taxon = taxon;
63
		this.parentNode = parentNode;
64
		this.synonym = synonym; 
65
		this.synonymsInHomotypicalGroup = synonymsInHomotypicalGroup;
66
	}
67
	
68
	/* (non-Javadoc)
69
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
70
	 */
71
	/** {@inheritDoc} */
72
	@Override
73
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
74
			throws ExecutionException {
75
		
76
		newTaxon = CdmStore.getService(ITaxonService.class).changeSynonymToAcceptedTaxon(synonym, taxon, true, true, null, null);
77
		monitor.worked(20);
78
		
79
//		synonym.setSec(null);
80
        
81
		// TODO let user choose parent
82
		newNode = parentNode.addChildTaxon(newTaxon, null, null, null);
83
		
84
		if(synonymsInHomotypicalGroup != null){
85
			Taxon taxon = newNode.getTaxon();
86
			for (Synonym synonym : synonymsInHomotypicalGroup){
87
				taxon.addHomotypicSynonym(synonym, null, null);
88
			}
89
		}
90
		
91
		monitor.worked(40);
92

    
93
		return postExecute(newNode);
94
	}
95

    
96
	/* (non-Javadoc)
97
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
98
	 */
99
	/** {@inheritDoc} */
100
	@Override
101
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
102
			throws ExecutionException {
103
		return execute(monitor, info);
104
	}
105

    
106
	/* (non-Javadoc)
107
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
108
	 */
109
	/** {@inheritDoc} */
110
	@Override
111
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
112
			throws ExecutionException {
113
		
114
		// TODO implement - biggest problem is that any window open for new taxon must be closed first
115
		StoreUtil.warn(this.getClass(), "Not yet implemented");
116
		
117
		return postExecute(taxon);
118
	}
119

    
120
}
(6-6/17)