Project

General

Profile

« Previous | Next » 

Revision 9370d21c

Added by Katja Luther almost 4 years ago

#8785: move aggregation to context menu

View differences:

eu.etaxonomy.taxeditor.editor/fragment.e4xmi
302 302
        <children xsi:type="menu:HandledMenuItem" xmi:id="_AyHbgLKSEeikjKoOnLFm2w" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.createdefaultdescription" label="%handledmenuitem.label.19" command="_ZHC3oLKVEeikjKoOnLFm2w"/>
303 303
        <children xsi:type="menu:HandledMenuItem" xmi:id="_DYlHcLKSEeikjKoOnLFm2w" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.createliteraturedescription" label="%handledmenuitem.label.20" command="_fkPkkLKVEeikjKoOnLFm2w"/>
304 304
        <children xsi:type="menu:HandledMenuItem" xmi:id="__SlnwI97EeqyUKRuXQ8miw" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.deletedescription" label="%handledmenuitem.label.28" command="_MYd44I98EeqyUKRuXQ8miw"/>
305
        <children xsi:type="menu:HandledMenuItem" xmi:id="_ARo78KSvEeq8Gc-K2nsNRg" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.adddescription" label="command.commandname.25" command="_zCGQ8JN1EeqyUKRuXQ8miw"/>
305
        <children xsi:type="menu:HandledMenuItem" xmi:id="_ARo78KSvEeq8Gc-K2nsNRg" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.adddescription" label="%command.commandname.25" command="_zCGQ8JN1EeqyUKRuXQ8miw"/>
306
        <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"/>
306 307
      </menus>
307 308
    </elements>
308 309
    <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">
......
408 409
    <elements xsi:type="commands:Command" xmi:id="__8WFwL9OEemCian_vXpNsA" elementId="eu.etaxonomy.taxeditor.editor.view.descriptive.command.moveDescriptionElementsSetNameInSource" commandName="%command.name.132"/>
409 410
    <elements xsi:type="commands:Command" xmi:id="_MYd44I98EeqyUKRuXQ8miw" elementId="eu.etaxonomy.taxeditor.editor.command.deletedescription" commandName="%command.commandname.24"/>
410 411
    <elements xsi:type="commands:Command" xmi:id="_zCGQ8JN1EeqyUKRuXQ8miw" elementId="eu.etaxonomy.taxeditor.editor.charactermatrix.command.addDescription" commandName="%command.commandname.25"/>
412
    <elements xsi:type="commands:Command" xmi:id="_K2C_oKZAEeq8Gc-K2nsNRg" elementId="eu.etaxonomy.taxeditor.editor.command.aggregation" commandName="Aggregate"/>
411 413
  </fragments>
412 414
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_pZmusEalEeeXMc6kSYO7Xg" featurename="children" parentElementId="eu.etaxonomy.taxeditor.menu.showView" positionInList="after:eu.etaxonomy.taxeditor.workbench.menuseparator.navigation">
413 415
    <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">
......
445 447
    <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"/>
446 448
    <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"/>
447 449
    <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"/>
450
    <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"/>
448 451
  </fragments>
449 452
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_OyvD8KNOEee5fYT78qEx0A" featurename="children" parentElementId="bulkeditor.menus.openmenu" positionInList="last">
450 453
    <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">
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
663 663
        propertyToLabelMap.put(property, label);
664 664
    }
665 665

  
666
    public void loadDescriptions(UUID descriptiveDataSetUuid, boolean isInitialExpandToDeepestTaxonLevel) {
667
        UUID monitorUuid =  CdmApplicationState.getLongRunningTasksService().monitGetRowWrapper(descriptiveDataSetUuid);
666
    public void loadDescriptions(boolean isInitialExpandToDeepestTaxonLevel, boolean initialLoading) {
667
        UUID monitorUuid =  CdmApplicationState.getLongRunningTasksService().monitGetRowWrapper(this.getDescriptiveDataSet().getUuid());
668 668

  
669 669
        final Collection<RowWrapperDTO> wrappers = new ArrayList<>();
670 670
        String jobLabel = Messages.CharacterMatrix_LOAD_CHARACTER_DATA;
......
715 715
                    }
716 716
                    descriptions.clear();
717 717
                    wrappers.stream().filter(row->row.getTaxonNode()!=null).forEach(wrapper->CharacterMatrix.this.descriptions.add(wrapper));
718
                    loadingDone(isInitialExpandToDeepestTaxonLevel);
718
                    if(initialLoading){
719
                        loadingDone(isInitialExpandToDeepestTaxonLevel);
720
                    }
719 721

  
720 722
                });
