1
|
/**
|
2
|
* Copyright (C) 2017 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.UUID;
|
12
|
|
13
|
import org.apache.log4j.Logger;
|
14
|
import org.eclipse.core.runtime.Assert;
|
15
|
import org.eclipse.core.runtime.IAdaptable;
|
16
|
import org.eclipse.core.runtime.IProgressMonitor;
|
17
|
import org.eclipse.core.runtime.IStatus;
|
18
|
import org.eclipse.core.runtime.Status;
|
19
|
import org.eclipse.core.runtime.jobs.Job;
|
20
|
import org.eclipse.swt.widgets.Display;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.application.CdmApplicationException;
|
23
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
24
|
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
|
25
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
26
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
27
|
import eu.etaxonomy.cdm.api.service.config.SecundumForSubtreeConfigurator;
|
28
|
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
|
29
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
30
|
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
|
31
|
import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
|
32
|
import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
|
33
|
|
34
|
/**
|
35
|
* @author k.luther
|
36
|
* @date 10.02.2017
|
37
|
*
|
38
|
*/
|
39
|
public class SetSecundumForSubtreeOperation extends RemotingCdmUpdateOperation implements IPostMoniteredOperationEnabled{
|
40
|
|
41
|
private final static String LABEL = Messages.SetSecundumForSubtreeOperation_CHANGE_SEC_OP;
|
42
|
private static final Logger logger = Logger
|
43
|
.getLogger(SetSecundumForSubtreeOperation.class);
|
44
|
UUID parentUuid;
|
45
|
SecundumForSubtreeConfigurator config;
|
46
|
|
47
|
|
48
|
/**
|
49
|
* @param label
|
50
|
* @param action
|
51
|
* @param source
|
52
|
* @param async
|
53
|
*/
|
54
|
public SetSecundumForSubtreeOperation(Object source,
|
55
|
boolean async,
|
56
|
UUID taxonNodeUuid,
|
57
|
SecundumForSubtreeConfigurator config) {
|
58
|
super(LABEL, Action.Update, source, async);
|
59
|
parentUuid = taxonNodeUuid;
|
60
|
this.config = config;
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* {@inheritDoc}
|
65
|
*/
|
66
|
@Override
|
67
|
protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
|
68
|
runMoniteredOperation();
|
69
|
|
70
|
// Job job = createJob(monitor);
|
71
|
// // configure the job
|
72
|
// job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
|
73
|
// job.setUser(true);
|
74
|
// // schedule job
|
75
|
// job.schedule();
|
76
|
|
77
|
return updateResult;
|
78
|
|
79
|
|
80
|
}
|
81
|
|
82
|
|
83
|
private Job createJob(IProgressMonitor monitor){
|
84
|
Assert.isNotNull(config, "Configuration may not be null");
|
85
|
|
86
|
final Display display = Display.getDefault();
|
87
|
|
88
|
Job job = new Job(Messages.SetSecundumForSubtreeOperation_SET_SEC_TASK) {
|
89
|
|
90
|
|
91
|
@Override
|
92
|
protected IStatus run(IProgressMonitor monitor) {
|
93
|
|
94
|
try {
|
95
|
// eu.etaxonomy.cdm.common.monitor.IProgressMonitor cdmMonitor = CdmProgressMonitorAdapter.CreateMonitor(monitor);
|
96
|
// config.setMonitor(cdmMonitor);
|
97
|
ITaxonNodeService taxonService = CdmApplicationState.getService(ITaxonNodeService.class);
|
98
|
// taxonService.setSecundumForSubtree(config.getSubtreeUuid(), config.getNewSecundum(), config.isIncludeAcceptedTaxa(), config.isIncludeSynonyms(), config.isOverwriteExistingAccepted(), config.isOverwriteExistingSynonyms(), config.isIncludeSharedTaxa(), config.isEmptySecundumDetail(), null);
|
99
|
updateResult = taxonService.setSecundumForSubtree(config);
|
100
|
|
101
|
// Display.getDefault().asyncExec(new Runnable() {
|
102
|
// @Override
|
103
|
// public void run() {
|
104
|
// AbstractUtility.executeMoniteredOperation("Update: " + config.getClass().getSimpleName(),
|
105
|
// uuid,
|
106
|
// 1000,
|
107
|
// false,
|
108
|
// SetSecundumForSubtreeOperation.this,
|
109
|
// null);
|
110
|
// }
|
111
|
// });
|
112
|
|
113
|
} catch (CdmApplicationException e) {
|
114
|
// TODO Auto-generated catch block
|
115
|
e.printStackTrace();
|
116
|
}
|
117
|
//
|
118
|
return Status.OK_STATUS;
|
119
|
|
120
|
}
|
121
|
};
|
122
|
return job;
|
123
|
}
|
124
|
|
125
|
|
126
|
public void runMoniteredOperation() {
|
127
|
ITaxonNodeService nodeService;
|
128
|
try {
|
129
|
nodeService = CdmApplicationState.getService(ITaxonNodeService.class);
|
130
|
|
131
|
final UUID uuid = nodeService.monitSetSecundum(config);
|
132
|
Display.getDefault().asyncExec(new Runnable() {
|
133
|
@Override
|
134
|
public void run() {
|
135
|
AbstractUtility.executeMoniteredOperation("Set Secundum Reference for Subtree: ",
|
136
|
uuid,
|
137
|
1000,
|
138
|
false,
|
139
|
SetSecundumForSubtreeOperation.this,
|
140
|
null);
|
141
|
}
|
142
|
});
|
143
|
} catch (CdmApplicationException e) {
|
144
|
// TODO Auto-generated catch block
|
145
|
e.printStackTrace();
|
146
|
}
|
147
|
|
148
|
}
|
149
|
|
150
|
|
151
|
|
152
|
/**
|
153
|
* {@inheritDoc}
|
154
|
*/
|
155
|
@Override
|
156
|
public void postOperation(IRemotingProgressMonitor monitor) {
|
157
|
// TODO Auto-generated method stub
|
158
|
|
159
|
}
|
160
|
}
|