Skip to main content

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

Thilo this group is for discussion about the development of Eclipse rather 
than questions - you should use the newsgroup for these.

The basic answer is that all SWT operations need to run in the UI Thread - 
getCurrent() is used here as this code is not to be used in a background 
Thread.

Tod




"Thilo Brandt" <swt@xxxxxxxxxxxxxxxxxxx> 
Sent by: platform-ui-dev-admin@xxxxxxxxxxx
01/04/2005 06:59 PM
Please respond to
platform-ui-dev


To
<platform-ui-dev@xxxxxxxxxxx>
cc

Subject
[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


_______________________________________________
platform-ui-dev mailing list
platform-ui-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/platform-ui-dev




Back to the top