Search in sources :

Example 1 with IContributionManagerOverrides

use of org.eclipse.jface.action.IContributionManagerOverrides in project archi by archimatetool.

the class ToolbarDropdownContributionItem method update.

/**
 * Synchronizes the UI with the given property.
 *
 * @param propertyName
 *            the name of the property, or <code>null</code> meaning all
 *            applicable properties
 */
@SuppressWarnings("deprecation")
@Override
public void update(String propertyName) {
    if (widget != null) {
        // determine what to do
        boolean textChanged = propertyName == null || propertyName.equals(IAction.TEXT);
        boolean imageChanged = propertyName == null || propertyName.equals(IAction.IMAGE);
        boolean tooltipTextChanged = propertyName == null || propertyName.equals(IAction.TOOL_TIP_TEXT);
        boolean enableStateChanged = propertyName == null || propertyName.equals(IAction.ENABLED) || propertyName.equals(IContributionManagerOverrides.P_ENABLED);
        boolean checkChanged = (action.getStyle() == IAction.AS_CHECK_BOX) && (propertyName == null || propertyName.equals(IAction.CHECKED));
        if (widget instanceof ToolItem) {
            ToolItem ti = (ToolItem) widget;
            if (imageChanged) {
                updateImages(true);
            }
            if (tooltipTextChanged)
                ti.setToolTipText(action.getToolTipText());
            if (enableStateChanged) {
                boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed();
                if (ti.getEnabled() != shouldBeEnabled)
                    ti.setEnabled(shouldBeEnabled);
            }
            if (checkChanged) {
                boolean bv = action.isChecked();
                if (ti.getSelection() != bv)
                    ti.setSelection(bv);
            }
            return;
        }
        if (widget instanceof MenuItem) {
            MenuItem mi = (MenuItem) widget;
            boolean isContextMenu = belongsToContextMenu(mi);
            // belong to a context menu (right mouse button menu).
            if (textChanged) {
                if (isContextMenu) {
                    String text = action.getText();
                    if (text != null) {
                        text = Action.removeAcceleratorText(text);
                        mi.setText(text);
                    }
                } else {
                    String text = null;
                    IContributionManagerOverrides overrides = null;
                    if (getParent() != null)
                        overrides = getParent().getOverrides();
                    if (overrides != null)
                        text = getParent().getOverrides().getText(this);
                    if (text == null)
                        text = action.getText();
                    if (text != null) {
                        String label = Action.removeAcceleratorText(text);
                        String accText = null;
                        Integer acc = null;
                        if (overrides != null) {
                            accText = overrides.getAcceleratorText(this);
                            acc = overrides.getAccelerator(this);
                        }
                        if ((accText == null) && (label.length() + 1 < text.length()))
                            accText = text.substring(label.length() + 1);
                        if (acc == null)
                            acc = new Integer(action.getAccelerator());
                        if (acc.intValue() >= 0)
                            mi.setAccelerator(acc.intValue());
                        if (accText == null)
                            mi.setText(label);
                        else
                            mi.setText(label + '\t' + accText);
                    }
                }
            }
            if (imageChanged) {
                updateImages(false);
            }
            if (enableStateChanged) {
                boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed();
                if (mi.getEnabled() != shouldBeEnabled)
                    mi.setEnabled(shouldBeEnabled);
            }
            if (checkChanged) {
                boolean bv = action.isChecked();
                if (mi.getSelection() != bv)
                    mi.setSelection(bv);
            }
            return;
        }
        if (widget instanceof Button) {
            Button button = (Button) widget;
            if (imageChanged) {
                if (updateImages(false)) {
                    // don't update text if it has an image
                    textChanged = false;
                }
            }
            if (textChanged) {
                String text = action.getText();
                if (text != null)
                    button.setText(text);
            }
            if (tooltipTextChanged)
                button.setToolTipText(action.getToolTipText());
            if (enableStateChanged) {
                boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed();
                if (button.getEnabled() != shouldBeEnabled)
                    button.setEnabled(shouldBeEnabled);
            }
            if (checkChanged) {
                boolean bv = action.isChecked();
                if (button.getSelection() != bv)
                    button.setSelection(bv);
            }
            return;
        }
    }
}
Also used : Button(org.eclipse.swt.widgets.Button) MenuItem(org.eclipse.swt.widgets.MenuItem) ToolItem(org.eclipse.swt.widgets.ToolItem) IContributionManagerOverrides(org.eclipse.jface.action.IContributionManagerOverrides)

Example 2 with IContributionManagerOverrides

use of org.eclipse.jface.action.IContributionManagerOverrides in project eclipse.platform.ui by eclipse-platform.

the class ToolBarManagerRenderer method subscribeUIElementTopicVisible.

@Inject
@Optional
private void subscribeUIElementTopicVisible(@UIEventTopic(UIEvents.UIElement.TOPIC_VISIBLE) Event event) {
    // Ensure that this event is for a MToolBarElement
    if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBarElement)) {
        return;
    }
    MToolBarElement itemModel = (MToolBarElement) event.getProperty(UIEvents.EventTags.ELEMENT);
    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();
    // 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());
        }
    }
    updateWidget(parent);
}
Also used : IContributionItem(org.eclipse.jface.action.IContributionItem) MenuManager(org.eclipse.jface.action.MenuManager) ContributionItem(org.eclipse.jface.action.ContributionItem) IContributionItem(org.eclipse.jface.action.IContributionItem) MToolBarElement(org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ToolBarManager(org.eclipse.jface.action.ToolBarManager) IContributionManagerOverrides(org.eclipse.jface.action.IContributionManagerOverrides) Inject(javax.inject.Inject) Optional(org.eclipse.e4.core.di.annotations.Optional)

Example 3 with IContributionManagerOverrides

use of org.eclipse.jface.action.IContributionManagerOverrides in project eclipse.platform.ui by eclipse-platform.

the class ToolBarManagerRenderer method createToolbar.

private ToolBar createToolbar(final MUIElement element, Composite parent) {
    int orientation = getOrientation(element);
    int style = orientation | SWT.WRAP | SWT.FLAT | SWT.RIGHT;
    ToolBarManager manager = getManager((MToolBar) element);
    if (manager == null) {
        manager = new ToolBarManager(style);
        IContributionManagerOverrides overrides = null;
        MApplicationElement parentElement = element.getParent();
        if (parentElement == null) {
            parentElement = modelService.getContainer(element);
        }
        if (parentElement != null) {
            overrides = (IContributionManagerOverrides) parentElement.getTransientData().get(IContributionManagerOverrides.class.getName());
        }
        manager.setOverrides(overrides);
        linkModelToManager((MToolBar) element, manager);
    } else {
        ToolBar toolBar = manager.getControl();
        if (toolBar != null && !toolBar.isDisposed() && (toolBar.getStyle() & orientation) == 0) {
            toolBar.dispose();
        }
        manager.setStyle(style);
    }
    ToolBar btoolbar = manager.createControl(parent);
    btoolbar.setData(manager);
    btoolbar.setData(AbstractPartRenderer.OWNING_ME, element);
    btoolbar.requestLayout();
    return btoolbar;
}
Also used : MApplicationElement(org.eclipse.e4.ui.model.application.MApplicationElement) ToolBar(org.eclipse.swt.widgets.ToolBar) MToolBar(org.eclipse.e4.ui.model.application.ui.menu.MToolBar) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ToolBarManager(org.eclipse.jface.action.ToolBarManager) IContributionManagerOverrides(org.eclipse.jface.action.IContributionManagerOverrides)

Aggregations

IContributionManagerOverrides (org.eclipse.jface.action.IContributionManagerOverrides)3 IToolBarManager (org.eclipse.jface.action.IToolBarManager)2 ToolBarManager (org.eclipse.jface.action.ToolBarManager)2 Inject (javax.inject.Inject)1 Optional (org.eclipse.e4.core.di.annotations.Optional)1 MApplicationElement (org.eclipse.e4.ui.model.application.MApplicationElement)1 MToolBar (org.eclipse.e4.ui.model.application.ui.menu.MToolBar)1 MToolBarElement (org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement)1 ContributionItem (org.eclipse.jface.action.ContributionItem)1 IContributionItem (org.eclipse.jface.action.IContributionItem)1 MenuManager (org.eclipse.jface.action.MenuManager)1 Button (org.eclipse.swt.widgets.Button)1 MenuItem (org.eclipse.swt.widgets.MenuItem)1 ToolBar (org.eclipse.swt.widgets.ToolBar)1 ToolItem (org.eclipse.swt.widgets.ToolItem)1