aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Besedin2012-01-31 09:51:30 (EST)
committerOleg Besedin2012-01-31 09:52:08 (EST)
commit435a1052e7ed59def5756fc6d97cc01a129be9f9 (patch)
treeb8f2d88ceef45da9893d711628edd90f1d8dd14f
parentaaa101d65a906bb54b37f73455f7e097735809cd (diff)
downloadeclipse.platform.ui-435a1052e7ed59def5756fc6d97cc01a129be9f9.zip
eclipse.platform.ui-435a1052e7ed59def5756fc6d97cc01a129be9f9.tar.gz
eclipse.platform.ui-435a1052e7ed59def5756fc6d97cc01a129be9f9.tar.bz2
Bug 370219 - Selection service could use an ability to pause dependencyv20120131-1452
recording
-rw-r--r--bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionAggregator.java60
-rw-r--r--tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/UITest.java13
2 files changed, 36 insertions, 37 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionAggregator.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionAggregator.java
index 8f3af55..08df85a 100644
--- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionAggregator.java
+++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionAggregator.java
@@ -18,12 +18,14 @@ import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Named;
+import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.ListenerList;
+import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.contexts.RunAndTrack;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.services.events.IEventBroker;
-import org.eclipse.e4.ui.di.UISynchronize;
+import org.eclipse.e4.core.services.log.Logger;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.e4.ui.workbench.UIEvents;
@@ -40,9 +42,6 @@ public class SelectionAggregator {
private Map<String, ListenerList> targetedListeners = new HashMap<String, ListenerList>();
private Set<IEclipseContext> tracked = new HashSet<IEclipseContext>();
- @Inject
- UISynchronize synchService;
-
private EventHandler eventHandler = new EventHandler() {
public void handleEvent(Event event) {
Object element = event.getProperty(UIEvents.EventTags.ELEMENT);
@@ -64,12 +63,16 @@ public class SelectionAggregator {
private IEventBroker eventBroker;
+ private Logger logger;
+
@Inject
- SelectionAggregator(IEclipseContext context, EPartService partService, IEventBroker eventBroker) {
+ SelectionAggregator(IEclipseContext context, EPartService partService,
+ IEventBroker eventBroker, Logger logger) {
super();
this.context = context;
this.partService = partService;
this.eventBroker = eventBroker;
+ this.logger = logger;
}
@PreDestroy
@@ -100,20 +103,38 @@ public class SelectionAggregator {
}
}
- private void notifyListeners(MPart part, Object selection) {
+ private void notifyListeners(final MPart part, final Object selection) {
for (Object listener : genericListeners.getListeners()) {
- ((ISelectionListener) listener).selectionChanged(part, selection);
+ final ISelectionListener myListener = (ISelectionListener) listener;
+ SafeRunner.run(new ISafeRunnable() {
+ public void run() throws Exception {
+ myListener.selectionChanged(part, selection);
+ }
+
+ public void handleException(Throwable exception) {
+ logger.error(exception);
+ }
+ });
}
notifyTargetedListeners(part, selection);
}
- private void notifyTargetedListeners(MPart part, Object selection) {
+ private void notifyTargetedListeners(final MPart part, final Object selection) {
String id = part.getElementId();
if (id != null) {
ListenerList listenerList = targetedListeners.get(id);
if (listenerList != null) {
for (Object listener : listenerList.getListeners()) {
- ((ISelectionListener) listener).selectionChanged(part, selection);
+ final ISelectionListener myListener = (ISelectionListener) listener;
+ SafeRunner.run(new ISafeRunnable() {
+ public void run() throws Exception {
+ myListener.selectionChanged(part, selection);
+ }
+
+ public void handleException(Throwable exception) {
+ logger.error(exception);
+ }
+ });
}
}
}
@@ -135,24 +156,15 @@ public class SelectionAggregator {
}
}
- // TBD the async calls below are used to avoid listeners
- // interfering with the context (listeners adding dependincies
- // for this RaT and listeners creating values in the context
- // going into infinite loops). We probably need to add a method
- // to RaT to stop recoding.
if (activePart == part) {
myContext.set(IServiceConstants.ACTIVE_SELECTION, selection);
- synchService.asyncExec(new Runnable() {
- public void run() {
- notifyListeners(part, selection);
- }
- });
+ pauseRecording();
+ notifyListeners(part, selection);
+ resumeRecoding();
} else {
- synchService.asyncExec(new Runnable() {
- public void run() {
- notifyTargetedListeners(part, selection);
- }
- });
+ pauseRecording();
+ notifyTargetedListeners(part, selection);
+ resumeRecoding();
// we don't need to keep tracking non-active parts unless
// they have targeted listeners
String partId = part.getElementId();
diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/UITest.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/UITest.java
index e3f573f..125e5f9 100644
--- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/UITest.java
+++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/UITest.java
@@ -13,12 +13,10 @@ package org.eclipse.e4.ui.tests.application;
import junit.framework.TestCase;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.contributions.IContributionFactory;
-import org.eclipse.e4.ui.di.UISynchronize;
import org.eclipse.e4.ui.internal.workbench.swt.E4Application;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.impl.ApplicationFactoryImpl;
import org.eclipse.e4.ui.workbench.IPresentationEngine;
-import org.eclipse.swt.widgets.Display;
public class UITest extends TestCase {
@@ -38,17 +36,6 @@ public class UITest extends TestCase {
application.setContext(applicationContext);
applicationContext.set(MApplication.class, application);
- final Display display = Display.getDefault();
- applicationContext.set(UISynchronize.class, new UISynchronize() {
- public void syncExec(Runnable runnable) {
- display.syncExec(runnable);
- }
-
- public void asyncExec(Runnable runnable) {
- display.asyncExec(runnable);
- }
- });
-
E4Application.initializeServices(application);
}