简体   繁体   English

如何将按钮添加到JFace ErrorDialog

[英]How to add buttons to the JFace ErrorDialog

I'm trying to add a "Cancel" button to this popup dialog, the dialog basically just gives the user some info and allows them to hit Yes or view details. 我正在尝试向此弹出对话框添加“取消”按钮,该对话框基本上只是为用户提供一些信息,并允许他们单击“是”或查看详细信息。 The problem is that there is no Cancel button and I would like to add one. 问题是没有取消按钮,我想添加一个。

The dialog is a JFace ErrorDialog which uses a premade MultiStatus to display the error message. 该对话框是一个JFace ErrorDialog ,它使用预制的MultiStatus显示错误消息。 The dialog opens and gives an OK button or a Cancel button. 对话框打开,并显示“确定”按钮或“取消”按钮。 Is there anyway to directly manipulate how the dialog creates buttons or some other method I could use to change how it looks? 无论如何,是否可以直接操纵对话框如何创建按钮或我可以用来更改其外观的其他方法? Any help is appreciated! 任何帮助表示赞赏!

if (ErrorDialog.openError(shell, 
    Messages.ConsistencyAction_confirm_dialog_title, null,
    multiStatus, IStatus.WARNING) != Window.OK) {
    return;
}

This is the dialog I'm trying to change. 这是我要更改的对话框。 This is basically checking to make sure that someone presses ok, if they don't then you exit. 基本上,这是在进行检查以确保有人按ok,否则,您将退出。 You can exit it by hitting the red X in the corner but it'd be less confusing to have a button. 您可以通过点击角落的红色X退出它,但是拥有一个按钮会减少混乱。

You can extend the ErrorDialog class so that you can override the createButtonsForButtonBar method. 您可以扩展ErrorDialog类,以便可以覆盖createButtonsForButtonBar方法。

For example this is from the Eclipse p2 install plugin: 例如,这来自Eclipse p2安装插件:

public class OkCancelErrorDialog extends ErrorDialog {

    public OkCancelErrorDialog(Shell parentShell, String dialogTitle, String message, IStatus status, int displayMask) {
        super(parentShell, dialogTitle, message, status, displayMask);
    }

    @Override
    protected void createButtonsForButtonBar(Composite parent) {
        // create OK, Cancel and Details buttons
        createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
        createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, true);
        createDetailsButton(parent);
    }
}

With this you can't use the static ErrorDialog.openError method, instead you will have to do something like: 使用此方法,您不能使用静态的ErrorDialog.openError方法,而必须执行以下操作:

OkCancelErrorDialog dialog = new OkCancelErrorDialog(shell, Messages.ConsistencyAction_confirm_dialog_title, null, multiStatus, IStatus.WARNING);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM