Example usage for org.eclipse.jface.action IMenuCreator dispose

List of usage examples for org.eclipse.jface.action IMenuCreator dispose

Introduction

In this page you can find the example usage for org.eclipse.jface.action IMenuCreator dispose.

Prototype

public void dispose();

Source Link

Document

Disposes the menu returned by getMenu.

Usage

From source file:com.github.haixing_hu.swt.action.ActionContributionItemEx.java

License:Open Source License

/**
 * Handles a widget dispose event for the widget corresponding to this item.
 *///from w w w. jav a 2  s.c  o m
private void handleWidgetDispose(Event e) {
    // Check if our widget is the one being disposed.
    if (e.widget == widget) {
        // Dispose of the menu creator.
        if ((action.getStyle() == IAction.AS_DROP_DOWN_MENU) && menuCreatorCalled) {
            final IMenuCreator mc = action.getMenuCreator();
            if (mc != null) {
                mc.dispose();
            }
        }

        // Unhook all of the listeners.
        action.removePropertyChangeListener(propertyListener);
        if (action != null) {
            final String commandId = action.getActionDefinitionId();
            final ExternalActionManager.ICallback callback = ExternalActionManager.getInstance().getCallback();

            if ((callback != null) && (commandId != null)) {
                callback.removePropertyChangeListener(commandId, actionTextListener);
            }
        }

        // Clear the widget field.
        widget = null;

        disposeOldImages();
    }
}

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

License:Open Source License

protected Menu getMenu(final MMenu mmenu, ToolItem toolItem) {
    Object obj = mmenu.getWidget();
    if (obj instanceof Menu && !((Menu) obj).isDisposed()) {
        return (Menu) obj;
    }/*from w  w w . j a  va 2s.c  o  m*/
    // this is a temporary passthrough of the IMenuCreator
    if (RenderedElementUtil.isRenderedMenu(mmenu)) {
        obj = RenderedElementUtil.getContributionManager(mmenu);
        if (obj instanceof IContextFunction) {
            final IEclipseContext lclContext = getContext(mmenu);
            obj = ((IContextFunction) obj).compute(lclContext, null);
            RenderedElementUtil.setContributionManager(mmenu, obj);
        }
        if (obj instanceof IMenuCreator) {
            final IMenuCreator creator = (IMenuCreator) obj;
            final Menu menu = creator.getMenu(toolItem.getParent().getShell());
            if (menu != null) {
                toolItem.addDisposeListener(new DisposeListener() {
                    @Override
                    public void widgetDisposed(DisposeEvent e) {
                        if (menu != null && !menu.isDisposed()) {
                            creator.dispose();
                            mmenu.setWidget(null);
                        }
                    }
                });
                menu.setData(AbstractPartRenderer.OWNING_ME, menu);
                return menu;
            }
        }
    } else {
        final IEclipseContext lclContext = getContext(getModel());
        IPresentationEngine engine = lclContext.get(IPresentationEngine.class);
        obj = engine.createGui(mmenu, toolItem.getParent(), lclContext);
        if (obj instanceof Menu) {
            return (Menu) obj;
        }
        if (logger != null) {
            logger.debug("Rendering returned " + obj); //$NON-NLS-1$
        }
    }
    return null;
}

From source file:org.eclipse.e4.ui.workbench.renderers.swt.DirectContributionItem.java

License:Open Source License

protected Menu getMenu(final MMenu mmenu, ToolItem toolItem) {
    Object obj = mmenu.getWidget();
    if (obj instanceof Menu && !((Menu) obj).isDisposed()) {
        return (Menu) obj;
    }//from  w  w w.j a va 2  s. com
    // this is a temporary passthrough of the IMenuCreator
    if (mmenu instanceof MRenderedMenu) {
        obj = ((MRenderedMenu) mmenu).getContributionManager();
        if (obj instanceof IContextFunction) {
            final IEclipseContext lclContext = getContext(mmenu);
            obj = ((IContextFunction) obj).compute(lclContext);
            ((MRenderedMenu) mmenu).setContributionManager(obj);
        }
        if (obj instanceof IMenuCreator) {
            final IMenuCreator creator = (IMenuCreator) obj;
            final Menu menu = creator.getMenu(toolItem.getParent().getShell());
            if (menu != null) {
                toolItem.addDisposeListener(new DisposeListener() {
                    public void widgetDisposed(DisposeEvent e) {
                        if (menu != null && !menu.isDisposed()) {
                            creator.dispose();
                            ((MRenderedMenu) mmenu).setWidget(null);
                        }
                    }
                });
                // mmenu.setWidget(menu);
                menu.setData(AbstractPartRenderer.OWNING_ME, menu);
                return menu;
            }
        }
    }
    return null;
}

From source file:org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.java

License:Open Source License

