如何在 Eclipse 向导中打开文件对话框

How to open a filedialog within an Eclipse Wizard

我正在编写一个 Eclipse 插件,它必须创建一个新项目。到目前为止这有效,但我需要将一个外部文件复制到项目文件夹中。我打算在我的 WizardPages 之一上有一个 'Browse' 按钮,它会打开一个文件对话框,用户可以在其中浏览到文件,关闭对话框后我可以使用该文件的路径进行各种操作。我的问题是对话框 window 永远不会打开。现在我正在尝试这种方式(来自我的向导页面的片段):

    public void createControl(Composite composite) {
        this.container = new Composite(composite, SWT.NONE);
        GridLayout layout = new GridLayout();
        this.container.setLayout(layout);
        layout.numColumns = 2;

        Button browseButton = new Button(this.container, SWT.PUSH);
        browseButton.setText("Browse");
        browseButton.addSelectionListener(new SelectionListener() {

           @Override
           public void widgetDefaultSelected(SelectionEvent arg0) {

              FileDialog fileDialog = new FileDialog(DataPage.this.container.getShell(), SWT.OPEN);         
              fileDialog.setText("JZOS created File");
              String path = fileDialog.open();
              DataPage.this.setJzosCreatedName(path);

        }
    });

我尝试了几种我在示例和教程中看到的实现,但没有任何效果。我假设我给文件对话框的 Shell 有问题。我试图在 widgetDefaultSelected 函数中打开一个新的 Shell 但它也没有用。有什么建议吗?

您应该使用 SelectionListenerwidgetSelected 方法而不是 widgetDefaultSelected