debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/LaunchPlugin.java
branchC3_BUILDER_WORK
changeset 1863 0142fe025ce6
parent 1805 1d57e533b09e
parent 1848 2a6d912d3065
child 1968 3482df86a51d
equal deleted inserted replaced
1862:e3bac873e5c8 1863:0142fe025ce6
    16 */
    16 */
    17 package com.nokia.cdt.internal.debug.launch;
    17 package com.nokia.cdt.internal.debug.launch;
    18 
    18 
    19 import java.util.ArrayList;
    19 import java.util.ArrayList;
    20 import java.util.List;
    20 import java.util.List;
    21 import java.util.MissingResourceException;
       
    22 import java.util.ResourceBundle;
       
    23 
    21 
    24 import org.eclipse.cdt.core.model.CModelException;
    22 import org.eclipse.cdt.core.model.CModelException;
    25 import org.eclipse.cdt.core.model.CoreModel;
    23 import org.eclipse.cdt.core.model.CoreModel;
    26 import org.eclipse.cdt.core.model.IBinary;
    24 import org.eclipse.cdt.core.model.IBinary;
    27 import org.eclipse.cdt.core.model.ICProject;
    25 import org.eclipse.cdt.core.model.ICProject;
    29 import org.eclipse.cdt.debug.core.executables.Executable;
    27 import org.eclipse.cdt.debug.core.executables.Executable;
    30 import org.eclipse.cdt.ui.CUIPlugin;
    28 import org.eclipse.cdt.ui.CUIPlugin;
    31 import org.eclipse.core.resources.IProject;
    29 import org.eclipse.core.resources.IProject;
    32 import org.eclipse.core.runtime.CoreException;
    30 import org.eclipse.core.runtime.CoreException;
    33 import org.eclipse.core.runtime.IPath;
    31 import org.eclipse.core.runtime.IPath;
    34 import org.eclipse.core.runtime.IProgressMonitor;
       
    35 import org.eclipse.core.runtime.IStatus;
    32 import org.eclipse.core.runtime.IStatus;
    36 import org.eclipse.core.runtime.Status;
    33 import org.eclipse.core.runtime.Status;
    37 import org.eclipse.debug.core.DebugPlugin;
    34 import org.eclipse.debug.core.DebugPlugin;
    38 import org.eclipse.debug.core.ILaunch;
       
    39 import org.eclipse.debug.core.ILaunchConfiguration;
    35 import org.eclipse.debug.core.ILaunchConfiguration;
    40 import org.eclipse.debug.core.ILaunchConfigurationListener;
       
    41 import org.eclipse.debug.core.ILaunchConfigurationType;
    36 import org.eclipse.debug.core.ILaunchConfigurationType;
    42 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
    37 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
    43 import org.eclipse.debug.core.ILaunchListener;
       
    44 import org.eclipse.debug.core.ILaunchManager;
    38 import org.eclipse.debug.core.ILaunchManager;
    45 import org.eclipse.debug.ui.AbstractDebugView;
       
    46 import org.eclipse.debug.ui.DebugUITools;
    39 import org.eclipse.debug.ui.DebugUITools;
    47 import org.eclipse.debug.ui.IDebugUIConstants;
    40 import org.eclipse.debug.ui.IDebugUIConstants;
    48 import org.eclipse.debug.ui.IDebugView;
       
    49 import org.eclipse.debug.ui.contexts.DebugContextEvent;
       
    50 import org.eclipse.debug.ui.contexts.IDebugContextListener;
       
    51 import org.eclipse.jface.action.IMenuManager;
       
    52 import org.eclipse.jface.resource.ImageDescriptor;
    41 import org.eclipse.jface.resource.ImageDescriptor;
    53 import org.eclipse.jface.viewers.ISelection;
       
    54 import org.eclipse.jface.viewers.IStructuredSelection;
    42 import org.eclipse.jface.viewers.IStructuredSelection;
    55 import org.eclipse.jface.viewers.StructuredSelection;
    43 import org.eclipse.jface.viewers.StructuredSelection;
    56 import org.eclipse.swt.widgets.Display;
    44 import org.eclipse.swt.widgets.Display;
    57 import org.eclipse.ui.IActionBars;
       
    58 import org.eclipse.ui.IPartListener2;
       
    59 import org.eclipse.ui.IStartup;
       
    60 import org.eclipse.ui.IWindowListener;
       
    61 import org.eclipse.ui.IWorkbenchPage;
       
    62 import org.eclipse.ui.IWorkbenchPartReference;
       
    63 import org.eclipse.ui.IWorkbenchWindow;
    45 import org.eclipse.ui.IWorkbenchWindow;
    64 import org.eclipse.ui.plugin.AbstractUIPlugin;
    46 import org.eclipse.ui.plugin.AbstractUIPlugin;
    65 import org.eclipse.ui.progress.UIJob;
       
    66 import org.osgi.framework.BundleContext;
    47 import org.osgi.framework.BundleContext;
    67 
    48 
    68 import com.freescale.cdt.debug.cw.core.CWPlugin;
       
    69 import com.freescale.cdt.debug.cw.core.ui.ShowAllVariablesToggleAction;
       
    70 import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin;
    49 import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin;
    71 import com.nokia.carbide.cdt.builder.EpocEngineHelper;
    50 import com.nokia.carbide.cdt.builder.EpocEngineHelper;
    72 import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration;
    51 import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration;
    73 import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo;
    52 import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo;
    74 import com.nokia.carbide.cpp.internal.api.sdk.ISBSv1BuildContext;
    53 import com.nokia.carbide.cpp.internal.api.sdk.ISBSv1BuildContext;
    80 import com.nokia.cpp.internal.api.utils.core.Logging;
    59 import com.nokia.cpp.internal.api.utils.core.Logging;
    81 
    60 
    82 /**
    61 /**
    83  * The main plugin class to be used in the desktop.
    62  * The main plugin class to be used in the desktop.
    84  */
    63  */
    85 public class LaunchPlugin extends AbstractUIPlugin implements ILaunchListener, ILaunchConfigurationListener, IStartup {
    64 public class LaunchPlugin extends AbstractUIPlugin {
    86 	
    65 	
    87 	public interface ILaunchCreationWizardFactory {
    66 	public interface ILaunchCreationWizardFactory {
    88 		ILaunchCreationWizard createLaunchCreationWizard(LaunchOptions launchOptions) throws Exception;
    67 		ILaunchCreationWizard createLaunchCreationWizard(LaunchOptions launchOptions) throws Exception;
    89 	}
    68 	}
    90 
    69 
    91 	//The shared instance.
    70 	//The shared instance.
    92 	private static LaunchPlugin plugin;
    71 	private static LaunchPlugin plugin;
    93 	//Resource bundle.
       
    94 	private ResourceBundle resourceBundle;
       
    95 	
       
    96 	private ArrayList<ILaunchConfiguration> recentlyLaunchedConfigs = new ArrayList<ILaunchConfiguration>();
       
    97 	
    72 	
    98 	public static final String PLUGIN_ID = "com.nokia.cdt.debug.launch"; //$NON-NLS-1$
    73 	public static final String PLUGIN_ID = "com.nokia.cdt.debug.launch"; //$NON-NLS-1$
    99 
    74 
   100 	public static final String EMULATION_LAUNCH_TYPE = "com.nokia.cdt.debug.launch.emulationLaunch"; //$NON-NLS-1$
    75 	public static final String EMULATION_LAUNCH_TYPE = "com.nokia.cdt.debug.launch.emulationLaunch"; //$NON-NLS-1$
   101 	public static final String PROXY_LAUNCH_TYPE = "com.nokia.cdt.debug.launch.proxyLaunch"; //$NON-NLS-1$
       
   102 	
    76 	
   103 	public static final String REMOTE_CONNECTIONS_TRK_SERVICE = "com.nokia.carbide.trk.support.service.TRKService"; //$NON-NLS-1$
    77 	public static final String REMOTE_CONNECTIONS_TRK_SERVICE = "com.nokia.carbide.trk.support.service.TRKService"; //$NON-NLS-1$
   104 	public static final String REMOTE_CONNECTIONS_TRACING_SERVICE = "com.nokia.carbide.trk.support.service.TracingService"; //$NON-NLS-1$
    78 	public static final String REMOTE_CONNECTIONS_TRACING_SERVICE = "com.nokia.carbide.trk.support.service.TracingService"; //$NON-NLS-1$
   105 
       
   106 	// Preference constants
       
   107 	public static final String Use_New_Project_Assist = "com.nokia.cdt.debug.launch.Use_New_Project_Assist"; //$NON-NLS-1$
       
   108 
       
   109 	
       
   110 
    79 
   111 	
    80 	
   112 	/**
    81 	/**
   113 	 * The constructor.
    82 	 * The constructor.
   114 	 */
    83 	 */
   120 	/**
    89 	/**
   121 	 * This method is called upon plug-in activation
    90 	 * This method is called upon plug-in activation
   122 	 */
    91 	 */
   123 	public void start(BundleContext context) throws Exception {
    92 	public void start(BundleContext context) throws Exception {
   124 		super.start(context);
    93 		super.start(context);
   125 
       
   126 		DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this);
       
   127 		DebugPlugin.getDefault().getLaunchManager().addLaunchConfigurationListener(this);
       
   128 	}
    94 	}
   129 
    95 
   130 	/**
    96 	/**
   131 	 * This method is called when the plug-in is stopped
    97 	 * This method is called when the plug-in is stopped
   132 	 */
    98 	 */
   133 	public void stop(BundleContext context) throws Exception {
    99 	public void stop(BundleContext context) throws Exception {
   134 		super.stop(context);
   100 		super.stop(context);
   135 		plugin = null;
   101 		plugin = null;
   136 		resourceBundle = null;
       
   137 		
       
   138 		DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this);
       
   139 		DebugPlugin.getDefault().getLaunchManager().removeLaunchConfigurationListener(this);
       
   140 	}
   102 	}
   141 
   103 
   142 	/**
   104 	/**
   143 	 * Returns the shared instance.
   105 	 * Returns the shared instance.
   144 	 */
   106 	 */
   145 	public static LaunchPlugin getDefault() {
   107 	public static LaunchPlugin getDefault() {
   146 		return plugin;
   108 		return plugin;
   147 	}
       
   148 
       
   149 	/**
       
   150 	 * Returns the string from the plugin's resource bundle,
       
   151 	 * or 'key' if not found.
       
   152 	 */
       
   153 	public static String getResourceString(String key) {
       
   154 		ResourceBundle bundle = LaunchPlugin.getDefault().getResourceBundle();
       
   155 		try {
       
   156 			return (bundle != null) ? bundle.getString(key) : key;
       
   157 		} catch (MissingResourceException e) {
       
   158 			return key;
       
   159 		}
       
   160 	}
       
   161 
       
   162 	/**
       
   163 	 * Returns the plugin's resource bundle,
       
   164 	 */
       
   165 	public ResourceBundle getResourceBundle() {
       
   166 		try {
       
   167 			if (resourceBundle == null)
       
   168 				resourceBundle = ResourceBundle.getBundle("com.nokia.cdt.debug.launch.LaunchPluginResources"); //$NON-NLS-1$
       
   169 		} catch (MissingResourceException x) {
       
   170 			resourceBundle = null;
       
   171 		}
       
   172 		return resourceBundle;
       
   173 	}
   109 	}
   174 
   110 
   175 	/**
   111 	/**
   176 	 * Convenience method which returns the unique identifier of this plugin.
   112 	 * Convenience method which returns the unique identifier of this plugin.
   177 	 */
   113 	 */
   202 
   138 
   203 	public ILaunchConfigurationType getEmulationLaunchConfigType() {
   139 	public ILaunchConfigurationType getEmulationLaunchConfigType() {
   204 		return getLaunchManager().getLaunchConfigurationType(LaunchPlugin.EMULATION_LAUNCH_TYPE);
   140 		return getLaunchManager().getLaunchConfigurationType(LaunchPlugin.EMULATION_LAUNCH_TYPE);
   205 	}
   141 	}
   206 
   142 
   207 	public ILaunchConfigurationType getProxyLaunchConfigType() {
   143 	private ILaunchManager getLaunchManager() {
   208 		return getLaunchManager().getLaunchConfigurationType(LaunchPlugin.PROXY_LAUNCH_TYPE);
       
   209 	}
       
   210 
       
   211 	protected ILaunchManager getLaunchManager() {
       
   212 		return DebugPlugin.getDefault().getLaunchManager();
   144 		return DebugPlugin.getDefault().getLaunchManager();
   213 	}
   145 	}
   214 	
   146 	
   215 	private boolean isEmulatorBinaryPath(IPath binaryPath) {
   147 	private boolean isEmulatorBinaryPath(IPath binaryPath) {
   216 		for (String segment : binaryPath.segments()) {
   148 		for (String segment : binaryPath.segments()) {
   446 	 */
   378 	 */
   447 	public static ImageDescriptor getImageDescriptor(String path) {
   379 	public static ImageDescriptor getImageDescriptor(String path) {
   448 		return AbstractUIPlugin.imageDescriptorFromPlugin("com.nokia.cdt.debug.launch", path); //$NON-NLS-1$
   380 		return AbstractUIPlugin.imageDescriptorFromPlugin("com.nokia.cdt.debug.launch", path); //$NON-NLS-1$
   449 	}
   381 	}
   450 
   382 
   451 	public void launchRemoved(ILaunch launch) {
       
   452 		// don't care about this
       
   453 	}
       
   454 
       
   455 	public void launchAdded(ILaunch launch) {
       
   456 		// keep a list of recent launches.  we're really just interested in the
       
   457 		// order so we can launch the most recently used config if more than one
       
   458 		// exists for a particular project/build config combo.
       
   459 		ILaunchConfiguration config = launch.getLaunchConfiguration();
       
   460 		if (recentlyLaunchedConfigs.contains(config)) {
       
   461 			recentlyLaunchedConfigs.remove(config);
       
   462 		}
       
   463 		
       
   464 		// insert at the front of the list
       
   465 		recentlyLaunchedConfigs.add(0, config);
       
   466 	}
       
   467 
       
   468 	public void launchChanged(ILaunch launch) {
       
   469 		// don't care about this
       
   470 	}
       
   471 
       
   472 	public void launchConfigurationAdded(ILaunchConfiguration configuration) {
       
   473 		// don't care about this
       
   474 	}
       
   475 
       
   476 	public void launchConfigurationChanged(ILaunchConfiguration configuration) {
       
   477 		// don't care about this
       
   478 	}
       
   479 
       
   480 	public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
       
   481 		// remove this launch config from our list of recent launches if necessary
       
   482 		if (recentlyLaunchedConfigs.contains(configuration)) {
       
   483 			recentlyLaunchedConfigs.remove(configuration);
       
   484 		}
       
   485 	}
       
   486 
       
   487 	public void earlyStartup() {
       
   488 		UIJob earlyJob = new UIJob("Startup"){//$NON-NLS-1$
       
   489 
       
   490 			@Override
       
   491 			public IStatus runInUIThread(IProgressMonitor monitor) {
       
   492 				listenForVariablesView();
       
   493 				return Status.OK_STATUS;
       
   494 			}};
       
   495 			// earlyJob.schedule();
       
   496 	}
       
   497 
       
   498 	public static IProject getSelectedProject() {
   383 	public static IProject getSelectedProject() {
   499 		return CarbideBuilderPlugin.getProjectInContext();
   384 		return CarbideBuilderPlugin.getProjectInContext();
   500 	}
       
   501 	
       
   502 	public void addShowAllVariablesAction(final IDebugView variablesView)
       
   503 	{
       
   504 		UIJob installSAVJob = new UIJob("Show All Variables Action"){//$NON-NLS-1$
       
   505 
       
   506 			@Override
       
   507 			public IStatus runInUIThread(IProgressMonitor monitor) {
       
   508 		    	ShowAllVariablesToggleAction showAllVarsAction = new ShowAllVariablesToggleAction();
       
   509 		    	variablesView.setAction("com.freescale.cdt.debug.cw.core.ui.showAllVariablesToggle", showAllVarsAction); //$NON-NLS-1$
       
   510 
       
   511 				IActionBars actionBars = variablesView.getViewSite().getActionBars();
       
   512 				IMenuManager viewMenu = actionBars.getMenuManager();
       
   513 				viewMenu.add(showAllVarsAction);								
       
   514 				return Status.OK_STATUS;
       
   515 			}};
       
   516 			
       
   517 			installSAVJob.schedule();
       
   518 		
       
   519 	}
       
   520 
       
   521 	private void addVariablesViewListener(IWorkbenchWindow window)
       
   522 	{
       
   523 		window.getPartService().addPartListener(new IPartListener2() {
       
   524 
       
   525 			public void partActivated(IWorkbenchPartReference partRef) {}
       
   526 
       
   527 			public void partBroughtToTop(IWorkbenchPartReference partRef) {}
       
   528 
       
   529 			public void partClosed(IWorkbenchPartReference partRef) {}
       
   530 
       
   531 			public void partDeactivated(IWorkbenchPartReference partRef) {}
       
   532 
       
   533 			public void partHidden(IWorkbenchPartReference partRef) {}
       
   534 
       
   535 			public void partInputChanged(IWorkbenchPartReference partRef) {}
       
   536 
       
   537 			public void partOpened(IWorkbenchPartReference partRef) {
       
   538 				if (partRef.getId().equals(IDebugUIConstants.ID_VARIABLE_VIEW))
       
   539 				{
       
   540 					IDebugView variablesView = (IDebugView) partRef.getPart(true);
       
   541 					addShowAllVariablesAction(variablesView);
       
   542 				}
       
   543 			}
       
   544 
       
   545 			public void partVisible(IWorkbenchPartReference partRef) {}});
       
   546 	}
       
   547 	
       
   548 	private void setupShowAllVariablesAction(IWorkbenchWindow window)
       
   549 	{
       
   550 	    IWorkbenchPage page = window.getActivePage();
       
   551 	    AbstractDebugView variablesView = (AbstractDebugView) page.findView(IDebugUIConstants.ID_VARIABLE_VIEW);
       
   552         if (variablesView == null)
       
   553 			addVariablesViewListener(window);
       
   554         else
       
   555         	addShowAllVariablesAction(variablesView);
       
   556         
       
   557 		DebugUITools.getDebugContextManager().getContextService(window).addDebugContextListener(new IDebugContextListener() {
       
   558 
       
   559 			public void debugContextChanged(DebugContextEvent event) {
       
   560 				if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0) {
       
   561 					contextActivated(event.getContext());
       
   562 				}
       
   563 			}
       
   564 
       
   565 			private void contextActivated(ISelection context) {
       
   566 				CWPlugin.setDebugContext(((IStructuredSelection) context).getFirstElement());
       
   567 			}});
       
   568 
       
   569 	}
       
   570 	
       
   571 	public void listenForVariablesView()
       
   572 	{
       
   573 
       
   574 		Display.getDefault().asyncExec(new Runnable() {
       
   575 			public void run() {
       
   576 
       
   577 				IWorkbenchWindow[] windows = getDefault().getWorkbench().getWorkbenchWindows();
       
   578 				
       
   579 				for (int i = 0; i < windows.length; i++) {
       
   580 					setupShowAllVariablesAction(windows[i]);
       
   581 				}
       
   582 				
       
   583 				getDefault().getWorkbench().addWindowListener(new IWindowListener() {
       
   584 
       
   585 					public void windowActivated(IWorkbenchWindow window) {}
       
   586 
       
   587 					public void windowClosed(IWorkbenchWindow window) {}
       
   588 
       
   589 					public void windowDeactivated(IWorkbenchWindow window) {}
       
   590 
       
   591 					public void windowOpened(IWorkbenchWindow window) {
       
   592 						setupShowAllVariablesAction(window);
       
   593 					}});
       
   594 				
       
   595 			}
       
   596 		});
       
   597 		
       
   598 	}
   385 	}
   599 	
   386 	
   600 	public static IService getTRKService() {
   387 	public static IService getTRKService() {
   601 		return RemoteConnectionsActivator.getConnectionTypeProvider().
   388 		return RemoteConnectionsActivator.getConnectionTypeProvider().
   602 					findServiceByID(REMOTE_CONNECTIONS_TRK_SERVICE);
   389 					findServiceByID(REMOTE_CONNECTIONS_TRK_SERVICE);