Project

General

Profile

Download (2.91 KB) Statistics
| Branch: | Tag: | Revision:
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.navigation.navigator.operation.AggregateTaxonDescriptionsOperation;
21
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
22

    
23
public class AggregateTaxonDescriptionsHandler extends RemotingCdmHandlerE4 {
24

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

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

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

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

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

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

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

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

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

    
82
}
(1-1/15)