Example usage for org.eclipse.jface.action IContributionManagerOverrides getVisible

List of usage examples for org.eclipse.jface.action IContributionManagerOverrides getVisible

Introduction

In this page you can find the example usage for org.eclipse.jface.action IContributionManagerOverrides getVisible.

Prototype

public Boolean getVisible(IContributionItem item);

Source Link

Document

Visiblity override.

Usage

From source file:net.yatomiya.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer.java

License:Open Source License

@Inject
@Optional//from   w  ww . ja v  a 2 s . c  o m
private void subscribeTopicUpdateToBeRendered(@UIEventTopic(UIEvents.UIElement.TOPIC_ALL) Event event) {
    // Ensure that this event is for a MMenuItem
    if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBarElement)) {
        return;
    }

    MToolBarElement itemModel = (MToolBarElement) event.getProperty(UIEvents.EventTags.ELEMENT);
    String attName = (String) event.getProperty(UIEvents.EventTags.ATTNAME);
    if (UIEvents.UIElement.TOBERENDERED.equals(attName)) {
        Object obj = itemModel.getParent();
        if (!(obj instanceof MToolBar)) {
            return;
        }
        ToolBarManager parent = getManager((MToolBar) obj);
        if (itemModel.isToBeRendered()) {
            if (parent != null) {
                modelProcessSwitch(parent, itemModel);
                parent.update(true);
                ToolBar tb = parent.getControl();
                if (tb != null && !tb.isDisposed()) {
                    tb.pack(true);
                    tb.getShell().layout(new Control[] { tb }, SWT.DEFER);
                }
            }
        } else {
            IContributionItem ici = modelToContribution.remove(itemModel);
            if (ici != null && parent != null) {
                parent.remove(ici);
            }
            if (ici != null) {
                ici.dispose();
            }
        }
    } else if (UIEvents.UIElement.VISIBLE.equals(attName)) {
        IContributionItem ici = getContribution(itemModel);
        if (ici == null) {
            return;
        }

        ToolBarManager parent = null;
        if (ici instanceof MenuManager) {
            parent = (ToolBarManager) ((MenuManager) ici).getParent();
        } else if (ici instanceof ContributionItem) {
            parent = (ToolBarManager) ((ContributionItem) ici).getParent();
        }

        if (parent == null) {
            ici.setVisible(itemModel.isVisible());
            return;
        }

        IContributionManagerOverrides ov = parent.getOverrides();
        // partial fix for bug 383569: only change state if there are no
        // extra override mechanics controlling element visibility
        if (ov == null) {
            ici.setVisible(itemModel.isVisible());
        } else {
            Boolean visible = ov.getVisible(ici);
            if (visible == null) {
                // same as above: only change state if there are no extra
                // override mechanics controlling element visibility
                ici.setVisible(itemModel.isVisible());
            }
        }

        parent.markDirty();
        parent.update(true);
        ToolBar tb = parent.getControl();
        if (tb != null && !tb.isDisposed()) {
            tb.pack(true);
            if (tb.getParent() != null) {
                tb.getParent().pack(true);
            }
            tb.getShell().layout(new Control[] { tb }, SWT.DEFER);
        }
    }
}