Project

General

Profile

Revision f57d8d08

IDf57d8d082d977047aa9ddc6bede9f698727c543c
Parent 1ae56e08
Child 2c5756ad

Added by Patrick Plitzner over 1 year ago

ref #6746 Hide menu items when nothing is selected

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/AddChildFeatureHandler.java
15 15
import org.eclipse.core.runtime.IStatus;
16 16
import org.eclipse.e4.core.di.annotations.CanExecute;
17 17
import org.eclipse.e4.core.di.annotations.Execute;
18
import org.eclipse.e4.core.di.annotations.Optional;
18 19
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
19 20
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
20 21
import org.eclipse.e4.ui.services.IServiceConstants;
......
57 58

  
58 59
    @CanExecute
59 60
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
60
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
61
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
61 62
            MHandledMenuItem menuItem) {
62 63
        boolean canExecute = false;
63 64
        canExecute = thisPart.getObject() instanceof FeatureTreeEditor
65
                && selection!=null
64 66
                && selection.size()==1
65 67
                && selection.iterator().next() instanceof FeatureNode;
66 68
        menuItem.setVisible(canExecute);
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/AddFeatureHandler.java
15 15
import org.eclipse.core.runtime.IStatus;
16 16
import org.eclipse.e4.core.di.annotations.CanExecute;
17 17
import org.eclipse.e4.core.di.annotations.Execute;
18
import org.eclipse.e4.core.di.annotations.Optional;
18 19
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
19 20
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
20 21
import org.eclipse.e4.ui.services.IServiceConstants;
......
57 58

  
58 59
    @CanExecute
59 60
    public boolean canExecute(
60
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
61
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
61 62
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
62 63
            MHandledMenuItem menuItem) {
63 64
        boolean canExecute = false;
64
        canExecute = selection.size()==1
65
        canExecute = selection!=null
66
                && selection.size()==1
65 67
                && selection.iterator().next() instanceof FeatureTree
66 68
                && thisPart.getObject() instanceof FeatureTreeEditor;
67 69
        menuItem.setVisible(canExecute);
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/FeatureTreeExportHandler.java
15 15
import org.eclipse.core.runtime.jobs.Job;
16 16
import org.eclipse.e4.core.di.annotations.CanExecute;
17 17
import org.eclipse.e4.core.di.annotations.Execute;
18
import org.eclipse.e4.core.di.annotations.Optional;
18 19
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
19 20
import org.eclipse.e4.ui.services.IServiceConstants;
20 21
import org.eclipse.jface.viewers.IStructuredSelection;
......
52 53

  
53 54
    @CanExecute
54 55
    public boolean canExecute(
55
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
56
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
56 57
            MHandledMenuItem menuItem) {
57 58
        boolean canExecute = false;
58
        canExecute = selection.size()==1 && selection.iterator().next() instanceof FeatureTree;
59
        canExecute = selection!=null
60
                && selection.size()==1
61
                && selection.iterator().next() instanceof FeatureTree;
59 62
        menuItem.setVisible(canExecute);
60 63
        return canExecute;
61 64
    }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/RemoveFeatureHandler.java
12 12

  
13 13
import org.eclipse.e4.core.di.annotations.CanExecute;
14 14
import org.eclipse.e4.core.di.annotations.Execute;
15
import org.eclipse.e4.core.di.annotations.Optional;
15 16
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
16 17
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
17 18
import org.eclipse.e4.ui.services.IServiceConstants;
......
43 44

  
44 45
    @CanExecute
45 46
    public boolean canExecute(
46
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
47
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
47 48
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
48 49
            MHandledMenuItem menuItem) {
49
        boolean canExecute = !selection.isEmpty();
50
        for(Object object:selection.toArray()){
51
            canExecute &= object instanceof FeatureNode;
50
        boolean canExecute = false;
51
        if(selection!=null && !selection.isEmpty()){
52
            for(Object object:selection.toArray()){
53
                canExecute &= object instanceof FeatureNode;
54
            }
52 55
        }
53 56
        canExecute &= thisPart.getObject() instanceof IE4ViewerPart;
54 57
        menuItem.setVisible(canExecute);
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/RemoveFeatureTreeHandler.java
14 14

  
15 15
import org.eclipse.e4.core.di.annotations.CanExecute;
16 16
import org.eclipse.e4.core.di.annotations.Execute;
17
import org.eclipse.e4.core.di.annotations.Optional;
17 18
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
18 19
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
19 20
import org.eclipse.e4.ui.services.IServiceConstants;
......
45 46

  
46 47
    @CanExecute
47 48
    public boolean canExecute(
48
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
49
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
49 50
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
50 51
            MHandledMenuItem menuItem) {
51
        boolean canExecute = !selection.isEmpty();
52
        for(Object object:selection.toArray()){
53
            canExecute &= object instanceof FeatureTree;
52
        boolean canExecute = false;
53
        if(selection!=null && !selection.isEmpty()){
54
            for(Object object:selection.toArray()){
55
                canExecute &= object instanceof FeatureTree;
56
            }
54 57
        }
55 58
        canExecute &= thisPart.getObject() instanceof FeatureTreeEditor;
56 59
        menuItem.setVisible(canExecute);

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)