1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 14:12:10 +02:00

Bug 437392 - Add support for multiple target types per launch thing.

Introduces a whole lot new concepts that will be documented in the
wiki.

Change-Id: Idd05d5232b88be7ac1d400e5b9618cf08716abf4
Reviewed-on: https://git.eclipse.org/r/29849
Tested-by: Hudson CI
Reviewed-by: Doug Schaefer <dschaefer@qnx.com>
This commit is contained in:
Doug Schaefer 2014-07-13 14:25:12 -04:00
parent 8f40037326
commit b318ffaedb
39 changed files with 1546 additions and 975 deletions

View file

@ -1,13 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
id="cdtLaunchConfigProvider"
name="CDT Launch Config Provider"
point="org.eclipse.cdt.launchbar.core.launchConfigProvider">
<provider
class="org.eclipse.cdt.launchbar.cdt.core.internal.CDTLaunchConfigProvider"
priority="5"></provider>
</extension>
</plugin>

View file

@ -1,3 +1,13 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.cdt.core.internal;
import org.osgi.framework.BundleActivator;
@ -5,6 +15,8 @@ import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
public static final String ID = "org.eclipse.cdt.launchbar.cdt.core";
private static BundleContext context;
static BundleContext getContext() {

View file

@ -1,128 +0,0 @@
package org.eclipse.cdt.launchbar.cdt.core.internal;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.ILaunchMode;
public class CDTLaunchConfigDescriptor implements ILaunchConfigurationDescriptor {
private final ILaunchBarManager manager;
private String projectName;
private ILaunchConfiguration config;
private ILaunchMode[] launchModes;
public CDTLaunchConfigDescriptor(ILaunchBarManager manager, IProject project) {
this.manager = manager;
this.projectName = project.getName();
}
public CDTLaunchConfigDescriptor(ILaunchBarManager manager, ILaunchConfiguration config) {
this.manager = manager;
this.config = config;
}
@Override
public String getName() {
if (config != null)
return config.getName();
else
return projectName;
}
private ILaunchManager getLaunchManager() {
return DebugPlugin.getDefault().getLaunchManager();
}
private IProject getProject() {
return ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
}
@Override
public ILaunchConfiguration getLaunchConfiguration() throws CoreException {
if (config == null) {
ILaunchConfigurationType configType = config.getType();
ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateLaunchConfigurationName(projectName));
wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
wc.setMappedResources(new IResource[] { getProject() });
wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);
// TODO finish this off
config = wc.doSave();
}
return config;
}
@Override
public boolean matches(ILaunchConfiguration launchConfiguration) throws CoreException {
if (config == launchConfiguration)
return true;
String pname = launchConfiguration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");
return pname.equals(projectName);
}
@Override
public ILaunchTarget[] getLaunchTargets() {
return new ILaunchTarget[] { manager.getLocalLaunchTarget() };
}
@Override
public ILaunchTarget getLaunchTarget(String id) {
ILaunchTarget localTarget = manager.getLocalLaunchTarget();
if (localTarget.getId().equals(id))
return localTarget;
return null;
}
@Override
public void setActiveLaunchTarget(ILaunchTarget target) {
// TODO Auto-generated method stub
}
@Override
public ILaunchMode[] getLaunchModes() throws CoreException {
if (launchModes == null) {
List<ILaunchMode> mymodes = new ArrayList<>();
ILaunchConfigurationType type = config.getType();
ILaunchMode[] modes = DebugPlugin.getDefault().getLaunchManager().getLaunchModes();
for (ILaunchMode mode : modes) {
if (type.supportsMode(mode.getIdentifier())) {
mymodes.add(mode);
}
}
launchModes = mymodes.toArray(new ILaunchMode[mymodes.size()]);
}
return launchModes;
}
@Override
public ILaunchMode getLaunchMode(String id) throws CoreException {
for (ILaunchMode mode : getLaunchModes())
if (mode.getIdentifier().equals(id))
return mode;
return null;
}
@Override
public void setActiveLaunchMode(ILaunchMode mode) {
// TODO Auto-generated method stub
}
}

View file

@ -1,24 +0,0 @@
package org.eclipse.cdt.launchbar.cdt.core.internal;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationsProvider;
public class CDTLaunchConfigProvider implements ILaunchConfigurationsProvider {
public CDTLaunchConfigProvider() {
// TODO Auto-generated constructor stub
}
@Override
public void init(ILaunchBarManager manager) {
// TODO Auto-generated method stub
}
@Override
public ILaunchConfigurationDescriptor filterDescriptor(ILaunchBarManager manager, ILaunchConfigurationDescriptor descriptor) {
return descriptor;
}
}

View file

@ -1,6 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension-point id="launchConfigProvider" name="Launch Configuration Descriptor Provider" schema="schema/launchConfigProvider.exsd"/>
<extension-point id="launchBarContributions" name="Launch Bar Contributions" schema="schema/launchBarContributions.exsd"/>
<extension
point="org.eclipse.cdt.launchbar.core.launchBarContributions">
<descriptorType
class="org.eclipse.cdt.launchbar.core.internal.DefaultLaunchDescriptorType"
id="org.eclipse.cdt.launchbar.core.descriptor.default"
priority="0">
</descriptorType>
<targetType
class="org.eclipse.cdt.launchbar.core.internal.LocalTargetType"
id="org.eclipse.cdt.launchbar.core.target.local">
</targetType>
<configProvider
class="org.eclipse.cdt.launchbar.core.internal.DefaultLaunchConfigurationProvider"
descriptorType="org.eclipse.cdt.launchbar.core.descriptor.default"
isDefault="true"
targetType="org.eclipse.cdt.launchbar.core.target.local">
</configProvider>
<objectProvider
class="org.eclipse.cdt.launchbar.core.internal.ProjectLaunchObjectProvider"
id="org.eclipse.cdt.launchbar.core.objectProvider.project">
</objectProvider>
</extension>
</plugin>

View file

@ -0,0 +1,205 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.cdt.launchbar.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="org.eclipse.cdt.launchbar.core" id="launchBarContributions" name="Launch Bar Contributions"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence minOccurs="0" maxOccurs="unbounded">
<element ref="descriptorType"/>
<element ref="targetType"/>
<element ref="configProvider"/>
<element ref="objectProvider"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="descriptorType">
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="priority" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.cdt.launchbar.core.ILaunchDescriptorType"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="targetType">
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.cdt.launchbar.core.ILaunchTargetType"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="configProvider">
<complexType>
<attribute name="descriptorType" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="identifier" basedOn="org.eclipse.cdt.launchbar.core.launchBarContributions/descriptorType/@id"/>
</appinfo>
</annotation>
</attribute>
<attribute name="targetType" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="identifier" basedOn="org.eclipse.cdt.launchbar.core.launchBarContributions/targetType/@id"/>
</appinfo>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.cdt.launchbar.core.ILaunchConfigurationProvider"/>
</appinfo>
</annotation>
</attribute>
<attribute name="isDefault" type="boolean">
<annotation>
<documentation>
Is this the default target type for this descriptor type.
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="objectProvider">
<complexType>
<attribute name="id" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.cdt.launchbar.core.ILaunchObjectProvider"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>

View file

@ -1,109 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.cdt.launchbar.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="org.eclipse.cdt.launchbar.core" id="launchConfigProvider" name="Launch Configuration Descriptor Provider"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence>
<element ref="provider"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="provider">
<complexType>
<attribute name="class" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.cdt.launchbar.core.ILaunchConfigurationsProvider"/>
</appinfo>
</annotation>
</attribute>
<attribute name="priority" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>

View file

@ -13,48 +13,53 @@ package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchMode;
public interface ILaunchBarManager extends IAdaptable {
ILaunchConfigurationDescriptor[] getLaunchConfigurationDescriptors();
ILaunchDescriptor[] getLaunchDescriptors() throws CoreException;
ILaunchConfigurationDescriptor getActiveLaunchConfigurationDescriptor();
ILaunchDescriptor getActiveLaunchDescriptor() throws CoreException;
void setActiveLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc) throws CoreException;
void addLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc) throws CoreException;
void removeLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc);
ILaunchConfigurationDescriptor getLaunchConfigurationDescriptor(ILaunchConfiguration configuration) throws CoreException;
void setActiveLaunchDescriptor(ILaunchDescriptor configDesc) throws CoreException;
ILaunchMode getActiveLaunchMode();
ILaunchMode[] getLaunchModes() throws CoreException;
ILaunchMode getActiveLaunchMode() throws CoreException;
void setActiveLaunchMode(ILaunchMode mode) throws CoreException;
ILaunchTarget[] getLaunchTargets() throws CoreException;
void setActiveLaunchMode(ILaunchMode mode);
ILaunchTarget getActiveLaunchTarget();
void setActiveLaunchTarget(ILaunchTarget target);
void addLaunchTarget(ILaunchTarget target);
void removeLaunchTarget(ILaunchTarget target);
ILaunchTarget getLocalLaunchTarget();
ILaunchTarget getLaunchTarget(String id) throws CoreException;
ILaunchTarget getActiveLaunchTarget() throws CoreException;
void setActiveLaunchTarget(ILaunchTarget target) throws CoreException;
ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException;
ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException;
ILaunchDescriptor launchObjectAdded(Object element) throws CoreException;
void launchObjectRemoved(Object element) throws CoreException;
interface Listener {
void activeConfigurationDescriptorChanged();
void activeLaunchModeChanged();
void activeLaunchTargetChanged();
void launchDescriptorRemoved(ILaunchDescriptor descriptor);
}
void addListener(Listener listener);
void removeListener(Listener listener);
}

