Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java72
1 files changed, 40 insertions, 32 deletions
diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java
index 2749824..283b53a 100644
--- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java
+++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java
@@ -11,6 +11,7 @@
package org.eclipse.launchbar.core.internal;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@@ -607,18 +608,31 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
return InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
}
+ private interface FireAction {
+ void run(ILaunchBarListener listener);
+ }
+
+ private void fireEvent(FireAction action) {
+ Collection<ILaunchBarListener> l;
+ synchronized (listeners) {
+ l = new ArrayList<>(listeners);
+ }
+
+ for (ILaunchBarListener listener : l) {
+ action.run(listener);
+ }
+ }
+
private void fireActiveLaunchDescriptorChanged() {
if (!initialized)
return;
- synchronized (listeners) {
- for (ILaunchBarListener listener : listeners) {
- try {
- listener.activeLaunchDescriptorChanged(activeLaunchDesc);
- } catch (Exception e) {
- Activator.log(e);
- }
+ fireEvent(listener -> {
+ try {
+ listener.activeLaunchDescriptorChanged(activeLaunchDesc);
+ } catch (Exception e) {
+ Activator.log(e);
}
- }
+ });
}
@Override
@@ -675,15 +689,13 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
private void fireActiveLaunchModeChanged() {
if (!initialized)
return;
- synchronized (listeners) {
- for (ILaunchBarListener listener : listeners) {
- try {
- listener.activeLaunchModeChanged(activeLaunchMode);
- } catch (Exception e) {
- Activator.log(e);
- }
+ fireEvent(listener -> {
+ try {
+ listener.activeLaunchModeChanged(activeLaunchMode);
+ } catch (Exception e) {
+ Activator.log(e);
}
- }
+ });
}
private void storeLaunchMode(ILaunchDescriptor desc, ILaunchMode mode) {
@@ -768,15 +780,13 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
private void fireActiveLaunchTargetChanged() {
if (!initialized)
return;
- synchronized (listeners) {
- for (ILaunchBarListener listener : listeners) {
- try {
- listener.activeLaunchTargetChanged(activeLaunchTarget);
- } catch (Exception e) {
- Activator.log(e);
- }
+ fireEvent(listener -> {
+ try {
+ listener.activeLaunchTargetChanged(activeLaunchTarget);
+ } catch (Exception e) {
+ Activator.log(e);
}
- }
+ });
}
private ILaunchTarget getDefaultLaunchTarget(ILaunchDescriptor descriptor) {
@@ -922,15 +932,13 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
private void fireLaunchTargetsChanged() {
if (!initialized)
return;
- synchronized (listeners) {
- for (ILaunchBarListener listener : listeners) {
- try {
- listener.launchTargetsChanged();
- } catch (Exception e) {
- Activator.log(e);
- }
+ fireEvent(listener -> {
+ try {
+ listener.launchTargetsChanged();
+ } catch (Exception e) {
+ Activator.log(e);
}
- }
+ });
}
@Override

Back to the top