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
.navigation
.l10n
.Messages
;
30 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
31 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
32 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
35 * <p>ChangeAcceptedTaxonToSynonymOperation class.</p>
38 * @created Jan 4, 2010
41 public class ChangeAcceptedTaxonToSynonymOperation
extends
44 private final TaxonNode newAcceptedTaxonNode
;
45 private final ICdmEntitySessionEnabled cdmEntitySessionEnabled
;
48 //private TaxonNode oldTaxonNode;
51 * <p>Constructor for ChangeAcceptedTaxonToSynonymOperation.</p>
53 * @param label a {@link java.lang.String} object.
54 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
55 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
56 * @param oldTaxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
57 * @param newAcceptedTaxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
58 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
60 public ChangeAcceptedTaxonToSynonymOperation(String label
,
61 IUndoContext undoContext
,
62 ITaxonTreeNode oldTaxonNode
,
63 TaxonNode newAcceptedTaxonNode
,
64 IPostOperationEnabled postOperationEnabled
,
65 IConversationEnabled conversationEnabled
,
66 ICdmEntitySessionEnabled cdmEntitySessionEnabled
) {
67 super(label
, undoContext
, oldTaxonNode
, new TaxonDeletionConfigurator(),postOperationEnabled
, conversationEnabled
, cdmEntitySessionEnabled
);
68 this.newAcceptedTaxonNode
= newAcceptedTaxonNode
;
69 this.cdmEntitySessionEnabled
= cdmEntitySessionEnabled
;
74 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
78 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
79 throws ExecutionException
{
84 Taxon oldTaxon
= HibernateProxyHelper
.deproxy(((TaxonNode
) taxonNode
).getTaxon(), Taxon
.class);
85 Taxon newAcceptedTaxon
= HibernateProxyHelper
.deproxy(newAcceptedTaxonNode
.getTaxon(), Taxon
.class);
88 UpdateResult result
= CdmStore
.getService(ITaxonNodeService
.class).makeTaxonNodeASynonymOfAnotherTaxonNode(taxonNode
.getUuid(), newAcceptedTaxonNode
.getUuid(), null, null, null);
91 if (!result
.getExceptions().isEmpty() && result
.isOk()){
92 String separator
= ", "; //$NON-NLS-1$
93 String exceptionString
= ""; //$NON-NLS-1$
94 int count
= result
.getExceptions().size();
96 for (Exception exception
: result
.getExceptions()) {
98 exceptionString
+= exception
.getLocalizedMessage();
100 exceptionString
+= separator
;
104 MessagingUtils
.informationDialog(Messages
.ChangeAcceptedTaxonToSynonymOperation_CREATE_SUCCESS
, exceptionString
);
105 } else if (result
.isAbort() || result
.isError()){
106 MessagingUtils
.errorDialog(Messages
.ChangeAcceptedTaxonToSynonymOperation_CREATE_FAIL
, null, result
.toString(), TaxeditorNavigationPlugin
.PLUGIN_ID
, null, true);
108 } catch (IllegalArgumentException e
) {
109 MessagingUtils
.errorDialog(Messages
.ChangeAcceptedTaxonToSynonymOperation_OP_FAIL
, this, e
.getMessage(), TaxeditorNavigationPlugin
.PLUGIN_ID
, e
, false);
110 return Status
.CANCEL_STATUS
;
115 return postExecute(oldTaxon
);
119 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
123 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
124 throws ExecutionException
{
125 // TODO Auto-generated method stub
130 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
134 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
135 throws ExecutionException
{
136 // TODO Auto-generated method stub