Merge branch 'develop' into remoting-4.0
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / operation / ChangeHomotypicalGroupBasionymOperation.java
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.TaxonNameBase;
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 * @version 1.0
34 */
35 public class ChangeHomotypicalGroupBasionymOperation extends
36 AbstractPostTaxonOperation {
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 /* (non-Javadoc)
56 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
57 */
58 /** {@inheritDoc} */
59 @Override
60 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
61 throws ExecutionException {
62
63 TaxonNameBase<?, ?> name = taxonBase.getName();
64
65 monitor.worked(20);
66 name = HibernateProxyHelper.deproxy(name, TaxonNameBase.class);
67 HomotypicalGroup group = HibernateProxyHelper.deproxy(name.getHomotypicalGroup(), HomotypicalGroup.class);
68 TaxonNameBase oldBasionym = name.getBasionym();
69
70 name.setAsGroupsBasionym();
71
72 monitor.worked(40);
73 oldBasionym = HibernateProxyHelper.deproxy(oldBasionym, TaxonNameBase.class);
74 if (oldBasionym != null){
75 Set<TaxonBase> taxonBases = oldBasionym.getTaxonBases();
76 if (!taxonBases.isEmpty()){
77 TaxonBase oldBasionymTaxonBase = taxonBases.iterator().next();
78 postExecute(oldBasionymTaxonBase);
79 }
80 }
81
82 return postExecute(taxonBase);
83 }
84
85 /* (non-Javadoc)
86 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
87 */
88 /** {@inheritDoc} */
89 @Override
90 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
91 throws ExecutionException {
92 return execute(monitor, info);
93 }
94
95 /* (non-Javadoc)
96 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
97 */
98 /** {@inheritDoc} */
99 @Override
100 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
101 throws ExecutionException {
102 // TODO replace w method from cdmlib
103 // FIXME this is also old code: reimplement
104 // CdmUtil.setGroupBasionym(synonym.getName());
105
106 return postExecute(taxonBase);
107 }
108
109
110 }