2 * Copyright (C) 2020 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.descriptiveDataSet
.matrix
.handler
;
11 import java
.util
.List
;
13 import java
.util
.UUID
;
15 import javax
.inject
.Named
;
17 import org
.eclipse
.core
.runtime
.ICoreRunnable
;
18 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
19 import org
.eclipse
.core
.runtime
.SubMonitor
;
20 import org
.eclipse
.core
.runtime
.jobs
.Job
;
21 import org
.eclipse
.e4
.core
.di
.annotations
.CanExecute
;
22 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
23 import org
.eclipse
.e4
.ui
.di
.UISynchronize
;
24 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
25 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
26 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
28 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
29 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
30 import eu
.etaxonomy
.cdm
.common
.monitor
.IRemotingProgressMonitor
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
32 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDto
;
33 import eu
.etaxonomy
.taxeditor
.editor
.descriptiveDataSet
.matrix
.CharacterMatrix
;
34 import eu
.etaxonomy
.taxeditor
.editor
.descriptiveDataSet
.matrix
.CharacterMatrixPart
;
35 import eu
.etaxonomy
.taxeditor
.editor
.internal
.TaxeditorEditorPlugin
;
36 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
37 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
38 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
39 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonSelectionDialog
;
45 public class GeneratePolytomousKeyHandler
{
48 public void execute(@Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
, UISynchronize sync
) {
49 // dependent on the selection the specimens are filtered
50 CharacterMatrixPart matrixPart
= (CharacterMatrixPart
) activePart
.getObject();
52 CharacterMatrix matrix
= matrixPart
.getMatrix();
53 if(StoreUtil
.promptCheckIsDirty(matrix
.getPart())){
56 Set
<TaxonNodeDto
> nodeDtos
= matrix
.getDescriptiveDataSet().getSubTreeFilter();
58 TaxonNodeDto parentDto
= CdmStore
.getService(ITaxonNodeService
.class).findCommonParentDto(nodeDtos
);
59 UUID taxonUuid
= parentDto
.getTaxonUuid();
60 int response
= MessagingUtils
.confirmDialog(
61 "Choose taxonomic scope",
62 String
.format("The common parent taxon of this dataset is :\n%s\n\n"
63 + "Do you want to use this as the taxonomic scope for the polytomous key?"
64 , parentDto
.getTaxonTitleCache()), "Yes", "Choose different taxon", "Cancel");
69 Taxon taxon
= TaxonSelectionDialog
.selectTaxon(matrix
.getShell(), null);
73 taxonUuid
= taxon
.getUuid();
77 UUID datasetUuid
= matrix
.getDescriptiveDataSet().getUuid();
78 UUID monitorUuid
= CdmApplicationState
.getLongRunningTasksService().generatePolytomousKey(datasetUuid
, taxonUuid
);
80 String jobLabel
= "Generate polytomous key";
81 Job job
= Job
.create(jobLabel
, (ICoreRunnable
) monitor
-> {
82 SubMonitor subMonitor
= SubMonitor
.convert(monitor
);
83 subMonitor
.beginTask(jobLabel
, IProgressMonitor
.UNKNOWN
);
84 IRemotingProgressMonitor remotingMonitor
;
86 remotingMonitor
= CdmStore
.getProgressMonitorClientManager()
87 .pollMonitor(jobLabel
,
93 Object resultObject
= remotingMonitor
.getResult();
94 if(resultObject
instanceof Exception
){
95 MessagingUtils
.errorDialog("Key generation failed", this, "Generating the polytomous key was not successfull", TaxeditorEditorPlugin
.PLUGIN_ID
, (Exception
)resultObject
, true, true);
97 } catch (InterruptedException e
) {
106 public boolean canExecute(@Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
107 MHandledMenuItem menuItem
){