Project

General

Profile

Revision 6328ed42

ID6328ed42739769367b35eac76706abea4370500e
Parent 7c29c9d5
Child 785b88aa

Added by Patrick Plitzner almost 2 years ago

ref #7597 Use remote progress monitor for taxon aggregation

View differences:

eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/handler/AggregateTaxonDescriptionsHandler.java
3 3

  
4 4
import javax.inject.Named;
5 5

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

  
12 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.navigation.navigator.operation.AggregateTaxonDescriptionsOperation;
21
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
13 22

  
14
public class AggregateTaxonDescriptionsHandler {
15
	@Execute
16
	public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection) {
17
	    TaxonNodeDto node = (TaxonNodeDto) selection.getFirstElement();
18

  
19
	}
20

  
21
	@CanExecute
22
	public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
23
	        MHandledMenuItem menuItem){
24
	    boolean canExecute = false;
25
//	    canExecute = selection instanceof TreeSelection
26
//	            && ((TreeSelection) selection).size()==1
27
//	            && ((TreeSelection) selection).getFirstElement() instanceof TaxonNodeDto;
28
	    menuItem.setVisible(canExecute);
29
	    return canExecute;
30
	}
23
public class AggregateTaxonDescriptionsHandler extends RemotingCdmHandlerE4 {
24
    private TaxonNavigatorE4 navigator;
25

  
26
    public AggregateTaxonDescriptionsHandler() {
27
        super("Aggregate taxon descriptions");
28
    }
29

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

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

  
44
            return confirm?Status.OK_STATUS:Status.CANCEL_STATUS;
45
        }
46
        return Status.CANCEL_STATUS;
47
    }
48

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

  
55
      return new AggregateTaxonDescriptionsOperation(getTrigger(),
56
              false,
57
              ((TaxonNodeDto) selection.getFirstElement()).getUuid()
58
              );
59
    }
60

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

  
70
    @Override
71
    public void onComplete() {
72
    }
73

  
74
    @Override
75
    protected Object getTrigger() {
76
        return this;
77
    }
31 78

  
32 79
}
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.CdmChangeEvent.Action;
18
import eu.etaxonomy.cdm.api.service.IDescriptionService;
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.navigation.navigator.e4.TaxonNavigatorE4;
25
import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
26
import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28

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

  
37
    private TaxonNavigatorE4 taxonNavigator;
38
    private UUID nodeUuid;
39

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

  
46
    }
47

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

  
54
    public void runMoniteredOperation() {
55
        UUID uuid = CdmStore.getService(IDescriptionService.class).aggregateComputedTaxonDescriptions(nodeUuid);
56

  
57
        Display.getDefault().asyncExec(new Runnable() {
58
            @Override
59
            public void run() {
60
                AbstractUtility.executeMoniteredOperation("Aggregate taxon descriptions: ",
61
                        uuid,
62
                        500,
63
                        false,
64
                        AggregateTaxonDescriptionsOperation.this,
65
                        null,
66
                        true);
67
            }
68
        });
69

  
70

  
71
    }
72

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

  
78
    }
79

  
80
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)