Why don't eclipse jface's MessageDialog static methods determine themselves the parent shell?
I'm doing an Eclipse RCP/Jface application, and I often use the MessageDialog
.open...
methods to show messages to the user.
However, the title for an information dialog, for example, is always the same. And the shell object provided, also, is always the top shell. As I wanted to keep my code DRY, I made some helper functions, which receive only the message as parameter. For the parent shell, I u开发者_如何学编程sed PlatformUI.getWorkbench().getModalDialogShellProvider().getShell()
. The documentation says that it returns "a shell ... that can be used to get the best parenting possible for a modal dialog" E.g.:
class Helper {
public static void openInformation(String message) {
MessageDialog.open(MessageDialog.INFORMATION,
PlatformUI.getWorkbench().getModalDialogShellProvider().getShell(),
Activator.translate("some.bundle.path.information"), message, SWT.NONE);
}
}
My question is why didn't they make the methods MessageDialog.open...
to determine themselves the parent shell for the message? And am I missing something if I always use this same way to provide a shell for the message boxes?
My two cents,
It might have more than one Workbench Windows opened by your application. So passing in the shell of the window, it could help decide make which window be modal.
If you check the JavaDoc, you'll see that the shell may even be null. I believe the shell is only used to center the dialog (with respect to the shell).
精彩评论