1
|
|
2
|
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.handler;
|
3
|
|
4
|
import java.util.Iterator;
|
5
|
import java.util.List;
|
6
|
import java.util.UUID;
|
7
|
import java.util.stream.Collectors;
|
8
|
|
9
|
import javax.inject.Named;
|
10
|
|
11
|
import org.eclipse.core.runtime.ICoreRunnable;
|
12
|
import org.eclipse.core.runtime.IProgressMonitor;
|
13
|
import org.eclipse.core.runtime.SubMonitor;
|
14
|
import org.eclipse.core.runtime.jobs.Job;
|
15
|
import org.eclipse.e4.core.di.annotations.Execute;
|
16
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
17
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
18
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
19
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
20
|
import org.eclipse.swt.widgets.Shell;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
23
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
24
|
import eu.etaxonomy.cdm.api.service.config.DeleteDescriptiveDataSetConfigurator;
|
25
|
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
|
26
|
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
|
27
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
28
|
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.DescriptiveDataSetNavigator;
|
29
|
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
|
30
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
31
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
32
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
33
|
import eu.etaxonomy.taxeditor.ui.dialog.configurator.deleteConfigurator.DeleteConfiguratorDialog;
|
34
|
|
35
|
public class DeleteDescriptiveDataSetHandler {
|
36
|
protected EPartService partService;
|
37
|
|
38
|
@Execute
|
39
|
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
40
|
@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
41
|
@Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
|
42
|
EPartService partService) {
|
43
|
// boolean confirm = MessagingUtils.confirmDialog(Messages.DeleteDescriptiveDataSetHandler_DELETE_TITLE, Messages.DeleteDescriptiveDataSetHandler_DELETE_MESSAGE);
|
44
|
this.partService = partService;
|
45
|
Object object = activePart.getObject();
|
46
|
if(!selection.isEmpty() && object instanceof DescriptiveDataSetNavigator){
|
47
|
Iterator iterator = selection.iterator();
|
48
|
while(iterator.hasNext()){
|
49
|
Object next = iterator.next();
|
50
|
if(next instanceof DescriptiveDataSet){
|
51
|
DeleteDescriptiveDataSetConfigurator deleteConfig = new DeleteDescriptiveDataSetConfigurator();
|
52
|
|
53
|
if (!DeleteConfiguratorDialog.openConfirmWithConfigurator(deleteConfig, shell, Messages.DeleteDescriptiveDataSetHandler_DELETE_TITLE, Messages.DeleteDescriptiveDataSetHandler_DELETE_MESSAGE)){
|
54
|
return;
|
55
|
}
|
56
|
// IDescriptiveDataSetService descriptiveDataSetService = CdmStore.getService(IDescriptiveDataSetService.class);
|
57
|
// descriptiveDataSetService.delete(((DescriptiveDataSet) next).getUuid());
|
58
|
deleteDescriptiveDataSet(((DescriptiveDataSet) next).getUuid(), deleteConfig);
|
59
|
DescriptiveDataSetNavigator navigator = (DescriptiveDataSetNavigator) object;
|
60
|
navigator.removeDescriptiveDataSet((DescriptiveDataSet) next);
|
61
|
navigator.getConversationHolder().commit();
|
62
|
navigator.getSelService().setSelection(null);
|
63
|
|
64
|
}
|
65
|
else{
|
66
|
MessagingUtils.errorDialog(Messages.DeleteDescriptiveDataSetHandler_DELETE_FAILED_TITLE, DeleteDescriptiveDataSetHandler.class, Messages.DeleteDescriptiveDataSetHandler_DELETE_FAILED_MESSAGE, TaxeditorEditorPlugin.PLUGIN_ID, null, false);
|
67
|
return;
|
68
|
}
|
69
|
}
|
70
|
}
|
71
|
}
|
72
|
|
73
|
private void deleteDescriptiveDataSet(UUID descriptiveDataSetUuid, DeleteDescriptiveDataSetConfigurator deleteConfig){
|
74
|
EditorUtil.closeObsoleteDescriptiveDatasetEditor(descriptiveDataSetUuid, partService);
|
75
|
UUID monitorUuid = CdmApplicationState.getLongRunningTasksService().deleteDescriptiveDataset(descriptiveDataSetUuid, deleteConfig);
|
76
|
|
77
|
String jobLabel = "Delete descriptive dataset";
|
78
|
Job job = Job.create(jobLabel, (ICoreRunnable) monitor -> {
|
79
|
SubMonitor subMonitor = SubMonitor.convert(monitor);
|
80
|
subMonitor.beginTask(jobLabel, IProgressMonitor.UNKNOWN);
|
81
|
IRemotingProgressMonitor remotingMonitor;
|
82
|
try {
|
83
|
remotingMonitor = CdmStore.getProgressMonitorClientManager()
|
84
|
.pollMonitor(jobLabel,
|
85
|
monitorUuid,
|
86
|
50,
|
87
|
null,
|
88
|
(List)null,
|
89
|
subMonitor);
|
90
|
Object resultObject = remotingMonitor.getResult();
|
91
|
if(resultObject instanceof Exception){
|
92
|
MessagingUtils.errorDialog("Deleting descriptive dataset failed", this, "Deleting descriptive dataset was not successfull", TaxeditorEditorPlugin.PLUGIN_ID, (Exception)resultObject, true, true);
|
93
|
}
|
94
|
else if(resultObject instanceof UpdateResult){
|
95
|
UpdateResult result = (UpdateResult)resultObject;
|
96
|
|
97
|
if(!result.getExceptions().isEmpty() && result.isOk()){
|
98
|
MessagingUtils.messageDialog(Messages.DeleteDescriptiveDatasetHandler_Warning_Message, this,
|
99
|
String.format(Messages.DeleteDescriptiveDatasetHandler_Warning_Message, result.getExceptions()
|
100
|
.stream().map(ex->ex.toString())
|
101
|
.collect(Collectors.joining("\n"))));
|
102
|
}
|
103
|
|
104
|
|
105
|
}
|
106
|
} catch (InterruptedException e) {
|
107
|
return;
|
108
|
}
|
109
|
monitor.done();
|
110
|
});
|
111
|
|
112
|
job.schedule();
|
113
|
}
|
114
|
|
115
|
|
116
|
|
117
|
|
118
|
}
|