How to invoke a windows file explorer from a SWT button?

182 Views Asked by At

Eclipse RAP consists of SWT FileDialog and it's internal implementation has been changed inside RAP. I don't want to use the FileDialog which is available in RAP. Instead I have a custom dialog called FileSelectionDialog which consists of a button, once I click on the button, I want to invoke windows file explorer? How can I do it?

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;

public class FileSelectionDialog extends Dialog {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    protected FileSelectionDialog(Shell parentShell) {
        super(parentShell);
    }

    @Override
    protected Control createDialogArea(Composite parentComposite) {
        Composite container = (Composite) super.createDialogArea(parentComposite);
        Button button = new Button(container, SWT.PUSH);
        button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
        button.setText("Browse");
        button.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                System.out.println(" Browse Pressed");

            }
        });

        return container;

    }

    @Override
    protected void configureShell(Shell newShell) {
        super.configureShell(newShell);
        newShell.setText("File Upload Dialog");
    }

    @Override
    protected Point getInitialSize() {
        return new Point(450, 300);
    }
}```
1

There are 1 best solutions below

0
Manjunath S On

I was able to find the answer through RAP Developer's Guide.

`final FileUpload fileUpload = new FileUpload( parent, SWT.NONE );
fileUpload.setText( "Select File" );
fileUpload.addSelectionListener( new SelectionAdapter() {
  @Override
  public void widgetSelected( SelectionEvent e ) {
    fileUpload.submit( uploadHandler.getUploadUrl() );
  }
} );`