#8785: move aggregation to context menu
authorKatja Luther <k.luther@bgbm.org>
Thu, 4 Jun 2020 13:04:13 +0000 (15:04 +0200)
committerKatja Luther <k.luther@bgbm.org>
Thu, 4 Jun 2020 13:04:13 +0000 (15:04 +0200)
eu.etaxonomy.taxeditor.editor/fragment.e4xmi
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixBottomToolbar.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixPart.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/AddDescriptionHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/AggregationHandler.java [new file with mode: 0755]

index f8d42f3922c7618395603b5a1a6a78fd466a50a8..b69e8c231eb15124484ff0804e3ecd916c5f97c1 100644 (file)
         <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">
index ba3f610c2d29bb83ede754c6f2e50dc2ad0d33d5..f3a90f479bfed44c0870fd9eeb09438e653762ba 100644 (file)
@@ -663,8 +663,8 @@ public class CharacterMatrix extends Composite {
         propertyToLabelMap.put(property, label);
     }
 
-    public void loadDescriptions(UUID descriptiveDataSetUuid, boolean isInitialExpandToDeepestTaxonLevel) {
-        UUID monitorUuid =  CdmApplicationState.getLongRunningTasksService().monitGetRowWrapper(descriptiveDataSetUuid);
+    public void loadDescriptions(boolean isInitialExpandToDeepestTaxonLevel, boolean initialLoading) {
+        UUID monitorUuid =  CdmApplicationState.getLongRunningTasksService().monitGetRowWrapper(this.getDescriptiveDataSet().getUuid());
 
         final Collection<RowWrapperDTO> wrappers = new ArrayList<>();
         String jobLabel = Messages.CharacterMatrix_LOAD_CHARACTER_DATA;
@@ -715,7 +715,9 @@ public class CharacterMatrix extends Composite {
                     }
                     descriptions.clear();
                     wrappers.stream().filter(row->row.getTaxonNode()!=null).forEach(wrapper->CharacterMatrix.this.descriptions.add(wrapper));
-                    loadingDone(isInitialExpandToDeepestTaxonLevel);
+                    if(initialLoading){
+                        loadingDone(isInitialExpandToDeepestTaxonLevel);
+                    }
 
                 });
             }
index 43893439b38896b50ced6f6652189427981709aa..90ac89cb3d7802e2f66b82794c4ab0a39bfc7b8e 100644 (file)
@@ -240,7 +240,7 @@ public class CharacterMatrixBottomToolbar extends Composite{
                     dataSet = matrix.getCdmEntitiySession().load(dataSet, true);
                     // update local dataset
                     matrix.setDescriptiveDataSet(dataSet);
-                    matrix.loadDescriptions(descriptiveDataSetUuid, false);
+                    matrix.loadDescriptions(false, false);
                 }
             } catch (InterruptedException e) {
                 return;
@@ -290,7 +290,7 @@ public class CharacterMatrixBottomToolbar extends Composite{
                     dataSet = matrix.getCdmEntitiySession().load(dataSet, true);
                     // update local dataset
                     matrix.setDescriptiveDataSet(dataSet);
-                    matrix.loadDescriptions(descriptiveDataSetUuid, false);
+                    matrix.loadDescriptions(false, false);
                 }
             } catch (InterruptedException e) {
                 return;
index ba901a641942783dcd6ee4623761dfd9f7dc93e5..132d3b69c3b875c2c74822dff88f956da5a46d3c 100644 (file)
@@ -155,7 +155,7 @@ ICdmEntitySessionEnabled, IPartContentHasSupplementalData, IPartContentHasDetail
             }
             matrix.createTable(treeView, true, true);
             thisPart.setLabel(descriptiveDataSet.getLabel());
-            matrix.loadDescriptions(descriptiveDataSetUuid, true);
+            matrix.loadDescriptions( true, true);
         }
     }
 
index 973cf57a83990d296e871c20c8e16b901d28c778..1ab3a7c5fa063f5bd30a64148a526985684ed1f8 100755 (executable)
@@ -24,6 +24,7 @@ import org.eclipse.e4.ui.services.IServiceConstants;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.window.Window;
 
+import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO;
 import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
 import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
 import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
@@ -80,12 +81,12 @@ public class AddDescriptionHandler {
     @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 SpecimenRowWrapperDTO) );
-//
-//        return canExecute;
-        return true;
+        CharacterMatrixPart matrixPart = (CharacterMatrixPart) activePart.getObject();
+        IStructuredSelection selection = matrixPart.getSelection();
+        boolean canExecute = (selection.isEmpty() ||
+                !(selection.getFirstElement() instanceof SpecimenRowWrapperDTO) );
+
+        return canExecute;
+
     }
 }
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/AggregationHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/AggregationHandler.java
new file mode 100755 (executable)
index 0000000..37ba5e4
--- /dev/null
@@ -0,0 +1,148 @@
+/**
+* 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;
+
+    }
+}