如何在Eclipse向导中打开一个filedialog

时间:2015-07-22 13:44:52

标签: eclipse wizard filedialog

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

    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);

        }
    });

我尝试了几个实现,我在示例和教程中看到过,但没有任何工作。我假设壳牌的问题,我给了filedialog。我试图在widgetDefaultSelected函数中打开一个新的Shell,但它也没有用。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

您应该使用widgetSelected而不是SelectionListener

widgetDefaultSelected方法