Project

General

Profile

Download (4.56 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.api.service.exception.HomotypicalGroupChangeException;
21
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
22
import eu.etaxonomy.cdm.model.taxon.Synonym;
23
import eu.etaxonomy.cdm.model.taxon.Taxon;
24
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
25
import eu.etaxonomy.taxeditor.editor.EditorUtil;
26
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
27
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29
import eu.etaxonomy.taxeditor.store.StoreUtil;
30

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

    
40
	private Taxon newTaxon;
41
	private Synonym synonym;
42
	private ITaxonTreeNode parentNode;
43

    
44
	private TaxonNode newNode;
45

    
46
	private Synonym[] synonymsInHomotypicalGroup;
47

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

    
64
		this.taxon = taxon;
65
		this.parentNode = parentNode;
66
		this.synonym = synonym;
67
		this.synonymsInHomotypicalGroup = synonymsInHomotypicalGroup;
68
	}
69

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

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

    
86
		synonym.setSec(null);
87
		newNode = parentNode.addChildTaxon(newTaxon, null, null);
88

    
89
		if(synonymsInHomotypicalGroup != null){
90
			Taxon taxon = newNode.getTaxon();
91
			for (Synonym synonym : synonymsInHomotypicalGroup){
92
				taxon.addHomotypicSynonym(synonym, null, null);
93
			}
94
		}
95

    
96
		monitor.worked(40);
97

    
98
		return postExecute(newNode);
99
	}
100

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

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

    
119
		// TODO implement - biggest problem is that any window open for new taxon must be closed first
120
		StoreUtil.warn(this.getClass(), "Not yet implemented");
121

    
122
		return postExecute(taxon);
123
	}
124

    
125
}
(6-6/19)