Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-ui-dev] Problem with ActionContributionItem.getImageCache() calls

Hi together,

I have written a littel JFace application extending the ApplicationWindow
class, having some menu bar added by calling addMenuBar() and I got the
following SWTException during the configureShell() method is called:

Exception in thread "HandlerThread#Journal" org.eclipse.swt.SWTException:
Invalid thread access
	at org.eclipse.swt.SWT.error(SWT.java:2827)
	at org.eclipse.swt.SWT.error(SWT.java:2752)
	at org.eclipse.swt.SWT.error(SWT.java:2723)
	at org.eclipse.swt.widgets.Display.error(Display.java:748)
	at org.eclipse.swt.widgets.Display.checkDevice(Display.java:573)
	at org.eclipse.swt.widgets.Display.disposeExec(Display.java:688)
	at
org.eclipse.jface.action.ActionContributionItem.getImageCache(ActionContribu
tionItem.java:389) <-- *
	at
org.eclipse.jface.action.ActionContributionItem.updateImages(ActionContribut
ionItem.java:887)
	at
org.eclipse.jface.action.ActionContributionItem.update(ActionContributionIte
m.java:824)
	at
org.eclipse.jface.action.ActionContributionItem.fill(ActionContributionItem.
java:274)
	at org.eclipse.jface.action.MenuManager.update(MenuManager.java:625)
	at org.eclipse.jface.action.MenuManager.update(MenuManager.java:547)
	at org.eclipse.jface.action.MenuManager.fill(MenuManager.java:232)
	at org.eclipse.jface.action.MenuManager.update(MenuManager.java:625)
	at org.eclipse.jface.action.MenuManager.update(MenuManager.java:547)
	at org.eclipse.jface.action.MenuManager.createMenuBar(MenuManager.java:158)
	at
org.eclipse.jface.window.ApplicationWindow.createTrimWidgets(ApplicationWind
ow.java:332)
	at
org.eclipse.jface.window.ApplicationWindow.configureShell(ApplicationWindow.
java:320)
	at
de.powerisdnmonitor.ui.jface.application.JournalApplication.configureShell(J
ournalApplication.java:43)
:
:

My configureShell() method is simple an overriden method from
ApplicationWindow:

	protected void configureShell(Shell shell) {
		super.configureShell(shell);
		shell.setText("MyApplication");
	}


* The exception only occurs if I call the Application from user-interface
thread which does not belong to Display.getDefault(). The method
getImageCache() of the class ActionContributionItem calls
Display.getDefault() for my Thread "HandlerThread#Journal" although it does
not belong to this Display object:

    private static ImageCache getImageCache() {
        ImageCache cache = globalImageCache;
        if (cache == null) {
            globalImageCache = cache = new ImageCache();
            Display display = Display.getDefault();        <-- *
            if (display != null) {
                display.disposeExec(new Runnable() {
                    public void run() {
                        if (globalImageCache != null) {
                            globalImageCache.dispose();
                            globalImageCache = null;
                        }
                    }
                });
            }
        }
        return cache;
    }

Wouldn't it be better to call Display.getCurrent() in the getImageCache()
method? Or should I do something different in my coding?

Best regards,
Thilo




Back to the top