Project

General

Profile

« Previous | Next » 

Revision ed6a16ee

Added by Patrick Plitzner over 4 years ago

ref #7597 Remove taxon tree aggregation command and handler

View differences:

eu.etaxonomy.taxeditor.navigation/fragment.e4xmi
38 38
        <command href="../eu.etaxonomy.taxeditor.editor/fragment.e4xmi#_j2cfsJMmEeeR4YRjNqCKeA"/>
39 39
      </handlers>
40 40
      <handlers xmi:id="_-GirMLVbEeeZf_R8QJbACw" elementId="eu.etaxonomy.taxeditor.navigation.navigator.e4.handler.LinkWithTaxonHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.navigation/eu.etaxonomy.taxeditor.navigation.navigator.e4.handler.LinkWithTaxonHandlerE4" command="_6iiY8LVbEeeZf_R8QJbACw"/>
41
      <handlers xmi:id="_gWjsEJO5EeiqbJlqxN0v2w" elementId="eu.etaxonomy.taxeditor.navigation.handler.0" contributionURI="bundleclass://eu.etaxonomy.taxeditor.navigation/eu.etaxonomy.taxeditor.navigation.navigator.e4.handler.AggregateTaxonDescriptionsHandler" command="_jd_XEJO5EeiqbJlqxN0v2w"/>
42 41
      <handlers xmi:id="_Jr9BQM0xEeiHbMP3rrIRKQ" elementId="eu.etaxonomy.taxeditor.navigation.navigator.e4.handler.SetUnplacedHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.navigation/eu.etaxonomy.taxeditor.navigation.navigator.e4.handler.SetUnplacedHandler" command="_oghMkM0vEeiHbMP3rrIRKQ"/>
43 42
      <handlers xmi:id="_lct0oM1AEeiHbMP3rrIRKQ" elementId="eu.etaxonomy.taxeditor.navigation.navigator.e4.handler.RemoveUnplacedHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.navigation/eu.etaxonomy.taxeditor.navigation.navigator.e4.handler.RemoveUnplacedHandler" command="_gMQnoM1AEeiHbMP3rrIRKQ"/>
44 43
      <handlers xmi:id="_x1T9cM1KEeiHbMP3rrIRKQ" elementId="eu.etaxonomy.taxeditor.navigation.navigator.e4.handler.SetExcludedHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.navigation/eu.etaxonomy.taxeditor.navigation.navigator.e4.handler.SetExcludedHandler" command="_3laT0M1KEeiHbMP3rrIRKQ"/>
......
169 168
    <elements xsi:type="commands:Command" xmi:id="_6S6M4KQVEeeTrq_CRrR-jg" elementId="eu.etaxonomy.taxeditor.navigation.key.polytomous.refreshKeyNodes" commandName="%command.name.9"/>
170 169
    <elements xsi:type="commands:Command" xmi:id="_8C8AEKQVEeeTrq_CRrR-jg" elementId="eu.etaxonomy.taxeditor.navigation.key.polytomous.command.delete" commandName="%command.name.11"/>
171 170
    <elements xsi:type="commands:Command" xmi:id="_6iiY8LVbEeeZf_R8QJbACw" elementId="eu.etaxonomy.taxeditor.navigation.command.linkWithTaxon" commandName="Link with taxon"/>
172
    <elements xsi:type="commands:Command" xmi:id="_jd_XEJO5EeiqbJlqxN0v2w" elementId="eu.etaxonomy.taxeditor.navigation.command.aggregateTaxonDescriptions" commandName="Aggregate taxon descriptions"/>
173 171
    <elements xsi:type="commands:Command" xmi:id="_oghMkM0vEeiHbMP3rrIRKQ" elementId="eu.etaxonomy.taxeditor.navigator.command.update.setUnplaced" commandName="%command.name.setUnplaced"/>
174 172
    <elements xsi:type="commands:Command" xmi:id="_gMQnoM1AEeiHbMP3rrIRKQ" elementId="eu.etaxonomy.taxeditor.navigator.command.update.removeUnplaced" commandName="%command.name.removeUnplaced"/>
