Project

General

Profile

Revision a1764026

IDa176402688900c5b07eddc6a3705a7f63fa8c39a
Parent 459a7535
Child 15cd5e08

Added by Patrick Plitzner about 3 years ago

ref #6595 Migrate conversation handling of moveSynonym operation

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/MoveSynonymToAnotherAcceptedTaxonHandlerE4.java
21 21
import eu.etaxonomy.cdm.model.taxon.Taxon;
22 22
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
23 23
import eu.etaxonomy.taxeditor.editor.EditorUtil;
24
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
24
import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInputE4;
25 25
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
26 26
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
27
import eu.etaxonomy.taxeditor.editor.name.e4.operation.MoveSynonymToAnotherAcceptedTaxonOperationE4;
27 28
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
28
import eu.etaxonomy.taxeditor.editor.name.operation.MoveSynonymToAnotherAcceptedTaxonOperation;
29 29
import eu.etaxonomy.taxeditor.model.AbstractUtility;
30 30
import eu.etaxonomy.taxeditor.model.MessagingUtils;
31 31
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
......
48 48
			return ;
49 49
		}
50 50

  
51
		if (!(input instanceof TaxonEditorInput)) {
51
		if (!(input instanceof TaxonEditorInputE4)) {
52 52
			logger.error("Editor input is not TaxonEditorInput"); //$NON-NLS-1$
53 53
			return ;
54 54
		}
......
60 60
		}
61 61

  
62 62
		Synonym synonym = (Synonym) selection.getFirstElement();
63
		Taxon oldParent = ((TaxonEditorInput)input).getTaxon();
63
		Taxon oldParent = ((TaxonEditorInputE4)input).getTaxon();
64 64
		List<UUID> excludeTaxa = new ArrayList<UUID>();
65 65
		excludeTaxa.add(oldParent.getUuid());
66 66

  
67 67

  
68
		TaxonNode newParentNode = TaxonNodeSelectionDialog.select(shell, editor.getConversationHolder(), Messages.MoveSynonymToAnotherAcceptedTaxonHandler_SELECT_ACC_TAXON, excludeTaxa,  ((TaxonEditorInput)input).getTaxonNode(), ((TaxonEditorInput)input).getTaxonNode().getClassification());
68
		TaxonNode newParentNode = TaxonNodeSelectionDialog.select(shell, editor.getConversationHolder(), Messages.MoveSynonymToAnotherAcceptedTaxonHandler_SELECT_ACC_TAXON, excludeTaxa,  ((TaxonEditorInputE4)input).getTaxonNode(), ((TaxonEditorInputE4)input).getTaxonNode().getClassification());
69 69

  
70 70
		if(newParentNode!=null){
71
		   MoveSynonymToAnotherAcceptedTaxonOperation operation = new MoveSynonymToAnotherAcceptedTaxonOperation(Messages.MoveSynonymToAnotherAcceptedTaxonHandler_CHANGE_ACC_TAXON, EditorUtil.getUndoContext(),
72
		            oldParent.getUuid(), synonym.getUuid(), newParentNode.getTaxon(), editor);
71
		   MoveSynonymToAnotherAcceptedTaxonOperationE4 operation = new MoveSynonymToAnotherAcceptedTaxonOperationE4(Messages.MoveSynonymToAnotherAcceptedTaxonHandler_CHANGE_ACC_TAXON, EditorUtil.getUndoContext(),
72
		            synonym.getUuid(), newParentNode.getTaxon(), editor, editor);
73 73

  
74 74
		    AbstractUtility.executeOperation(operation);
75 75
		}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/operation/MoveSynonymToAnotherAcceptedTaxonOperationE4.java
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.exception.HomotypicalGroupChangeException;
16
import eu.etaxonomy.cdm.model.taxon.Synonym;
17
import eu.etaxonomy.cdm.model.taxon.Taxon;
18
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
19
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
20
import eu.etaxonomy.taxeditor.store.CdmStore;
21

  
22
public class MoveSynonymToAnotherAcceptedTaxonOperationE4 extends
23
		AbstractPostTaxonOperation {
24

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

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

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

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

  
50
		monitor.worked(20);
51

  
52
		// Switch groups
53

  
54
		monitor.worked(40);
55

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

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

  
72
		// Redraw editor if it exists
73
		return postExecute(synonym);
74
	}
75

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

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

  
88
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)