Project

General

Profile

Download (5.76 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.metadata.SecReferenceHandlingEnum;
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
    private UUID secundumUuid;
44
    private boolean setNameInSource ;
45
    private SecReferenceHandlingEnum secHandling;
46

    
47

    
48
    private final static String LABEL = Messages.RemotingChangeAcceptedTaxonToSynonymOperation_CHANGE_OP;
49

    
50
    /**
51
     * @param label
52
     */
53
    public RemotingChangeAcceptedTaxonToSynonymOperation(Object source,
54
            boolean async,
55
            Set<UUID> oldTaxonNodeUuids,
56
            UUID newAcceptedTaxonNodeUuid,
57
            UUID newSecUuid,
58
            SecReferenceHandlingEnum secHandling,
59
            EPartService partService,
60
            MPart activePart,
61
            MApplication application,
62
            boolean setNameInSource) {
63
        super(LABEL, Action.Update, source, async, partService, activePart, application);
64
        this.oldTaxonNodeUuids.addAll(oldTaxonNodeUuids);
65
        this.newAcceptedTaxonNodeUuid = newAcceptedTaxonNodeUuid;
66
        this.setNameInSource = setNameInSource;
67
        this.secundumUuid = newSecUuid;
68
        this.secHandling = secHandling;
69

    
70
    }
71

    
72
    /**
73
     * @param label
74
     */
75
    public RemotingChangeAcceptedTaxonToSynonymOperation(Object source,
76
            boolean async,
77
            UUID oldTaxonNodeUuid,
78
            UUID newAcceptedTaxonNodeUuid,
79
            UUID newSecUuid,
80
            SecReferenceHandlingEnum secHandling,
81
            EPartService partService,
82
    		MPart activePart,
83
    		MApplication application,
84
    		boolean setNameInSource) {
85
        super(LABEL, Action.Update, source, async, partService, activePart, application);
86
        this.oldTaxonNodeUuids.add(oldTaxonNodeUuid);
87
        this.newAcceptedTaxonNodeUuid = newAcceptedTaxonNodeUuid;
88
        this.setNameInSource = setNameInSource;
89
        this.secundumUuid = newSecUuid;
90
        this.secHandling = secHandling;
91
    }
92

    
93
    /**
94
     * @param label
95
     */
96
    public RemotingChangeAcceptedTaxonToSynonymOperation(Object source,
97
            boolean async,
98
            UUID oldTaxonNodeUuid,
99
            UUID newAcceptedTaxonNodeUuid,
100
            UUID newSecUuid,
101
            SecReferenceHandlingEnum secHandling,
102
            boolean setNameInSource) {
103
        super(LABEL, Action.Update, source, async);
104
        this.oldTaxonNodeUuids.add(oldTaxonNodeUuid);
105
        this.newAcceptedTaxonNodeUuid = newAcceptedTaxonNodeUuid;
106
        this.setNameInSource = setNameInSource;
107
        this.secundumUuid = newSecUuid;
108
        this.secHandling = secHandling;
109
    }
110

    
111
    /* (non-Javadoc)
112
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation#doUpdateExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
113
     */
114
    @Override
115
    protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
116

    
117
    	if (this.oldTaxonNodeUuids.size() == 1){
118
    		updateResult = CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode(oldTaxonNodeUuids.iterator().next(),
119
                    newAcceptedTaxonNodeUuid,
120
                    null,
121
                    secundumUuid,
122
                    null,
123
                    secHandling,
124
                    setNameInSource);//TODO
125
    	}else{
126
    		updateResult = CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeSynonymsOfAnotherTaxonNode(oldTaxonNodeUuids,
127
                    newAcceptedTaxonNodeUuid,
128
                    null,
129
                    secundumUuid,
130
                    null,
131
                    secHandling,
132
                    setNameInSource);//TODO
133
    	}
134
    	updateNameEditor();
135
    	return updateResult;
136

    
137
    }
138

    
139
    private void updateNameEditor(){
140
    	if (partService != null){
141
	    Display.getDefault().asyncExec(new Runnable() {
142

    
143
            @Override
144
            public void run() {
145
		    	for (MPart part : partService.getParts()){
146
					Object object = part.getObject();
147
					boolean setFocus = false;
148
					if (part == activePart){
149
					    setFocus = true;
150
					}
151
					if (part.getContributionURI().endsWith("TaxonNameEditorE4")){
152

    
153
					}
154
					if (object instanceof TaxonNameEditorE4 ){
155
						Set<TaxonNode> nodes = ((TaxonNameEditorE4)object).getTaxon().getTaxonNodes();
156
						for (TaxonNode node: nodes){
157
							if (node.getUuid().equals(newAcceptedTaxonNodeUuid)){
158
								EditorUtil.updateEditor(node, (TaxonNameEditorE4)object);
159
							}
160

    
161
						}
162
					}
163
				}
164
		    }
165
		});
166
    	}
167
    }
168
}
(3-3/10)