721 723
            }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixBottomToolbar.java
240 240
                    dataSet = matrix.getCdmEntitiySession().load(dataSet, true);
241 241
                    // update local dataset
242 242
                    matrix.setDescriptiveDataSet(dataSet);
243
                    matrix.loadDescriptions(descriptiveDataSetUuid, false);
243
                    matrix.loadDescriptions(false, false);
244 244
                }
245 245
            } catch (InterruptedException e) {
246 246
                return;
......
290 290
                    dataSet = matrix.getCdmEntitiySession().load(dataSet, true);
291 291
                    // update local dataset
292 292
                    matrix.setDescriptiveDataSet(dataSet);
293
                    matrix.loadDescriptions(descriptiveDataSetUuid, false);
293
                    matrix.loadDescriptions(false, false);
294 294
                }
295 295
            } catch (InterruptedException e) {
296 296
                return;
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixPart.java
155 155
            }
156 156
            matrix.createTable(treeView, true, true);
157 157
            thisPart.setLabel(descriptiveDataSet.getLabel());
158
            matrix.loadDescriptions(descriptiveDataSetUuid, true);
158
            matrix.loadDescriptions( true, true);
159 159
        }
160 160
    }
161 161

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/AddDescriptionHandler.java
24 24
import org.eclipse.jface.viewers.IStructuredSelection;
25 25
import org.eclipse.jface.window.Window;
26 26

  
27
import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO;
27 28
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
28 29
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
29 30
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
......
80 81
    @CanExecute
81 82
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
82 83
            MHandledMenuItem menuItem){
83
//        CharacterMatrixPart matrixPart = (CharacterMatrixPart) activePart.getObject();
84
//        IStructuredSelection selection = matrixPart.getSelection();
85
//        boolean canExecute = (selection.isEmpty() ||
86
//                !(selection.getFirstElement() instanceof SpecimenRowWrapperDTO) );
87
//
88
//        return canExecute;
89
        return true;
84
        CharacterMatrixPart matrixPart = (CharacterMatrixPart) activePart.getObject();
85
        IStructuredSelection selection = matrixPart.getSelection();
86
        boolean canExecute = (selection.isEmpty() ||
87
                !(selection.getFirstElement() instanceof SpecimenRowWrapperDTO) );
88

  
89
        return canExecute;
90

  
90 91
    }
91 92
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/handler/AggregationHandler.java
1
/**
2
* Copyright (C) 2020 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.handler;
10

  
11
import java.util.List;
12
import java.util.UUID;
13

  
14
import javax.inject.Named;
15

  
16
import org.eclipse.core.runtime.ICoreRunnable;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.SubMonitor;
19
import org.eclipse.core.runtime.jobs.Job;
20
import org.eclipse.e4.core.di.annotations.CanExecute;
21
import org.eclipse.e4.core.di.annotations.Execute;
22
import org.eclipse.e4.ui.di.UISynchronize;
23
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
24
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
25
import org.eclipse.e4.ui.services.IServiceConstants;
26
import org.eclipse.jface.viewers.IStructuredSelection;
27
import org.eclipse.jface.window.Window;
28
import org.eclipse.jface.wizard.WizardDialog;
29

  
30
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
31
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
32
import eu.etaxonomy.cdm.api.service.UpdateResult;
33
import eu.etaxonomy.cdm.api.service.description.AggregationMode;
34
import eu.etaxonomy.cdm.api.service.description.StructuredDescriptionAggregationConfiguration;
35
import eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO;
36
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
37
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
38
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
39
import eu.etaxonomy.cdm.model.location.NamedArea;
40
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
41
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
42
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
43
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixPart;
44
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
45
import eu.etaxonomy.taxeditor.model.MessagingUtils;
46
import eu.etaxonomy.taxeditor.store.CdmStore;
47
import eu.etaxonomy.taxeditor.store.StoreUtil;
48
import eu.etaxonomy.taxeditor.ui.dialog.configurator.StructuredAggregationConfigurationWizard;
49

  
50
/**
51
 * @author k.luther
52
 * @since Jun 4, 2020
53
 */
