ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / operation / ChangeAcceptedTaxonToSynonymOperation.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.navigation.navigator.operation;
11
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;
18
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;
32
33 /**
34 * <p>ChangeAcceptedTaxonToSynonymOperation class.</p>
35 *
36 * @author n.hoffmann
37 * @created Jan 4, 2010
38 * @version 1.0
39 */
40 public class ChangeAcceptedTaxonToSynonymOperation extends
41 DeleteOperation {
42
43 private final TaxonNode newAcceptedTaxonNode;
44 private final ICdmEntitySessionEnabled cdmEntitySessionEnabled;
45
46
47 //private TaxonNode oldTaxonNode;
48
49 /**
50 * <p>Constructor for ChangeAcceptedTaxonToSynonymOperation.</p>
51 *
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.
58 */
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;
69 }
70
71
72 /* (non-Javadoc)
73 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
74 */
75 /** {@inheritDoc} */
76 @Override
77 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
78 throws ExecutionException {
79
80 monitor.worked(20);
81 bind();
82
83 Taxon oldTaxon = HibernateProxyHelper.deproxy(((TaxonNode) taxonNode).getTaxon(), Taxon.class);
84 Taxon newAcceptedTaxon = HibernateProxyHelper.deproxy(newAcceptedTaxonNode.getTaxon(), Taxon.class);
85
86 try {
87 UpdateResult result = CdmStore.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode(taxonNode.getUuid(), newAcceptedTaxonNode.getUuid(), null, null, null);
88
89
90 if (!result.getExceptions().isEmpty() && result.isOk()){
91 String separator = ", ";
92 String exceptionString = "";
93 int count = result.getExceptions().size();
94 int n = 0;
95 for (Exception exception : result.getExceptions()) {
96 n++;
97 exceptionString += exception.getLocalizedMessage();
98 if (n<count){
99 exceptionString += separator;
100 }
101 }
102
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);
106 }
107 } catch (IllegalArgumentException e) {
108 MessagingUtils.errorDialog("Operation failed", this, e.getMessage(), TaxeditorNavigationPlugin.PLUGIN_ID, e, false);
109 return Status.CANCEL_STATUS;
110 }
111
112 monitor.worked(40);
113
114 return postExecute(oldTaxon);
115 }
116
117 /* (non-Javadoc)
118 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
119 */
120 /** {@inheritDoc} */
121 @Override
122 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
123 throws ExecutionException {
124 // TODO Auto-generated method stub
125 return null;
126 }
127
128 /* (non-Javadoc)
129 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
130 */
131 /** {@inheritDoc} */
132 @Override
133 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
134 throws ExecutionException {
135 // TODO Auto-generated method stub
136 return null;
137 }
138 }