protected Menu getMenu(final MMenu mmenu, ToolItem toolItem) {
    Object obj = mmenu.getWidget();
    if (obj instanceof Menu && !((Menu) obj).isDisposed()) {
        return (Menu) obj;
    }/* www .  j  ava2  s .  c  o  m*/
    // this is a temporary passthrough of the IMenuCreator
    if (mmenu instanceof MRenderedMenu) {
        obj = ((MRenderedMenu) mmenu).getContributionManager();
        if (obj instanceof IContextFunction) {
            final IEclipseContext lclContext = getContext(mmenu);
            obj = ((IContextFunction) obj).compute(lclContext);
            ((MRenderedMenu) mmenu).setContributionManager(obj);
        }
        if (obj instanceof IMenuCreator) {
            final IMenuCreator creator = (IMenuCreator) obj;
            final Menu menu = creator.getMenu(toolItem.getParent().getShell());
            if (menu != null) {
                toolItem.addDisposeListener(new DisposeListener() {
                    public void widgetDisposed(DisposeEvent e) {
                        if (menu != null && !menu.isDisposed()) {
                            creator.dispose();
                            ((MRenderedMenu) mmenu).setWidget(null);
                        }
                    }
                });
                // mmenu.setWidget(menu);
                menu.setData(AbstractPartRenderer.OWNING_ME, menu);
                return menu;
            }
        }
    } else {
        final IEclipseContext lclContext = getContext(model);
        IPresentationEngine engine = lclContext.get(IPresentationEngine.class);
        obj = engine.createGui(mmenu, toolItem.getParent(), lclContext);
        if (obj instanceof Menu) {
            Menu menu = (Menu) obj;
            // menu.setData(AbstractPartRenderer.OWNING_ME, menu);
            return menu;
        } else {
            System.err.println("Rendering returned " + obj); //$NON-NLS-1$
        }
    }
    return null;
}

From source file:org.eclipse.e4.ui.workbench.renderers.swt.ToolItemRenderer.java

License:Open Source License

/**
 * @param mmenu/*from  ww w  .jav a  2  s  .com*/
 * @param shell
 * @return
 */
protected Menu getMenu(final MMenu mmenu, ToolItem toolItem) {
    Object obj = mmenu.getWidget();
    if (obj instanceof Menu) {
        return (Menu) obj;
    }
    // this is a temporary passthrough of the IMenuCreator
    if (mmenu instanceof MRenderedMenu) {
        obj = ((MRenderedMenu) mmenu).getContributionManager();
        if (obj instanceof IContextFunction) {
            final IEclipseContext lclContext = getContext(mmenu);
            obj = ((IContextFunction) obj).compute(lclContext);
            ((MRenderedMenu) mmenu).setContributionManager(obj);
        }
        if (obj instanceof IMenuCreator) {
            final IMenuCreator creator = (IMenuCreator) obj;
            final Menu menu = creator.getMenu(toolItem.getParent().getShell());
            if (menu != null) {
                toolItem.addDisposeListener(new DisposeListener() {
                    public void widgetDisposed(DisposeEvent e) {
                        if (menu != null && !menu.isDisposed()) {
                            creator.dispose();
                            ((MRenderedMenu) mmenu).setWidget(null);
                        }
                    }
                });
                mmenu.setWidget(menu);
                menu.setData(AbstractPartRenderer.OWNING_ME, menu);
                return menu;
            }
        }
    }
    return null;
}

From source file:org.springframework.ide.eclipse.boot.dash.util.ToolbarPulldownContributionItem.java

License:Open Source License

/**
 * Handles a widget dispose event for the widget corresponding to this item.
 *///from  www .j  a  va  2  s. c  o m
private void handleWidgetDispose(Event e) {
    // Check if our widget is the one being disposed.
    if (e.widget == widget) {
        // Dispose of the menu creator.
        if (action.getStyle() == IAction.AS_DROP_DOWN_MENU && menuCreatorCalled) {
            IMenuCreator mc = action.getMenuCreator();
            if (mc != null) {
                mc.dispose();
            }
        }

        // Unhook all of the listeners.
        action.removePropertyChangeListener(propertyListener);
        if (action != null) {
            String commandId = action.getActionDefinitionId();
            ExternalActionManager.ICallback callback = ExternalActionManager.getInstance().getCallback();

            if ((callback != null) && (commandId != null)) {
                callback.removePropertyChangeListener(commandId, actionTextListener);
            }
        }

        // Clear the widget field.
        widget = null;

        disposeOldImages();
    }
}

From source file:org.xmind.ui.color.ColorPicker.java

License:Open Source License

/**
 * Handles a widget dispose event for the widget corresponding to this item.
 *///www  . j  av  a  2 s  . c o  m
private void handleWidgetDispose(Event e) {
    // Check if our widget is the one being disposed.
    if (e.widget == widget) {
        // Dispose of the menu creator.
        if (action.getStyle() == IAction.AS_DROP_DOWN_MENU) {
            IMenuCreator mc = action.getMenuCreator();
            if (mc != null) {
                mc.dispose();
            }
        }

        // Unhook all of the listeners.
        action.removePropertyChangeListener(propertyListener);
        if (action != null) {
            String commandId = action.getActionDefinitionId();
            ExternalActionManager.ICallback callback = ExternalActionManager.getInstance().getCallback();

            if ((callback != null) && (commandId != null)) {
                callback.removePropertyChangeListener(commandId, actionTextListener);
            }
        }

        // Clear the widget field.
        widget = null;

        disposeOldImages();
    }
}