Project

General

Profile

Download (4.89 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.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;
33

    
34
/**
35
 * <p>MoveDescriptionToOtherTaxonOperation</p>
36
 *
37
 * @author a.kohlbecker
38
 * @created Okt. 11, 2013
39
 */
40
public class MoveDescriptionToOtherTaxonOperation extends
41
		AbstractPersistentPostOperation {
42

    
43
	private final TaxonNode newAcceptedTaxonNode;
44

    
45
	private final TaxonDescription description;
46

    
47
	/**
48
	 * <p>Constructor for ChangeAcceptedTaxonToSynonymOperation.</p>
49
	 *
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.
56
	 */
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;
67
	}
68

    
69

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

    
78
		monitor.worked(20);
79
		bind();
80

    
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())){
85
				separator = " - ";
86
			}
87
			description.setTitleCache(description.getTitleCache() + separator + moveMessage, true);
88
		}
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);
95
        } else {
96
            CdmStore.getService(IDescriptionService.class).saveOrUpdate(description);
97
        }
98

    
99
	//	CdmStore.getService(IDescriptionService.class).moveTaxonDescription(description.getUuid(), newAcceptedTaxonNode.getTaxon().getUuid());
100
		monitor.worked(40);
101

    
102
		return postExecute(description);
103
	}
104

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

    
116
	/* (non-Javadoc)
117
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
118
	 */
119
	/** {@inheritDoc} */
120
	@Override
121
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
122
			throws ExecutionException {
123
		// TODO Auto-generated method stub
124
		return null;
125
	}
126
}
(10-10/10)