1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-23 00:03:53 +02:00

launch-bar: prevent event storm on initialization

- prevent events dispatch during initialization of launch bar manager
- also fix case when connection is renamed - we don't need to remove it

Change-Id: I8ba5938afd21c9b2459563cd9e3385fb9a69f673
This commit is contained in:
Alena Laskavaia 2015-04-10 11:01:52 -04:00
parent baa294b085
commit 013c6fa1fe

View file

@ -123,6 +123,8 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
private static final String PREF_ACTIVE_LAUNCH_MODE = "activeLaunchMode"; private static final String PREF_ACTIVE_LAUNCH_MODE = "activeLaunchMode";
private static final String PREF_ACTIVE_LAUNCH_TARGET = "activeLaunchTarget"; private static final String PREF_ACTIVE_LAUNCH_TARGET = "activeLaunchTarget";
private static final String PREF_CONFIG_DESC_ORDER = "configDescList"; private static final String PREF_CONFIG_DESC_ORDER = "configDescList";
boolean initialized = false;
public LaunchBarManager() { public LaunchBarManager() {
this(true); this(true);
@ -168,43 +170,47 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
// When testing, call this after setting up the mocks. // When testing, call this after setting up the mocks.
void init() throws CoreException { void init() throws CoreException {
// Fetch the desc order before the init messes it up try {
IEclipsePreferences store = getPreferenceStore(); // Fetch the desc order before the init messes it up
String configDescIds = store.get(PREF_CONFIG_DESC_ORDER, ""); IEclipsePreferences store = getPreferenceStore();
String configDescIds = store.get(PREF_CONFIG_DESC_ORDER, "");
// Load up the types // Load up the types
loadExtensions(); loadExtensions();
// Add in the default descriptor type
// Add in the default descriptor type LaunchDescriptorTypeInfo defaultInfo = new LaunchDescriptorTypeInfo(DefaultLaunchDescriptorType.ID,
LaunchDescriptorTypeInfo defaultInfo = new LaunchDescriptorTypeInfo(DefaultLaunchDescriptorType.ID, 0, defaultDescriptorType);
0, defaultDescriptorType); addDescriptorType(defaultInfo);
addDescriptorType(defaultInfo); // Hook up the existing launch configurations and listen
ILaunchManager launchManager = getLaunchManager();
// Hook up the existing launch configurations and listen for (ILaunchConfiguration configuration : launchManager.getLaunchConfigurations()) {
ILaunchManager launchManager = getLaunchManager(); launchConfigurationAdded(configuration);
for (ILaunchConfiguration configuration : launchManager.getLaunchConfigurations()) { }
launchConfigurationAdded(configuration); launchManager.addLaunchConfigurationListener(this);
} // Reorder the descriptors based on the preference
launchManager.addLaunchConfigurationListener(this); if (!configDescIds.isEmpty()) {
String[] split = configDescIds.split(",");
// Reorder the descriptors based on the preference ILaunchDescriptor last = null;
if (!configDescIds.isEmpty()) { for (String id : split) {
String[] split = configDescIds.split(","); Pair<String, String> key = toId(id);
ILaunchDescriptor last = null; ILaunchDescriptor desc = descriptors.get(key);
for (String id : split) { if (desc != null) {
Pair<String, String> key = toId(id); descriptors.remove(key);
ILaunchDescriptor desc = descriptors.get(key); descriptors.put(key, desc);
if (desc != null) { last = desc;
descriptors.remove(key); }
descriptors.put(key, desc); }
last = desc; // Set the active desc, with MRU, it should be the last one
if (last != null) {
setActiveLaunchDescriptor(last);
} }
} }
// Set the active desc, with MRU, it should be the last one } finally {
if (last != null) { initialized = true;
setActiveLaunchDescriptor(last);
}
} }
fireActiveLaunchDescriptorChanged();
fireActiveLaunchTargetChanged();
fireActiveLaunchModeChanged();
fireLaunchTargetsChanged();
} }
private void loadExtensions() throws CoreException { private void loadExtensions() throws CoreException {
@ -680,6 +686,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
} }
private void fireActiveLaunchDescriptorChanged() { private void fireActiveLaunchDescriptorChanged() {
if (!initialized) return;
for (Listener listener : listeners) { for (Listener listener : listeners) {
try { try {
listener.activeLaunchDescriptorChanged(); listener.activeLaunchDescriptorChanged();
@ -737,6 +744,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
} }
private void fireActiveLaunchModeChanged() { private void fireActiveLaunchModeChanged() {
if (!initialized) return;
for (Listener listener : listeners) { for (Listener listener : listeners) {
try { try {
listener.activeLaunchModeChanged(); listener.activeLaunchModeChanged();
@ -826,6 +834,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
} }
private void fireActiveLaunchTargetChanged() { private void fireActiveLaunchTargetChanged() {
if (!initialized) return;
for (Listener listener : listeners) { for (Listener listener : listeners) {
try { try {
listener.activeLaunchTargetChanged(); listener.activeLaunchTargetChanged();
@ -1027,38 +1036,46 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
Activator.log(e); Activator.log(e);
} }
break; break;
case RemoteConnectionChangeEvent.CONNECTION_REMOVED: case RemoteConnectionChangeEvent.CONNECTION_REMOVED:
case RemoteConnectionChangeEvent.CONNECTION_RENAMED:
try { try {
launchTargetRemoved(event.getConnection()); launchTargetRemoved(event.getConnection());
} catch (CoreException e) { } catch (CoreException e) {
Activator.log(e); Activator.log(e);
} }
break;
case RemoteConnectionChangeEvent.CONNECTION_RENAMED:
fireLaunchTargetsChanged();
break;
default:
break;
}
}
private void fireLaunchTargetsChanged() {
if (!initialized) return;
for (Listener listener : listeners) {
try {
listener.launchTargetsChanged();
} catch (Exception e) {
Activator.log(e);
}
} }
} }
private void launchTargetAdded(IRemoteConnection target) throws CoreException { private void launchTargetAdded(IRemoteConnection target) throws CoreException {
for (Listener listener : listeners) { if (!initialized)
try { return;
listener.launchTargetsChanged(); fireLaunchTargetsChanged();
} catch (Exception e) { // if we added new target we probably want to use it
Activator.log(e); if (activeLaunchDesc != null && supportsTargetType(activeLaunchDesc, target)) {
}
}
if (activeLaunchDesc != null && activeLaunchTarget == null && supportsTargetType(activeLaunchDesc, target)) {
setActiveLaunchTarget(target); setActiveLaunchTarget(target);
} }
} }
private void launchTargetRemoved(IRemoteConnection target) throws CoreException { private void launchTargetRemoved(IRemoteConnection target) throws CoreException {
for (Listener listener : listeners) { if (!initialized)
try { return;
listener.launchTargetsChanged(); fireLaunchTargetsChanged();
} catch (Exception e) {
Activator.log(e);
}
}
if (activeLaunchTarget == target) { if (activeLaunchTarget == target) {
setActiveLaunchTarget(getDefaultLaunchTarget(activeLaunchDesc)); setActiveLaunchTarget(getDefaultLaunchTarget(activeLaunchDesc));
} }