我试图让ProgressMonitorDialog
起作用,但由于某种原因它在E4(4.7.2)应用程序中不起作用。但它可以独立运行。
我的所作所为:在标准的E3兼容性处理程序中,我执行以下操作:
new ProgressMonitorDialog(HandlerUtil.getActiveShell(event)).run(false, false, monitor -> {
monitor.beginTask("My Task", 20);
for (int i = 0; i < 20; i++) {
Thread.sleep(100);
monitor.worked(1);
}
monitor.done();
});
当我执行处理程序时,我得到以下异常:
org.eclipse.e4.core.di.InjectionException: java.lang.ArrayIndexOutOfBoundsException: 1600
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:65)
at org.eclipse.e4.ui.internal.di.UIEventObjectSupplier$UIEventHandler$1.run(UIEventObjectSupplier.java:64)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:233)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:144)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4889)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:212)
at org.eclipse.e4.ui.internal.di.UIEventObjectSupplier$UIEventHandler.handleEvent(UIEventObjectSupplier.java:61)
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:201)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:52)
at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:60)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
at org.eclipse.e4.ui.model.application.ui.menu.impl.ItemImpl.setEnabled(ItemImpl.java:284)
at org.eclipse.e4.ui.workbench.renderers.swt.AbstractContributionItem$1.run(AbstractContributionItem.java:515)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.workbench.renderers.swt.AbstractContributionItem.updateItemEnablement(AbstractContributionItem.java:554)
at org.eclipse.e4.ui.workbench.renderers.swt.ToolItemUpdater.updateContributionItems(ToolItemUpdater.java:37)
at org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer.subscribeTopicUpdateToolbarEnablement(ToolBarManagerRenderer.java:289)
at jdk.internal.reflect.GeneratedMethodAccessor38.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
at org.eclipse.e4.ui.internal.di.UIEventObjectSupplier$UIEventHandler$1.run(UIEventObjectSupplier.java:64)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:233)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:144)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4889)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:212)
at org.eclipse.e4.ui.internal.di.UIEventObjectSupplier$UIEventHandler.handleEvent(UIEventObjectSupplier.java:61)
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:201)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:52)
at org.eclipse.ui.internal.services.EvaluationService$1.changed(EvaluationService.java:81)
at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:114)
at org.eclipse.e4.core.internal.contexts.EclipseContext.processScheduled(EclipseContext.java:355)
at org.eclipse.e4.core.internal.contexts.EclipseContext.set(EclipseContext.java:370)
at org.eclipse.e4.core.internal.contexts.EclipseContext.activate(EclipseContext.java:674)
at org.eclipse.e4.ui.internal.workbench.swt.ShellActivationListener$2.run(ShellActivationListener.java:127)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.internal.workbench.swt.ShellActivationListener.activate(ShellActivationListener.java:123)
at org.eclipse.e4.ui.internal.workbench.swt.ShellActivationListener.handleEvent(ShellActivationListener.java:73)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1271)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1078)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1103)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1088)
at org.eclipse.swt.widgets.Decorations.WM_ACTIVATE(Decorations.java:1698)
at org.eclipse.swt.widgets.Shell.WM_ACTIVATE(Shell.java:2277)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4840)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:359)
at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1657)
at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2199)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:5178)
at org.eclipse.swt.internal.win32.OS.BringWindowToTop(Native Method)
at org.eclipse.swt.widgets.Decorations.bringToTop(Decorations.java:232)
at org.eclipse.swt.widgets.Shell.open(Shell.java:1270)
at org.eclipse.jface.window.Window.open(Window.java:790)
at org.eclipse.jface.dialogs.ProgressMonitorDialog.open(ProgressMonitorDialog.java:646)
at org.eclipse.jface.dialogs.ProgressMonitorDialog.aboutToRun(ProgressMonitorDialog.java:555)
at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:480)
at org.acme.project.MyHandler.execute(MyHandler.java:74)
如果您尝试上面的代码,您会发现它有效。因为我省略了破坏代码的行:
DPIUtil.setDeviceZoom(100);
无论我把它放在哪里,打开对话框时都会抛出上述异常。但是我需要该行,因为当前的RCP仍然具有与显示器相关联的缩放,因此当主监视器具有缩放活动时我无法打印。 (有关该问题的更多信息,我收集了所有调查结果in this question。)
有没有办法解决这个问题?我认为其他公司在打印和缩放方面存在同样的问题,因此我必须要做的事情。