【问题标题】:Eclipse WizardPage for exporting a file用于导出文件的 Eclipse WizardPage
【发布时间】:2011-12-10 19:36:56
【问题描述】:

我想为 Eclipse 插件使用 exportWizard 扩展点。我在弄清楚一个简单的文件对话框向导页面应该是什么样子时遇到了一些困难。

public class ExportWizardPage extends WizardPage {

private FileDialog fileDialog=null;

protected ExportWizardPage(String pageName) {
    super(pageName);
}

@Override
public void createControl(Composite parent) {

    fileDialog = new FileDialog(parent.getShell(), SWT.SAVE);
    fileDialog.setFilterExtensions(new String[] { "*.bm" });
}
}

我目前正在尝试上面的方法,并使用 FileDialog 来选择目标文件。基本上它可以工作,打开对话框,我得到文件的名称,但是一旦对话框关闭,我就会得到一个异常。

org.eclipse.core.runtime.AssertionFailedException: null argument:
    at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:85)
    at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:73)
    at org.eclipse.jface.wizard.Wizard.createPageControls(Wizard.java:178)

我认为我错误地使用了这个 Wizard/WizardPage 机制,但我真的找不到一个简单的例子来告诉我某些东西应该是什么样子。

【问题讨论】:

    标签: export swt wizard


    【解决方案1】:

    您的向导页面不包含任何控件。您应该创建一个组合,然后将所有控件添加到其中(而不是直接添加 parent)。也绝对需要调用setControl(..)。它应该看起来像这样:

    @Override
    public void createControl(Composite parent) {
      Composite content = new Composite(parent, SWT.NONE);
    
      // add all the controls to your wizard page here with 'content' as parent
    
      FileDialog fileDialog = new FileDialog(parent.getShell(), SWT.SAVE);
      fileDialog.setFilterExtensions(new String[] { "*.bm" });
    
      setControl(content);
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-01
      • 2018-05-11
      • 2019-01-11
      • 2014-07-08
      • 1970-01-01
      • 2012-04-08
      • 2014-06-01
      • 2014-12-21
      • 2012-06-25
      相关资源
      最近更新 更多