Project

General

Profile

Download (2.77 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.editor.name.e4.operation;
2

    
3
import java.util.ArrayList;
4
import java.util.List;
5
import java.util.UUID;
6

    
7
import org.eclipse.core.commands.ExecutionException;
8
import org.eclipse.core.commands.operations.IUndoContext;
9
import org.eclipse.core.runtime.IAdaptable;
10
import org.eclipse.core.runtime.IProgressMonitor;
11
import org.eclipse.core.runtime.IStatus;
12

    
13
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
14
import eu.etaxonomy.cdm.api.service.ITaxonService;
15
import eu.etaxonomy.cdm.api.service.UpdateResult;
16
import eu.etaxonomy.cdm.api.service.exception.HomotypicalGroupChangeException;
17
import eu.etaxonomy.cdm.model.taxon.Synonym;
18
import eu.etaxonomy.cdm.model.taxon.Taxon;
19
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
20
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
21
import eu.etaxonomy.taxeditor.store.CdmStore;
22

    
23
public class MoveSynonymToAnotherAcceptedTaxonOperationE4 extends
24
		AbstractPostTaxonOperation {
25

    
26
	/**
27
	 * The synonym to be moved.
28
	 */
29
	private final Synonym synonym;
30
	private IConversationEnabled conversationEnabled;
31

    
32
    public MoveSynonymToAnotherAcceptedTaxonOperationE4(String label, IUndoContext undoContext, UUID synonymUUID,
33
            Taxon taxon, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled) {
34

    
35
		super(label, undoContext, taxon, postOperationEnabled);
36
		List<String> propertyPaths =  new ArrayList<String>();
37
		propertyPaths.add("synonymRelations"); //$NON-NLS-1$
38
		this.conversationEnabled = conversationEnabled;
39
		this.element = (Taxon) CdmStore.getService(ITaxonService.class).load(taxon.getUuid(),propertyPaths);
40
		this.synonym = (Synonym) CdmStore.getService(ITaxonService.class).load(synonymUUID);
41
		if(synonym == null){
42
			throw new IllegalArgumentException(
43
					"A null synonym was provided."); //$NON-NLS-1$
44
		}
45
	}
46

    
47
	@Override
48
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
49
			throws ExecutionException {
50

    
51
		monitor.worked(20);
52

    
53
		// Switch groups
54

    
55
		monitor.worked(40);
56

    
57
		conversationEnabled.getConversationHolder().commit();
58

    
59
		try {
60
			UpdateResult result = CdmStore.getService(ITaxonService.class).moveSynonymToAnotherTaxon(synonym,
61
			        this.element.getUuid(),
62
			        true,
63
			        synonym.getType(),
64
			        null,
65
			        null,
66
			        true);
67
		} catch (HomotypicalGroupChangeException e) {
68
			// TODO Auto-generated catch block
69
			e.printStackTrace();
70
		}
71
		conversationEnabled.getConversationHolder().commit();
72

    
73
		// Redraw editor if it exists
74
		return postExecute(null);
75
	}
76

    
77
	@Override
78
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
79
			throws ExecutionException {
80
		return null;
81
	}
82

    
83
	@Override
84
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
85
			throws ExecutionException {
86
		return null;
87
	}
88

    
89
}
    (1-1/1)