3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
;
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 import org
.eclipse
.core
.runtime
.Status
;
19 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
21 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
22 import eu
.etaxonomy
.cdm
.api
.service
.DeleteResult
;
23 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
24 import eu
.etaxonomy
.cdm
.api
.service
.UpdateResult
;
25 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
26 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
30 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
31 import eu
.etaxonomy
.taxeditor
.navigation
.internal
.TaxeditorNavigationPlugin
;
32 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
33 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
34 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
37 * <p>ChangeAcceptedTaxonToSynonymOperation class.</p>
40 * @created Jan 4, 2010
43 public class ChangeAcceptedTaxonToSynonymOperation
extends
46 private final TaxonNode newAcceptedTaxonNode
;
47 private final ICdmEntitySessionEnabled cdmEntitySessionEnabled
;
50 //private TaxonNode oldTaxonNode;
53 * <p>Constructor for ChangeAcceptedTaxonToSynonymOperation.</p>
55 * @param label a {@link java.lang.String} object.
56 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
57 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
58 * @param oldTaxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
59 * @param newAcceptedTaxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
60 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
62 public ChangeAcceptedTaxonToSynonymOperation(String label
,
63 IUndoContext undoContext
,
64 ITaxonTreeNode oldTaxonNode
,
65 TaxonNode newAcceptedTaxonNode
,
66 IPostOperationEnabled postOperationEnabled
,
67 IConversationEnabled conversationEnabled
,
68 ICdmEntitySessionEnabled cdmEntitySessionEnabled
) {
69 super(label
, undoContext
, oldTaxonNode
, new TaxonDeletionConfigurator(),postOperationEnabled
, conversationEnabled
, cdmEntitySessionEnabled
);
70 this.newAcceptedTaxonNode
= newAcceptedTaxonNode
;
71 this.cdmEntitySessionEnabled
= cdmEntitySessionEnabled
;
76 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
80 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
81 throws ExecutionException
{
86 Taxon oldTaxon
= (Taxon
) HibernateProxyHelper
.deproxy(((TaxonNode
) taxonNode
).getTaxon());
89 UpdateResult result
= CdmStore
.getService(ITaxonNodeService
.class).makeTaxonNodeASynonymOfAnotherTaxonNode(taxonNode
.getUuid(), newAcceptedTaxonNode
.getUuid(), null, null, null);
91 if (!result
.getExceptions().isEmpty() && result
.isOk()){
92 String separator
= ", ";
93 String exceptionString
= "";
94 for (Exception exception
: result
.getExceptions()) {
95 exceptionString
+= exception
.getLocalizedMessage()+separator
;
98 MessagingUtils
.informationDialog("Synonym created but taxon is not deleted.", exceptionString
);
99 } else if (result
.isAbort() || result
.isError()){
100 MessagingUtils
.errorDialog("Synonym could not created", null, result
.toString(), TaxeditorNavigationPlugin
.PLUGIN_ID
, null, true);
102 } catch (IllegalArgumentException e
) {
103 MessagingUtils
.errorDialog("Operation failed", this, e
.getMessage(), TaxeditorNavigationPlugin
.PLUGIN_ID
, e
, false);
104 return Status
.CANCEL_STATUS
;
109 return postExecute(oldTaxon
);
113 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
117 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
118 throws ExecutionException
{
119 // TODO Auto-generated method stub
124 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
128 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
129 throws ExecutionException
{
130 // TODO Auto-generated method stub