Project

General

Profile

Download (4.44 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.editor.view.descriptive.operation;
11

    
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;
18

    
19
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
20
import eu.etaxonomy.cdm.api.service.IDescriptionService;
21
import eu.etaxonomy.cdm.model.common.Annotation;
22
import eu.etaxonomy.cdm.model.common.AnnotationType;
23
import eu.etaxonomy.cdm.model.common.Language;
24
import eu.etaxonomy.cdm.model.description.TaxonDescription;
25
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
26
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
27
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
28
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
29
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
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 final TaxonNode newAcceptedTaxonNode;
42

    
43
	private final 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,
57
			TaxonDescription description,
58
			TaxonNode targetTaxonNode,
59
			IPostOperationEnabled postOperationEnabled,
60
			IConversationEnabled conversationEnabled,
61
            ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
62
		super(label, undoContext, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled); // FIXME is this the right constructor ???
63
		this.description = description;
64
		this.newAcceptedTaxonNode = targetTaxonNode;
65
	}
66

    
67

    
68
	/* (non-Javadoc)
69
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
70
	 */
71
	/** {@inheritDoc} */
72
	@Override
73
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
74
			throws ExecutionException {
75

    
76
		monitor.worked(20);
77
		bind();
78

    
79
		String moveMessage = String.format(Messages.MoveDescriptionToOtherTaxonOperation_MOVED_FROM, description.getTaxon());
80
		if(description.isProtectedTitleCache()){
81
			String separator = ""; //$NON-NLS-1$
82
			if(!StringUtils.isBlank(description.getTitleCache())){
83
				separator = " - "; //$NON-NLS-1$
84
			}
85
			description.setTitleCache(description.getTitleCache() + separator + moveMessage, true);
86
		}
87
		Annotation annotation = Annotation.NewInstance(moveMessage, Language.getDefaultLanguage());
88
		annotation.setAnnotationType(AnnotationType.TECHNICAL());
89
		description.addAnnotation(annotation);
90
		CdmStore.getService(IDescriptionService.class).moveTaxonDescription(description.getUuid(), newAcceptedTaxonNode.getTaxon().getUuid());
91
		monitor.worked(40);
92

    
93
		return postExecute(description);
94
	}
95

    
96
	/* (non-Javadoc)
97
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
98
	 */
99
	/** {@inheritDoc} */
100
	@Override
101
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
102
			throws ExecutionException {
103
		// TODO Auto-generated method stub
104
		return null;
105
	}
106

    
107
	/* (non-Javadoc)
108
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
109
	 */
110
	/** {@inheritDoc} */
111
	@Override
112
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
113
			throws ExecutionException {
114
		// TODO Auto-generated method stub
115
		return null;
116
	}
117
}
(10-10/10)