Project

General

Profile

Download (3.07 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
	@Override
56
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
57
			throws ExecutionException {
58

    
59
		TaxonName name = taxonBase.getName();
60

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

    
66
		name.setAsGroupsBasionym();
67

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

    
78
		return postExecute(taxonBase);
79
	}
80

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

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

    
94
		return postExecute(taxonBase);
95
	}
96

    
97

    
98
}
(4-4/15)