54
public class AggregationHandler {
55
    @Execute
56
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart, UISynchronize sync) {
57

  
58
        // dependent on the selection the specimens are filtered
59
        CharacterMatrixPart matrixPart = (CharacterMatrixPart) activePart.getObject();
60

  
61
        CharacterMatrix matrix = matrixPart.getMatrix();
62

  
63
        StructuredDescriptionAggregationConfiguration config = StructuredDescriptionAggregationConfiguration.NewInstance(
64
                null, null);
65
        IStructuredSelection sel = matrix.getSelection();
66
        Object o = sel.getFirstElement();
67
        TaxonNodeFilter filter = TaxonNodeFilter.NewRankInstance(matrix.getDescriptiveDataSet().getMinRank(),
68
                matrix.getDescriptiveDataSet().getMaxRank());
69
        for (NamedArea namedArea : matrix.getDescriptiveDataSet().getGeoFilter()) {
70
            filter = filter.orArea(namedArea.getUuid());
71
        }
72

  
73

  
74
        if (o instanceof TaxonNodeDto){
75
            filter = filter.orSubtree(CdmStore.getService(ITaxonNodeService.class).load(((TaxonNodeDto)o).getUuid()));
76
        }else{
77
            for (TaxonNode taxonNode : matrix.getDescriptiveDataSet().getTaxonSubtreeFilter()) {
78
                filter = filter.orSubtree(taxonNode);
79
            }
80
        }
81
        config.setTaxonNodeFilter(filter);
82

  
83
        config.setDatasetUuid(matrix.getDescriptiveDataSet().getUuid());
84
        config.setAggregateToHigherRanks(true);
85
        config.setAggregationMode(AggregationMode.byAreasAndRanks());
86
        config.setAdaptBatchSize(false);
87
        StructuredAggregationConfigurationWizard aggregationWizard = new StructuredAggregationConfigurationWizard(config, matrix.getDescriptiveDataSet());
88
        WizardDialog dialog = new WizardDialog(StoreUtil.getShell(),
89
                aggregationWizard);
90

  
91
        int open = dialog.open();
92
        if (open != Window.OK){
93
            return;
94
        }
95
        UUID monitorUuid =  CdmApplicationState.getLongRunningTasksService().invoke(config);
96

  
97
        String jobLabel = "Aggregate Descriptive Data Set";
98
        Job job = Job.create(jobLabel, (ICoreRunnable) monitor -> {
99
            SubMonitor subMonitor = SubMonitor.convert(monitor);
100
            subMonitor.beginTask(jobLabel, IProgressMonitor.UNKNOWN);
101
            IRemotingProgressMonitor remotingMonitor;
102
            try {
103
                remotingMonitor = CdmStore.getProgressMonitorClientManager()
104
                        .pollMonitor(jobLabel,
105
                                monitorUuid,
106
                                50,
107
                                null,
108
                                (List)null,
109
                                subMonitor);
110
                Object resultObject = remotingMonitor.getResult();
111
                if(resultObject instanceof Exception){
112
                    MessagingUtils.errorDialog("Aggregation failed", this, "Aggregation was not successfull", TaxeditorEditorPlugin.PLUGIN_ID, (Exception)resultObject, true, true);
113
                }
114
                else if(resultObject instanceof UpdateResult){
115
                    DescriptiveDataSet dataSet = (DescriptiveDataSet) ((UpdateResult) resultObject).getCdmEntity();
116
                    dataSet = matrix.getCdmEntitiySession().load(dataSet, true);
117
                    // update local dataset
118
                    matrix.setDescriptiveDataSet(dataSet);
119
                    matrix.loadDescriptions(false, false);
120
                }
121
            } catch (InterruptedException e) {
122
                return;
123
            }
124
            monitor.done();
125
        });
126
//        job.addJobChangeListener(new JobChangeAdapter(){
127
//            @Override
128
//            public void done(IJobChangeEvent event) {
129
//                CharacterMatrixBottomToolbar.this.getDisplay().asyncExec(()->{
130
//                    matrix.redraw();
131
//                });
132
//            }
133
//        });
134
        job.schedule();
135
    }
136

  
137
    @CanExecute
138
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
139
            MHandledMenuItem menuItem){
140
        CharacterMatrixPart matrixPart = (CharacterMatrixPart) activePart.getObject();
141
        IStructuredSelection selection = matrixPart.getSelection();
142
        boolean canExecute = (selection.isEmpty() ||
143
                !(selection.getFirstElement() instanceof TaxonRowWrapperDTO) );
144

  
145
        return canExecute;
146

  
147
    }
148
}

Also available in: Unified diff