简体   繁体   中英

Adding custom trim to Eclipse workbench window does not work in Kepler 4.3

I'm maintaining some pre-existing code for an Eclipse plugin that forms part of a larger project. This code is supposed to display an icon for a notification in Eclipse's workbench window at the bottom right through the use of a custom trim named NotificationTrim . The code works perfectly in Indigo, but in Kepler it does not work anymore and the icon never appears. The code is as follows, with createTrim() being called by the notification handler:

private NotificationTrim createTrim() {
    IWorkbenchWindow[] windows = 
        PlatformUI.getWorkbench().getWorkbenchWindows();

    if (windows == null || windows.length < 1) {
        return null;
    }

    IWorkbenchWindow main = windows[0];

    if (!(main instanceof WorkbenchWindow)) {
        return null;
    }

    WorkbenchWindow window = (WorkbenchWindow)main;
    ITrimManager manager = window.getTrimManager();

    if (manager.getTrim(getClass().getName()) == null) {
        int height = getBottomTrimHeight(manager);

        trim = new NotificationTrim(main.getShell(), height);

        manager.addTrim(ITrimManager.BOTTOM, trim);
        manager.forceLayout();

        return trim;
    }

    return null;
}

private int getBottomTrimHeight (ITrimManager manager) {
    List<IWindowTrim> items = manager.getAreaTrim(SWT.BOTTOM);
    int height = -1;

    if (items != null) {
        for (IWindowTrim item : items) {
            int itemHeight = item.getControl().getSize().y;

            if (itemHeight > height) {
                height = itemHeight;
            }
        }
    }

    return height;
}

As far as I can tell, calling window.getTrimManager() returns a barebones ITrimManager that does nothing for its implementation of any of ITrimManager's methods (particularly getAreaTrim() and addTrim() ), so nothing ever gets added to the workbench window's trim. I'm well aware that this code relies on an undocumented internal API that has changed since Indigo, so my question would be whether there exists a better way of adding a custom trim to the bottom of Eclipse's workbench window? Failing that, would there be an alternative method of adding the notification image and label to the window such that it remains persistent across all perspectives, essentially equivalent to the old code?

As you have found these internal classes no longer do anything.

To add to the window you will probably need to edit the Eclipse 4 application model. For an existing Eclipse this is the LegacyIDE.e4xmi file in the org.eclipse.platform plugin.

See Eclipse 4 RCP for more details on editing application models.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM