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