diff options
2 files changed, 131 insertions, 16 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceImpl.java index 259ca541ff7..2b842bb7dc7 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceImpl.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceImpl.java @@ -19,7 +19,9 @@ import javax.annotation.PreDestroy; import javax.inject.Inject; import javax.inject.Named; import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.ListenerList; +import org.eclipse.core.runtime.SafeRunner; import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.di.InjectionException; @@ -182,33 +184,73 @@ public class PartServiceImpl implements EPartService { partActivationHistory.clear(); } - private void firePartActivated(MPart part) { - for (Object listener : listeners.getListeners()) { - ((IPartListener) listener).partActivated(part); + private void firePartActivated(final MPart part) { + for (final Object listener : listeners.getListeners()) { + SafeRunner.run(new ISafeRunnable() { + public void run() throws Exception { + ((IPartListener) listener).partActivated(part); + } + + public void handleException(Throwable throwable) { + logger.error(throwable, "An exception occurred while notifying part listeners"); //$NON-NLS-1$ + } + }); } } - private void firePartDeactivated(MPart part) { - for (Object listener : listeners.getListeners()) { - ((IPartListener) listener).partDeactivated(part); + private void firePartDeactivated(final MPart part) { + for (final Object listener : listeners.getListeners()) { + SafeRunner.run(new ISafeRunnable() { + public void run() throws Exception { + ((IPartListener) listener).partDeactivated(part); + } + + public void handleException(Throwable throwable) { + logger.error(throwable, "An exception occurred while notifying part listeners"); //$NON-NLS-1$ + } + }); } } - private void firePartHidden(MPart part) { - for (Object listener : listeners.getListeners()) { - ((IPartListener) listener).partHidden(part); + private void firePartHidden(final MPart part) { + for (final Object listener : listeners.getListeners()) { + SafeRunner.run(new ISafeRunnable() { + public void run() throws Exception { + ((IPartListener) listener).partHidden(part); + } + + public void handleException(Throwable throwable) { + logger.error(throwable, "An exception occurred while notifying part listeners"); //$NON-NLS-1$ + } + }); } } - private void firePartVisible(MPart part) { - for (Object listener : listeners.getListeners()) { - ((IPartListener) listener).partVisible(part); + private void firePartVisible(final MPart part) { + for (final Object listener : listeners.getListeners()) { + SafeRunner.run(new ISafeRunnable() { + public void run() throws Exception { + ((IPartListener) listener).partVisible(part); + } + + public void handleException(Throwable throwable) { + logger.error(throwable, "An exception occurred while notifying part listeners"); //$NON-NLS-1$ + } + }); } } - private void firePartBroughtToTop(MPart part) { - for (Object listener : listeners.getListeners()) { - ((IPartListener) listener).partBroughtToTop(part); + private void firePartBroughtToTop(final MPart part) { + for (final Object listener : listeners.getListeners()) { + SafeRunner.run(new ISafeRunnable() { + public void run() throws Exception { + ((IPartListener) listener).partBroughtToTop(part); + } + + public void handleException(Throwable throwable) { + logger.error(throwable, "An exception occurred while notifying part listeners"); //$NON-NLS-1$ + } + }); } } diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/EPartServiceTest.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/EPartServiceTest.java index b3e9bd29573..bd4e8457b1a 100644 --- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/EPartServiceTest.java +++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/EPartServiceTest.java @@ -10464,6 +10464,45 @@ public class EPartServiceTest extends TestCase { assertNull("The part should no longer be reachable", ref.get()); } + public void testsEventWithExceptions() { + MApplication application = ApplicationFactoryImpl.eINSTANCE + .createApplication(); + + MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); + application.getChildren().add(window); + application.setSelectedElement(window); + + MPartStack partStack = BasicFactoryImpl.eINSTANCE.createPartStack(); + window.getChildren().add(partStack); + window.setSelectedElement(partStack); + + MPart partA = BasicFactoryImpl.eINSTANCE.createPart(); + window.getChildren().add(partA); + window.setSelectedElement(partA); + + MPart partB = BasicFactoryImpl.eINSTANCE.createPart(); + window.getChildren().add(partB); + + initialize(applicationContext, application); + getEngine().createGui(window); + + EPartService partService = window.getContext().get(EPartService.class); + partService.activate(partA); + partService.activate(partB); + partService.activate(partA); + + partService.addPartListener(new ExceptionListener()); + PartListener listener = new PartListener(); + partService.addPartListener(listener); + + partService.activate(partB); + assertEquals(1, listener.getActivated()); + assertEquals(1, listener.getDeactivated()); + assertEquals(1, listener.getVisible()); + assertEquals(1, listener.getHidden()); + assertEquals(1, listener.getBroughtToTop()); + } + private MApplication createApplication(String partId) { return createApplication(new String[] { partId }); } @@ -10527,11 +10566,13 @@ public class EPartServiceTest extends TestCase { private List<MPart> deactivatedParts = new ArrayList<MPart>(); private List<MPart> hiddenParts = new ArrayList<MPart>(); private List<MPart> visibleParts = new ArrayList<MPart>(); + private List<MPart> broughtToTopParts = new ArrayList<MPart>(); private int activated = 0; private int deactivated = 0; private int hidden = 0; private int visible = 0; + private int broughtToTop = 0; private boolean valid = true; @@ -10565,6 +10606,10 @@ public class EPartServiceTest extends TestCase { return visible; } + public int getBroughtToTop() { + return broughtToTop; + } + public boolean isValid() { return valid; } @@ -10594,7 +10639,11 @@ public class EPartServiceTest extends TestCase { } public void partBroughtToTop(MPart part) { - + if (valid && part == null) { + valid = false; + } + broughtToTop++; + broughtToTopParts.add(part); } public void partDeactivated(MPart part) { @@ -10622,4 +10671,28 @@ public class EPartServiceTest extends TestCase { } } + + class ExceptionListener implements IPartListener { + + public void partActivated(MPart part) { + throw new RuntimeException(); + } + + public void partBroughtToTop(MPart part) { + throw new RuntimeException(); + } + + public void partDeactivated(MPart part) { + throw new RuntimeException(); + } + + public void partHidden(MPart part) { + throw new RuntimeException(); + } + + public void partVisible(MPart part) { + throw new RuntimeException(); + } + + } } |