merge-update from trunk
[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.apache.commons.lang.StringUtils;
14 import org.eclipse.core.commands.ExecutionException;
15 import org.eclipse.core.commands.operations.IUndoContext;
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.IStatus;
19
20 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
21 import eu.etaxonomy.cdm.api.service.IDescriptionService;
22 import eu.etaxonomy.cdm.model.common.Annotation;
23 import eu.etaxonomy.cdm.model.common.AnnotationType;
24 import eu.etaxonomy.cdm.model.common.Language;
25 import eu.etaxonomy.cdm.model.description.TaxonDescription;
26 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
27 import eu.etaxonomy.taxeditor.editor.EditorUtil;
28 import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
29 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
30 import eu.etaxonomy.taxeditor.store.CdmStore;
31
32 /**
33 * <p>MoveDescriptionToOtherTaxonOperation</p>
34 *
35 * @author a.kohlbecker
36 * @created Okt. 11, 2013
37 */
38 public class MoveDescriptionToOtherTaxonOperation extends
39 AbstractPersistentPostOperation {
40
41 private TaxonNode newAcceptedTaxonNode;
42
43 private TaxonDescription description;
44
45 /**
46 * <p>Constructor for ChangeAcceptedTaxonToSynonymOperation.</p>
47 *
48 * @param label a {@link java.lang.String} object.
49 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
50 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
51 * @param description a {@link TaxonDescription} object.
52 * @param targetTaxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
53 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
54 */
55 public MoveDescriptionToOtherTaxonOperation(String label,
56 IUndoContext undoContext, TaxonDescription description, TaxonNode targetTaxonNode,
57 IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled) {
58 super(label, undoContext, postOperationEnabled, conversationEnabled); // 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 monitor.worked(40);
89
90 return postExecute(description);
91 }
92
93 /* (non-Javadoc)
94 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
95 */
96 /** {@inheritDoc} */
97 @Override
98 public IStatus redo(IProgressMonitor monitor, IAdaptable info)
99 throws ExecutionException {
100 // TODO Auto-generated method stub
101 return null;
102 }
103
104 /* (non-Javadoc)
105 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
106 */
107 /** {@inheritDoc} */
108 @Override
109 public IStatus undo(IProgressMonitor monitor, IAdaptable info)
110 throws ExecutionException {
111 // TODO Auto-generated method stub
112 return null;
113 }
114 }