<children xsi:type="menu:HandledMenuItem" xmi:id="_AyHbgLKSEeikjKoOnLFm2w" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.createdefaultdescription" label="%handledmenuitem.label.19" command="_ZHC3oLKVEeikjKoOnLFm2w"/>
<children xsi:type="menu:HandledMenuItem" xmi:id="_DYlHcLKSEeikjKoOnLFm2w" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.createliteraturedescription" label="%handledmenuitem.label.20" command="_fkPkkLKVEeikjKoOnLFm2w"/>
<children xsi:type="menu:HandledMenuItem" xmi:id="__SlnwI97EeqyUKRuXQ8miw" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.deletedescription" label="%handledmenuitem.label.28" command="_MYd44I98EeqyUKRuXQ8miw"/>
- <children xsi:type="menu:HandledMenuItem" xmi:id="_ARo78KSvEeq8Gc-K2nsNRg" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.adddescription" label="command.commandname.25" command="_zCGQ8JN1EeqyUKRuXQ8miw"/>
+ <children xsi:type="menu:HandledMenuItem" xmi:id="_ARo78KSvEeq8Gc-K2nsNRg" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.adddescription" label="%command.commandname.25" command="_zCGQ8JN1EeqyUKRuXQ8miw"/>
+ <children xsi:type="menu:HandledMenuItem" xmi:id="_vBrWQKY-Eeq8Gc-K2nsNRg" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.aggregate" label="%command.commandname.26" command="_K2C_oKZAEeq8Gc-K2nsNRg"/>
</menus>
</elements>
<elements xsi:type="basic:PartDescriptor" xmi:id="_XcQMEN8mEee9zP45RW4C3A" elementId="eu.etaxonomy.taxeditor.editor.descriptiveDataSet.DescriptiveDataSetNavigator" label="%partdescriptor.label.5" closeable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.descriptiveDataSet.DescriptiveDataSetNavigator">
<elements xsi:type="commands:Command" xmi:id="__8WFwL9OEemCian_vXpNsA" elementId="eu.etaxonomy.taxeditor.editor.view.descriptive.command.moveDescriptionElementsSetNameInSource" commandName="%command.name.132"/>
<elements xsi:type="commands:Command" xmi:id="_MYd44I98EeqyUKRuXQ8miw" elementId="eu.etaxonomy.taxeditor.editor.command.deletedescription" commandName="%command.commandname.24"/>
<elements xsi:type="commands:Command" xmi:id="_zCGQ8JN1EeqyUKRuXQ8miw" elementId="eu.etaxonomy.taxeditor.editor.charactermatrix.command.addDescription" commandName="%command.commandname.25"/>
+ <elements xsi:type="commands:Command" xmi:id="_K2C_oKZAEeq8Gc-K2nsNRg" elementId="eu.etaxonomy.taxeditor.editor.command.aggregation" commandName="Aggregate"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_pZmusEalEeeXMc6kSYO7Xg" featurename="children" parentElementId="eu.etaxonomy.taxeditor.menu.showView" positionInList="after:eu.etaxonomy.taxeditor.workbench.menuseparator.navigation">
<elements xsi:type="menu:HandledMenuItem" xmi:id="_FPIHQKNwEeebGZ23ERGMGw" elementId="eu.etaxonomy.taxeditor.editor.showViewMenu.conceptGraph" label="%view.name.3" iconURI="" tooltip="%view.name.3" command="_WPjpoDSnEeek0dKsFNy--Q">
<elements xsi:type="commands:Handler" xmi:id="_KxUSAE3pEeivZbtHG8C6kA" elementId="eu.etaxonomy.taxeditor.editor.view.derivate.handler.OpenDerivativeEditorForDescriptionElement" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.derivate.handler.OpenDerivativeEditorForDescriptionElement" command="_j2cfsJMmEeeR4YRjNqCKeA"/>
<elements xsi:type="commands:Handler" xmi:id="_0bRjII9_EeqyUKRuXQ8miw" elementId="eu.etaxonomy.taxeditor.editor.handler.deleteDescription" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.handler.DeleteDescriptionHandler" command="_MYd44I98EeqyUKRuXQ8miw"/>
<elements xsi:type="commands:Handler" xmi:id="_HN2_oJN2EeqyUKRuXQ8miw" elementId="eu.etaxonomy.taxeditor.editor.handler.addDescription" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.handler.AddDescriptionHandler" command="_gE3lwIGyEeehlNPrK_b5JA"/>
+ <elements xsi:type="commands:Handler" xmi:id="_EBL2EKY_Eeq8Gc-K2nsNRg" elementId="eu.etaxonomy.taxeditor.editor.handler.aggregate" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.handler.AggregationHandler" command="_K2C_oKZAEeq8Gc-K2nsNRg"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_OyvD8KNOEee5fYT78qEx0A" featurename="children" parentElementId="bulkeditor.menus.openmenu" positionInList="last">
<elements xsi:type="menu:HandledMenuItem" xmi:id="_SZZBkKNOEee5fYT78qEx0A" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.specimen_editor" label="%command.label.DERIVATIVE_EDITOR" tooltip="%command.label.DERIVATIVE_EDITOR" command="_PDjFMLsKEeeQJq8FDGEi1g">
--- /dev/null
+/**
+* Copyright (C) 2020 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.handler;
+
+import java.util.List;
+import java.util.UUID;
+
+import javax.inject.Named;
+
+import org.eclipse.core.runtime.ICoreRunnable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.di.UISynchronize;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardDialog;
+
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
+import eu.etaxonomy.cdm.api.service.UpdateResult;
+import eu.etaxonomy.cdm.api.service.description.AggregationMode;
+import eu.etaxonomy.cdm.api.service.description.StructuredDescriptionAggregationConfiguration;
+import eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO;
+import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
+import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
+import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
+import eu.etaxonomy.cdm.model.location.NamedArea;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
+import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
+import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixPart;
+import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
+import eu.etaxonomy.taxeditor.ui.dialog.configurator.StructuredAggregationConfigurationWizard;
+
+/**
+ * @author k.luther
+ * @since Jun 4, 2020
+ */
+public class AggregationHandler {
+ @Execute
+ public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart, UISynchronize sync) {
+
+ // dependent on the selection the specimens are filtered
+ CharacterMatrixPart matrixPart = (CharacterMatrixPart) activePart.getObject();
+
+ CharacterMatrix matrix = matrixPart.getMatrix();
+
+ StructuredDescriptionAggregationConfiguration config = StructuredDescriptionAggregationConfiguration.NewInstance(
+ null, null);
+ IStructuredSelection sel = matrix.getSelection();
+ Object o = sel.getFirstElement();
+ TaxonNodeFilter filter = TaxonNodeFilter.NewRankInstance(matrix.getDescriptiveDataSet().getMinRank(),
+ matrix.getDescriptiveDataSet().getMaxRank());
+ for (NamedArea namedArea : matrix.getDescriptiveDataSet().getGeoFilter()) {
+ filter = filter.orArea(namedArea.getUuid());
+ }
+
+
+ if (o instanceof TaxonNodeDto){
+ filter = filter.orSubtree(CdmStore.getService(ITaxonNodeService.class).load(((TaxonNodeDto)o).getUuid()));
+ }else{
+ for (TaxonNode taxonNode : matrix.getDescriptiveDataSet().getTaxonSubtreeFilter()) {
+ filter = filter.orSubtree(taxonNode);
+ }
+ }
+ config.setTaxonNodeFilter(filter);
+
+ config.setDatasetUuid(matrix.getDescriptiveDataSet().getUuid());
+ config.setAggregateToHigherRanks(true);
+ config.setAggregationMode(AggregationMode.byAreasAndRanks());
+ config.setAdaptBatchSize(false);
+ StructuredAggregationConfigurationWizard aggregationWizard = new StructuredAggregationConfigurationWizard(config, matrix.getDescriptiveDataSet());
+ WizardDialog dialog = new WizardDialog(StoreUtil.getShell(),
+ aggregationWizard);
+
+ int open = dialog.open();
+ if (open != Window.OK){
+ return;
+ }
+ UUID monitorUuid = CdmApplicationState.getLongRunningTasksService().invoke(config);
+
+ String jobLabel = "Aggregate Descriptive Data Set";
+ Job job = Job.create(jobLabel, (ICoreRunnable) monitor -> {
+ SubMonitor subMonitor = SubMonitor.convert(monitor);
+ subMonitor.beginTask(jobLabel, IProgressMonitor.UNKNOWN);
+ IRemotingProgressMonitor remotingMonitor;
+ try {
+ remotingMonitor = CdmStore.getProgressMonitorClientManager()
+ .pollMonitor(jobLabel,
+ monitorUuid,
+ 50,
+ null,
+ (List)null,
+ subMonitor);
+ Object resultObject = remotingMonitor.getResult();
+ if(resultObject instanceof Exception){
+ MessagingUtils.errorDialog("Aggregation failed", this, "Aggregation was not successfull", TaxeditorEditorPlugin.PLUGIN_ID, (Exception)resultObject, true, true);
+ }
+ else if(resultObject instanceof UpdateResult){
+ DescriptiveDataSet dataSet = (DescriptiveDataSet) ((UpdateResult) resultObject).getCdmEntity();
+ dataSet = matrix.getCdmEntitiySession().load(dataSet, true);
+ // update local dataset
+ matrix.setDescriptiveDataSet(dataSet);
+ matrix.loadDescriptions(false, false);
+ }
+ } catch (InterruptedException e) {
+ return;
+ }
+ monitor.done();
+ });
+// job.addJobChangeListener(new JobChangeAdapter(){
+// @Override
+// public void done(IJobChangeEvent event) {
+// CharacterMatrixBottomToolbar.this.getDisplay().asyncExec(()->{
+// matrix.redraw();
+// });
+// }
+// });
+ job.schedule();
+ }
+
+ @CanExecute
+ public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
+ MHandledMenuItem menuItem){
+ CharacterMatrixPart matrixPart = (CharacterMatrixPart) activePart.getObject();
+ IStructuredSelection selection = matrixPart.getSelection();
+ boolean canExecute = (selection.isEmpty() ||
+ !(selection.getFirstElement() instanceof TaxonRowWrapperDTO) );
+
+ return canExecute;
+
+ }
+}