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

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

Introduction

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

Prototype

void update(String id);

Source Link

Document

Updates any SWT controls cached by this contribution item with changes for the the given property.

Usage

From source file:com.github.haixing_hu.swt.menu.MenuManagerEx.java

License:Open Source License

@Override
public void update(String property) {
    final IContributionItem items[] = getItems();

    for (final IContributionItem item : items) {
        item.update(property);
    }//from   w  w  w .  j  av  a  2 s.  com

    if ((menu != null) && !menu.isDisposed() && (menu.getParentItem() != null)) {
        if (IAction.TEXT.equals(property)) {
            String text = getOverrides().getText(this);

            if (text == null) {
                text = getMenuText();
            }

            if (text != null) {
                final ExternalActionManager.ICallback callback = ExternalActionManager.getInstance()
                        .getCallback();

                if (callback != null) {
                    final int index = text.indexOf('&');

                    if ((index >= 0) && (index < (text.length() - 1))) {
                        final char character = Character.toUpperCase(text.charAt(index + 1));

                        if (callback.isAcceleratorInUse(SWT.ALT | character) && isTopLevelMenu()) {
                            if (index == 0) {
                                text = text.substring(1);
                            } else {
                                text = text.substring(0, index) + text.substring(index + 1);
                            }
                        }
                    }
                }

                menu.getParentItem().setText(text);
            }
        } else if (IAction.IMAGE.equals(property) && (image != null)) {
            final LocalResourceManager localManager = new LocalResourceManager(JFaceResources.getResources());
            menu.getParentItem().setImage(localManager.createImage(image));
            disposeOldImages();
            imageManager = localManager;
        }
    }
}

From source file:org.eclipse.ui.internal.ActionSetActionBars.java

License:Open Source License

/**
 * Activate / Deactivate the contributions.
 *///from  w  ww  .  j  a  va2 s.c  om
protected void setActive(boolean set) {
    super.setActive(set);

    ICoolBarManager coolBarManager = getCastedParent().getCoolBarManager();
    if (coolBarManager == null) {
        return;
    }

    // 1. Need to set visibility for all non-adjunct actions
    if (coolItemToolBarMgr != null) {
        IContributionItem[] items = coolItemToolBarMgr.getItems();
        for (int i = 0; i < items.length; i++) {
            IContributionItem item = items[i];
            if (item instanceof PluginActionCoolBarContributionItem) {
                PluginActionCoolBarContributionItem actionSetItem = (PluginActionCoolBarContributionItem) item;
                // Only if the action set id for this contribution item is
                // the same
                // as this object
                if (actionSetItem.getActionSetId().equals(actionSetId)) {
                    item.setVisible(set);
                    coolItemToolBarMgr.markDirty();
                    if (!coolBarManager.isDirty()) {
                        coolBarManager.markDirty();
                    }
                }
            }
        }
        // Update the manager
        coolItemToolBarMgr.update(false);
        if (toolBarContributionItem != null) {
            toolBarContributionItem.update(ICoolBarManager.SIZE);
        }
    }

    // 2. Need to set visibility for all adjunct actions
    if (adjunctContributions.size() > 0) {
        for (Iterator i = adjunctContributions.iterator(); i.hasNext();) {
            IContributionItem item = (IContributionItem) i.next();
            if (item instanceof ContributionItem) {
                item.setVisible(set);
                IContributionManager manager = ((ContributionItem) item).getParent();
                manager.markDirty();
                manager.update(false);
                if (!coolBarManager.isDirty()) {
                    coolBarManager.markDirty();
                }
                item.update(ICoolBarManager.SIZE);
            }

        }

    }
}

From source file:org.eclipse.ui.internal.EditorActionBars.java

License:Open Source License

/**
 * Sets the enablement ability of all the items contributed by the editor.
 * /*ww  w. j  ava2 s .c o m*/
 * @param enabledAllowed
 *            <code>true</code> if the items may enable
 * @since 2.0
 */
private void setEnabledAllowed(boolean enabledAllowed) {
    if (this.enabledAllowed == enabledAllowed) {
        return;
    }
    this.enabledAllowed = enabledAllowed;
    if (coolItemToolBarMgr != null) {
        IContributionItem[] items = coolItemToolBarMgr.getItems();
        for (int i = 0; i < items.length; i++) {
            IContributionItem item = items[i];
            if (item != null) {
                item.update(IContributionManagerOverrides.P_ENABLED);
            }
        }
    }
}