debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/LaunchPlugin.java
changeset 0 fb279309251b
child 194 5dd39ff8dbd0
equal deleted inserted replaced
-1:000000000000 0:fb279309251b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 package com.nokia.cdt.internal.debug.launch;
       
    18 
       
    19 import java.util.*;
       
    20 
       
    21 import org.eclipse.cdt.core.model.*;
       
    22 import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
       
    23 import org.eclipse.cdt.debug.core.executables.Executable;
       
    24 import org.eclipse.cdt.debug.core.executables.ExecutablesManager;
       
    25 import org.eclipse.cdt.ui.CUIPlugin;
       
    26 import org.eclipse.core.resources.IProject;
       
    27 import org.eclipse.core.runtime.*;
       
    28 import org.eclipse.debug.core.*;
       
    29 import org.eclipse.debug.ui.*;
       
    30 import org.eclipse.debug.ui.contexts.DebugContextEvent;
       
    31 import org.eclipse.debug.ui.contexts.IDebugContextListener;
       
    32 import org.eclipse.jface.action.IMenuManager;
       
    33 import org.eclipse.jface.resource.ImageDescriptor;
       
    34 import org.eclipse.jface.viewers.*;
       
    35 import org.eclipse.swt.widgets.Display;
       
    36 import org.eclipse.ui.*;
       
    37 import org.eclipse.ui.plugin.AbstractUIPlugin;
       
    38 import org.eclipse.ui.progress.UIJob;
       
    39 import org.osgi.framework.BundleContext;
       
    40 
       
    41 import com.freescale.cdt.debug.cw.core.CWPlugin;
       
    42 import com.freescale.cdt.debug.cw.core.ui.ShowAllVariablesToggleAction;
       
    43 import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin;
       
    44 import com.nokia.carbide.cdt.builder.EpocEngineHelper;
       
    45 import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration;
       
    46 import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo;
       
    47 import com.nokia.carbide.cpp.sdk.core.ISymbianBuildContext;
       
    48 import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
       
    49 import com.nokia.carbide.remoteconnections.interfaces.IConnectionTypeProvider;
       
    50 import com.nokia.carbide.remoteconnections.interfaces.IService;
       
    51 import com.nokia.cdt.debug.cw.symbian.*;
       
    52 import com.nokia.cdt.debug.cw.symbian.ui.executables.SymbianSourceFileRemapping;
       
    53 import com.nokia.cdt.internal.debug.launch.wizard.LaunchCreationWizard;
       
    54 import com.nokia.cpp.internal.api.utils.core.Logging;
       
    55 
       
    56 /**
       
    57  * The main plugin class to be used in the desktop.
       
    58  */
       
    59 public class LaunchPlugin extends AbstractUIPlugin implements ILaunchListener, ILaunchConfigurationListener, IStartup {
       
    60 	//The shared instance.
       
    61 	private static LaunchPlugin plugin;
       
    62 	//Resource bundle.
       
    63 	private ResourceBundle resourceBundle;
       
    64 	
       
    65 	private ArrayList<ILaunchConfiguration> recentlyLaunchedConfigs = new ArrayList<ILaunchConfiguration>();
       
    66 	
       
    67 	public static final String PLUGIN_ID = "com.nokia.cdt.debug.launch"; //$NON-NLS-1$
       
    68 
       
    69 	public static final String EMULATION_LAUNCH_TYPE = "com.nokia.cdt.debug.launch.emulationLaunch"; //$NON-NLS-1$
       
    70 	public static final String PROXY_LAUNCH_TYPE = "com.nokia.cdt.debug.launch.proxyLaunch"; //$NON-NLS-1$
       
    71 
       
    72 	// Preference constants
       
    73 	public static final String Use_New_Project_Assist = "com.nokia.cdt.debug.launch.Use_New_Project_Assist"; //$NON-NLS-1$
       
    74 
       
    75 	
       
    76 	/**
       
    77 	 * The constructor.
       
    78 	 */
       
    79 	public LaunchPlugin() {
       
    80 		super();
       
    81 		plugin = this;
       
    82 	}
       
    83 
       
    84 	/**
       
    85 	 * This method is called upon plug-in activation
       
    86 	 */
       
    87 	public void start(BundleContext context) throws Exception {
       
    88 		super.start(context);
       
    89 
       
    90 		DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this);
       
    91 		DebugPlugin.getDefault().getLaunchManager().addLaunchConfigurationListener(this);
       
    92 	}
       
    93 
       
    94 	/**
       
    95 	 * This method is called when the plug-in is stopped
       
    96 	 */
       
    97 	public void stop(BundleContext context) throws Exception {
       
    98 		super.stop(context);
       
    99 		plugin = null;
       
   100 		resourceBundle = null;
       
   101 		
       
   102 		DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this);
       
   103 		DebugPlugin.getDefault().getLaunchManager().removeLaunchConfigurationListener(this);
       
   104 	}
       
   105 
       
   106 	/**
       
   107 	 * Returns the shared instance.
       
   108 	 */
       
   109 	public static LaunchPlugin getDefault() {
       
   110 		return plugin;
       
   111 	}
       
   112 
       
   113 	/**
       
   114 	 * Returns the string from the plugin's resource bundle,
       
   115 	 * or 'key' if not found.
       
   116 	 */
       
   117 	public static String getResourceString(String key) {
       
   118 		ResourceBundle bundle = LaunchPlugin.getDefault().getResourceBundle();
       
   119 		try {
       
   120 			return (bundle != null) ? bundle.getString(key) : key;
       
   121 		} catch (MissingResourceException e) {
       
   122 			return key;
       
   123 		}
       
   124 	}
       
   125 
       
   126 	/**
       
   127 	 * Returns the plugin's resource bundle,
       
   128 	 */
       
   129 	public ResourceBundle getResourceBundle() {
       
   130 		try {
       
   131 			if (resourceBundle == null)
       
   132 				resourceBundle = ResourceBundle.getBundle("com.nokia.cdt.debug.launch.LaunchPluginResources"); //$NON-NLS-1$
       
   133 		} catch (MissingResourceException x) {
       
   134 			resourceBundle = null;
       
   135 		}
       
   136 		return resourceBundle;
       
   137 	}
       
   138 
       
   139 	/**
       
   140 	 * Convenience method which returns the unique identifier of this plugin.
       
   141 	 */
       
   142 	public static String getUniqueIdentifier() {
       
   143 		if (getDefault() == null) {
       
   144 			// If the default instance is not yet initialized,
       
   145 			// return a static identifier. This identifier must
       
   146 			// match the plugin id defined in plugin.xml
       
   147 			return PLUGIN_ID;
       
   148 		}
       
   149 		return getDefault().getBundle().getSymbolicName();
       
   150 	}
       
   151 
       
   152 	public String getDefaultLaunchConfigName(IProject project, Executable executable) {
       
   153 		// calculate the default name
       
   154 		String name = project.getName();
       
   155         ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project);
       
   156 		if (cpi != null) {
       
   157 			name = name + " " + cpi.getDefaultBuildConfigName(); //$NON-NLS-1$
       
   158 		}
       
   159 		else if (executable != null)
       
   160 		{
       
   161 			name = executable.getName();
       
   162 		}
       
   163 		return name;
       
   164 	}
       
   165 	
       
   166 
       
   167 	public ILaunchConfigurationType getEmulationLaunchConfigType() {
       
   168 		return getLaunchManager().getLaunchConfigurationType(LaunchPlugin.EMULATION_LAUNCH_TYPE);
       
   169 	}
       
   170 
       
   171 	public ILaunchConfigurationType getProxyLaunchConfigType() {
       
   172 		return getLaunchManager().getLaunchConfigurationType(LaunchPlugin.PROXY_LAUNCH_TYPE);
       
   173 	}
       
   174 
       
   175 	protected ILaunchManager getLaunchManager() {
       
   176 		return DebugPlugin.getDefault().getLaunchManager();
       
   177 	}
       
   178 	
       
   179 	private boolean isEmulatorBinaryPath(IPath binaryPath) {
       
   180 		for (String segment : binaryPath.segments()) {
       
   181 			if (segment.equalsIgnoreCase("winscw")) //$NON-NLS-1$
       
   182 				return true;
       
   183 		}
       
   184 		
       
   185 		return false;
       
   186 	}
       
   187 	
       
   188 	private boolean getExePathsFromProjectAndDetermineIfX86(IProject project, List<IPath> exePaths) {
       
   189 		boolean isX86 = false;
       
   190         ICProject cProject = CoreModel.getDefault().create(project);
       
   191         if (cProject != null) {
       
   192 			try {
       
   193     			for (IBinary bin : cProject.getBinaryContainer().getBinaries()) {
       
   194     				if (bin.isExecutable()) {
       
   195     					IPath path = bin.getResource().getLocation();
       
   196     					
       
   197     					if (isEmulatorBinaryPath(path)) {
       
   198 							isX86 = true;
       
   199 						}
       
   200 
       
   201     					exePaths.add(path);
       
   202     				}
       
   203     			}
       
   204 			} catch (CModelException e) {
       
   205 				log(e);
       
   206 			}
       
   207         }
       
   208         return isX86;
       
   209 	}
       
   210 
       
   211 	private ILaunchConfiguration createConfigurationForProject(IProject project, Executable executable, IPath defaultMMP, String mode) throws CoreException {
       
   212 
       
   213 		boolean openLaunchConfigDialog = false;
       
   214 
       
   215 		// get the default config name and make sure it's unique
       
   216 		final String defaultConfigName = getLaunchManager().generateUniqueLaunchConfigurationNameFrom(getDefaultLaunchConfigName(project, executable));
       
   217 		
       
   218 		// try to determine if this is for the emulator or not.  also get the list of binaries for the current
       
   219 		// build configuration or project.
       
   220 		boolean isX86 = false;
       
   221 		boolean useEmulatorByDefault = false;
       
   222 		IPath defaultExecutable = null;
       
   223 		
       
   224 		List<IPath> exePaths = new ArrayList<IPath>(0);
       
   225 		List<IPath> mmpPaths = new ArrayList<IPath>(0);
       
   226 
       
   227         ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project);
       
   228         ICarbideBuildConfiguration buildConfig = null;
       
   229 		if (cpi != null) {
       
   230 			buildConfig = cpi.getDefaultConfiguration();
       
   231 			
       
   232 			if (buildConfig == null) {
       
   233 				return null;
       
   234 			}
       
   235 			
       
   236 			// just check the platform for the default config
       
   237 			if (buildConfig.getPlatformString().equals(ISymbianBuildContext.EMULATOR_PLATFORM)) {
       
   238 				isX86 = true;
       
   239 			}
       
   240 
       
   241 			if (defaultMMP != null)
       
   242 			{
       
   243 				defaultExecutable = EpocEngineHelper.getHostPathForExecutable(buildConfig, defaultMMP);
       
   244 				if (!"exe".equalsIgnoreCase(defaultExecutable.getFileExtension())) //$NON-NLS-1$
       
   245 					defaultExecutable = null;
       
   246 			}
       
   247 			// get the list of binaries that are being built for the build config and their corresponding mmp's
       
   248 			EpocEngineHelper.getPathToAllExecutables(buildConfig, new ArrayList<IPath>(), exePaths, new ArrayList<IPath>(), mmpPaths);
       
   249 
       
   250 		} else {
       
   251 			if (executable != null) {
       
   252 				exePaths.add(executable.getPath());				
       
   253 				isX86 = isEmulatorBinaryPath(executable.getPath());
       
   254 			}
       
   255 			else {
       
   256 				isX86 = getExePathsFromProjectAndDetermineIfX86(project, exePaths);
       
   257 			}
       
   258 		}
       
   259 		
       
   260 		if (exePaths.size() < 1) {
       
   261 			// no binaries.  bail.
       
   262 			throw new CoreException(new Status(IStatus.ERROR, getUniqueIdentifier(), 0, Messages.getString("LaunchPlugin.17"), null )); //$NON-NLS-1$
       
   263 		}
       
   264 
       
   265 		if (buildConfig == null) {
       
   266 			useEmulatorByDefault = SettingsData.isEmulatorRequired(exePaths.get(0));
       
   267 		}
       
   268 		else
       
   269 		if (buildConfig != null) {
       
   270 			// pick the first exe in the list, otherwise the first binary in the list
       
   271 			// note that since there is a build config, the exePaths and mmpPaths list
       
   272 			// will be the same size
       
   273 			IPath firstExePath = exePaths.get(0);
       
   274 			IPath firstMmpPath = mmpPaths.get(0);
       
   275 			for (int i=0; i<exePaths.size(); i++) {
       
   276 				String fileExt = exePaths.get(i).getFileExtension();
       
   277 				if (fileExt != null && fileExt.compareToIgnoreCase("exe") == 0) { //$NON-NLS-1$
       
   278 					firstExePath = exePaths.get(i);
       
   279 					firstMmpPath = mmpPaths.get(i);
       
   280 					break;
       
   281 				}
       
   282 			}
       
   283 
       
   284 			useEmulatorByDefault = SettingsData.isEmulatorRequired(buildConfig, firstExePath, firstMmpPath);
       
   285 		}
       
   286 		ILaunchConfigurationWorkingCopy config = null;
       
   287 		
       
   288 		if (exePaths.size() == 1 && isX86 && useEmulatorByDefault) {
       
   289 			// no need to launch wizard.  we have what we need
       
   290 			config = this.getEmulationLaunchConfigType().newInstance(null, defaultConfigName);
       
   291 			SettingsData.setDefaults(config, SettingsData.LaunchConfig_Emulator, project, mmpPaths.size() == 1 ? mmpPaths.get(0) : null, exePaths.get(0));
       
   292 		} else {
       
   293 			// need to launch the wizard to determine:
       
   294 			// which exe to launch or emulator if not required, 
       
   295 			// which non-emulator launch type,
       
   296 			// or both
       
   297 			try {
       
   298 				final LaunchCreationWizard wizard = 
       
   299 					new LaunchCreationWizard(project, defaultConfigName, mmpPaths, exePaths, defaultExecutable, isX86, useEmulatorByDefault);
       
   300 				Display.getDefault().syncExec(new Runnable() {
       
   301 					public void run() {
       
   302 						wizard.init(PlatformUI.getWorkbench(), null);
       
   303 						LaunchCreationWizard.openWizard(CUIPlugin.getActiveWorkbenchShell(), wizard);
       
   304 					}
       
   305 				});
       
   306 				config = wizard.getLaunchConfiguration();
       
   307 				openLaunchConfigDialog = wizard.shouldOpenLaunchConfigurationDialog();
       
   308 			}
       
   309 			catch (Exception e) {
       
   310 				throw new CoreException(new Status(IStatus.ERROR, getUniqueIdentifier(), 0, e.getMessage(), null )); //$NON-NLS-1$
       
   311 			}
       
   312 		}
       
   313 		
       
   314 		if (config != null) {
       
   315 			if (openLaunchConfigDialog) {
       
   316 				IStructuredSelection selection = new StructuredSelection(config.doSave());
       
   317 				String identifier;
       
   318 				if (mode.equals("run")) //$NON-NLS-1$
       
   319 					identifier = new String("org.eclipse.debug.ui.launchGroup.run"); //$NON-NLS-1$
       
   320 				else
       
   321 					identifier = new String("org.eclipse.debug.ui.launchGroup.debug"); //$NON-NLS-1$
       
   322 
       
   323 				DebugUITools.openLaunchConfigurationDialogOnGroup(CUIPlugin.getActiveWorkbenchShell(), selection, identifier);
       
   324 			}
       
   325 			else
       
   326 				return config.doSave();
       
   327 		}
       
   328 		return null;
       
   329 	}
       
   330 
       
   331 	public ILaunchConfiguration[] getLaunchConfigurations(IProject project, Executable executable, IPath defaultMMP)
       
   332 	{
       
   333 		IPath defaultExecutable = null;
       
   334 		if (defaultMMP != null) {
       
   335 			ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager()
       
   336 					.getProjectInfo(project);
       
   337 			ICarbideBuildConfiguration buildConfig = null;
       
   338 			if (cpi != null) {
       
   339 				buildConfig = cpi.getDefaultConfiguration();
       
   340 				defaultExecutable = EpocEngineHelper.getHostPathForExecutable(buildConfig, defaultMMP);
       
   341 				if (!"exe".equalsIgnoreCase(defaultExecutable.getFileExtension())) //$NON-NLS-1$
       
   342 					defaultExecutable = null;
       
   343 			}
       
   344 		}
       
   345 		String defaultConfigName = getDefaultLaunchConfigName(project, executable);
       
   346 		ArrayList<ILaunchConfiguration> configs = new ArrayList<ILaunchConfiguration>();
       
   347 		// Try the configurations not from the launch history
       
   348 		ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
       
   349 		try {
       
   350 			ILaunchConfiguration[] launches = launchManager.getLaunchConfigurations();
       
   351 			for (ILaunchConfiguration launchConfiguration : launches) {
       
   352 				if (launchConfiguration.getAttribute(SettingsData.ATTR_originalName, launchConfiguration.getName()).equals(defaultConfigName))
       
   353 				{
       
   354 					if (defaultExecutable != null)
       
   355 					{
       
   356 						String programName = launchConfiguration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, ""); //$NON-NLS-1$
       
   357 						if (programName.equalsIgnoreCase(defaultExecutable.toOSString()))
       
   358 							configs.add(launchConfiguration);				
       
   359 					}
       
   360 					else
       
   361 						configs.add(launchConfiguration);
       
   362 					break;
       
   363 				}					
       
   364 			}
       
   365 		} catch (CoreException e) { 
       
   366 			log(e);
       
   367 		}
       
   368 
       
   369 		return configs.toArray(new ILaunchConfiguration[configs.size()]);		
       
   370 	}
       
   371 	
       
   372 	public void launchProject(IProject project, Executable executable, IPath defaultMMP, String mode) {
       
   373 		ILaunchConfiguration configuration = null;
       
   374 		try {
       
   375 			configuration = createConfigurationForProject(project, executable, defaultMMP, mode);
       
   376 		} catch (CoreException e) {
       
   377 			log(e);
       
   378 		}
       
   379 
       
   380 		if (configuration != null) {
       
   381 			DebugUITools.launch(configuration, mode);
       
   382 		}
       
   383 	}
       
   384 
       
   385 	/**
       
   386 	 * Returns an image descriptor for the image file at the given
       
   387 	 * plug-in relative path.
       
   388 	 *
       
   389 	 * @param path the path
       
   390 	 * @return the image descriptor
       
   391 	 */
       
   392 	public static ImageDescriptor getImageDescriptor(String path) {
       
   393 		return AbstractUIPlugin.imageDescriptorFromPlugin("com.nokia.cdt.debug.launch", path); //$NON-NLS-1$
       
   394 	}
       
   395 
       
   396 	public void launchRemoved(ILaunch launch) {
       
   397 		// don't care about this
       
   398 	}
       
   399 
       
   400 	public void launchAdded(ILaunch launch) {
       
   401 		// keep a list of recent launches.  we're really just interested in the
       
   402 		// order so we can launch the most recently used config if more than one
       
   403 		// exists for a particular project/build config combo.
       
   404 		ILaunchConfiguration config = launch.getLaunchConfiguration();
       
   405 		if (recentlyLaunchedConfigs.contains(config)) {
       
   406 			recentlyLaunchedConfigs.remove(config);
       
   407 		}
       
   408 		
       
   409 		// insert at the front of the list
       
   410 		recentlyLaunchedConfigs.add(0, config);
       
   411 	}
       
   412 
       
   413 	public void launchChanged(ILaunch launch) {
       
   414 		// don't care about this
       
   415 	}
       
   416 
       
   417 	public void launchConfigurationAdded(ILaunchConfiguration configuration) {
       
   418 		// don't care about this
       
   419 	}
       
   420 
       
   421 	public void launchConfigurationChanged(ILaunchConfiguration configuration) {
       
   422 		// don't care about this
       
   423 	}
       
   424 
       
   425 	public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
       
   426 		// remove this launch config from our list of recent launches if necessary
       
   427 		if (recentlyLaunchedConfigs.contains(configuration)) {
       
   428 			recentlyLaunchedConfigs.remove(configuration);
       
   429 		}
       
   430 	}
       
   431 
       
   432 	public void earlyStartup() {
       
   433 		UIJob earlyJob = new UIJob("Startup"){//$NON-NLS-1$
       
   434 
       
   435 			@Override
       
   436 			public IStatus runInUIThread(IProgressMonitor monitor) {
       
   437 				listenForVariablesView();
       
   438 				
       
   439 				CarbideExecutablesProvider provider = new CarbideExecutablesProvider();
       
   440 				ExecutablesManager em = ExecutablesManager.getExecutablesManager();
       
   441 				em.addSourceFileRemapping(new SymbianSourceFileRemapping());
       
   442 				em.addExecutablesProvider(provider);
       
   443 				em.addExecutableImporter(new CarbideExecutableImporter(provider));
       
   444 				em.scheduleRefresh(provider, 0);
       
   445 				em.addSourceFilesProvider(new CarbideSourceFilesProvider());
       
   446 				
       
   447 				return Status.OK_STATUS;
       
   448 			}};
       
   449 			earlyJob.schedule();
       
   450 	}
       
   451 
       
   452 	public static IProject getSelectedProject() {
       
   453 		return CarbideBuilderPlugin.getProjectInContext();
       
   454 	}
       
   455 	
       
   456 	public void addShowAllVariablesAction(final IDebugView variablesView)
       
   457 	{
       
   458 		UIJob installSAVJob = new UIJob("Show All Variables Action"){//$NON-NLS-1$
       
   459 
       
   460 			@Override
       
   461 			public IStatus runInUIThread(IProgressMonitor monitor) {
       
   462 		    	ShowAllVariablesToggleAction showAllVarsAction = new ShowAllVariablesToggleAction();
       
   463 		    	variablesView.setAction("com.freescale.cdt.debug.cw.core.ui.showAllVariablesToggle", showAllVarsAction); //$NON-NLS-1$
       
   464 
       
   465 				IActionBars actionBars = variablesView.getViewSite().getActionBars();
       
   466 				IMenuManager viewMenu = actionBars.getMenuManager();
       
   467 				viewMenu.add(showAllVarsAction);								
       
   468 				return Status.OK_STATUS;
       
   469 			}};
       
   470 			
       
   471 			installSAVJob.schedule();
       
   472 		
       
   473 	}
       
   474 
       
   475 	private void addVariablesViewListener(IWorkbenchWindow window)
       
   476 	{
       
   477 		window.getPartService().addPartListener(new IPartListener2() {
       
   478 
       
   479 			public void partActivated(IWorkbenchPartReference partRef) {}
       
   480 
       
   481 			public void partBroughtToTop(IWorkbenchPartReference partRef) {}
       
   482 
       
   483 			public void partClosed(IWorkbenchPartReference partRef) {}
       
   484 
       
   485 			public void partDeactivated(IWorkbenchPartReference partRef) {}
       
   486 
       
   487 			public void partHidden(IWorkbenchPartReference partRef) {}
       
   488 
       
   489 			public void partInputChanged(IWorkbenchPartReference partRef) {}
       
   490 
       
   491 			public void partOpened(IWorkbenchPartReference partRef) {
       
   492 				if (partRef.getId().equals(IDebugUIConstants.ID_VARIABLE_VIEW))
       
   493 				{
       
   494 					IDebugView variablesView = (IDebugView) partRef.getPart(true);
       
   495 					addShowAllVariablesAction(variablesView);
       
   496 				}
       
   497 			}
       
   498 
       
   499 			public void partVisible(IWorkbenchPartReference partRef) {}});
       
   500 	}
       
   501 	
       
   502 	private void setupShowAllVariablesAction(IWorkbenchWindow window)
       
   503 	{
       
   504 	    IWorkbenchPage page = window.getActivePage();
       
   505 	    AbstractDebugView variablesView = (AbstractDebugView) page.findView(IDebugUIConstants.ID_VARIABLE_VIEW);
       
   506         if (variablesView == null)
       
   507 			addVariablesViewListener(window);
       
   508         else
       
   509         	addShowAllVariablesAction(variablesView);
       
   510         
       
   511 		DebugUITools.getDebugContextManager().getContextService(window).addDebugContextListener(new IDebugContextListener() {
       
   512 
       
   513 			public void debugContextChanged(DebugContextEvent event) {
       
   514 				if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0) {
       
   515 					contextActivated(event.getContext());
       
   516 				}
       
   517 			}
       
   518 
       
   519 			private void contextActivated(ISelection context) {
       
   520 				CWPlugin.setDebugContext(((IStructuredSelection) context).getFirstElement());
       
   521 			}});
       
   522 
       
   523 	}
       
   524 	
       
   525 	public void listenForVariablesView()
       
   526 	{
       
   527 
       
   528 		Display.getDefault().asyncExec(new Runnable() {
       
   529 			public void run() {
       
   530 
       
   531 				IWorkbenchWindow[] windows = getDefault().getWorkbench().getWorkbenchWindows();
       
   532 				
       
   533 				for (int i = 0; i < windows.length; i++) {
       
   534 					setupShowAllVariablesAction(windows[i]);
       
   535 				}
       
   536 				
       
   537 				getDefault().getWorkbench().addWindowListener(new IWindowListener() {
       
   538 
       
   539 					public void windowActivated(IWorkbenchWindow window) {}
       
   540 
       
   541 					public void windowClosed(IWorkbenchWindow window) {}
       
   542 
       
   543 					public void windowDeactivated(IWorkbenchWindow window) {}
       
   544 
       
   545 					public void windowOpened(IWorkbenchWindow window) {
       
   546 						setupShowAllVariablesAction(window);
       
   547 					}});
       
   548 				
       
   549 			}
       
   550 		});
       
   551 		
       
   552 	}
       
   553 
       
   554 	public static IService getTRKService() {
       
   555 		return RemoteConnectionsActivator.getConnectionTypeProvider().
       
   556 					findServiceByID("com.nokia.carbide.trk.support.service.TRKService"); //$NON-NLS-1$
       
   557 	}
       
   558 	
       
   559 	/**
       
   560 	 * Returns the currently active workbench window or <code>null</code>
       
   561 	 * if none.
       
   562 	 * 
       
   563 	 * @return the currently active workbench window or <code>null</code>
       
   564 	 */
       
   565 	public static IWorkbenchWindow getActiveWorkbenchWindow() {
       
   566 		return getDefault().getWorkbench().getActiveWorkbenchWindow();
       
   567 	}
       
   568 
       
   569 	/**
       
   570 	 * Log throwable to the error log
       
   571 	 * @param t Throwable
       
   572 	 */
       
   573 	public static void log(Throwable t) {
       
   574 		Logging.log(plugin, Logging.newStatus(plugin, t));
       
   575 	}
       
   576 	
       
   577 	/**
       
   578 	 * Log status to the error log
       
   579 	 * @param status status
       
   580 	 */
       
   581 	public static void log(IStatus status) {
       
   582 		Logging.log(plugin, status);
       
   583 	}
       
   584 }