175 173
    <elements xsi:type="commands:Command" xmi:id="_3laT0M1KEeiHbMP3rrIRKQ" elementId="eu.etaxonomy.taxeditor.navigator.command.update.setExcluded" commandName="%command.name.setExcluded"/>
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/AggregateTaxonDescriptionsHandler.java
1

  
2
package eu.etaxonomy.taxeditor.navigation.navigator.e4.handler;
3

  
4
import javax.inject.Named;
5

  
6
import org.eclipse.core.commands.operations.AbstractOperation;
7
import org.eclipse.core.runtime.IStatus;
8
import org.eclipse.core.runtime.Status;
9
import org.eclipse.e4.core.di.annotations.CanExecute;
10
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
11
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
12
import org.eclipse.e4.ui.services.IServiceConstants;
13
import org.eclipse.jface.viewers.IStructuredSelection;
14
import org.eclipse.jface.viewers.TreeSelection;
15
import org.eclipse.swt.widgets.Shell;
16

  
17
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
18
import eu.etaxonomy.taxeditor.model.MessagingUtils;
19
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TaxonNavigatorE4;
20
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
21

  
22
public class AggregateTaxonDescriptionsHandler extends RemotingCdmHandlerE4 {
23

  
24
    public AggregateTaxonDescriptionsHandler() {
25
        super("Aggregate taxon descriptions");
26
    }
27

  
28
    @Override
29
    public IStatus allowOperations(IStructuredSelection selection,
30
            Shell shell,
31
            MPart activePart,
32
            MHandledMenuItem menuItem) {
33
        if(selection!=null
34
                && !selection.isEmpty()
35
                && selection.getFirstElement() instanceof TaxonNodeDto){
36

  
37
            TaxonNodeDto node = (TaxonNodeDto) selection.getFirstElement();
38
            boolean confirm = MessagingUtils.confirmDialog("Create aggregated description",
39
                    String.format("The aggregated description will be stored at the selected taxon %s"
40
                            , node.getTaxonTitleCache()));
41

  
42
            return confirm?Status.OK_STATUS:Status.CANCEL_STATUS;
43
        }
44
        return Status.CANCEL_STATUS;
45
    }
46

  
47
    @Override
48
    public AbstractOperation prepareOperation(IStructuredSelection selection,
49
            Shell shell,
50
            MPart activePart,
51
            MHandledMenuItem menuItem) {
52

  
53
        //FIXME: this handler will probably be removed and secondary aggregation will be handled in the matrix editor
54
      return null;
55
//              new AggregateTaxonDescriptionsOperation(getTrigger(),
56
//              false,
57
//              ((TaxonNodeDto) selection.getFirstElement()).getUuid()
58
//              );
59
    }
60

  
61
    @CanExecute
62
    private boolean canExecute(
63
            @Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection,
64
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
65
            MHandledMenuItem menuItem){
66
        boolean canExecute = false;
67
        canExecute = activePart.getObject() instanceof TaxonNavigatorE4
68
                && selection.getFirstElement() instanceof TaxonNodeDto
69
                && ((TaxonNodeDto)selection.getFirstElement()).getTaxonUuid() != null;
70
        menuItem.setVisible(canExecute);
71
        return canExecute;
72
    }
73

  
74
    @Override
75
    public void onComplete() {
76
    }
77

  
78
    @Override
79
    protected Object getTrigger() {
80
        return this;
81
    }
82

  
83
}
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/AggregateTaxonDescriptionsOperation.java
1
/**
2
* Copyright (C) 2015 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.navigation.navigator.operation;
10

  
11
import java.util.UUID;
12

  
13
import org.eclipse.core.runtime.IAdaptable;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.swt.widgets.Display;
16

  
17
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
18
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
19
import eu.etaxonomy.cdm.api.service.UpdateResult;
20
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
21
import eu.etaxonomy.taxeditor.event.EventUtility;
22
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
23
import eu.etaxonomy.taxeditor.model.AbstractUtility;
24
import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
25
import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
26

  
27
/**
28
 *
29
 * @author pplitzner
30
 * @date 06.08.2018
31
 *
32
 */
33
public class AggregateTaxonDescriptionsOperation extends RemotingCdmUpdateOperation implements IPostMoniteredOperationEnabled {
34

  
35
    private UUID nodeUuid;
36
    private UUID descriptiveDataSetUuid;
37
    private UUID monitorUuid;
38

  
39
    public AggregateTaxonDescriptionsOperation(Object source,
40
            boolean async,
41
            UUID nodeUuid,
42
            UUID descriptiveDataSetUuid
43
            ) {
44
        super("Aggregate taxon descriptions", Action.Update, source,async);
45
        this.nodeUuid = nodeUuid;
46
        this.descriptiveDataSetUuid = descriptiveDataSetUuid;
47

  
48
    }
49

  
50
    @Override
51
    protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
52
        runMoniteredOperation();
53
        return updateResult;
54
    }
55

  
56
    public void runMoniteredOperation() {
57
        monitorUuid = CdmApplicationState.getLongRunningTasksService().aggregateComputedTaxonDescriptions(nodeUuid, descriptiveDataSetUuid);
58

  
59
                Display.getDefault().asyncExec(new Runnable() {
60
                    @Override
61
                    public void run() {
62
                        AbstractUtility.executeMoniteredOperation("Move Taxon to new parent: ",
63
                                monitorUuid,
64
                                500,
65
                                false,
66
                                AggregateTaxonDescriptionsOperation.this,
67
                                null,
68
                                true);
69
                    }
70
                });
71

  
72
    }
73

  
74
    @Override
75
    public void postOperation(IRemotingProgressMonitor monitor) {
76
        monitor.done();
77
        EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAVIGATOR, true);
78
    }
79

  
80
}

Also available in: Unified diff