Eclipse RCP:如何在编辑器加载后显示消息对话框?

时间:2022-09-11 19:44:02

I am opening an editor from a view on click of a treenode. Now, when editor loads and controls are displayed to the user, I want to display a warning message dialog to the user based on certain values present on the editor.

我在点击treenode的视图中打开一个编辑器。现在,当向用户显示编辑器加载和控件时,我想根据编辑器上的某些值向用户显示警告消息对话框。

I tried by putting the warning dialog at the end of createPartControl method of the editor. Dialog appears on double cliking the treenode as per the required functionality. But, the problem is that when the dialog appears, the controls on the editor are not yet visible. It's only when I close the dialog the editor controls are shown.

我尝试将警告对话框放在编辑器的createPartControl方法的末尾。根据所需功能,对话框出现在双重按钮上。但问题是,当对话框出现时,编辑器上的控件仍然不可见。只有当我关闭对话框时才会显示编辑器控件。

I want it to happen the other way around. i.e. The editor controls to show up first and then the warning dialog should appear. What changes should I do to achieve this effect?

我希望它以相反的方式发生。即编辑器控件首先显示,然后出现警告对话框。我应该做些什么改变才能达到这个效果?

1 个解决方案

#1


You may want to call that MessageDialog in an asynchronous way, to leave the Editor the opportunity to complete itself, as suggested in this message.

您可能希望以异步方式调用MessageDialog,以使编辑器有机会完成自身,如此消息中所示。

show your warning dialog in an asyncExec() runnable would ensure that the editor's initialization all happens in the correct sequence.

在asyncExec()runnable中显示您的警告对话框将确保编辑器的初始化都以正确的顺序发生。

So, something like (not tested) this code might do the trick:

所以,像(未经测试)此代码的东西可能会做到这一点:

getSite().getShell().getDisplay().asyncExec
    (new Runnable() {
        public void run() {
            MessageDialog.openWarning(getSite().getShell(),"wrong","no)
        }
    });
}

Some other examples in this MapEditor class, where a MessageDialog is displayed through an asyncExec which waits for the result:

此MapEditor类中的其他一些示例,其中MessageDialog通过asyncExec显示,等待结果:

PlatformGIS.syncInDisplayThread

#1


You may want to call that MessageDialog in an asynchronous way, to leave the Editor the opportunity to complete itself, as suggested in this message.

您可能希望以异步方式调用MessageDialog,以使编辑器有机会完成自身,如此消息中所示。

show your warning dialog in an asyncExec() runnable would ensure that the editor's initialization all happens in the correct sequence.

在asyncExec()runnable中显示您的警告对话框将确保编辑器的初始化都以正确的顺序发生。

So, something like (not tested) this code might do the trick:

所以,像(未经测试)此代码的东西可能会做到这一点:

getSite().getShell().getDisplay().asyncExec
    (new Runnable() {
        public void run() {
            MessageDialog.openWarning(getSite().getShell(),"wrong","no)
        }
    });
}

Some other examples in this MapEditor class, where a MessageDialog is displayed through an asyncExec which waits for the result:

此MapEditor类中的其他一些示例,其中MessageDialog通过asyncExec显示,等待结果:

PlatformGIS.syncInDisplayThread