Project

General

Profile

Download (4.65 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.conversation.IConversationEnabled;
21
import eu.etaxonomy.cdm.api.service.ITaxonService;
22
import eu.etaxonomy.cdm.api.service.exception.HomotypicalGroupChangeException;
23
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
24
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
25
import eu.etaxonomy.cdm.model.taxon.Synonym;
26
import eu.etaxonomy.cdm.model.taxon.Taxon;
27
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
28
import eu.etaxonomy.taxeditor.model.MessagingUtils;
29
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
30
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
31
import eu.etaxonomy.taxeditor.store.CdmStore;
32

    
33
/**
34
 * Change the taxonomic parent of a given taxon.
35
 *
36
 * @author n.hoffmann
37
 * @created 16.01.2009
38
 * @version 1.0
39
 */
40
public class ChangeSynonymToAcceptedTaxonOperation extends AbstractPersistentPostOperation {
41

    
42
	private Taxon newTaxon;
43
	private Synonym synonym;
44
	private final ITaxonTreeNode parentNode;
45

    
46
	private TaxonNode newNode;
47

    
48
	//private final Set<TaxonNameBase> namesInHomotypicGroup;
49

    
50
	/**
51
	 * <p>Constructor for ChangeSynonymToAcceptedTaxonOperation.</p>
52
	 *
53
	 * @param label a {@link java.lang.String} object.
54
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
55
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
56
	 * @param parentNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
57
	 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
58
	 * @param synonymsInHomotypicalGroup an array of {@link eu.etaxonomy.cdm.model.taxon.Synonym} objects.
59
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
60
	 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
61
	 */
62
	public ChangeSynonymToAcceptedTaxonOperation(String label, IUndoContext undoContext,
63
			Taxon taxon, ITaxonTreeNode parentNode, Synonym synonym, Set<TaxonNameBase> namesInHomotypicalGroup, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled) {
64
		super(label, undoContext, postOperationEnabled, conversationEnabled);
65

    
66
		this.element = taxon;
67
		this.parentNode = parentNode;
68
		this.synonym = synonym;
69
		//this.namesInHomotypicGroup = namesInHomotypicalGroup;
70
	}
71

    
72
	/* (non-Javadoc)
73
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
74
	 */
75
	/** {@inheritDoc} */
76
	@Override
77
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
78
			throws ExecutionException {
79

    
80
		try {
81
			newTaxon = CdmStore.getService(ITaxonService.class).changeSynonymToAcceptedTaxon(synonym, element, true, true, null, null);
82
		} catch (HomotypicalGroupChangeException e) {
83
			MessagingUtils.warningDialog("Operation may lead to inconsistent data", getClass(), e.getMessage());
84
			return postExecute(null);
85
		}
86
		monitor.worked(20);
87

    
88
		element.removeSynonym(synonym);
89
		newNode = parentNode.addChildTaxon(newTaxon, null, null);
90

    
91
		/*if(namesInHomotypicGroup != null){
92
			Taxon taxon = newNode.getTaxon();
93
			for (TaxonNameBase synonymName : namesInHomotypicGroup){
94
				taxon.addHomotypicSynonymName(synonymName, null, null);
95
				
96
			}
97
		}*/
98

    
99
		monitor.worked(40);
100

    
101
		return postExecute(newNode);
102
	}
103

    
104
	/* (non-Javadoc)
105
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
106
	 */
107
	/** {@inheritDoc} */
108
	@Override
109
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
110
			throws ExecutionException {
111
		return execute(monitor, info);
112
	}
113

    
114
	/* (non-Javadoc)
115
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
116
	 */
117
	/** {@inheritDoc} */
118
	@Override
119
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
120
			throws ExecutionException {
121

    
122
		// TODO implement - biggest problem is that any window open for new taxon must be closed first
123
		MessagingUtils.warn(this.getClass(), "Not yet implemented");
124

    
125
		return postExecute(element);
126
	}
127

    
128
}
(5-5/19)