diff options
author | Camilo Bernal | 2012-07-18 16:23:21 +0000 |
---|---|---|
committer | Camilo Bernal | 2012-07-18 16:23:21 +0000 |
commit | bccf1d0668cf9d7404528449c9e1ddb8398578a8 (patch) | |
tree | a6e3c5af840f81c97032a86a2102cf027ac8ab0d | |
parent | d185189b1c712fe22273fca27582c8c2592bff6a (diff) | |
download | org.eclipse.linuxtools-bccf1d0668cf9d7404528449c9e1ddb8398578a8.tar.gz org.eclipse.linuxtools-bccf1d0668cf9d7404528449c9e1ddb8398578a8.tar.xz org.eclipse.linuxtools-bccf1d0668cf9d7404528449c9e1ddb8398578a8.zip |
Add delegate attribute to launch provider.
Launch provider has a delegate attribute that provides a handle to
specific launch configuration delegate. This is used to launch
plug-ins from the configurations tab.
Change-Id: I134b9f023882766e3dac95ac3a6731e71d0521ab
4 files changed, 95 insertions, 4 deletions
diff --git a/profiling/org.eclipse.linuxtools.profiling.launch/schema/org.eclipse.linuxtools.profiling.launch.provider.exsd b/profiling/org.eclipse.linuxtools.profiling.launch/schema/org.eclipse.linuxtools.profiling.launch.provider.exsd index c9035f7021..e5098925be 100644 --- a/profiling/org.eclipse.linuxtools.profiling.launch/schema/org.eclipse.linuxtools.profiling.launch.provider.exsd +++ b/profiling/org.eclipse.linuxtools.profiling.launch/schema/org.eclipse.linuxtools.profiling.launch.provider.exsd @@ -91,6 +91,16 @@ Invalid values will be assigned the lowest priority to the extension. </documentation> </annotation> </attribute> + <attribute name="delegate" type="string" use="required"> + <annotation> + <documentation> + A Class that extends <code>ProfileLaunchConfigurationDelegate</code> and that will provide a launch delegate for profiling. + </documentation> + <appinfo> + <meta.attribute kind="java" basedOn="org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationDelegate:"/> + </appinfo> + </annotation> + </attribute> </complexType> </element> diff --git a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/profiling/launch/ProfileLaunchConfigurationDelegate.java b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/profiling/launch/ProfileLaunchConfigurationDelegate.java index 7c918a0577..fe7fd8c54a 100644 --- a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/profiling/launch/ProfileLaunchConfigurationDelegate.java +++ b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/profiling/launch/ProfileLaunchConfigurationDelegate.java @@ -9,11 +9,15 @@ import org.eclipse.cdt.launch.AbstractCLaunchDelegate; import org.eclipse.cdt.utils.pty.PTY; import org.eclipse.cdt.utils.spawner.ProcessFactory; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.Platform; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.model.IProcess; import org.eclipse.jface.text.IDocument; +import org.eclipse.linuxtools.internal.profiling.launch.ProfileLaunchPlugin; import org.eclipse.ui.console.ConsolePlugin; import org.eclipse.ui.console.TextConsole; @@ -44,7 +48,45 @@ public abstract class ProfileLaunchConfigurationDelegate extends AbstractCLaunch } return true; } - + + /** + * Get a launch configuration delegate that is associated with the specified id. + * This looks through extensions of the extension point + * <code>org.eclipse.linuxtools.profiling.launch.launchProvider</code> that + * have a specific delegate attribute. + * + * @param id a unique identifier + * @return a launch configuration delegate that implements + * <code>ProfileLaunchConfigurationDelegate</code> , or <code>null</code> if + * none could be found. + */ + public static ProfileLaunchConfigurationDelegate getConfigurationDelegateFromId( + String id) { + IExtensionPoint extPoint = Platform.getExtensionRegistry() + .getExtensionPoint(ProfileLaunchPlugin.PLUGIN_ID, + "launchProvider"); //$NON-NLS-1$ + IConfigurationElement[] configs = extPoint.getConfigurationElements(); + for (IConfigurationElement config : configs) { + if (config.getName().equals("provider")) { //$NON-NLS-1$ + String currentId = config.getAttribute("id"); //$NON-NLS-1$ + String tabgroup = config.getAttribute("delegate"); //$NON-NLS-1$ + if (currentId != null && tabgroup != null + && currentId.equals(id)) { + try { + Object obj = config + .createExecutableExtension("delegate"); //$NON-NLS-1$ + if (obj instanceof ProfileLaunchConfigurationDelegate) { + return (ProfileLaunchConfigurationDelegate) obj; + } + } catch (CoreException e) { + // continue, perhaps another configuration will succeed + } + } + } + } + return null; + } + /** * This method will create a process in the command line with I/O directed to the Eclipse console. * It returns a reference to the process. Note that the process runs independently of Eclipse's threads, diff --git a/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/SnapshotOptionsTab.java b/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/SnapshotOptionsTab.java index 3c6d0f739a..a42e8d51ff 100644 --- a/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/SnapshotOptionsTab.java +++ b/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/SnapshotOptionsTab.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.linuxtools.profiling.snapshot; +import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; @@ -31,6 +32,7 @@ public class SnapshotOptionsTab extends ProfileLaunchConfigurationTab { Combo providerCombo; AbstractLaunchConfigurationTab[] tabs; ILaunchConfiguration initial; + String providerId = ""; public void createControl(Composite parent) { top = new Composite(parent, SWT.NONE); @@ -50,9 +52,10 @@ public class SnapshotOptionsTab extends ProfileLaunchConfigurationTab { item.dispose(); } + providerId = providerCombo.getText(); // get the tabs associated with the selected ID tabs = ProfileLaunchConfigurationTabGroup - .getTabGroupProviderFromId(providerCombo.getText()) + .getTabGroupProviderFromId(providerId) .getProfileTabs(); // create the tab item, and load the specified tab inside @@ -90,6 +93,11 @@ public class SnapshotOptionsTab extends ProfileLaunchConfigurationTab { * about them. We get access to this launch configuration to ensure * that we can properly load the widgets the first time. */ + + // store current provider id in the configuration + if (configuration != null) { + setProvider(configuration); + } if (initial == null){ initial = configuration; } @@ -111,5 +119,18 @@ public class SnapshotOptionsTab extends ProfileLaunchConfigurationTab { public String getName() { return "Snapshot"; } + /** + * Set the provider attribute in the specified configuration. + * @param configuration a configuration + */ + public void setProvider(ILaunchConfiguration configuration) { + try { + ILaunchConfigurationWorkingCopy wc = configuration.getWorkingCopy(); + wc.setAttribute("provider", providerId); + configuration = wc.doSave(); + } catch (CoreException e1) { + e1.printStackTrace(); + } + } } diff --git a/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/launch/SnapshotLaunchConfigurationDelegate.java b/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/launch/SnapshotLaunchConfigurationDelegate.java index 5064fd78c6..fea027dfb5 100644 --- a/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/launch/SnapshotLaunchConfigurationDelegate.java +++ b/profiling/org.eclipse.linuxtools.profiling.snapshot/src/org/eclipse/linuxtools/profiling/snapshot/launch/SnapshotLaunchConfigurationDelegate.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.linuxtools.profiling.snapshot.launch; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; @@ -24,8 +25,25 @@ public class SnapshotLaunchConfigurationDelegate extends } @Override - public void launch(ILaunchConfiguration arg0, String arg1, ILaunch arg2, - IProgressMonitor arg3) { + public void launch(ILaunchConfiguration config, String mode, ILaunch launch, + IProgressMonitor monitor) { + try { + + if (config != null) { + // get provider id from configuration. + String providerId = config.getAttribute("provider", ""); + if (providerId.equals("")) { + return; + } + // get configuration delegate associated with provider id. + ProfileLaunchConfigurationDelegate delegate = getConfigurationDelegateFromId(providerId); + if (delegate != null) { + delegate.launch(config, mode, launch, monitor); + } + } + } catch (CoreException e) { + e.printStackTrace(); + } return; } |