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 javax.inject.Inject;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.eclipse.core.runtime.Assert;
|
17
|
import org.eclipse.core.runtime.IAdaptable;
|
18
|
import org.eclipse.core.runtime.IProgressMonitor;
|
19
|
import org.eclipse.core.runtime.IStatus;
|
20
|
import org.eclipse.core.runtime.Status;
|
21
|
import org.eclipse.core.runtime.jobs.Job;
|
22
|
import org.eclipse.e4.ui.di.UISynchronize;
|
23
|
import org.eclipse.e4.ui.model.application.MApplication;
|
24
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
25
|
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
26
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
27
|
import org.eclipse.swt.widgets.Display;
|
28
|
import org.eclipse.ui.progress.IProgressConstants;
|
29
|
|
30
|
import eu.etaxonomy.cdm.api.application.CdmApplicationException;
|
31
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
32
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
33
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
34
|
import eu.etaxonomy.cdm.api.service.config.SecundumForSubtreeConfigurator;
|
35
|
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
|
36
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
37
|
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
|
38
|
import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
|
39
|
|
40
|
/**
|
41
|
* @author k.luther
|
42
|
* @date 10.02.2017
|
43
|
*
|
44
|
*/
|
45
|
public class SetSecundumForSubtreeOperation extends UpdateSubtreeOperation implements IPostMoniteredOperationEnabled{
|
46
|
|
47
|
private final static String LABEL = Messages.SetSecundumForSubtreeOperation_CHANGE_SEC_OP;
|
48
|
private static final Logger logger = Logger
|
49
|
.getLogger(SetSecundumForSubtreeOperation.class);
|
50
|
|
51
|
@Inject
|
52
|
UISynchronize sync;
|
53
|
|
54
|
|
55
|
public SetSecundumForSubtreeOperation(Object source, boolean async, UUID taxonNodeUuid, EPartService partService,
|
56
|
MPart activePart, MApplication application, EModelService modelService, SecundumForSubtreeConfigurator config) {
|
57
|
super(source, async, taxonNodeUuid, partService, activePart, application, modelService, config, LABEL);
|
58
|
|
59
|
}
|
60
|
|
61
|
/**
|
62
|
* {@inheritDoc}
|
63
|
*/
|
64
|
@Override
|
65
|
protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
|
66
|
// runMoniteredOperation();
|
67
|
|
68
|
Job job = createJob(monitor);
|
69
|
// configure the job
|
70
|
job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
|
71
|
job.setUser(true);
|
72
|
// schedule job
|
73
|
job.schedule();
|
74
|
|
75
|
return updateResult;
|
76
|
|
77
|
|
78
|
}
|
79
|
|
80
|
|
81
|
private Job createJob(IProgressMonitor monitor){
|
82
|
Assert.isNotNull(config, "Configuration may not be null");
|
83
|
|
84
|
final Display display = Display.getDefault();
|
85
|
|
86
|
Job job = new Job(Messages.SetSecundumForSubtreeOperation_SET_SEC_TASK) {
|
87
|
@Override
|
88
|
protected IStatus run(IProgressMonitor monitor) {
|
89
|
if (config instanceof SecundumForSubtreeConfigurator){
|
90
|
updateResult = taxonNodeService.setSecundumForSubtree((SecundumForSubtreeConfigurator)config);
|
91
|
}else{
|
92
|
return Status.CANCEL_STATUS;
|
93
|
}
|
94
|
updateNameEditors();
|
95
|
return Status.OK_STATUS;
|
96
|
|
97
|
}
|
98
|
};
|
99
|
return job;
|
100
|
}
|
101
|
|
102
|
|
103
|
public void runMoniteredOperation() {
|
104
|
ITaxonNodeService nodeService;
|
105
|
try {
|
106
|
nodeService = CdmApplicationState.getService(ITaxonNodeService.class);
|
107
|
|
108
|
final UUID uuid = nodeService.monitSetSecundum((SecundumForSubtreeConfigurator)config);
|
109
|
Display.getDefault().asyncExec(new Runnable() {
|
110
|
@Override
|
111
|
public void run() {
|
112
|
AbstractUtility.executeMoniteredOperation("Set Secundum Reference for Subtree: ",
|
113
|
uuid,
|
114
|
1000,
|
115
|
false,
|
116
|
SetSecundumForSubtreeOperation.this,
|
117
|
null);
|
118
|
}
|
119
|
});
|
120
|
} catch (CdmApplicationException e) {
|
121
|
// TODO Auto-generated catch block
|
122
|
e.printStackTrace();
|
123
|
}
|
124
|
|
125
|
}
|
126
|
|
127
|
|
128
|
|
129
|
/**
|
130
|
* {@inheritDoc}
|
131
|
*/
|
132
|
@Override
|
133
|
public void postOperation(IRemotingProgressMonitor monitor) {
|
134
|
// TODO Auto-generated method stub
|
135
|
|
136
|
}
|
137
|
}
|