bug fixxing in bulk editor and referencing objects view
[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 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.taxeditor.operation.AbstractPostTaxonOperation;
28 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
29
30 /**
31 * <p>ChangeHomotypicalGroupBasionymOperation class.</p>
32 *
33 * @author p.ciardelli
34 * @created 15.01.2009
35 * @version 1.0
36 */
37 public class ChangeHomotypicalGroupBasionymOperation extends
38 AbstractPostTaxonOperation {
39 private TaxonBase taxonBase;
40
41 /**
42 * <p>Constructor for ChangeHomotypicalGroupBasionymOperation.</p>
43 *
44 * @param text a {@link java.lang.String} object.
45 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
46 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
47 * @param taxonBase a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
48 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
49 */
50 public ChangeHomotypicalGroupBasionymOperation(String text,
51 IUndoContext undoContext, Taxon taxon, TaxonBase taxonBase, IPostOperationEnabled postOperationEnabled) {
52 super(text, undoContext, taxon, postOperationEnabled);
53
54 this.taxonBase = taxonBase;
55 }
56
57 /* (non-Javadoc)
58 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
59 */
60 /** {@inheritDoc} */
61 @Override
62 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
63 throws ExecutionException {
64
65 TaxonNameBase<?, ?> name = taxonBase.getName();
66
67 monitor.worked(20);
68 name = HibernateProxyHelper.deproxy(name, TaxonNameBase.class);
69 HomotypicalGroup group = HibernateProxyHelper.deproxy(name.getHomotypicalGroup(), HomotypicalGroup.class);
70 TaxonNameBase oldBasionym = name.getBasionym();
71
72 name.setAsGroupsBasionym();
73
74 monitor.worked(40);
75 oldBasionym = HibernateProxyHelper.deproxy(oldBasionym, TaxonNameBase.class);
76 if (oldBasionym != null){
77 Set<TaxonBase> taxonBases = oldBasionym.getTaxonBases();
78 if (!taxonBases.isEmpty()){
79 TaxonBase oldBasionymTaxonBase = taxonBases.iterator().next();
80 postExecute(oldBasionymTaxonBase);
81 }
82 }
83 return postExecute(taxonBase);
84 }
85
86 /* (non-Javadoc)
87 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
88 */
89 /** {@inheritDoc} */
90 @Override
91 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
92 throws ExecutionException {
93 return execute(monitor, info);
94 }
95
96 /* (non-Javadoc)
97 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
98 */
99 /** {@inheritDoc} */
100 @Override
101 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
102 throws ExecutionException {
103 // TODO replace w method from cdmlib
104 // FIXME this is also old code: reimplement
105 // CdmUtil.setGroupBasionym(synonym.getName());
106
107 return postExecute(taxonBase);
108 }
109
110
111 }