move descriptions in a service call
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / descriptive / operation / MoveDescriptionToOtherTaxonOperation.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.view.descriptive.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.conversation.IConversationEnabled;
20 import eu.etaxonomy.cdm.api.service.IDescriptionService;
21 import eu.etaxonomy.cdm.model.description.TaxonDescription;
22 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
23 import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
24 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
25 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
26 import eu.etaxonomy.taxeditor.store.CdmStore;
27
28 /**
29 * <p>MoveDescriptionToOtherTaxonOperation</p>
30 *
31 * @author a.kohlbecker
32 * @created Okt. 11, 2013
33 */
34 public class MoveDescriptionToOtherTaxonOperation extends
35 AbstractPersistentPostOperation {
36
37 private final TaxonNode newAcceptedTaxonNode;
38
39 private final TaxonDescription description;
40
41 /**
42 * <p>Constructor for ChangeAcceptedTaxonToSynonymOperation.</p>
43 *
44 * @param label a {@link java.lang.String} object.
45 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
46 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
47 * @param description a {@link TaxonDescription} object.
48 * @param targetTaxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
49 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
50 */
51 public MoveDescriptionToOtherTaxonOperation(String label,
52 IUndoContext undoContext,
53 TaxonDescription description,
54 TaxonNode targetTaxonNode,
55 IPostOperationEnabled postOperationEnabled,
56 IConversationEnabled conversationEnabled,
57 ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
58 super(label, undoContext, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled); // FIXME is this the right constructor ???
59 this.description = description;
60 this.newAcceptedTaxonNode = targetTaxonNode;
61 }
62
63
64 /* (non-Javadoc)
65 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
66 */
67 /** {@inheritDoc} */
68 @Override
69 public IStatus execute(IProgressMonitor monitor, IAdaptable info)
70 throws ExecutionException {
71
72 monitor.worked(20);
73 bind();
74
75 /*String moveMessage = String.format("Description moved from %s", EditorUtil.getActiveMultiPageTaxonEditor().getTaxon());
76 if(description.isProtectedTitleCache()){
77 String separator = "";
78 if(!StringUtils.isBlank(description.getTitleCache())){
79 separator = " - ";
80 }
81 description.setTitleCache(description.getTitleCache() + separator + moveMessage, true);
82 }
83 Annotation annotation = Annotation.NewInstance(moveMessage, Language.getDefaultLanguage());
84 annotation.setAnnotationType(AnnotationType.TECHNICAL());
85 description.addAnnotation(annotation);
86 newAcceptedTaxonNode.getTaxon().addDescription(description);
87 CdmStore.getService(IDescriptionService.class).saveOrUpdate(description);*/
88
89 CdmStore.getService(IDescriptionService.class).moveTaxonDescription(description.getUuid(), newAcceptedTaxonNode.getTaxon().getUuid());
90 monitor.worked(40);
91
92 return postExecute(description);
93 }
94
95 /* (non-Javadoc)
96 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
97 */
98 /** {@inheritDoc} */
99 @Override
100 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
101 throws ExecutionException {
102 // TODO Auto-generated method stub
103 return null;
104 }
105
106 /* (non-Javadoc)
107 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
108 */
109 /** {@inheritDoc} */
110 @Override
111 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
112 throws ExecutionException {
113 // TODO Auto-generated method stub
114 return null;
115 }
116 }