View file

@ -1,92 +0,0 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchMode;
public interface ILaunchConfigurationDescriptor {
/**
* Name to show in the launch configuration selector.
*
* @return name of the launch configuration
*/
String getName();
/**
* The corresponding launch configuration.
* If this launch config hasn't been created yet, it will be
*
* @return the corresponding launch configuration
* @throws CoreException
*/
ILaunchConfiguration getLaunchConfiguration() throws CoreException;
/**
* Is this launch configuration managed by this descriptor.
*
* @param launchConfiguration
* @return
* @throws CoreException
*/
boolean matches(ILaunchConfiguration launchConfiguration) throws CoreException;
/**
* Return the list of launch targets this configuration can launcht to.
*
* @return launch targets
*/
ILaunchTarget[] getLaunchTargets();
/**
* Return the launch target with the given id.
*
* @param id id of target
* @return launch target
*/
ILaunchTarget getLaunchTarget(String id);
/**
* Set the active launch target. Allows the descriptor to prepare for
* a launch on that target.
*
* @param target the new active launch target
*/
void setActiveLaunchTarget(ILaunchTarget target);
/**
* Return the launch modes supported by this descriptor.
*
* @return launch modes
* @throws CoreException
*/
ILaunchMode[] getLaunchModes() throws CoreException;
/**
* Returns the launch mode with the given identifier.
*
* @param id
* @return launch mode with id
* @throws CoreException
*/
ILaunchMode getLaunchMode(String id) throws CoreException;
/**
* Set the active launch mode. Allows the descriptor to prepare for a
* launch in that mode.
*
* @param mode the new active launch mode
*/
void setActiveLaunchMode(ILaunchMode mode);
}

View file

@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
public interface ILaunchConfigurationProvider {
/**
* Do any initialization.
*
* @param manager
* @throws CoreException
*/
void init(ILaunchBarManager manager) throws CoreException;
/**
* Does this provider own this launch configuration. If so, make sure the launch descriptor
* is properly constructed by sending in a launch object to the launch manager.
*
* @param configuration
* @return
* @throws CoreException
*/
boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException;
/**
* Returns the launch configuration type used to launch the descriptor on this target type.
*
* @param descriptor
* @param target
* @return launch configuration type
* @throws CoreException
*/
ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor) throws CoreException;
/**
* Create a launch configuration for the descriptor to launch on the target.
*
* @param descriptor
* @param target
* @return launch configuration
* @throws CoreException
*/
ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor) throws CoreException;
/**
* A launch configuration has been removed.
*
* @param configuration
* @throws CoreException
*/
void launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException;
}

View file

@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
/**
* Represents a thing that can be launched.
*/
public interface ILaunchDescriptor {
/**
* Name to show in the launch descriptor selector.
*
* @return name of the launch descriptor
*/
String getName();
/**
* The type of launch descriptor.
*
* @return provider
*/
ILaunchDescriptorType getType();
}

View file

@ -0,0 +1,64 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.runtime.CoreException;
/**
* Provides the list of launch configurations
*
*/
public interface ILaunchDescriptorType {
/**
* The id for the provider.
*
* @return provider id
*/
String getId();
/**
* Called after existing launch configs have been added. The provider
* can now add any more that they'd like to have.
*/
void init(ILaunchBarManager manager);
/**
* Does this type own this launch element.
*
* @param element
* @return owns element
* @throws CoreException
*/
boolean ownsLaunchObject(Object element) throws CoreException;
/**
* Return a descriptor for the given element. The element can be a launch
* configuration, a project, or anything else that gets fed to the
* launch bar manager.
*
* May return null to essentially eat the element so no other types
* create a descriptor for it.
*
* @param descriptor candidate descriptor
* @return the best descriptor
* @throws CoreException
*/
ILaunchDescriptor getDescriptor(Object element) throws CoreException;
/**
* Return a handle to the launch bar manager.
*
* @return launchbar manager
*/
ILaunchBarManager getManager();
}

View file

@ -0,0 +1,21 @@
package org.eclipse.cdt.launchbar.core;
/**
* An extension that serves up objects to feed launch descriptors.
*
*/
public interface ILaunchObjectProvider {
/**
* Add initial launch descriptors and set up listeners.
*
* @param launchbar manager
*/
void init(ILaunchBarManager manager);
/**
* Shutting down, remove any listeners.
*/
void dispose();
}

View file

@ -26,4 +26,17 @@ public interface ILaunchTarget {
* @return name
*/
String getName();
/**
* Returns the type for this target.
*
* @return target type
*/
ILaunchTargetType getType();
/**
* This target has been made active.
*/
void setActive();
}

View file

@ -10,25 +10,35 @@
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
/**
* Provides the list of launch configurations
*
*/
public interface ILaunchConfigurationsProvider {
public interface ILaunchTargetType {
/**
* Called after existing launch configs have been added. The provider
* can now add any more that they'd like to have.
* Called by the launchbar manager to initialize and pass a hendle to itself.
*
* @param manager
*/
void init(ILaunchBarManager manager);
/**
* If the provider has a better descriptor than the suggested one, return a better one.
* Otherwise, return the one that was passed in.
* The id of the target type.
*
* @param descriptor candidate descriptor
* @return the best descriptor
* @return target type id
*/
ILaunchConfigurationDescriptor filterDescriptor(ILaunchBarManager manager, ILaunchConfigurationDescriptor descriptor);
String getId();
/**
* Return the list of targets for this type.
*
* @return targets
*/
ILaunchTarget[] getTargets();
/**
* Return the target with the specified id.
*
* @param id
* @return target
*/
ILaunchTarget getTarget(String id);
}

View file

@ -1,96 +0,0 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.core.internal;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchMode;
public class DefaultLaunchConfigurationDescriptor implements ILaunchConfigurationDescriptor {
private final ILaunchBarManager manager;
private ILaunchConfiguration config;
private ILaunchMode[] launchModes;
public DefaultLaunchConfigurationDescriptor(ILaunchBarManager manager, ILaunchConfiguration config) {
this.manager = manager;
this.config = config;
}
@Override
public String getName() {
return config.getName();
}
@Override
public ILaunchConfiguration getLaunchConfiguration() throws CoreException {
return config;
}
@Override
public boolean matches(ILaunchConfiguration launchConfiguration) {
return config.equals(launchConfiguration);
}
@Override
public ILaunchTarget getLaunchTarget(String id) {
return LocalTarget.ID.equals(id) ? manager.getLocalLaunchTarget() : null;
}
@Override
public ILaunchTarget[] getLaunchTargets() {
return new ILaunchTarget[] { manager.getLocalLaunchTarget() };
}
@Override
public void setActiveLaunchTarget(ILaunchTarget target) {
// nothing to do
}
@Override
public ILaunchMode[] getLaunchModes() throws CoreException {
if (launchModes == null) {
List<ILaunchMode> mymodes = new ArrayList<>();
ILaunchConfigurationType type = config.getType();
ILaunchMode[] modes = DebugPlugin.getDefault().getLaunchManager().getLaunchModes();
for (ILaunchMode mode : modes) {
if (type.supportsMode(mode.getIdentifier())) {
mymodes.add(mode);
}
}
launchModes = mymodes.toArray(new ILaunchMode[mymodes.size()]);
}
return launchModes;
}
@Override
public ILaunchMode getLaunchMode(String id) throws CoreException {
for (ILaunchMode mode : getLaunchModes()) {
if (mode.getIdentifier().equals(id))
return mode;
}
return null;
}
@Override
public void setActiveLaunchMode(ILaunchMode mode) {
// nothing to do
}
}

View file

@ -0,0 +1,44 @@
package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationProvider;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
public class DefaultLaunchConfigurationProvider implements ILaunchConfigurationProvider {
@Override
public void init(ILaunchBarManager manager) throws CoreException {
// nothing to do
}
@Override
public boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException {
// We may own it but return false to let it percolate through to the descriptor type.
return false;
}
@Override
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor) throws CoreException {
if (descriptor instanceof DefaultLaunchDescriptor) {
return ((DefaultLaunchDescriptor) descriptor).getConfig();
}
return null;
}
@Override
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor) throws CoreException {
if (descriptor instanceof DefaultLaunchDescriptor) {
return ((DefaultLaunchDescriptor) descriptor).getConfig().getType();
}
return null;
}
@Override
public void launchConfigurationRemoved(ILaunchConfiguration configation) throws CoreException {
// The descriptor will handle the remove.
}
}

View file

@ -0,0 +1,41 @@
/*******************************************************************************
* Copyright (c) 2014 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Doug Schaefer
*******************************************************************************/
package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType;
import org.eclipse.debug.core.ILaunchConfiguration;
public class DefaultLaunchDescriptor implements ILaunchDescriptor {
private final DefaultLaunchDescriptorType type;
private final ILaunchConfiguration config;
public DefaultLaunchDescriptor(DefaultLaunchDescriptorType type, ILaunchConfiguration config) {
this.type = type;
this.config = config;
}
@Override
public String getName() {
return config.getName();
}
@Override
public ILaunchDescriptorType getType() {
return type;
}
public ILaunchConfiguration getConfig() {
return config;
}
}

