Project

General

Profile

« Previous | Next » 

Revision f55638a3

Added by Katja Luther over 9 years ago

View differences:

.gitattributes
472 472
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/DeleteSynonymOperation.java -text
473 473
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/DeleteTaxonBaseOperation.java -text
474 474
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/DeleteTaxonOperation.java -text
475
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/MoveSynonymToAnotherAcceptedTaxonOperation.java -text
475 476
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/RemoveHomotypicalGroupBasionymOperation.java -text
476 477
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/SwapSynonymAndAcceptedOperation.java -text
477 478
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistContentProvider.java -text
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/MoveSynonymToAnotherAcceptedTaxonOperation.java
1
package eu.etaxonomy.taxeditor.editor.name.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.service.ITaxonService;
14
import eu.etaxonomy.cdm.api.service.exception.HomotypicalGroupChangeException;
15
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
16
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
17
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
18
import eu.etaxonomy.cdm.model.taxon.Synonym;
19
import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
20
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
21
import eu.etaxonomy.cdm.model.taxon.Taxon;
22
import eu.etaxonomy.taxeditor.editor.EditorUtil;
23
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
24
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
25
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
26
import eu.etaxonomy.taxeditor.store.CdmStore;
27

  
28
public class MoveSynonymToAnotherAcceptedTaxonOperation extends
29
		AbstractPostTaxonOperation {
30

  
31
	/**
32
	 * The synonym to be moved.
33
	 */
34
	private final Synonym synonym;
35

  
36
	private final Taxon oldTaxon;
37
	
38
	
39
	/**
40
	 * <p>Constructor for MoveSynonymToAnotherAcceptedTaxon.</p>
41
	 *
42
	 * @param label a {@link java.lang.String} object.
43
	 * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
44
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
45
	 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
46
	 
47
	 * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
48
	 */
49
	public MoveSynonymToAnotherAcceptedTaxonOperation(String label, IUndoContext undoContext,
50
			UUID oldTaxonUUID, UUID synonymUUID, Taxon taxon, IPostOperationEnabled postOperationEnabled) {
51
		
52
		super(label, undoContext, taxon, postOperationEnabled);
53
		List<String> propertyPaths =  new ArrayList<String>();
54
		propertyPaths.add("synonymRelations");
55
		this.element = (Taxon) CdmStore.getService(ITaxonService.class).load(taxon.getUuid(),propertyPaths);
56
		this.oldTaxon = (Taxon) CdmStore.getService(ITaxonService.class).load(oldTaxonUUID);
57
		this.synonym = (Synonym) CdmStore.getService(ITaxonService.class).load(synonymUUID);
58
		if(synonym == null){
59
			throw new IllegalArgumentException(
60
					"A null synonym was provided.");
61
		}
62
	}
63

  
64
	@Override
65
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
66
			throws ExecutionException {
67

  
68
    	// Get synonym name
69
		TaxonNameBase<?, ?> synonymName = synonym.getName();
70
		monitor.worked(20);
71

  
72
		
73

  
74
		// Switch groups
75
		
76
		monitor.worked(40);
77
		SynonymRelationship synRel = synonym.getSynonymRelations().iterator().next();
78
		
79
		
80
		
81
		((TaxonNameEditor)EditorUtil.getActiveMultiPageTaxonEditor().getActiveEditor()).getConversationHolder().commit();
82
		
83
		
84
		
85
		try {
86
			synRel = CdmStore.getService(ITaxonService.class).moveSynonymToAnotherTaxon(synRel, this.element, true, synRel.getType(), null, null, true);
87
		} catch (HomotypicalGroupChangeException e) {
88
			// TODO Auto-generated catch block
89
			e.printStackTrace();
90
		}
91
		((TaxonNameEditor)EditorUtil.getActiveMultiPageTaxonEditor().getActiveEditor()).getConversationHolder().commit();
92
		
93
		
94

  
95
		// Redraw editor if it exists
96
		return postExecute(synRel.getSynonym());
97
	}
98

  
99
	@Override
100
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
101
			throws ExecutionException {
102
		// TODO Auto-generated method stub
103
		return null;
104
	}
105

  
106
	@Override
107
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
108
			throws ExecutionException {
109
		// TODO Auto-generated method stub
110
		return null;
111
	}
112

  
113
}

Also available in: Unified diff