Example usage for org.eclipse.jface.action IMenuManager isEnabled

List of usage examples for org.eclipse.jface.action IMenuManager isEnabled

Introduction

In this page you can find the example usage for org.eclipse.jface.action IMenuManager isEnabled.

Prototype

@Override
public boolean isEnabled();

Source Link

Document

Returns whether this menu should be enabled or not.

Usage

From source file:com.aptana.ide.ui.io.navigator.actions.OpenActionProvider.java

License:Open Source License

private void addOpenWithMenu(IMenuManager menu) {
    IStructuredSelection selection = getSelection();
    if (selection == null || selection.size() != 1) {
        return;/*  w w  w  . ja va2 s  . c om*/
    }

    Object element = selection.getFirstElement();
    if (!(element instanceof IAdaptable)) {
        return;
    }
    IMenuManager submenu = new MenuManager(Messages.OpenActionProvider_LBL_OpenWith,
            ICommonMenuConstants.GROUP_OPEN_WITH);
    submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_TOP));
    submenu.add(new OpenWithMenu(fSite.getPage(), (IAdaptable) element, new Client() {

        public void openEditor(IFileStore file, IEditorDescriptor editorDescriptor) {
            EditorUtils.openFileInEditor(file, editorDescriptor);
        }
    }));
    submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_ADDITIONS));

    // adds the submenu
    if (submenu.getItems().length > 2 && submenu.isEnabled()) {
        menu.appendToGroup(ICommonMenuConstants.GROUP_OPEN_WITH, submenu);
    }
}

From source file:es.cv.gvcase.ide.navigator.actions.resource.OpenFileActionProvider.java

License:Open Source License

private void addOpenWithMenu(IMenuManager aMenu) {
    IStructuredSelection ss = (IStructuredSelection) getContext().getSelection();

    if (ss == null || ss.size() != 1) {
        return;/*ww w. j  ava2 s .  c  o  m*/
    }

    Object o = ss.getFirstElement();

    // first try IResource
    IAdaptable openable = (IAdaptable) AdaptabilityUtility.getAdapter(o, IResource.class);
    // otherwise try ResourceMapping
    if (openable == null) {
        openable = (IAdaptable) AdaptabilityUtility.getAdapter(o, ResourceMapping.class);
    } else if (((IResource) openable).getType() != IResource.FILE) {
        openable = null;
    }

    if (openable != null) {
        // Create a menu flyout.
        IMenuManager submenu = new MenuManager("Open With", ICommonMenuConstants.GROUP_OPEN_WITH);
        submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_TOP));
        // use our OpenWithMenu in order to check Broken References
        submenu.add(new OpenWithMenu(viewSite.getPage(), openable));
        submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_ADDITIONS));

        // Add the submenu.
        if (submenu.getItems().length > 2 && submenu.isEnabled()) {
            aMenu.appendToGroup(ICommonMenuConstants.GROUP_OPEN_WITH, submenu);
        }
    }
}

From source file:gov.redhawk.sca.internal.ui.actions.OpenWithActionProvider.java

License:Open Source License

private void addOpenWithMenu(final IMenuManager aMenu) {
    final IStructuredSelection ss = (IStructuredSelection) getContext().getSelection();

    if (ss == null || ss.size() != 1) {
        return;/*from   w ww. jav a  2 s. c  om*/
    }

    final Object o = ss.getFirstElement();

    final EObject openable = PluginUtil.adapt(EObject.class, o);
    final IScaEditorDescriptor[] editors = ScaContentTypeRegistry.INSTANCE.getAllScaEditorDescriptors(openable);

    if (openable != null && editors.length > 0) {
        // Create a menu flyout.
        final IMenuManager submenu = new MenuManager("Open Wit&h", ICommonMenuConstants.GROUP_OPEN_WITH);
        submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_TOP));
        submenu.add(new OpenWithMenu(this.viewSite.getPage(), openable));
        submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_ADDITIONS));

        // Add the submenu.
        if (submenu.getItems().length > 2 && submenu.isEnabled()) {
            aMenu.appendToGroup(ICommonMenuConstants.GROUP_OPEN_WITH, submenu);
        }
    }
}

From source file:org.eclipse.sirius.ui.tools.internal.actions.session.OpenCloseSessionActionProvider.java

License:Open Source License

/**
 * /*w w w  . java2s  .  co m*/
 * {@inheritDoc}
 * 
 * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
 */
@Override
public void fillContextMenu(final IMenuManager menu) {
    super.fillContextMenu(menu);
    if (getContext().getSelection().isEmpty()) {
        return;
    }
    final IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
    OpenCloseSessionAction openCloseAnalysisAction = createOpenCloseAnalysisAction(selection);
    if (openCloseAnalysisAction.isEnabled() && openCloseAnalysisAction.isOpenMode()) {
        menu.insertAfter(ICommonMenuConstants.GROUP_OPEN, openCloseAnalysisAction);
    }
    if (selection.getFirstElement() instanceof IFile) {
        final IFile file = (IFile) selection.getFirstElement();
        final IMenuManager submenu = new MenuManager("Open With", ICommonMenuConstants.GROUP_OPEN_WITH);
        submenu.add(new OpenWithMenu(viewSite.getPage(), file));
        if (submenu.getItems().length > 0 && submenu.isEnabled()) {
            menu.appendToGroup(ICommonMenuConstants.GROUP_OPEN_WITH, submenu);
        }
    }
}