View file

@ -0,0 +1,39 @@
package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType;
import org.eclipse.debug.core.ILaunchConfiguration;
public class DefaultLaunchDescriptorType implements ILaunchDescriptorType {
public static final String ID = "org.eclipse.cdt.launchbar.core.descriptor.default";
private ILaunchBarManager manager;
@Override
public String getId() {
return ID;
}
@Override
public void init(ILaunchBarManager manager) {
this.manager = manager;
}
@Override
public boolean ownsLaunchObject(Object element) {
return element instanceof ILaunchConfiguration;
}
@Override
public ILaunchDescriptor getDescriptor(Object element) {
return new DefaultLaunchDescriptor(this, (ILaunchConfiguration) element);
}
@Override
public ILaunchBarManager getManager() {
return manager;
}
}

View file

@ -20,9 +20,12 @@ import java.util.List;
import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationsProvider;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationProvider;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType;
import org.eclipse.cdt.launchbar.core.ILaunchObjectProvider;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.core.ILaunchTargetType;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
@ -34,6 +37,7 @@ import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationListener;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.ILaunchMode;
import org.osgi.service.prefs.BackingStoreException;
@ -42,142 +46,183 @@ import org.osgi.service.prefs.Preferences;
public class LaunchBarManager extends PlatformObject implements ILaunchBarManager, ILaunchConfigurationListener {
private List<Listener> listeners = new LinkedList<>();
private List<ProviderExtensionDescriptor> providers = new ArrayList<>();
private Map<String, ILaunchConfigurationDescriptor> configDescs = new HashMap<>();
private ILaunchConfigurationDescriptor lastConfigDesc;
private ILaunchConfigurationDescriptor activeConfigDesc;
private Map<String, ILaunchTargetType> targetTypes = new HashMap<>();
private List<ILaunchDescriptorType> descriptorTypes = new ArrayList<>();
private Map<String, ILaunchDescriptor> descriptors = new HashMap<>();
private List<ILaunchObjectProvider> objectProviders = new ArrayList<>();
// Map descriptor type to target type to provider
private Map<String, Map<String, ILaunchConfigurationProvider>> configProviders = new HashMap<>();
// Map descriptor type to target type
private Map<String, String> defaultTargetTypes = new HashMap<>();
private Map<Object, ILaunchDescriptor> objectDescriptorMap = new HashMap<>();
private ILaunchDescriptor activeLaunchDesc;
private ILaunchMode activeLaunchMode;
private ILaunchTarget activeLaunchTarget;
private static final LocalTarget localLaunchTarget = new LocalTarget();
private ILaunchDescriptor lastLaunchDesc;
private static final String PREF_ACTIVE_CONFIG_DESC = "activeConfigDesc";
private static final String PREF_ACTIVE_LAUNCH_MODE = "activeLaunchMode";
private static final String PREF_ACTIVE_LAUNCH_TARGET = "activeLaunchTarget";
private class ProviderExtensionDescriptor {
private ILaunchConfigurationsProvider provider;
private int priority;
public ProviderExtensionDescriptor(ILaunchConfigurationsProvider provider, int priority) {
super();
this.provider = provider;
this.priority = priority;
}
public ILaunchConfigurationsProvider getProvider() {
return provider;
}
public int getPriority() {
return priority;
}
}
public LaunchBarManager() throws CoreException {
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchConfigProvider");
final Map<ILaunchDescriptorType, Integer> typePriorities = new HashMap<>();
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchBarContributions");
IExtension[] extensions = point.getExtensions();
for (IExtension extension : extensions) {
// provider is manditory
IConfigurationElement element = extension.getConfigurationElements()[0];
ILaunchConfigurationsProvider provider = (ILaunchConfigurationsProvider) element.createExecutableExtension("class");
String priorityString = element.getAttribute("priority");
int priority = 100;
if (priorityString != null) {
try {
priority = Integer.parseInt(priorityString);
} catch (NumberFormatException e) {
// Log it but keep going with the default
Activator.log(e);
for (IConfigurationElement element : extension.getConfigurationElements()) {
String elementName = element.getName();
if (elementName.equals("descriptorType")) {
String id = element.getAttribute("id");
String priorityStr = element.getAttribute("priority");
ILaunchDescriptorType type = (ILaunchDescriptorType) element.createExecutableExtension("class");
assert id.equals(type.getId());
descriptorTypes.add(type);
int priority = 1;
if (priorityStr != null) {
try {
priority = Integer.parseInt(priorityStr);
} catch (NumberFormatException e) {
// Log it but keep going with the default
Activator.log(e);
}
}
typePriorities.put(type, priority);
} else if (elementName.equals("targetType")) {
String id = element.getAttribute("id");
ILaunchTargetType targetType = (ILaunchTargetType) element.createExecutableExtension("class");
assert id.equals(targetType.getId());
targetTypes.put(id, targetType);
} else if (elementName.equals("objectProvider")) {
ILaunchObjectProvider objectProvider = (ILaunchObjectProvider) element.createExecutableExtension("class");
objectProviders.add(objectProvider);
} else if (elementName.equals("configProvider")) {
String descriptorType = element.getAttribute("descriptorType");
String targetType = element.getAttribute("targetType");
// TODO don't instantiate this until we need it
ILaunchConfigurationProvider configProvider = (ILaunchConfigurationProvider) element.createExecutableExtension("class");
Map<String, ILaunchConfigurationProvider> targetTypes = configProviders.get(descriptorType);
if (targetTypes == null) {
targetTypes = new HashMap<>();
configProviders.put(descriptorType, targetTypes);
}
targetTypes.put(targetType, configProvider);
String isDefault = element.getAttribute("isDefault");
if (isDefault != null && Boolean.valueOf(isDefault)) {
defaultTargetTypes.put(descriptorType, targetType);
}
}
}
providers.add(new ProviderExtensionDescriptor(provider, priority));
}
Collections.sort(providers, new Comparator<ProviderExtensionDescriptor>() {
Collections.sort(descriptorTypes, new Comparator<ILaunchDescriptorType>() {
@Override
public int compare(ProviderExtensionDescriptor o1, ProviderExtensionDescriptor o2) {
int p1 = o1.getPriority();
int p2 = o2.getPriority();
if (p1 > p2)
public int compare(ILaunchDescriptorType o1, ILaunchDescriptorType o2) {
int p1 = typePriorities.get(o1);
int p2 = typePriorities.get(o2);
// Reverse order, highest priority first
if (p1 < p2)
return 1;
else if (p1 < p2)
else if (p1 > p2)
return -1;
else
return 0;
}
});
for (ILaunchDescriptorType descriptorType : descriptorTypes) {
descriptorType.init(this);
}
for (ILaunchTargetType targetType : targetTypes.values()) {
targetType.init(this);
}
for (ILaunchObjectProvider objectProvider : objectProviders) {
objectProvider.init(this);
}
for (Map<String, ILaunchConfigurationProvider> targetMap : configProviders.values()) {
for (ILaunchConfigurationProvider configProvider : targetMap.values()) {
configProvider.init(this);
}
}
// Hook up the existing launch configurations and listen
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
for (ILaunchConfiguration configuration : launchManager.getLaunchConfigurations()) {
ILaunchConfigurationDescriptor configDesc = new DefaultLaunchConfigurationDescriptor(this, configuration);
for (ProviderExtensionDescriptor provider : providers) {
configDesc = provider.getProvider().filterDescriptor(this, configDesc);
}
configDescs.put(configDesc.getName(), configDesc);
launchConfigurationAdded(configuration);
}
for (ProviderExtensionDescriptor providerDesc : providers) {
providerDesc.getProvider().init(this);
}
launchManager.addLaunchConfigurationListener(this);
// Load up the active from the preferences or pick reasonable defaults
IEclipsePreferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
String activeConfigDescName = store.get(PREF_ACTIVE_CONFIG_DESC, null);
if (activeConfigDescName == null && !configDescs.isEmpty()) {
activeConfigDescName = configDescs.values().iterator().next().getName();
if (activeConfigDescName == null && !descriptors.isEmpty()) {
activeConfigDescName = descriptors.values().iterator().next().getName();
}
if (activeConfigDescName != null) {
ILaunchConfigurationDescriptor configDesc = configDescs.get(activeConfigDescName);
ILaunchDescriptor configDesc = descriptors.get(activeConfigDescName);
if (configDesc != null) {
setActiveLaunchConfigurationDescriptor(configDesc);
setActiveLaunchDescriptor(configDesc);
}
}
}
@Override
public void launchConfigurationAdded(ILaunchConfiguration configuration) {
ILaunchConfigurationDescriptor configDesc = new DefaultLaunchConfigurationDescriptor(this, configuration);
for (ProviderExtensionDescriptor provider : providers) {
configDesc = provider.getProvider().filterDescriptor(this, configDesc);
public ILaunchDescriptor launchObjectAdded(Object element) {
ILaunchDescriptor desc = objectDescriptorMap.get(element);
if (desc != null)
return desc;
for (ILaunchDescriptorType descriptorType : descriptorTypes) {
try {
if (descriptorType.ownsLaunchObject(element)) {
desc = descriptorType.getDescriptor(element);
if (desc != null) {
descriptors.put(desc.getName(), desc);
objectDescriptorMap.put(element, desc);
setActiveLaunchDescriptor(desc);
return desc;
}
break;
}
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
try {
addLaunchConfigurationDescriptor(configDesc);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
@Override
public void launchObjectRemoved(Object element) throws CoreException {
ILaunchDescriptor desc = objectDescriptorMap.get(element);
if (desc != null) {
descriptors.remove(desc.getName());
objectDescriptorMap.remove(element);
if (desc.equals(activeLaunchDesc)) {
// Roll back to the last one and make sure we don't come back
ILaunchDescriptor nextDesc = lastLaunchDesc;
activeLaunchDesc = null;
setActiveLaunchDescriptor(nextDesc);
}
}
}
@Override
public void launchConfigurationChanged(ILaunchConfiguration configuration) {
// TODO Auto-generated method stub
}
@Override
public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
try {
ILaunchConfigurationDescriptor configDesc = getLaunchConfigurationDescriptor(configuration);
if (configDesc != null)
removeLaunchConfigurationDescriptor(configDesc);
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
@Override
public ILaunchConfigurationDescriptor[] getLaunchConfigurationDescriptors() {
ILaunchConfigurationDescriptor[] descs = configDescs.values().toArray(new ILaunchConfigurationDescriptor[configDescs.size()]);
Arrays.sort(descs, new Comparator<ILaunchConfigurationDescriptor>() {
public ILaunchDescriptor[] getLaunchDescriptors() {
ILaunchDescriptor[] descs = descriptors.values().toArray(new ILaunchDescriptor[descriptors.size()]);
Arrays.sort(descs, new Comparator<ILaunchDescriptor>() {
@Override
public int compare(ILaunchConfigurationDescriptor o1, ILaunchConfigurationDescriptor o2) {
public int compare(ILaunchDescriptor o1, ILaunchDescriptor o2) {
return o1.getName().compareTo(o2.getName());
}
});
@ -185,51 +230,27 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
}
@Override
public ILaunchConfigurationDescriptor getActiveLaunchConfigurationDescriptor() {
return activeConfigDesc;
public ILaunchDescriptor getActiveLaunchDescriptor() {
return activeLaunchDesc;
}
@Override
public ILaunchConfigurationDescriptor getLaunchConfigurationDescriptor(ILaunchConfiguration configuration) throws CoreException {
// Check by name
ILaunchConfigurationDescriptor configDesc = configDescs.get(configuration.getName());
if (configDesc.matches(configuration))
return configDesc;
// Nope, try all descs
for (ILaunchConfigurationDescriptor cd : configDescs.values()) {
if (cd.matches(configuration))
return cd;
}
// nothing, weird
return null;
}
@Override
public void setActiveLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc) throws CoreException {
if (activeConfigDesc == configDesc)
public void setActiveLaunchDescriptor(ILaunchDescriptor configDesc) throws CoreException {
if (activeLaunchDesc != null && activeLaunchDesc == configDesc)
return;
lastConfigDesc = activeConfigDesc;
activeConfigDesc = configDesc;
lastLaunchDesc = activeLaunchDesc;
activeLaunchDesc = configDesc;
IEclipsePreferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
if (activeConfigDesc != null) {
store.put(PREF_ACTIVE_CONFIG_DESC, activeConfigDesc.getName());
if (activeLaunchDesc != null) {
store.put(PREF_ACTIVE_CONFIG_DESC, activeLaunchDesc.getName());
} else {
store.remove(PREF_ACTIVE_CONFIG_DESC);
}
try {
store.flush();
} catch (BackingStoreException e) {
// TODO log
e.printStackTrace();
}
if (activeConfigDesc == null) {
setActiveLaunchMode(null);
setActiveLaunchTarget(null);
return;
Activator.log(e);
}
// Send notifications
@ -237,76 +258,58 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
listener.activeConfigurationDescriptorChanged();
}
// Set active mode
String activeModeName = store.node(activeConfigDesc.getName()).get(PREF_ACTIVE_LAUNCH_MODE, null);
ILaunchMode[] launchModes = activeConfigDesc.getLaunchModes();
boolean foundMode = false;
if (activeModeName != null) {
for (ILaunchMode mode : launchModes) {
if (activeModeName.equals(mode.getIdentifier())) {
setActiveLaunchMode(mode);
foundMode = true;
break;
}
}
}
if (!foundMode) {
if (launchModes.length > 0) {
ILaunchMode mode = activeConfigDesc.getLaunchMode("debug");
if (mode == null) {
mode = activeConfigDesc.getLaunchMode("run");
}
if (mode == null) {
mode = launchModes[0];
}
setActiveLaunchMode(mode);
} else {
setActiveLaunchMode(null);
}
if (activeLaunchDesc == null) {
setActiveLaunchMode(null);
setActiveLaunchTarget(null);
return;
}
// Set active target
String activeTargetId = store.node(activeConfigDesc.getName()).get(PREF_ACTIVE_LAUNCH_TARGET, null);
String activeTargetId = store.node(activeLaunchDesc.getName()).get(PREF_ACTIVE_LAUNCH_TARGET, null);
ILaunchTarget target = null;
if (activeTargetId != null) {
target = activeConfigDesc.getLaunchTarget(activeTargetId);
target = getLaunchTarget(activeTargetId);
}
if (target == null) {
ILaunchTarget[] targets = activeConfigDesc.getLaunchTargets();
ILaunchTarget[] targets = getLaunchTargets();
if (targets.length > 0) {
target = targets[0];
}
}
setActiveLaunchTarget(target);
// Set active mode
String activeModeName = store.node(activeLaunchDesc.getName()).get(PREF_ACTIVE_LAUNCH_MODE, null);
ILaunchConfigurationType configType = getLaunchConfigurationType(activeLaunchDesc, activeLaunchTarget);
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
ILaunchMode foundMode = null;
if (activeModeName != null && configType.supportsMode(activeModeName)) {
foundMode = launchManager.getLaunchMode(activeModeName);
}
if (foundMode == null && configType.supportsMode("debug")) {
foundMode = launchManager.getLaunchMode("debug");
}
if (foundMode == null && configType.supportsMode("run")) {
foundMode = launchManager.getLaunchMode("run");
}
setActiveLaunchMode(foundMode);
}
@Override
public void addLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc) throws CoreException {
configDescs.put(configDesc.getName(), configDesc);
setActiveLaunchConfigurationDescriptor(configDesc);
}
public ILaunchMode[] getLaunchModes() throws CoreException {
ILaunchConfigurationType configType = getLaunchConfigurationType(activeLaunchDesc, activeLaunchTarget);
if (configType == null)
return new ILaunchMode[0];
@Override
public void removeLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc) {
configDescs.remove(configDesc.getName());
// Fix up the active config if this one was it
if (activeConfigDesc.equals(configDesc)) {
try {
if (configDescs.isEmpty()) {
setActiveLaunchConfigurationDescriptor(null);
} else if (lastConfigDesc != null) {
setActiveLaunchConfigurationDescriptor(lastConfigDesc);
// Clear out the last desc since we just used it
lastConfigDesc = null;
} else {
setActiveLaunchConfigurationDescriptor(configDescs.values().iterator().next());
}
} catch (CoreException e) {
// TODO log
e.printStackTrace();
List<ILaunchMode> modeList = new ArrayList<>();
ILaunchMode[] modes = DebugPlugin.getDefault().getLaunchManager().getLaunchModes();
for (ILaunchMode mode : modes) {
if (configType.supportsMode(mode.getIdentifier())) {
modeList.add(mode);
}
}
return modeList.toArray(new ILaunchMode[modeList.size()]);
}
@Override
@ -320,10 +323,13 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
return;
activeLaunchMode = mode;
if (activeConfigDesc == null)
for (Listener listener : listeners)
listener.activeLaunchModeChanged();
if (activeLaunchDesc == null)
return;
Preferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).node(activeConfigDesc.getName());
Preferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).node(activeLaunchDesc.getName());
if (mode != null) {
store.put(PREF_ACTIVE_LAUNCH_MODE, mode.getIdentifier());
} else {
@ -335,10 +341,27 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
// TODO log
e.printStackTrace();
}
}
activeConfigDesc.setActiveLaunchMode(mode);
for (Listener listener : listeners)
listener.activeLaunchModeChanged();
@Override
public ILaunchTarget[] getLaunchTargets() {
if (activeLaunchDesc == null)
return new ILaunchTarget[0];
List<ILaunchTarget> targetList = new ArrayList<>();
Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(activeLaunchDesc.getType().getId());
if (targetMap != null) {
for (String id : targetMap.keySet()) {
ILaunchTargetType type = targetTypes.get(id);
if (type != null) {
ILaunchTarget[] targets = type.getTargets();
for (ILaunchTarget target : targets) {
targetList.add(target);
}
}
}
}
return targetList.toArray(new ILaunchTarget[targetList.size()]);
}
@Override
@ -349,13 +372,16 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
@Override
public void setActiveLaunchTarget(ILaunchTarget target) {
if (activeLaunchTarget == target) return;
activeLaunchTarget = target;
if (activeConfigDesc == null)
for (Listener listener : listeners)
listener.activeLaunchTargetChanged();
if (activeLaunchDesc == null)
return;
Preferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).node(activeConfigDesc.getName());
Preferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).node(activeLaunchDesc.getName());
if (target != null) {
store.put(PREF_ACTIVE_LAUNCH_TARGET, target.getId());
} else {
@ -368,25 +394,51 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
e.printStackTrace();
}
activeConfigDesc.setActiveLaunchTarget(target);
for (Listener listener : listeners)
listener.activeLaunchTargetChanged();
}
public LocalTarget getLocalLaunchTarget() {
return localLaunchTarget;
}
@Override
public void addLaunchTarget(ILaunchTarget target) {
// TODO Auto-generated method stub
target.setActive();
}
@Override
public void removeLaunchTarget(ILaunchTarget target) {
// TODO Auto-generated method stub
public ILaunchTarget getLaunchTarget(String id) {
for (ILaunchTargetType type : targetTypes.values()) {
ILaunchTarget target = type.getTarget(id);
if (target != null)
return target;
}
return null;
}
@Override
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException {
if (descriptor == null)
return null;
String descriptorTypeId = descriptor.getType().getId();
Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(descriptorTypeId);
if (targetMap != null) {
String targetTypeId = target != null ? target.getType().getId() : defaultTargetTypes.get(descriptorTypeId);
if (targetTypeId != null) {
ILaunchConfigurationProvider configProvider = targetMap.get(targetTypeId);
if (configProvider != null) {
return configProvider.getLaunchConfigurationType(descriptor);
}
}
}
return null;
}
@Override
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException {
if (activeLaunchDesc == null)
return null;
Map<String, ILaunchConfigurationProvider> targetMap = configProviders.get(descriptor.getType().getId());
if (targetMap != null) {
ILaunchConfigurationProvider configProvider = targetMap.get(target.getType().getId());
if (configProvider != null) {
return configProvider.getLaunchConfiguration(descriptor);
}
}
return null;
}
@Override
@ -399,4 +451,39 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
listeners.remove(listener);
}
@Override
public void launchConfigurationAdded(ILaunchConfiguration configuration) {
try {
boolean owned = false;
// TODO filter by launch configuration type
for (Map<String, ILaunchConfigurationProvider> targetMap : configProviders.values()) {
for (ILaunchConfigurationProvider configProvider : targetMap.values()) {
if (configProvider.ownsLaunchConfiguration(configuration)) {
owned = true;
break;
}
}
}
if (!owned) {
launchObjectAdded(configuration);
}
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
@Override
public void launchConfigurationChanged(ILaunchConfiguration configuration) {
// TODO Auto-generated method stub
}
@Override
public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
// TODO Auto-generated method stub
}
}

View file

@ -11,19 +11,35 @@
package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.core.ILaunchTargetType;
public class LocalTarget implements ILaunchTarget {
public static final String ID = "org.eclipse.cdt.local";
private final LocalTargetType type;
public LocalTarget(LocalTargetType type) {
this.type = type;
}
@Override
public String getId() {
return ID;
// Use the same ID as the type since we're really a singleton
return type.getId();
}
@Override
public String getName() {
return "Local Machine"; // TODO externalize
}
@Override
public ILaunchTargetType getType() {
return type;
}
@Override
public void setActive() {
// nothing to do
}
}

View file

@ -0,0 +1,34 @@
package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.core.ILaunchTargetType;
public class LocalTargetType implements ILaunchTargetType {
public static final String ID = "org.eclipse.cdt.launchbar.core.target.local";
private LocalTarget localTarget;
@Override
public void init(ILaunchBarManager manager) {
localTarget = new LocalTarget(this);
}
@Override
public String getId() {
return ID;
}
@Override
public ILaunchTarget[] getTargets() {
return new ILaunchTarget[] { localTarget };
}
@Override
public ILaunchTarget getTarget(String id) {
if (ID.equals(id))
return localTarget;
return null;
}
}

View file

@ -0,0 +1,67 @@
package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchObjectProvider;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
public class ProjectLaunchObjectProvider implements ILaunchObjectProvider, IResourceChangeListener {
private ILaunchBarManager manager;
@Override
public void init(ILaunchBarManager manager) {
this.manager = manager;
try {
for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
manager.launchObjectAdded(project);
}
} catch (CoreException e) {
Activator.log(e.getStatus());
}
ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
}
@Override
public void dispose() {
ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
}
@Override
public void resourceChanged(IResourceChangeEvent event) {
try {
event.getDelta().accept(new IResourceDeltaVisitor() {
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
IResource res = delta.getResource();
if (res instanceof IProject) {
IProject project = (IProject) delta.getResource();
int kind = delta.getKind();
if ((kind & IResourceDelta.ADDED) != 0) {
manager.launchObjectAdded(project);
} else if ((kind & IResourceDelta.REMOVED) != 0) {
manager.launchObjectRemoved(project);
}
return false;
} else if (res instanceof IFile || res instanceof IFolder) {
return false;
}
return true;
}
});
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
}

View file

@ -19,3 +19,4 @@ Require-Bundle: org.eclipse.ui,
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
Export-Package: org.eclipse.cdt.launchbar.ui

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension-point id="launchBarUIContributions" name="launchBar UI Contributions" schema="schema/launchBarUIContributions.exsd"/>
<extension
id="launchBarInjector"
point="org.eclipse.e4.workbench.model">
@ -58,5 +59,16 @@
name="Launch Bar">
</page>
</extension>
<extension
point="org.eclipse.cdt.launchbar.ui.launchBarUIContributions">
<descriptorUI
descriptorTypeId="org.eclipse.cdt.launchbar.core.descriptor.default"
labelProvider="org.eclipse.cdt.launchbar.ui.internal.DefaultDescriptorLabelProvider">
</descriptorUI>
<targetUI
labelProvider="org.eclipse.cdt.launchbar.ui.internal.LocalTargetLabelProvider"
targetTypeId="org.eclipse.cdt.launchbar.core.target.local">
</targetUI>
</extension>
</plugin>

View file

@ -0,0 +1,168 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.cdt.launchbar.ui" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="org.eclipse.cdt.launchbar.ui" id="launchBarUIContributions" name="launchBar UI Contributions"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence minOccurs="0" maxOccurs="unbounded">
<element ref="descriptorUI"/>
<element ref="targetUI"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="descriptorUI">
<complexType>
<attribute name="descriptorTypeId" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="identifier" basedOn="org.eclipse.cdt.launchbar.core.launchBarContributions/descriptorType/@id"/>
</appinfo>
</annotation>
</attribute>
<attribute name="labelProvider" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.jface.viewers.ILabelProvider"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="targetUI">
<complexType>
<attribute name="targetTypeId" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="identifier" basedOn="org.eclipse.cdt.launchbar.core.launchBarContributions/targetType/@id"/>
</appinfo>
</annotation>
</attribute>
<attribute name="labelProvider" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.jface.viewers.ILabelProvider"/>
</appinfo>
</annotation>
</attribute>
<attribute name="hoverProvider" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.cdt.launchbar.ui.IHoverProvider"/>
</appinfo>
</annotation>
</attribute>
<attribute name="editCommandId" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="identifier" basedOn="org.eclipse.ui.commands/command/@id"/>
</appinfo>
</annotation>
</attribute>
<attribute name="addNewTargetCommandId" type="string">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="identifier" basedOn="org.eclipse.ui.commands/command/@id"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>

View file

@ -12,6 +12,9 @@ package org.eclipse.cdt.launchbar.ui;
public interface ILaunchBarUIConstants {
/**
* Parameter name for the edit target command.
*/
public static final String TARGET_NAME = "targetName";
}

View file

@ -125,11 +125,13 @@ public class Activator extends AbstractUIPlugin {
}
}
public static void log(CoreException e) {
plugin.getLog().log(e.getStatus());
public static void log(IStatus status) {
plugin.getLog().log(status);
}
public static void log(Exception e) {
if (e instanceof CoreException)
log(((CoreException) e).getStatus());
plugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e));
}

View file

@ -0,0 +1,60 @@
package org.eclipse.cdt.launchbar.ui.internal;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
public class DefaultDescriptorLabelProvider extends LabelProvider {
private Map<ImageDescriptor, Image> images = new HashMap<>();
@Override
public void dispose() {
super.dispose();
for (Image image : images.values()) {
image.dispose();
}
}
@Override
public Image getImage(Object element) {
if (element instanceof ILaunchDescriptor) {
try {
ILaunchDescriptor desc = (ILaunchDescriptor) element;
ILaunchBarManager manager = desc.getType().getManager();
ILaunchTarget target = manager.getActiveLaunchTarget();
ILaunchConfigurationType type = manager.getLaunchConfigurationType(desc, target);
ImageDescriptor imageDescriptor = DebugUITools.getDefaultImageDescriptor(type);
if (imageDescriptor != null) {
Image image = images.get(imageDescriptor);
if (image == null) {
image = imageDescriptor.createImage();
images.put(imageDescriptor, image);
}
return image;
}
} catch (CoreException e) {
Activator.log(e);
}
}
return super.getImage(element);
}
@Override
public String getText(Object element) {
if (element instanceof ILaunchDescriptor) {
return ((ILaunchDescriptor) element).getName();
}
return super.getText(element);
}
}

View file

@ -10,46 +10,95 @@
*******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.core.ILaunchTargetType;
import org.eclipse.cdt.launchbar.core.internal.Activator;
import org.eclipse.cdt.launchbar.ui.IHoverProvider;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.viewers.ILabelProvider;
public class LaunchBarUIManager {
ILaunchBarManager manager;
Map<String, ILabelProvider> descriptorLabelProviders = new HashMap<>();
Map<String, ILabelProvider> targetLabelProviders = new HashMap<>();
Map<String, IHoverProvider> targetHoverProviders = new HashMap<>();
Map<String, String> targetEditCommandIds = new HashMap<>();
Map<String, String> targetAddNewCommandIds = new HashMap<>();
public LaunchBarUIManager(ILaunchBarManager manager) {
this.manager = manager;
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchBarContributions");
IExtension[] extensions = point.getExtensions();
for (IExtension extension : extensions) {
for (IConfigurationElement element : extension.getConfigurationElements()) {
String elementName = element.getName();
if (elementName.equals("descriptorUI")) {
try {
String descriptorTypeId = element.getAttribute("descriptorTypeId");
ILabelProvider labelProvider = (ILabelProvider) element.createExecutableExtension("labelProvider");
descriptorLabelProviders.put(descriptorTypeId, labelProvider);
} catch (CoreException e) {
Activator.log(e.getStatus());
}
} else if (elementName.equals("targetUI")) {
try {
String targetTypeId = element.getAttribute("targetTypeId");
ILabelProvider labelProvider = (ILabelProvider) element.createExecutableExtension("labelProvider");
targetLabelProviders.put(targetTypeId, labelProvider);
IHoverProvider hoverProvider = (IHoverProvider) element.createExecutableExtension("hoverProvider");
if (hoverProvider != null)
targetHoverProviders.put(targetTypeId, hoverProvider);
String editCommandId = element.getAttribute("editCommandId");
if (editCommandId != null && editCommandId.length() > 0)
targetEditCommandIds.put(targetTypeId, editCommandId);
String addNewCommandId = element.getAttribute("addNewTargetCommandId");
if (addNewCommandId != null && addNewCommandId.length() > 0)
targetAddNewCommandIds.put(targetTypeId, addNewCommandId);
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
}
}
}
public ILaunchBarManager getManager() {
return manager;
}
public ILabelProvider getLabelProvider(ILaunchConfigurationDescriptor configDesc) {
// TODO
return null;
public ILabelProvider getLabelProvider(ILaunchDescriptor descriptor) {
return descriptorLabelProviders.get(descriptor.getType().getId());
}
public ILabelProvider getLabelProvider(ILaunchTarget target) {
// TODO
return null;
}
public String getEditCommand(ILaunchTarget target) {
// TODO
return null;
return targetLabelProviders.get(target.getType().getId());
}
public IHoverProvider getHoverProvider(ILaunchTarget target) {
// TODO
return null;
return targetHoverProviders.get(target.getType().getId());
}
public String getAddTargetCommand(ILaunchConfigurationDescriptor configDesc) {
// TODO
return null;
public String getEditCommand(ILaunchTarget target) {
return targetEditCommandIds.get(target.getType().getId());
}
public String getAddTargetCommand(ILaunchTargetType targetType) {
return targetAddNewCommandIds.get(targetType.getId());
}
}

View file

@ -0,0 +1,16 @@
package org.eclipse.cdt.launchbar.ui.internal;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.jface.viewers.LabelProvider;
public class LocalTargetLabelProvider extends LabelProvider {
@Override
public String getText(Object element) {
if (element instanceof ILaunchTarget) {
return ((ILaunchTarget) element).getName();
}
return super.getText(element);
}
}

View file

@ -16,7 +16,8 @@ import java.util.HashSet;
import java.util.Set;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
@ -31,7 +32,6 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchDelegate;
import org.eclipse.debug.core.ILaunchMode;
@ -60,70 +60,60 @@ public class BuildActiveCommandHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
new UIJob(Display.getDefault(), "Building Active Configuration") {
@Override
public boolean belongsTo(Object family) {
return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family);
}
public IStatus runInUIThread(IProgressMonitor monitor) {
final ILaunchConfigurationDescriptor desc = launchBarManager.getActiveLaunchConfigurationDescriptor();
try {
ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor();
ILaunchTarget target = launchBarManager.getActiveLaunchTarget();
ILaunchConfiguration config = launchBarManager.getLaunchConfiguration(desc, target);
if (desc == null) {
// popout - No launch configuration
// showConfigurationErrorCallOut(NLS.bind("{0}\n{1}", Messages.RunActiveCommandHandler_No_Launch_Configuration_Selected,
// Messages.RunActiveCommandHanlder_Create_Launch_Configuration));
}
new Job("Building Active Configuration") {
@Override
public boolean belongsTo(Object family) {
return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family);
}
protected IStatus run(IProgressMonitor monitor) {
try {
if (desc == null) {
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
return Status.OK_STATUS;
}
ILaunchMode launchMode = launchBarManager.getActiveLaunchMode();
ILaunchConfiguration config = desc.getLaunchConfiguration();
Collection<IProject> projects = getProjects(config);
if (BuildAction.isSaveAllSet()) {
saveEditors(projects);
}
String mode = launchMode.getIdentifier();
Set<String> modes = new HashSet<>();
modes.add(mode);
ILaunchDelegate delegate = config.getType().getPreferredDelegate(modes);
if (delegate == null)
delegate = config.getType().getDelegates(modes)[0];
ILaunchConfigurationDelegate configDel = delegate.getDelegate();
if (configDel instanceof ILaunchConfigurationDelegate2) {
ILaunchConfigurationDelegate2 configDel2 = (ILaunchConfigurationDelegate2)configDel;
boolean ret;
ret = configDel2.preLaunchCheck(config, mode, monitor);
if (!ret)
return Status.CANCEL_STATUS;
if (!configDel2.buildForLaunch(config, mode, monitor))
return Status.OK_STATUS;
}
// Fall through, do a normal build
if (projects.isEmpty()) {
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
} else {
Collection<IBuildConfiguration> buildConfigs = getBuildConfigs(projects);
ResourcesPlugin.getWorkspace().build(buildConfigs.toArray(new IBuildConfiguration[buildConfigs.size()]),
IncrementalProjectBuilder.INCREMENTAL_BUILD, true, monitor);
// TODO, may need to get the buildReferences argument from the descriptor
}
} catch (CoreException e) {
return e.getStatus();
}
if (config == null) {
// Default, build the workspace
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
return Status.OK_STATUS;
}
}.schedule();
ILaunchMode launchMode = launchBarManager.getActiveLaunchMode();
Collection<IProject> projects = getProjects(config);
if (BuildAction.isSaveAllSet()) {
saveEditors(projects);
}
String mode = launchMode.getIdentifier();
Set<String> modes = new HashSet<>();
modes.add(mode);
ILaunchDelegate delegate = config.getType().getPreferredDelegate(modes);
if (delegate == null)
delegate = config.getType().getDelegates(modes)[0];
ILaunchConfigurationDelegate configDel = delegate.getDelegate();
if (configDel instanceof ILaunchConfigurationDelegate2) {
ILaunchConfigurationDelegate2 configDel2 = (ILaunchConfigurationDelegate2)configDel;
boolean ret;
ret = configDel2.preLaunchCheck(config, mode, monitor);
if (!ret)
return Status.CANCEL_STATUS;
if (!configDel2.buildForLaunch(config, mode, monitor))
return Status.OK_STATUS;
}
// Fall through, do a normal build
if (projects.isEmpty()) {
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
} else {
Collection<IBuildConfiguration> buildConfigs = getBuildConfigs(projects);
ResourcesPlugin.getWorkspace().build(buildConfigs.toArray(new IBuildConfiguration[buildConfigs.size()]),
IncrementalProjectBuilder.INCREMENTAL_BUILD, true, monitor);
// TODO, may need to get the buildReferences argument from the descriptor
}
} catch (CoreException e) {
return e.getStatus();
}
return Status.OK_STATUS;
};
}.schedule();

View file

@ -11,7 +11,8 @@
package org.eclipse.cdt.launchbar.ui.internal.commands;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
@ -37,22 +38,15 @@ public class ConfigureActiveLaunchHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ILaunchConfigurationDescriptor activeLaunchConfiguration = launchBarManager.getActiveLaunchConfigurationDescriptor();
ILaunchMode activeLaunchMode = launchBarManager.getActiveLaunchMode();
if (activeLaunchConfiguration == null)
return Status.OK_STATUS;
ILaunchConfiguration launchConfiguration;
try {
launchConfiguration = activeLaunchConfiguration.getLaunchConfiguration();
} catch (CoreException e1) {
return e1.getStatus();
}
try {
ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor();
ILaunchTarget target = launchBarManager.getActiveLaunchTarget();
ILaunchConfiguration launchConfiguration = launchBarManager.getLaunchConfiguration(desc, target);
if (launchConfiguration == null)
return Status.OK_STATUS;
ILaunchConfigurationWorkingCopy wc = launchConfiguration.getWorkingCopy();
// TODO, gah, this is internal. Get it added to DebugUIUtil
ILaunchMode activeLaunchMode = launchBarManager.getActiveLaunchMode();
ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(launchConfiguration.getType(), activeLaunchMode.getIdentifier());
if (DebugUITools.openLaunchConfigurationPropertiesDialog(HandlerUtil.getActiveShell(event), wc, group.getIdentifier()) == Window.OK)
@ -60,11 +54,6 @@ public class ConfigureActiveLaunchHandler extends AbstractHandler {
} catch (CoreException e) {
return e.getStatus();
}
return Status.OK_STATUS;
}
protected String getMode() {
return "config"; //$NON-NLS-1$
}
}

View file

@ -11,7 +11,7 @@
package org.eclipse.cdt.launchbar.ui.internal.commands;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.core.commands.AbstractHandler;
@ -21,50 +21,32 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.progress.UIJob;
public class LaunchActiveCommandHandler extends AbstractHandler {
private final ILaunchBarManager launchBarManager;
public LaunchActiveCommandHandler() {
launchBarManager = Activator.getService(ILaunchBarManager.class);
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
new UIJob(Display.getDefault(), "Launching Active Configuration") {
public IStatus runInUIThread(IProgressMonitor monitor) {
try {
ILaunchConfigurationDescriptor desc = launchBarManager.getActiveLaunchConfigurationDescriptor();
if (desc == null) {
// popout - No launch configuration
// showConfigurationErrorCallOut(NLS.bind("{0}\n{1}", Messages.RunActiveCommandHandler_No_Launch_Configuration_Selected,
// Messages.RunActiveCommandHanlder_Create_Launch_Configuration));
return Status.OK_STATUS;
}
ILaunchMode launchMode = launchBarManager.getActiveLaunchMode();
ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor();
ILaunchTarget target = launchBarManager.getActiveLaunchTarget();
if (target == null) {
// popout - No target
// if (TargetCorePlugin.getDefault().getTargetRegistry().getTargets().length == 1) {
// showTargetErrorCallOut(NLS.bind("{0}{1}", Messages.RunActiveCommandHandler_Cannot, getMode(launchMode)),
// DeviceErrors.Error.NO_DEVICES, Messages.RunActiveCommandHandler_Select_Manage_Devices);
// } else { // Don't think this can occur. Leaving just in case.
// showTargetErrorCallOut(NLS.bind("{0}{1}", Messages.RunActiveCommandHandler_Cannot, getMode(launchMode)),
// DeviceErrors.Error.NO_ACTIVE, Messages.RunActiveCommandHandler_Select_Device_Or_Simulator);
// }
ILaunchConfiguration config = launchBarManager.getLaunchConfiguration(desc, target);
if (config == null)
return Status.OK_STATUS;
}
DebugUITools.launch(desc.getLaunchConfiguration(), launchMode.getIdentifier());
ILaunchMode launchMode = launchBarManager.getActiveLaunchMode();
DebugUITools.launch(config, launchMode.getIdentifier());
} catch (CoreException e) {
return e.getStatus();
}
@ -75,24 +57,6 @@ public class LaunchActiveCommandHandler extends AbstractHandler {
return Status.OK_STATUS;
}
protected void showConfigurationErrorCallOut(final String error) {
// Control activeProjectControl = LaunchToolBar.getInstance().getActiveConfigurationControl();
// showErrorToolTipOnControl(error, activeProjectControl);
}
// protected void showTargetErrorCallOut(final String title, DeviceErrors.Error e, String action) {
// Control activeTargetControl = LaunchToolBar.getInstance().getActiveTargetControl();
// DeviceErrors.showCallOutErrorOnControl(activeTargetControl, title, e, action);
// }
public static void showErrorToolTipOnControl(final String error, Control activeProjectControl) {
// CalloutError tip = new CalloutError();
// tip.setTarget(activeProjectControl);
// tip.setHook(Position.BOTTOM_CENTER, Position.TOP_CENTER, new Point(0, 0));
// tip.setData(error);
// tip.show();
}
protected String getMode(ILaunchMode launchMode) {
return launchMode.getIdentifier(); //$NON-NLS-1$
}

View file

@ -11,13 +11,11 @@
package org.eclipse.cdt.launchbar.ui.internal.commands;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@ -26,7 +24,6 @@ import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
public class StopActiveCommandHandler extends AbstractHandler {
private ILaunchBarManager launchBarManager;
@ -47,39 +44,25 @@ public class StopActiveCommandHandler extends AbstractHandler {
}
protected void stopActiveLaunches() {
ILaunch[] activeLaunches = DebugPlugin.getDefault().getLaunchManager().getLaunches();
ILaunchConfigurationDescriptor desc = launchBarManager.getActiveLaunchConfigurationDescriptor();
ILaunchConfiguration activeLaunchConfiguration;
try {
activeLaunchConfiguration = desc.getLaunchConfiguration();
} catch (CoreException e) {
Activator.log(e);
return;
}
for (int i = 0; i < activeLaunches.length; i++) {
final ILaunch launch = activeLaunches[i];
if (!launch.isTerminated() && activeLaunchConfiguration != null
&& matches(activeLaunchConfiguration, launch.getLaunchConfiguration())) {
Job job = new Job("Stopping " + activeLaunchConfiguration.getName()) {
@Override
protected IStatus run(IProgressMonitor monitor) {
final ILaunch[] activeLaunches = DebugPlugin.getDefault().getLaunchManager().getLaunches();
if (activeLaunches != null && activeLaunches.length > 0) {
new Job("Stopping launches") {
protected IStatus run(IProgressMonitor monitor) {
// TODO only stop the launches for the active launch descriptor
// Not sure we have the API to map that out yet.
for (ILaunch launch : activeLaunches) {
try {
launch.terminate();
} catch (DebugException e) {
Activator.log(e);
return e.getStatus();
}
return Status.OK_STATUS;
}
return Status.OK_STATUS;
};
job.schedule();
}
}.schedule();
}
}
protected boolean matches(ILaunchConfiguration activeLaunchConfiguration, ILaunchConfiguration launchConfiguration) {
return activeLaunchConfiguration.getName().equals(launchConfiguration.getName()); // just name for now
}
protected void stopBuild() {
Job job = new Job("Stopping build") {
@Override

View file

@ -11,12 +11,10 @@
package org.eclipse.cdt.launchbar.ui.internal.controls;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.internal.DefaultLaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager;
import org.eclipse.cdt.launchbar.ui.internal.dialogs.LaunchConfigurationEditDialog;
@ -26,13 +24,12 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.ILaunchGroup;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
@ -78,58 +75,35 @@ public class ConfigSelector extends CSelector {
}
@Override
public Object[] getElements(Object inputElement) {
ILaunchConfigurationDescriptor[] descs = getManager().getLaunchConfigurationDescriptors();
if (descs.length > 0)
return descs;
try {
ILaunchDescriptor[] descs = getManager().getLaunchDescriptors();
if (descs.length > 0)
return descs;
} catch (CoreException e) {
Activator.log(e.getStatus());
}
return noConfigs;
}
});
setLabelProvider(new LabelProvider() {
private Map<ImageDescriptor, Image> images = new HashMap<>();
@Override
public void dispose() {
super.dispose();
for (Image image : images.values()) {
image.dispose();
}
}
@Override
public Image getImage(Object element) {
if (element instanceof ILaunchConfigurationDescriptor) {
ILaunchConfigurationDescriptor configDesc = (ILaunchConfigurationDescriptor)element;
if (element instanceof ILaunchDescriptor) {
ILaunchDescriptor configDesc = (ILaunchDescriptor)element;
ILabelProvider labelProvider = uiManager.getLabelProvider(configDesc);
if (labelProvider != null) {
return labelProvider.getImage(element);
}
// Default
if (element instanceof DefaultLaunchConfigurationDescriptor) {
try {
ILaunchConfigurationType type = configDesc.getLaunchConfiguration().getType();
ImageDescriptor imageDescriptor = DebugUITools.getDefaultImageDescriptor(type);
if (imageDescriptor != null) {
Image image = images.get(imageDescriptor);
if (image == null) {
image = imageDescriptor.createImage();
images.put(imageDescriptor, image);
}
return image;
}
} catch (CoreException e) {
Activator.log(e);
}
}
}
// Default
return null;
return super.getImage(element);
}
@Override
public String getText(Object element) {
if (element instanceof String) {
return (String)element;
} else if (element instanceof ILaunchConfigurationDescriptor) {
ILaunchConfigurationDescriptor configDesc = (ILaunchConfigurationDescriptor)element;
} else if (element instanceof ILaunchDescriptor) {
ILaunchDescriptor configDesc = (ILaunchDescriptor)element;
ILabelProvider labelProvider = uiManager.getLabelProvider(configDesc);
if (labelProvider != null) {
return labelProvider.getText(element);
@ -137,8 +111,7 @@ public class ConfigSelector extends CSelector {
// Default
return configDesc.getName();
}
return null;
return super.getText(element);
}
});
@ -155,10 +128,10 @@ public class ConfigSelector extends CSelector {
@Override
protected void fireSelectionChanged() {
Object selected = getSelection();
if (selected instanceof ILaunchConfigurationDescriptor) {
ILaunchConfigurationDescriptor configDesc = (ILaunchConfigurationDescriptor) selected;
if (selected instanceof ILaunchDescriptor) {
ILaunchDescriptor configDesc = (ILaunchDescriptor) selected;
try {
getManager().setActiveLaunchConfigurationDescriptor(configDesc);
getManager().setActiveLaunchDescriptor(configDesc);
} catch (CoreException e) {
Activator.log(e);
}
@ -167,20 +140,22 @@ public class ConfigSelector extends CSelector {
@Override
public boolean isEditable(Object element) {
return element instanceof ILaunchConfigurationDescriptor;
return element instanceof ILaunchDescriptor;
}
@Override
public void handleEdit(Object element) {
try {
ILaunchConfigurationDescriptor config = (ILaunchConfigurationDescriptor) element;
ILaunchDescriptor desc = (ILaunchDescriptor) element;
ILaunchMode mode = getManager().getActiveLaunchMode();
ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager()
.getLaunchGroup(config.getLaunchConfiguration().getType(), mode.getIdentifier());
ILaunchTarget target = getManager().getActiveLaunchTarget();
ILaunchConfigurationType configType = getManager().getLaunchConfigurationType(desc, target);
ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(configType, mode.getIdentifier());
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
LaunchGroupExtension groupExt = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(group.getIdentifier());
if (groupExt != null) {
final LaunchConfigurationEditDialog dialog = new LaunchConfigurationEditDialog(shell, config.getLaunchConfiguration(), groupExt);
ILaunchConfiguration config = getManager().getLaunchConfiguration(desc, target);
final LaunchConfigurationEditDialog dialog = new LaunchConfigurationEditDialog(shell, config, groupExt);
dialog.setInitialStatus(Status.OK_STATUS);
dialog.open();
}

View file

@ -15,10 +15,11 @@ import javax.annotation.PreDestroy;
import javax.inject.Inject;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.cdt.launchbar.ui.internal.Messages;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
@ -80,14 +81,18 @@ public class LaunchBarControl implements ILaunchBarManager.Listener {
targetSelector.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
targetSelector.setInput(manager);
ILaunchConfigurationDescriptor configDesc = manager.getActiveLaunchConfigurationDescriptor();
configSelector.setSelection(configDesc == null ? null : configDesc);
ILaunchMode mode = manager.getActiveLaunchMode();
modeSelector.setSelection(mode == null ? null : mode);
ILaunchTarget target = manager.getActiveLaunchTarget();
targetSelector.setSelection(target == null ? null : target);
try {
ILaunchDescriptor configDesc = manager.getActiveLaunchDescriptor();
configSelector.setSelection(configDesc == null ? null : configDesc);
ILaunchMode mode = manager.getActiveLaunchMode();
modeSelector.setSelection(mode == null ? null : mode);
ILaunchTarget target = manager.getActiveLaunchTarget();
targetSelector.setSelection(target == null ? null : target);
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
@PreDestroy
@ -113,43 +118,61 @@ public class LaunchBarControl implements ILaunchBarManager.Listener {
@Override
public void activeConfigurationDescriptorChanged() {
if (configSelector != null && !configSelector.isDisposed()) {
final ILaunchConfigurationDescriptor configDesc = manager.getActiveLaunchConfigurationDescriptor();
configSelector.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (!configSelector.isDisposed())
configSelector.setSelection(configDesc == null ? null : configDesc);
}
});
try {
final ILaunchDescriptor configDesc = manager.getActiveLaunchDescriptor();
configSelector.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (!configSelector.isDisposed())
configSelector.setSelection(configDesc == null ? null : configDesc);
}
});
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
}
@Override
public void activeLaunchModeChanged() {
if (modeSelector != null && !modeSelector.isDisposed()) {
final ILaunchMode mode = manager.getActiveLaunchMode();
modeSelector.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (!modeSelector.isDisposed())
modeSelector.setSelection(mode == null ? null : mode);
}
});
try {
final ILaunchMode mode = manager.getActiveLaunchMode();
modeSelector.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (!modeSelector.isDisposed())
modeSelector.setSelection(mode == null ? null : mode);
}
});
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
}
@Override
public void activeLaunchTargetChanged() {
if (targetSelector != null && !targetSelector.isDisposed()) {
final ILaunchTarget target = manager.getActiveLaunchTarget();
targetSelector.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (!targetSelector.isDisposed())
targetSelector.setSelection(target == null ? null : target);
}
});
try {
final ILaunchTarget target = manager.getActiveLaunchTarget();
targetSelector.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (!targetSelector.isDisposed())
targetSelector.setSelection(target == null ? null : target);
}
});
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
}
@Override
public void launchDescriptorRemoved(ILaunchDescriptor descriptor) {
// TODO Auto-generated method stub
}
}

View file

@ -15,7 +15,6 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchMode;
@ -49,7 +48,7 @@ public class ModeSelector extends CSelector {
@Override
public Object[] getElements(Object inputElement) {
try {
ILaunchMode[] modes = getManager().getActiveLaunchConfigurationDescriptor().getLaunchModes();
ILaunchMode[] modes = getManager().getLaunchModes();
if (modes.length > 0)
return modes;
} catch (CoreException e) {
@ -70,8 +69,7 @@ public class ModeSelector extends CSelector {
}
@Override
public Image getImage(Object element) {
ILaunchConfigurationDescriptor config = getManager().getActiveLaunchConfigurationDescriptor();
if (config != null && element instanceof ILaunchMode) {
if (element instanceof ILaunchMode) {
ILaunchMode mode = (ILaunchMode) element;
ILaunchGroup group = getLaunchGroup(mode.getIdentifier());
if (group != null) {
@ -88,8 +86,7 @@ public class ModeSelector extends CSelector {
}
@Override
public String getText(Object element) {
ILaunchConfigurationDescriptor config = getManager().getActiveLaunchConfigurationDescriptor();
if (config != null && element instanceof ILaunchMode) {
if (element instanceof ILaunchMode) {
ILaunchMode mode = (ILaunchMode) element;
ILaunchGroup group = getLaunchGroup(mode.getIdentifier());
if (group != null) {
@ -147,7 +144,11 @@ public class ModeSelector extends CSelector {
Object selected = getSelection();
if (selected instanceof ILaunchMode) {
ILaunchMode mode = (ILaunchMode) selected;
getManager().setActiveLaunchMode(mode);
try {
getManager().setActiveLaunchMode(mode);
} catch (CoreException e) {
Activator.log(e);
}
}
}

View file

@ -18,14 +18,13 @@ import org.eclipse.cdt.launchbar.ui.IHoverProvider;
import org.eclipse.cdt.launchbar.ui.ILaunchBarUIConstants;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.PaintEvent;
@ -63,9 +62,13 @@ public class TargetSelector extends CSelector {
@Override
public Object[] getElements(Object inputElement) {
ILaunchTarget[] targets = getManager().getActiveLaunchConfigurationDescriptor().getLaunchTargets();
if (targets.length > 0)
return targets;
try {
ILaunchTarget[] targets = getManager().getLaunchTargets();
if (targets.length > 0)
return targets;
} catch (CoreException e) {
Activator.log(e.getStatus());
}
return noTargets;
}
});
@ -151,7 +154,10 @@ public class TargetSelector extends CSelector {
@Override
public boolean hasActionArea() {
return uiManager.getAddTargetCommand(getManager().getActiveLaunchConfigurationDescriptor()) != null;
// TODO need an add target command similar to the add configuration that allows the user
// to select the target type.
// return uiManager.getAddTargetCommand(getManager().getActiveLaunchDescriptor()) != null;
return false;
}
@Override
@ -184,15 +190,19 @@ public class TargetSelector extends CSelector {
createLabel.setText("Add New Target...");
createLabel.setBackground(white);
final String command = uiManager.getAddTargetCommand(getManager().getActiveLaunchConfigurationDescriptor());
MouseListener mouseListener = new MouseAdapter() {
public void mouseUp(org.eclipse.swt.events.MouseEvent e) {
Activator.runCommand(command);
}
};
createButton.addMouseListener(mouseListener);
createLabel.addMouseListener(mouseListener);
// try {
// final String command = uiManager.getAddTargetCommand(getManager().getActiveLaunchDescriptor());
// MouseListener mouseListener = new MouseAdapter() {
// public void mouseUp(org.eclipse.swt.events.MouseEvent e) {
// Activator.runCommand(command);
// }
// };
//
// createButton.addMouseListener(mouseListener);
// createLabel.addMouseListener(mouseListener);
// } catch (CoreException e) {
// Activator.log(e.getStatus());
// }
MouseTrackListener mouseTrackListener = new MouseTrackAdapter() {
@Override
@ -216,7 +226,11 @@ public class TargetSelector extends CSelector {
Object selection = getSelection();
if (selection instanceof ILaunchTarget) {
ILaunchTarget target = (ILaunchTarget) selection;
uiManager.getManager().setActiveLaunchTarget(target);
try {
uiManager.getManager().setActiveLaunchTarget(target);
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
}