Project

General

Profile

Download (3.13 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.hibernate.HibernateProxyHelper;
21
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
22
import eu.etaxonomy.cdm.model.name.TaxonName;
23
import eu.etaxonomy.cdm.model.taxon.Taxon;
24
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
25
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
26
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
27

    
28
/**
29
 * <p>ChangeHomotypicalGroupBasionymOperation class.</p>
30
 *
31
 * @author p.ciardelli
32
 * @created 15.01.2009
33
 */
34
public class ChangeHomotypicalGroupBasionymOperation extends
35
		AbstractPostTaxonOperation {
36
	
37
	private final TaxonBase taxonBase;
38

    
39
	/**
40
	 * <p>Constructor for ChangeHomotypicalGroupBasionymOperation.</p>
41
	 *
42
	 * @param text a {@link java.lang.String} object.
43
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
44
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
45
	 * @param taxonBase a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
46
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
47
	 */
48
	public ChangeHomotypicalGroupBasionymOperation(String text,
49
			IUndoContext undoContext, Taxon taxon, TaxonBase taxonBase, IPostOperationEnabled postOperationEnabled) {
50
		super(text, undoContext, taxon, postOperationEnabled);
51

    
52
		this.taxonBase = taxonBase;
53
	}
54

    
55
	/** {@inheritDoc} */
56
	@Override
57
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
58
			throws ExecutionException {
59

    
60
		TaxonName name = taxonBase.getName();
61

    
62
		monitor.worked(20);
63
		name = HibernateProxyHelper.deproxy(name);
64
		HomotypicalGroup group = HibernateProxyHelper.deproxy(name.getHomotypicalGroup(), HomotypicalGroup.class);
65
        TaxonName oldBasionym = name.getBasionym();
66

    
67
		name.setAsGroupsBasionym();
68

    
69
		monitor.worked(40);
70
		oldBasionym = HibernateProxyHelper.deproxy(oldBasionym);
71
		if (oldBasionym != null){
72
			Set<TaxonBase> taxonBases = oldBasionym.getTaxonBases();
73
			if (!taxonBases.isEmpty()){
74
				TaxonBase oldBasionymTaxonBase = taxonBases.iterator().next();
75
				postExecute(oldBasionymTaxonBase);
76
			}
77
		}
78

    
79
		return postExecute(taxonBase);
80
	}
81

    
82
	/** {@inheritDoc} */
83
	@Override
84
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
85
			throws ExecutionException {
86
		return execute(monitor, info);
87
	}
88

    
89
	/** {@inheritDoc} */
90
	@Override
91
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
92
			throws ExecutionException {
93
		// TODO replace w method from cdmlib
94
		// FIXME this is also old code: reimplement
95
//		CdmUtil.setGroupBasionym(synonym.getName());
96

    
97
		return postExecute(taxonBase);
98
	}
99

    
100

    
101
}
(4-4/19)