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