Finding an RCP Application Display

I am writing a test framework that runs a GUI application. To test this GUI in the case of an SWT application, I need to know its display. In general, this display is being loaded by another classloader, so I use the findDisplay (Thread t) method of the swt Display class by reflection to accomplish this task. My code looks something like this:

Thread[] threads = new Thread[10];
Thread.enumerate(threads);
Object foundObject = null;
for (Thread t : Arrays.asList(threads)){
    foundObject = null;
    Class<?> clazz = t.getContextClassLoader().loadClass("org.eclipse.swt.widgets.Display");
    final Method method = clazz.getMethod("findDisplay", Thread.class);
    foundObject = method.invoke(null, new Object[] {t});
    if (foundObject != null) {
        System.out.println("yeah, found it!");
        break;
    }
}

      

In my opinion this should find every Display object in the current threadgroup. However, I am not getting any response for the RCP editor example, although the GUI starts up just fine.

Any ideas what is going wrong or how I can debug this in a sane way?

0


a source to share


2 answers


I figured out what the main problem was: The ContextClassloader had nothing to do with the classloader that actually loaded the classes.



To solve the problem, I made sure that the classloader was loading the swt display class both in the RCP program hierarchy and in my infrastructure hierarchy. This was possible with the java extension classloader. (I couldn't use the application classloader since the RCP application doesn't work with it as a parent, I haven't figured out why yet). Then it was just a matter of adding swt.jar to the java.ext.dirs property.

0


a source


If you are using Eclipse RCP, maybe you can use:



PlatformUI.getWorkbench (). GetDisplay ()

0


a source







All Articles