Project

General

Profile

Download (4.42 KB) Statistics
| Branch: | Tag: | Revision:
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.api.service.ITaxonNodeService;
23
import eu.etaxonomy.cdm.api.service.exception.DataChangeNoRollbackException;
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.Synonym;
29
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
30
import eu.etaxonomy.taxeditor.editor.EditorUtil;
31
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
32
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
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 TaxonNode newAcceptedTaxonNode;
45

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

    
66

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

    
75
		monitor.worked(20);
76
		bind();
77
		
78
		String moveMessage = String.format("Description moved from %s", EditorUtil.getActiveMultiPageTaxonEditor().getTaxon());
79
		if(description.isProtectedTitleCache()){
80
			String separator = "";
81
			if(!StringUtils.isBlank(description.getTitleCache())){
82
				separator = " - ";
83
			}
84
			description.setTitleCache(description.getTitleCache() + separator + moveMessage);
85
		}
86
		Annotation annotation = Annotation.NewInstance(moveMessage, Language.DEFAULT());
87
		annotation.setAnnotationType(AnnotationType.TECHNICAL());
88
		description.addAnnotation(annotation);
89
		description.setTaxon(newAcceptedTaxonNode.getTaxon());
90
		CdmStore.getService(IDescriptionService.class).saveOrUpdate(description);	
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
}
(7-7/7)