2 package eu
.etaxonomy
.taxeditor
.editor
.descriptiveDataSet
.handler
;
4 import java
.util
.Iterator
;
7 import java
.util
.stream
.Collectors
;
9 import javax
.inject
.Named
;
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
.jface
.viewers
.IStructuredSelection
;
20 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
21 import eu
.etaxonomy
.cdm
.api
.service
.UpdateResult
;
22 import eu
.etaxonomy
.cdm
.common
.monitor
.IRemotingProgressMonitor
;
23 import eu
.etaxonomy
.cdm
.model
.description
.DescriptiveDataSet
;
24 import eu
.etaxonomy
.taxeditor
.editor
.descriptiveDataSet
.DescriptiveDataSetNavigator
;
25 import eu
.etaxonomy
.taxeditor
.editor
.internal
.TaxeditorEditorPlugin
;
26 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
27 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
28 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
30 public class DeleteDescriptiveDataSetHandler
{
33 public void execute(@Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
34 @Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
) {
35 boolean confirm
= MessagingUtils
.confirmDialog(Messages
.DeleteDescriptiveDataSetHandler_DELETE_TITLE
, Messages
.DeleteDescriptiveDataSetHandler_DELETE_MESSAGE
);
36 Object object
= activePart
.getObject();
37 if(!selection
.isEmpty() && confirm
&& object
instanceof DescriptiveDataSetNavigator
){
38 Iterator iterator
= selection
.iterator();
39 while(iterator
.hasNext()){
40 Object next
= iterator
.next();
41 if(next
instanceof DescriptiveDataSet
){
42 // IDescriptiveDataSetService descriptiveDataSetService = CdmStore.getService(IDescriptiveDataSetService.class);
43 // descriptiveDataSetService.delete(((DescriptiveDataSet) next).getUuid());
44 deleteDescriptiveDataSet(((DescriptiveDataSet
) next
).getUuid());
45 DescriptiveDataSetNavigator navigator
= (DescriptiveDataSetNavigator
) object
;
46 navigator
.removeDescriptiveDataSet((DescriptiveDataSet
) next
);
47 navigator
.getConversationHolder().commit();
50 MessagingUtils
.errorDialog(Messages
.DeleteDescriptiveDataSetHandler_DELETE_FAILED_TITLE
, DeleteDescriptiveDataSetHandler
.class, Messages
.DeleteDescriptiveDataSetHandler_DELETE_FAILED_MESSAGE
, TaxeditorEditorPlugin
.PLUGIN_ID
, null, false);
57 private void deleteDescriptiveDataSet(UUID descriptiveDataSetUuid
){
58 UUID monitorUuid
= CdmApplicationState
.getLongRunningTasksService().deleteDescriptiveDataset(descriptiveDataSetUuid
);
60 String jobLabel
= "Delete descriptive dataset";
61 Job job
= Job
.create(jobLabel
, (ICoreRunnable
) monitor
-> {
62 SubMonitor subMonitor
= SubMonitor
.convert(monitor
);
63 subMonitor
.beginTask(jobLabel
, IProgressMonitor
.UNKNOWN
);
64 IRemotingProgressMonitor remotingMonitor
;
66 remotingMonitor
= CdmStore
.getProgressMonitorClientManager()
67 .pollMonitor(jobLabel
,
73 Object resultObject
= remotingMonitor
.getResult();
74 if(resultObject
instanceof Exception
){
75 MessagingUtils
.errorDialog("Deleting descriptive dataset failed", this, "Deleting descriptive dataset was not successfull", TaxeditorEditorPlugin
.PLUGIN_ID
, (Exception
)resultObject
, true, true);
77 else if(resultObject
instanceof UpdateResult
){
78 UpdateResult result
= (UpdateResult
)resultObject
;
79 if(!result
.getExceptions().isEmpty() && result
.isOk()){
80 MessagingUtils
.warningDialog(Messages
.DeleteDescriptiveDatasetHandler_Warning_Message
, this,
81 String
.format(Messages
.DeleteDescriptiveDatasetHandler_Warning_Message
, result
.getExceptions()
82 .stream().map(ex
->ex
.toString())
83 .collect(Collectors
.joining("\n"))));
87 } catch (InterruptedException e
) {