2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
;
12 import org
.eclipse
.core
.commands
.ExecutionException
;
13 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
14 import org
.eclipse
.core
.runtime
.IAdaptable
;
15 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
16 import org
.eclipse
.core
.runtime
.IStatus
;
17 import org
.eclipse
.core
.runtime
.Status
;
19 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
20 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
21 import eu
.etaxonomy
.cdm
.api
.service
.UpdateResult
;
22 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
23 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
27 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
28 import eu
.etaxonomy
.taxeditor
.navigation
.internal
.TaxeditorNavigationPlugin
;
29 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
30 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
31 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
34 * <p>ChangeAcceptedTaxonToSynonymOperation class.</p>
37 * @created Jan 4, 2010
40 public class ChangeAcceptedTaxonToSynonymOperation
extends
43 private final TaxonNode newAcceptedTaxonNode
;
44 private final ICdmEntitySessionEnabled cdmEntitySessionEnabled
;
47 //private TaxonNode oldTaxonNode;
50 * <p>Constructor for ChangeAcceptedTaxonToSynonymOperation.</p>
52 * @param label a {@link java.lang.String} object.
53 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
54 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
55 * @param oldTaxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
56 * @param newAcceptedTaxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
57 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
59 public ChangeAcceptedTaxonToSynonymOperation(String label
,
60 IUndoContext undoContext
,
61 ITaxonTreeNode oldTaxonNode
,
62 TaxonNode newAcceptedTaxonNode
,
63 IPostOperationEnabled postOperationEnabled
,
64 IConversationEnabled conversationEnabled
,
65 ICdmEntitySessionEnabled cdmEntitySessionEnabled
) {
66 super(label
, undoContext
, oldTaxonNode
, new TaxonDeletionConfigurator(),postOperationEnabled
, conversationEnabled
, cdmEntitySessionEnabled
);
67 this.newAcceptedTaxonNode
= newAcceptedTaxonNode
;
68 this.cdmEntitySessionEnabled
= cdmEntitySessionEnabled
;
73 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
77 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
78 throws ExecutionException
{
83 Taxon oldTaxon
= HibernateProxyHelper
.deproxy(((TaxonNode
) taxonNode
).getTaxon(), Taxon
.class);
84 Taxon newAcceptedTaxon
= HibernateProxyHelper
.deproxy(newAcceptedTaxonNode
.getTaxon(), Taxon
.class);
87 UpdateResult result
= CdmStore
.getService(ITaxonNodeService
.class).makeTaxonNodeASynonymOfAnotherTaxonNode(taxonNode
.getUuid(), newAcceptedTaxonNode
.getUuid(), null, null, null);
90 if (!result
.getExceptions().isEmpty() && result
.isOk()){
91 String separator
= ", ";
92 String exceptionString
= "";
93 int count
= result
.getExceptions().size();
95 for (Exception exception
: result
.getExceptions()) {
97 exceptionString
+= exception
.getLocalizedMessage();
99 exceptionString
+= separator
;
103 MessagingUtils
.informationDialog("Synonym created but taxon deletion not possible.", exceptionString
);
104 } else if (result
.isAbort() || result
.isError()){
105 MessagingUtils
.errorDialog("Synonym creation not possible", null, result
.toString(), TaxeditorNavigationPlugin
.PLUGIN_ID
, null, true);
107 } catch (IllegalArgumentException e
) {
108 MessagingUtils
.errorDialog("Operation failed", this, e
.getMessage(), TaxeditorNavigationPlugin
.PLUGIN_ID
, e
, false);
109 return Status
.CANCEL_STATUS
;
114 return postExecute(oldTaxon
);
118 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
122 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
123 throws ExecutionException
{
124 // TODO Auto-generated method stub
129 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
133 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
134 throws ExecutionException
{
135 // TODO Auto-generated method stub