From source file:org.eclipse.titan.log.viewer.actions.LogFileActionProvider.java

License:Open Source License

private void addOpenWithMenu(final IMenuManager aMenu) {
    final IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();

    if (selection == null || selection.size() != 1 || !(selection.getFirstElement() instanceof IFile)) {
        return;/*ww  w . j  a v  a  2 s.c om*/
    }

    final IFile file = (IFile) selection.getFirstElement();

    IMenuManager submenu = new MenuManager("Open with", ICommonMenuConstants.GROUP_OPEN_WITH);
    submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_TOP));
    submenu.add(new OpenWithMenu(viewSite.getPage(), file));
    submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_ADDITIONS));

    if (submenu.getItems().length > 2 && submenu.isEnabled()) {
        aMenu.appendToGroup(ICommonMenuConstants.GROUP_OPEN_WITH, submenu);
    }
}

From source file:org.eclipse.ui.internal.navigator.resources.actions.OpenActionProvider.java

License:Open Source License

private void addOpenWithMenu(IMenuManager aMenu) {
    IStructuredSelection ss = (IStructuredSelection) getContext().getSelection();

    if (ss == null || ss.size() != 1) {
        return;/*ww w . j  a v  a2  s .  c  o  m*/
    }

    Object o = ss.getFirstElement();

    // first try IResource
    IAdaptable openable = (IAdaptable) AdaptabilityUtility.getAdapter(o, IResource.class);
    // otherwise try ResourceMapping
    if (openable == null) {
        openable = (IAdaptable) AdaptabilityUtility.getAdapter(o, ResourceMapping.class);
    } else if (((IResource) openable).getType() != IResource.FILE) {
        openable = null;
    }

    if (openable != null) {
        // Create a menu flyout.
        IMenuManager submenu = new MenuManager(WorkbenchNavigatorMessages.OpenActionProvider_OpenWithMenu_label,
                ICommonMenuConstants.GROUP_OPEN_WITH);
        submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_TOP));
        submenu.add(new OpenWithMenu(viewSite.getPage(), openable));
        submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_ADDITIONS));

        // Add the submenu.
        if (submenu.getItems().length > 2 && submenu.isEnabled()) {
            aMenu.appendToGroup(ICommonMenuConstants.GROUP_OPEN_WITH, submenu);
        }
    }
}

From source file:org.eclipse.virgo.ide.runtime.internal.ui.providers.RuntimeActionProvider.java

License:Open Source License

private void addOpenWithMenu(IMenuManager aMenu) {
    IStructuredSelection ss = (IStructuredSelection) getContext().getSelection();

    if (ss == null || ss.size() != 1) {
        return;/*from w  w  w  .j a  v a2s  .  c o  m*/
    }

    Object o = ss.getFirstElement();

    // first try IResource
    Platform.getAdapterManager().getAdapter(o, IResource.class);
    IAdaptable openable = (IAdaptable) getAdapter(o, IResource.class);
    // otherwise try ResourceMapping
    if (openable == null) {
        openable = (IAdaptable) getAdapter(o, ResourceMapping.class);
    } else if (((IResource) openable).getType() != IResource.FILE) {
        openable = null;
    }

    if (openable != null) {
        // Create a menu flyout.
        IMenuManager submenu = new MenuManager(WorkbenchNavigatorMessages.OpenActionProvider_OpenWithMenu_label,
                ICommonMenuConstants.GROUP_OPEN_WITH);
        submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_TOP));
        submenu.add(new OpenWithMenu(this.viewSite.getPage(), openable));
        submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_ADDITIONS));

        // Add the submenu.
        if (submenu.getItems().length > 2 && submenu.isEnabled()) {
            aMenu.appendToGroup(ICommonMenuConstants.GROUP_OPEN_WITH, submenu);
        }
    }
}

From source file:ummisco.gama.ui.navigator.actions.OpenActionProvider.java

License:Open Source License

private void addOpenWithMenu(final IMenuManager aMenu) {
    final IStructuredSelection ss = (IStructuredSelection) getContext().getSelection();
    if (ss == null || ss.size() != 1) {
        return;//  w  w w.  jav  a  2 s  .  c  o m
    }
    final Object o = ss.getFirstElement();
    // first try IResource
    IAdaptable openable = CloseResourceAction.getAdapter(o, IResource.class);
    // otherwise try ResourceMapping
    if (openable == null) {
        openable = CloseResourceAction.getAdapter(o, ResourceMapping.class);
    } else if (((IResource) openable).getType() != IResource.FILE) {
        openable = null;
    }
    if (openable != null) {
        // Create a menu flyout.
        final IMenuManager submenu = new MenuManager(
                WorkbenchNavigatorMessages.OpenActionProvider_OpenWithMenu_label,
                ICommonMenuConstants.GROUP_OPEN_WITH);
        submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_TOP));
        submenu.add(new OpenWithMenu(viewSite.getPage(), openable));
        submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_ADDITIONS));

        // Add the submenu.
        if (submenu.getItems().length > 2 && submenu.isEnabled()) {
            aMenu.appendToGroup(ICommonMenuConstants.GROUP_OPEN_WITH, submenu);
        }
    }
}