Project

General

Profile

Download (4.63 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2015 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
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
10

    
11
import java.util.HashSet;
12
import java.util.Set;
13
import java.util.UUID;
14

    
15
import org.eclipse.core.runtime.IAdaptable;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.e4.ui.model.application.MApplication;
18
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
19
import org.eclipse.e4.ui.workbench.modeling.EPartService;
20
import org.eclipse.swt.widgets.Display;
21

    
22
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
23
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
24
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
25
import eu.etaxonomy.cdm.api.service.UpdateResult;
26
import eu.etaxonomy.cdm.model.common.CdmBase;
27
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
28
import eu.etaxonomy.taxeditor.editor.EditorUtil;
29
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
30
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
31
import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
32

    
33

    
34
/**
35
 * @author cmathew
36
 * @date 17 Jun 2015
37
 *
38
 */
39
public class RemotingChangeAcceptedTaxonToSynonymOperation extends RemotingCdmUpdateOperation {
40

    
41
    private Set<UUID> oldTaxonNodeUuids = new HashSet();
42
    private final UUID newAcceptedTaxonNodeUuid;
43

    
44

    
45
    private final static String LABEL = Messages.RemotingChangeAcceptedTaxonToSynonymOperation_CHANGE_OP;
46

    
47
    /**
48
     * @param label
49
     */
50
    public RemotingChangeAcceptedTaxonToSynonymOperation(Object source,
51
            boolean async,
52
            Set<UUID> oldTaxonNodeUuids,
53
            UUID newAcceptedTaxonNodeUuid,
54
            EPartService partService,
55
            MPart activePart,
56
            MApplication application) {
57
        super(LABEL, Action.Update, source, async, partService, activePart, application);
58
        this.oldTaxonNodeUuids.addAll(oldTaxonNodeUuids);
59
        this.newAcceptedTaxonNodeUuid = newAcceptedTaxonNodeUuid;
60
        
61
    }
62
    
63
    /**
64
     * @param label
65
     */
66
    public RemotingChangeAcceptedTaxonToSynonymOperation(Object source,
67
            boolean async,
68
            UUID oldTaxonNodeUuid,
69
            UUID newAcceptedTaxonNodeUuid,
70
            EPartService partService,
71
    		MPart activePart,
72
    		MApplication application) {
73
        super(LABEL, Action.Update, source, async, partService, activePart, application);
74
        this.oldTaxonNodeUuids.add(oldTaxonNodeUuid);
75
        this.newAcceptedTaxonNodeUuid = newAcceptedTaxonNodeUuid;
76
    }
77
    
78
    /**
79
     * @param label
80
     */
81
    public RemotingChangeAcceptedTaxonToSynonymOperation(Object source,
82
            boolean async,
83
            UUID oldTaxonNodeUuid,
84
            UUID newAcceptedTaxonNodeUuid) {
85
        super(LABEL, Action.Update, source, async);
86
        this.oldTaxonNodeUuids.add(oldTaxonNodeUuid);
87
        this.newAcceptedTaxonNodeUuid = newAcceptedTaxonNodeUuid;
88
    }
89

    
90
    /* (non-Javadoc)
91
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation#doUpdateExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
92
     */
93
    @Override
94
    protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
95
    	
96
    	if (this.oldTaxonNodeUuids.size() == 1){
97
    		updateResult = CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode(oldTaxonNodeUuids.iterator().next(),
98
                    newAcceptedTaxonNodeUuid,
99
                    null,
100
                    null,
101
                    null);
102
    	}else{
103
    		updateResult = CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeSynonymsOfAnotherTaxonNode(oldTaxonNodeUuids,
104
                    newAcceptedTaxonNodeUuid,
105
                    null,
106
                    null,
107
                    null);
108
    	}
109
    	updateNameEditor();
110
    	return updateResult;
111
        
112
    }
113
    
114
    private void updateNameEditor(){
115
    	if (partService != null){
116
	    Display.getDefault().asyncExec(new Runnable() {
117
		    public void run() {
118
		    	for (MPart part : partService.getParts()){
119
					Object object = part.getObject();
120
					if (object instanceof TaxonNameEditorE4){
121
						Set<TaxonNode> nodes = ((TaxonNameEditorE4)object).getTaxon().getTaxonNodes();
122
						for (TaxonNode node: nodes){
123
							if (node.getTaxon().getUuid().equals(newAcceptedTaxonNodeUuid)){
124
								EditorUtil.updateEditor(node, partService, application);										   
125
							}
126
								
127
						}
128
					}
129
				} 
130
		    }
131
		});
132
    	}
133
    }
134
}
(5-5/11)