Example usage for org.eclipse.jface.action ActionContributionItem update

List of usage examples for org.eclipse.jface.action ActionContributionItem update

Introduction

In this page you can find the example usage for org.eclipse.jface.action ActionContributionItem update.

Prototype

@Override
public final void update() 

Source Link

Document

The action item implementation of this IContributionItem method calls update(null).

Usage

From source file:gda.rcp.ApplicationWorkbenchAdvisor.java

License:Open Source License

/**
 * This method adds a part listener which enables the text next to the icon in the views' toolbar. Also enables the
 * text for the views that are open during workbench window creation(for the default perspective).
 * /*w  ww . j  a  v  a 2s  .  c om*/
 * @param workbenchWindow
 */
private void applyViewMenuText(final IWorkbenchWindow workbenchWindow) {
    if (GDAClientActivator.getDefault().getPreferenceStore().getBoolean(GdaRootPreferencePage.SHOW_MENU_TEXT)) {
        workbenchWindow.getPartService().addPartListener(new MenuDisplayPartListener());
        IViewReference[] viewReferences = workbenchWindow.getActivePage().getViewReferences();
        for (IViewReference vr : viewReferences) {
            IViewPart view = vr.getView(false);
            if (view != null) {
                IToolBarManager toolBarManager = view.getViewSite().getActionBars().getToolBarManager();
                IContributionItem[] items = toolBarManager.getItems();
                for (IContributionItem iContributionItem : items) {
                    if (iContributionItem instanceof ActionContributionItem) {
                        ActionContributionItem commandContributionItem = (ActionContributionItem) iContributionItem;
                        commandContributionItem.setMode(ActionContributionItem.MODE_FORCE_TEXT);
                        commandContributionItem.update();
                    }
                    if (iContributionItem instanceof CommandContributionItem) {
                        // As per https://bugs.eclipse.org/bugs/show_bug.cgi?id=256340 the
                        // CommandContributionItem
                        // doesn't expose the setMode() method. Therefore, setting the mode using reflection.
                        CommandContributionItem commandContributionItem = (CommandContributionItem) iContributionItem;
                        commandContributionItem.getData().mode = CommandContributionItem.MODE_FORCE_TEXT;
                        commandContributionItem.getId();
                        Class<? extends CommandContributionItem> class1 = commandContributionItem.getClass();
                        try {
                            Field field = class1.getDeclaredField("mode");
                            field.setAccessible(true);
                            field.set(commandContributionItem, new Integer(1));
                        } catch (SecurityException e) {
                            logger.error("Security exception - cant access private member", e);
                        } catch (IllegalArgumentException e) {
                            logger.error("IllegalArgumentException - Problem setting mode", e);
                        } catch (IllegalAccessException e) {
                            logger.error("IllegalAccessException - Problem setting mode", e);
                        } catch (NoSuchFieldException e) {
                            logger.error("NoSuchFieldException - Problem setting mode", e);
                        }
                        commandContributionItem.update();
                    }
                }
                if (toolBarManager instanceof ToolBarManager) {
                    ToolBarManager tm = (ToolBarManager) toolBarManager;
                    tm.getControl().pack(true);
                }
            }
        }
        workbenchWindow.getActivePage().savePerspective();
        workbenchWindow.getActivePage().resetPerspective();
    }
}

From source file:org.eclipse.babel.runtime.actions.LocalizableMenuSet.java

License:Open Source License

public void associate(final ActionContributionItem pluginAction, ITranslatableText localizableText) {
    associate(pluginAction, new TranslatableTextInput(localizableText) {
        @Override//from w  w  w .  ja  v  a  2 s .com
        public void updateControl(String text) {
            pluginAction.getAction().setText(text);
            pluginAction.update();
        }
    });
}