Merge branch 'release/3.12.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / operation / SwapSynonymAndAcceptedOperation.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.editor.name.operation;
12
13 import org.eclipse.core.commands.ExecutionException;
14 import org.eclipse.core.commands.operations.IUndoContext;
15 import org.eclipse.core.runtime.IAdaptable;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18
19 import eu.etaxonomy.cdm.api.service.ITaxonService;
20 import eu.etaxonomy.cdm.api.service.UpdateResult;
21 import eu.etaxonomy.cdm.model.taxon.Synonym;
22 import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
23 import eu.etaxonomy.cdm.model.taxon.Taxon;
24 import eu.etaxonomy.taxeditor.model.MessagingUtils;
25 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
26 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
27 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
28 import eu.etaxonomy.taxeditor.store.CdmStore;
29
30 /**
31 * <p>SwapSynonymAndAcceptedOperation class.</p>
32 *
33 * @author n.hoffmann
34 * @created 23.04.2009
35 * @version 1.0
36 */
37 public class SwapSynonymAndAcceptedOperation extends AbstractPostTaxonOperation {
38
39 private final Synonym synonym;
40 // TODO store the old relationship for undo reasons
41 private SynonymRelationshipType synonymRelationshipType;
42
43 /**
44 * <p>Constructor for SwapSynonymAndAcceptedOperation.</p>
45 *
46 * @param label a {@link java.lang.String} object.
47 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
48 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
49 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
50 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
51 */
52 public SwapSynonymAndAcceptedOperation(String label, IUndoContext undoContext,
53 Taxon taxon, Synonym synonym, IPostOperationEnabled postOperationEnabled,
54 ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
55 super("Swap Synonym And Accepted Taxon Operation", undoContext, taxon, postOperationEnabled, cdmEntitySessionEnabled);
56
57 this.synonym = synonym;
58 }
59
60 /* (non-Javadoc)
61 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
62 */
63 /** {@inheritDoc} */
64 @Override
65 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
66 throws ExecutionException {
67
68 monitor.worked(20);
69
70 UpdateResult result = CdmStore.getService(ITaxonService.class).swapSynonymAndAcceptedTaxon(synonym.getUuid(), element.getUuid());
71
72 monitor.worked(40);
73
74 return postExecute(element);
75 }
76
77 /* (non-Javadoc)
78 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
79 */
80 /** {@inheritDoc} */
81 @Override
82 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
83 throws ExecutionException {
84 // TODO Auto-generated method stub
85 return execute(monitor, info);
86 }
87
88 /* (non-Javadoc)
89 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
90 */
91 /** {@inheritDoc} */
92 @Override
93 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
94 throws ExecutionException {
95 MessagingUtils.error(this.getClass(), "Not yet implemented", null);
96 return null;
97 }
98 }