用于导出文件的 Eclipse WizardPage

发布于 2024-12-20 11:23:53 字数 901 浏览 4 评论 0原文

我想使用 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 机制,但我确实找不到一个简单的示例来向我展示某些东西应该是什么样子。

I want to use the exportWizard extension point for an eclipse plugin. I am having some difficulties figuring out how a simple filedialog wizard page should look like.

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

I am trying it currently like above and use a FileDialog for selecting the target file. Basically it works, the dialog is opened and I get the name of the file, but as soon the dialog closes I get an exception.

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)

I think I am using this Wizard/WizardPage mechanism wrongly, but I really could not found a simple example that showed me how something should look like.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖乖 2024-12-27 11:23:53

您的向导页面不包含任何控件。您应该创建一个组合,然后将所有控件添加到其中(而不是直接添加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);
}

Your wizard page does not contain any controls. You should create one composite and then add all your controls to it (and NOT parent directly). Calling setControl(..) is also absolutely required. It should look something like this:

@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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文