Search code examples
windows-10swteclipse-rcp

SWT FileDialog is missing the navigation bar on windows 10


I have a small eclipse RCP application.

I have noticed that on windows 10 FileDialog doesn't have the path part available.

I have tried different combinations of Style flags during the initialization of the dialog but it didn't work.

It is worth mentioning that everything is alright on windows 7.

No navigation bar on windows 10: SWT FileDialog with no navigation bar

Expected: Expected file dialog with navigation bar

Further investigation of that issue I got to the following:

The dialog appears correctly with the navigation bar if I start it out of the WorkbenchAdvisor.

The code basically is like this:

@Override 
public Object start(IApplicationContext context) throws Exception {       
    try {
        int returnCode = PlatformUI.createAndRunWorkbench(display, new WorkbenchAdvisor() {

            @Override
            public void postStartup() {
                // THIS MAKES THE DIALOG APPEAR WITHOUT NAVIGATION BAR
                Display display = new Display();
                Shell shell = new Shell(display);
                FileDialog dialog = new FileDialog (shell, SWT.OPEN | SWT.MULTI);
                dialog.open();
                shell.close();
                while (!shell.isDisposed ()) {
                    if (!display.readAndDispatch ()) {
                        display.sleep ();
                    }
                }
            }

        });
        if (returnCode == PlatformUI.RETURN_RESTART) {
            return IApplication.EXIT_RESTART;
        }
        return IApplication.EXIT_OK;
    } finally {
        Display.getDefault().dispose();
    }
    return IApplication.EXIT_OK;
}

I need to be able to start the FileDialog correctly after starting my workbench.

If I do the following the dialog appears correctly with the navigation bar but this is not the desired:

@Override 
public Object start(IApplicationContext context) throws Exception {
    // THIS MAKES THE DIALOG APPEAR WITH THE NAVIGATION BAR CORRECTLY
    Display display = new Display();
    Shell shell = new Shell(display);
    FileDialog dialog = new FileDialog (shell, SWT.OPEN | SWT.MULTI);
    dialog.open();
    shell.close();
    while (!shell.isDisposed ()) {
        if (!display.readAndDispatch ()) {
            display.sleep ();
        }
    }
    Display.getDefault().dispose();
    return IApplication.EXIT_OK;
}

I still can't figure out how to fix this or what is really happening.

Another piece of info is that if I start my RCP from eclipse using a launch configuration it works just fine, the file dialog appears with the navigation bar even if I start it inside the WorkbenchAdvisor.


Solution

  • I'd suggest you use the org.eclipse.ui.startup extension. You declare it on your plugin.xml.

    This extension requires you to provide a class that implements the IStartup interface. This class' earlyStartup method runs after WorkbenchAdvisor.postStartup.

    Maybe by this time the navigation bar appears.