diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/PDAAdapterFactory.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/PDAAdapterFactory.java index e30d9ba61c2..9316f2511d7 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/PDAAdapterFactory.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/PDAAdapterFactory.java @@ -165,9 +165,17 @@ public class PDAAdapterFactory implements IAdapterFactory, ILaunchesListener2 } } - private Map fLaunchAdapterSets = + private static Map fgLaunchAdapterSets = Collections.synchronizedMap(new HashMap()); - + + static void disposeAdapterSet(ILaunch launch) { + synchronized(fgLaunchAdapterSets) { + if ( fgLaunchAdapterSets.containsKey(launch) ) { + fgLaunchAdapterSets.remove(launch).dispose(); + } + } + } + public PDAAdapterFactory() { DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this); } @@ -183,11 +191,11 @@ public class PDAAdapterFactory implements IAdapterFactory, ILaunchesListener2 // it means that we have a new launch, and we have to create a // new set of adapters. LaunchAdapterSet adapterSet; - synchronized(fLaunchAdapterSets) { - adapterSet = fLaunchAdapterSets.get(launch); + synchronized(fgLaunchAdapterSets) { + adapterSet = fgLaunchAdapterSets.get(launch); if (adapterSet == null) { adapterSet = new LaunchAdapterSet(launch); - fLaunchAdapterSets.put(launch, adapterSet); + fgLaunchAdapterSets.put(launch, adapterSet); } } @@ -208,12 +216,7 @@ public class PDAAdapterFactory implements IAdapterFactory, ILaunchesListener2 // are still needed to populate the contents of the view. for (ILaunch launch : launches) { if (launch instanceof PDALaunch) { - PDALaunch pdaLaunch = (PDALaunch)launch; - synchronized(fLaunchAdapterSets) { - if ( fLaunchAdapterSets.containsKey(pdaLaunch) ) { - fLaunchAdapterSets.remove(pdaLaunch).dispose(); - } - } + disposeAdapterSet(launch); } } } diff --git a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/PDAUIPlugin.java b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/PDAUIPlugin.java index 327d9a9a399..4e2904d9769 100644 --- a/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/PDAUIPlugin.java +++ b/plugins/org.eclipse.dd.examples.pda.ui/src/org/eclipse/dd/examples/pda/ui/PDAUIPlugin.java @@ -16,6 +16,9 @@ import java.net.URL; import java.util.HashMap; import java.util.Map; +import org.eclipse.dd.examples.pda.launch.PDALaunch; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunch; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.swt.graphics.Color; @@ -67,6 +70,7 @@ public class PDAUIPlugin extends AbstractUIPlugin { /** * This method is called upon plug-in activation */ + @Override public void start(BundleContext context) throws Exception { fContext = context; super.start(context); @@ -79,7 +83,9 @@ public class PDAUIPlugin extends AbstractUIPlugin { /** * This method is called when the plug-in is stopped */ + @Override public void stop(BundleContext context) throws Exception { + disposeAdapterSets(); super.stop(context); plugin = null; fContext = null; @@ -99,6 +105,7 @@ public class PDAUIPlugin extends AbstractUIPlugin { return fContext; } + @Override protected void initializeImageRegistry(ImageRegistry reg) { declareImage(IMG_OBJ_PDA, PATH_OBJECT + "pda.gif"); } @@ -134,4 +141,15 @@ public class PDAUIPlugin extends AbstractUIPlugin { return color; } + /** + * Dispose adapter sets for all launches. + */ + private void disposeAdapterSets() { + for (ILaunch launch : DebugPlugin.getDefault().getLaunchManager().getLaunches()) { + if (launch instanceof PDALaunch) { + PDAAdapterFactory.disposeAdapterSet(launch); + } + } + } + } diff --git a/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/GdbAdapterFactory.java b/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/GdbAdapterFactory.java index 822a00b6d6f..8a7abde4890 100644 --- a/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/GdbAdapterFactory.java +++ b/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/GdbAdapterFactory.java @@ -184,9 +184,17 @@ public class GdbAdapterFactory } - private Map fLaunchAdapterSets = + private static Map fgLaunchAdapterSets = Collections.synchronizedMap(new HashMap()); + static void disposeAdapterSet(ILaunch launch) { + synchronized(fgLaunchAdapterSets) { + if ( fgLaunchAdapterSets.containsKey(launch) ) { + fgLaunchAdapterSets.remove(launch).dispose(); + } + } + } + public GdbAdapterFactory() { DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this); } @@ -207,11 +215,11 @@ public class GdbAdapterFactory if (session == null) return null; SessionAdapterSet adapterSet; - synchronized(fLaunchAdapterSets) { - adapterSet = fLaunchAdapterSets.get(launch); + synchronized(fgLaunchAdapterSets) { + adapterSet = fgLaunchAdapterSets.get(launch); if (adapterSet == null) { adapterSet = new SessionAdapterSet(launch); - fLaunchAdapterSets.put(launch, adapterSet); + fgLaunchAdapterSets.put(launch, adapterSet); } } @@ -236,11 +244,7 @@ public class GdbAdapterFactory // removed. for (ILaunch launch : launches) { if (launch instanceof GdbLaunch) { - synchronized(fLaunchAdapterSets) { - if ( fLaunchAdapterSets.containsKey(launch) ) { - fLaunchAdapterSets.remove(launch).dispose(); - } - } + disposeAdapterSet(launch); } } } diff --git a/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/GdbUIPlugin.java b/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/GdbUIPlugin.java index 344b4bc1d40..da7f961d0dc 100644 --- a/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/GdbUIPlugin.java +++ b/plugins/org.eclipse.dd.gdb.ui/src/org/eclipse/dd/gdb/internal/ui/GdbUIPlugin.java @@ -13,7 +13,10 @@ package org.eclipse.dd.gdb.internal.ui; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.dd.gdb.internal.provisional.launching.GdbLaunch; import org.eclipse.dd.gdb.internal.provisional.launching.LaunchMessages; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunch; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbenchPage; @@ -57,11 +60,23 @@ public class GdbUIPlugin extends AbstractUIPlugin { */ @Override public void stop(BundleContext context) throws Exception { + disposeAdapterSets(); plugin = null; super.stop(context); fgBundleContext = null; } + /** + * Dispose adapter sets for all launches. + */ + private void disposeAdapterSets() { + for (ILaunch launch : DebugPlugin.getDefault().getLaunchManager().getLaunches()) { + if (launch instanceof GdbLaunch) { + GdbAdapterFactory.disposeAdapterSet(launch); + } + } + } + /** * Returns the shared instance *