Project

General

Profile

Download (2.68 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.handler.defaultHandler;
2

    
3
import java.util.List;
4

    
5
import javax.inject.Named;
6

    
7
import org.eclipse.e4.core.di.annotations.CanExecute;
8
import org.eclipse.e4.core.di.annotations.Execute;
9
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
10
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
11
import org.eclipse.e4.ui.services.IServiceConstants;
12
import org.eclipse.e4.ui.workbench.modeling.EPartService;
13
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
14

    
15
import eu.etaxonomy.cdm.model.common.ICdmBase;
16
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
17
import eu.etaxonomy.taxeditor.bulkeditor.AppModelId;
18
import eu.etaxonomy.taxeditor.editor.IReferencingObjectsView;
19
import eu.etaxonomy.taxeditor.view.CdmViewerUtil;
20

    
21
public class OpenReferencingObjectsViewHandler {
22

    
23
    private List<UuidAndTitleCache<? extends ICdmBase>> selectedObjectList;
24

    
25
    @Execute
26
    public void execute(EPartService partService) {
27

    
28
        MPart part = partService.createPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_BULKEDITOR_REFERENCINGOBJECTS_E4_REFERENCINGOBJECTSVIEWE4);
29
        part = partService.showPart(part, PartState.ACTIVATE);
30
        IReferencingObjectsView view = (IReferencingObjectsView)part.getObject();
31

    
32
        if (selectedObjectList != null && !selectedObjectList.isEmpty()) {
33
            UuidAndTitleCache<? extends ICdmBase> dto = selectedObjectList.get(0);
34
            view.handleNewSelection(dto);
35
        }
36
    }
37

    
38
    @CanExecute
39
    public boolean canExecute(EPartService partService,
40
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
41
            MHandledMenuItem menuItem) {
42

    
43
        boolean canExecute = false;
44
        MPart part = partService.findPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_BULKEDITOR_REFERENCINGOBJECTS_E4_REFERENCINGOBJECTSVIEWE4);
45
        canExecute = part.equals(activePart)  //we explicitly want to allow calling the view recursively
46
                || part.getObject() == null ;  //we show the menu item only if the view is not yet open (otherwise by setting the focus data will be shown anyway
47
                                               //but this may change in future for some data where explicitly calling the view is required
48

    
49
        selectedObjectList = null;
50
        if (canExecute){
51
            String commandId = menuItem.getCommand().getElementId();
52
            Object selectedObject = menuItem.getTransientData().get(commandId+".uuid");
53
            selectedObjectList = CdmViewerUtil.transformSelectionToUuidAndTitleCacheList(selectedObject);
54
            canExecute = selectedObjectList.size() == 1;
55
        }
56
        menuItem.setVisible(canExecute);
57
        return canExecute;
58
    }
59
}
    (1-1/1)