Project

General

Profile

Download (3.86 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
import org.eclipse.core.runtime.Status;
20

    
21
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
22
import eu.etaxonomy.cdm.model.common.CdmBase;
23
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
24
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
25
import eu.etaxonomy.cdm.model.taxon.Taxon;
26
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
27
import eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonName;
28
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
29
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
30

    
31
/**
32
 * <p>ChangeHomotypicalGroupBasionymOperation class.</p>
33
 *
34
 * @author p.ciardelli
35
 * @created 15.01.2009
36
 * @version 1.0
37
 */
38
public class ChangeHomotypicalGroupBasionymOperation extends
39
		AbstractPostTaxonOperation {
40
	private TaxonBase taxonBase;
41

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

    
58
	/* (non-Javadoc)
59
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
60
	 */
61
	/** {@inheritDoc} */
62
	@Override
63
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
64
			throws ExecutionException {
65
		
66
		TaxonNameBase<?, ?> name = taxonBase.getName();
67
		
68
		monitor.worked(20);
69
		name = HibernateProxyHelper.deproxy(name, TaxonNameBase.class);
70
		HomotypicalGroup group = HibernateProxyHelper.deproxy(name.getHomotypicalGroup(), HomotypicalGroup.class);
71
        TaxonNameBase oldBasionym = name.getBasionym();
72
        
73
		name.setAsGroupsBasionym();
74
		
75
		monitor.worked(40);
76
		oldBasionym = HibernateProxyHelper.deproxy(oldBasionym, TaxonNameBase.class);
77
		if (oldBasionym != null){
78
			Set<TaxonBase> taxonBases = oldBasionym.getTaxonBases();
79
			if (!taxonBases.isEmpty()){
80
				TaxonBase oldBasionymTaxonBase = taxonBases.iterator().next();
81
				postExecute(oldBasionymTaxonBase);
82
			}
83
		}
84
		return postExecute(taxonBase);
85
	}
86

    
87
	/* (non-Javadoc)
88
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
89
	 */
90
	/** {@inheritDoc} */
91
	@Override
92
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
93
			throws ExecutionException {
94
		return execute(monitor, info);
95
	}
96

    
97
	/* (non-Javadoc)
98
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
99
	 */
100
	/** {@inheritDoc} */
101
	@Override
102
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
103
			throws ExecutionException {
104
		// TODO replace w method from cdmlib
105
		// FIXME this is also old code: reimplement
106
//		CdmUtil.setGroupBasionym(synonym.getName());
107
				
108
		return postExecute(taxonBase);
109
	}
110
	
111
	
112
}
(4-4/18)