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
.editor
.view
.descriptive
.operation
;
12 import org
.apache
.commons
.lang
.StringUtils
;
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
;
19 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationRemoteController
;
20 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
21 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
22 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
23 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
24 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
25 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
26 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
28 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
29 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPersistentPostOperation
;
30 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
31 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
32 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
35 * <p>MoveDescriptionToOtherTaxonOperation</p>
37 * @author a.kohlbecker
38 * @created Okt. 11, 2013
40 public class MoveDescriptionToOtherTaxonOperation
extends
41 AbstractPersistentPostOperation
{
43 private final TaxonNode newAcceptedTaxonNode
;
45 private final TaxonDescription description
;
48 * <p>Constructor for ChangeAcceptedTaxonToSynonymOperation.</p>
50 * @param label a {@link java.lang.String} object.
51 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
52 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
53 * @param description a {@link TaxonDescription} object.
54 * @param targetTaxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
55 * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
57 public MoveDescriptionToOtherTaxonOperation(String label
,
58 IUndoContext undoContext
,
59 TaxonDescription description
,
60 TaxonNode targetTaxonNode
,
61 IPostOperationEnabled postOperationEnabled
,
62 IConversationEnabled conversationEnabled
,
63 ICdmEntitySessionEnabled cdmEntitySessionEnabled
) {
64 super(label
, undoContext
, postOperationEnabled
, conversationEnabled
, cdmEntitySessionEnabled
); // FIXME is this the right constructor ???
65 this.description
= description
;
66 this.newAcceptedTaxonNode
= targetTaxonNode
;
71 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
75 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
76 throws ExecutionException
{
81 String moveMessage
= String
.format("Description moved from %s", EditorUtil
.getActiveMultiPageTaxonEditor().getTaxon());
82 if(description
.isProtectedTitleCache()){
83 String separator
= "";
84 if(!StringUtils
.isBlank(description
.getTitleCache())){
87 description
.setTitleCache(description
.getTitleCache() + separator
+ moveMessage
, true);
89 Annotation annotation
= Annotation
.NewInstance(moveMessage
, Language
.getDefaultLanguage());
90 annotation
.setAnnotationType(AnnotationType
.TECHNICAL());
91 description
.addAnnotation(annotation
);
92 newAcceptedTaxonNode
.getTaxon().addDescription(description
);
93 if (CdmApplicationState
.getCurrentAppConfig() instanceof CdmApplicationRemoteController
) {
94 CdmStore
.getService(IDescriptionService
.class).merge(description
, true);
96 CdmStore
.getService(IDescriptionService
.class).saveOrUpdate(description
);
99 // CdmStore.getService(IDescriptionService.class).moveTaxonDescription(description.getUuid(), newAcceptedTaxonNode.getTaxon().getUuid());
102 return postExecute(description
);
106 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
110 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
111 throws ExecutionException
{
112 // TODO Auto-generated method stub
117 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
121 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
122 throws ExecutionException
{
123 // TODO Auto-generated method stub