Java 在应用程序之前显示登录对话框
我想要实现的非常简单:我希望用户在未登录时不能看到应用程序 所以我需要做的是显示一个登录对话框,然后创建应用程序。我试图在Java 在应用程序之前显示登录对话框,java,eclipse-plugin,Java,Eclipse Plugin,我想要实现的非常简单:我希望用户在未登录时不能看到应用程序 所以我需要做的是显示一个登录对话框,然后创建应用程序。我试图在iaapplication#start(iaapplicationcontext)中这样做,但该方法显然没有在UI线程中运行,因此我没有机会在那里显示对话框 之后,我尝试了WorkbenchHadVisor#preStartup(): 我不认为emergencyClose()是在这里调用的正确方法,但是IWorkbench#close()抛出一个NullPointerExce
iaapplication#start(iaapplicationcontext)
中这样做,但该方法显然没有在UI线程中运行,因此我没有机会在那里显示对话框
之后,我尝试了WorkbenchHadVisor#preStartup()
:
我不认为emergencyClose()
是在这里调用的正确方法,但是IWorkbench#close()
抛出一个NullPointerException
并仍然打开一个窗口存根
当然,emergencyClose()
也会抛出NullPointerException
,但除此之外,它还能正常工作:
java.lang.NullPointerException
at org.eclipse.ui.internal.Workbench.busyClose(Workbench.java:1204)
at org.eclipse.ui.internal.Workbench.access$22(Workbench.java:1113)
at org.eclipse.ui.internal.Workbench$19.run(Workbench.java:1454)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.Workbench.close(Workbench.java:1451)
at org.eclipse.ui.internal.WorkbenchConfigurer.emergencyClose(WorkbenchConfigurer.java:159)
at org.acme.project.ApplicationWorkbenchAdvisor.preStartup(ApplicationWorkbenchAdvisor.java:36)
at org.eclipse.ui.internal.Workbench$24.runWithException(Workbench.java:1718)
at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:32)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4155)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3772)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2989)
at org.eclipse.ui.internal.Workbench.access$9(Workbench.java:2894)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:685)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:606)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
有没有办法防止这种例外?还是有更好的方法在第一个应用程序窗口打开之前打开登录对话框?您可以像这样在iApplicationStart(IApplicationContext)的UI线程上调用一些方法。但我不确定这是不是正确的方法
final int[] result = new int[]{0};
Display.syncExec(new Runnable() {
result[0] = new YourLoginDialog(Display.getCurrent().getShell()).open();
});
if (result[0] != Windows.OK) {
// failed to login
return IApplicaton.EXIT_OK;
}
人们似乎大多使用启动屏幕登录。在xxx.product文件编辑器的“Splash”选项卡上有一个用于此的模板(我自己从未尝试过)。@greg-449这是一个很棒的功能。可怕的GUI支持,但功能强大。现在它可以正常工作了,谢谢。检查你的IApplication#start方法,你可能会发现一些方法可以创建显示。
final int[] result = new int[]{0};
Display.syncExec(new Runnable() {
result[0] = new YourLoginDialog(Display.getCurrent().getShell()).open();
});
if (result[0] != Windows.OK) {
// failed to login
return IApplicaton.EXIT_OK;
}