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

Bug 437392: Major API changes to turn the Launch Bar Model a beauty

Pretty major changes but heavily reduce the size of the API. Check
out the ILaunchBarManager which now only supports providers. All other
methods are now for internal use by the UI plugin. Also change to the
model. The extension point has much more documentation now. Please see
it for an explanation. But essentially made launch configuration types
part of the model to make a nice cleaner bridge to the platform.

Also includes change to Launch Targets view to make it a common
navigator so different target types can add objects to the tree.

Also a number of changes to try and delay plug-in loading with the
providers.

Change-Id: Icdd300e99f831c84cd0a25a23410aa1cd2ccfd7c
Reviewed-on: https://git.eclipse.org/r/33061
Tested-by: Hudson CI
Reviewed-by: Doug Schaefer <dschaefer@qnx.com>
This commit is contained in:
Doug Schaefer 2014-09-01 12:50:11 -04:00
parent 1ffa0a9bb2
commit 63b9ba54f5
58 changed files with 2359 additions and 2799 deletions

View file

@ -4,21 +4,10 @@
<extension-point id="launchBarContributions" name="Launch Bar Contributions" schema="schema/launchBarContributions.exsd"/> <extension-point id="launchBarContributions" name="Launch Bar Contributions" schema="schema/launchBarContributions.exsd"/>
<extension <extension
point="org.eclipse.cdt.launchbar.core.launchBarContributions"> 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 <targetType
class="org.eclipse.cdt.launchbar.core.internal.LocalTargetType" class="org.eclipse.cdt.launchbar.core.internal.LocalTargetType"
id="org.eclipse.cdt.launchbar.core.target.local"> id="org.eclipse.cdt.launchbar.core.targetType.local">
</targetType> </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 <objectProvider
class="org.eclipse.cdt.launchbar.core.internal.ProjectLaunchObjectProvider" class="org.eclipse.cdt.launchbar.core.internal.ProjectLaunchObjectProvider"
id="org.eclipse.cdt.launchbar.core.objectProvider.project"> id="org.eclipse.cdt.launchbar.core.objectProvider.project">

View file

@ -20,8 +20,10 @@
<sequence minOccurs="0" maxOccurs="unbounded"> <sequence minOccurs="0" maxOccurs="unbounded">
<element ref="descriptorType"/> <element ref="descriptorType"/>
<element ref="targetType"/> <element ref="targetType"/>
<element ref="configType"/>
<element ref="configProvider"/> <element ref="configProvider"/>
<element ref="objectProvider"/> <element ref="objectProvider"/>
<element ref="defaultConfigTarget"/>
</sequence> </sequence>
<attribute name="point" type="string" use="required"> <attribute name="point" type="string" use="required">
<annotation> <annotation>
@ -51,6 +53,11 @@
</element> </element>
<element name="descriptorType"> <element name="descriptorType">
<annotation>
<documentation>
A descriptor represents an object that can be converted into a launch configuration. The typical example is IProject. Launch configurations can be created that launch the build output of the project.
</documentation>
</annotation>
<complexType> <complexType>
<attribute name="id" type="string" use="required"> <attribute name="id" type="string" use="required">
<annotation> <annotation>
@ -80,6 +87,11 @@
</element> </element>
<element name="targetType"> <element name="targetType">
<annotation>
<documentation>
A target is the machine you launch on. Typical examples include the local machine we are running on, or remote embedded or server targets.
</documentation>
</annotation>
<complexType> <complexType>
<attribute name="id" type="string" use="required"> <attribute name="id" type="string" use="required">
<annotation> <annotation>
@ -101,7 +113,12 @@
</complexType> </complexType>
</element> </element>
<element name="configProvider"> <element name="configType">
<annotation>
<documentation>
Descriptor types and target types map to a launch configuration type. Configurations of that type knows how to launch for the desciptor on targets of that type.
</documentation>
</annotation>
<complexType> <complexType>
<attribute name="descriptorType" type="string" use="required"> <attribute name="descriptorType" type="string" use="required">
<annotation> <annotation>
@ -123,13 +140,13 @@
</appinfo> </appinfo>
</annotation> </annotation>
</attribute> </attribute>
<attribute name="class" type="string" use="required"> <attribute name="launchConfigurationType" type="string" use="required">
<annotation> <annotation>
<documentation> <documentation>
</documentation> </documentation>
<appinfo> <appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.cdt.launchbar.core.ILaunchConfigurationProvider"/> <meta.attribute kind="identifier" basedOn="org.eclipse.debug.core.launchConfigurationTypes/launchConfigurationType/@id"/>
</appinfo> </appinfo>
</annotation> </annotation>
</attribute> </attribute>
@ -143,11 +160,10 @@
</complexType> </complexType>
</element> </element>
<element name="defaultConfigProvider"> <element name="configProvider">
<annotation> <annotation>
<documentation> <documentation>
default provider provides direct mapping between launch configuration types The config provider knows how to create launch configurations from descriptors. It tracks which configs it has created so that they don&apos;t show up as descriptors on their own.
and launch objects/types without any extra classes involved. The object for this provider is launch configuration, and descriptor is DefaultLaunchDescriptor
</documentation> </documentation>
</annotation> </annotation>
<complexType> <complexType>
@ -161,13 +177,33 @@ and launch objects/types without any extra classes involved. The object for this
</appinfo> </appinfo>
</annotation> </annotation>
</attribute> </attribute>
<attribute name="descriptorType" type="string"> <attribute name="class" type="string" use="required">
<annotation> <annotation>
<documentation> <documentation>
</documentation> </documentation>
<appinfo> <appinfo>
<meta.attribute kind="identifier" basedOn="org.eclipse.cdt.launchbar.core.launchBarContributions/descriptorType/@id"/> <meta.attribute kind="java" basedOn=":org.eclipse.cdt.launchbar.core.ILaunchConfigurationProvider"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<element name="defaultConfigTarget">
<annotation>
<documentation>
The default config provider is brought in when no other config providers claim a given launch configuration. This entry associates a target type with the launch configuration so that it can be launched on targets of that type.
</documentation>
</annotation>
<complexType>
<attribute name="launchConfigurationType" type="string" use="required">
<annotation>
<documentation>
</documentation>
<appinfo>
<meta.attribute kind="identifier" basedOn="org.eclipse.debug.core.launchConfigurationTypes/launchConfigurationType/@id"/>
</appinfo> </appinfo>
</annotation> </annotation>
</attribute> </attribute>
@ -192,6 +228,11 @@ and launch objects/types without any extra classes involved. The object for this
</element> </element>
<element name="objectProvider"> <element name="objectProvider">
<annotation>
<documentation>
Object providers pump launch objects into the model as they are created and removed. These are used to create descriptors for these objects.
</documentation>
</annotation>
<complexType> <complexType>
<attribute name="id" type="string" use="required"> <attribute name="id" type="string" use="required">
<annotation> <annotation>

View file

@ -1,57 +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:
* Elena Laskavaia - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
/**
* Abstract launch descriptor type provide convenience methods to implement hashcode, equals and store lanch bar manager object. It
* is recommended to use this method instead of implementing interface
*/
public abstract class AbstarctLaunchDescriptorType implements ILaunchDescriptorType {
private ILaunchBarManager manager;
@Override
public abstract String getId();
@Override
public void init(ILaunchBarManager barmanager) {
this.manager = barmanager;
}
@Override
public ILaunchBarManager getManager() {
return manager;
}
@Override
public int hashCode() {
return 37 + getId().hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj.getClass().equals(getClass())))
return false;
ILaunchDescriptorType other = (ILaunchDescriptorType) obj;
if (!getId().equals(other.getId()))
return false;
return true;
}
@Override
public String toString() {
return getId();
}
}

View file

@ -1,48 +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:
* Elena Laskavaia - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
/**
* Abstract provider can work with any ILaunchDescriptorConfigBased to provide launch configurations
*/
public abstract class AbstractLaunchConfigurationProvider implements ILaunchConfigurationProvider {
protected ILaunchBarManager manager;
@Override
public void init(ILaunchBarManager manager) throws CoreException {
this.manager = manager;
}
public ILaunchBarManager getManager() {
return manager;
}
@Override
public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor) throws CoreException {
if (descriptor instanceof ILaunchDescriptorConfigBased) {
return ((ILaunchDescriptorConfigBased) descriptor).getLaunchConfiguration();
}
return null;
}
@Override
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor) throws CoreException {
if (descriptor instanceof ILaunchDescriptorConfigBased) {
return ((ILaunchDescriptorConfigBased) descriptor).getLaunchConfigurationType();
}
return null;
}
}

View file

@ -1,56 +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:
* Elena Laskavaia - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
/**
* Convenience implementation of ILaunchDescriptor
*/
public abstract class AbstractLaunchDescriptor implements ILaunchDescriptor {
private boolean open = true;
@Override
public abstract String getName();
@Override
public abstract ILaunchDescriptorType getType();
public String getId() {
return getName() + "." + getType().getId();
}
@Override
public int hashCode() {
return 17 + getId().hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof AbstractLaunchDescriptor))
return false;
AbstractLaunchDescriptor other = (AbstractLaunchDescriptor) obj;
if (!getId().equals(other.getId()))
return false;
return true;
}
@Override
public boolean isOpen() {
return open;
}
public void setOpen(boolean open) {
this.open = open;
}
}

View file

@ -1,59 +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:
* Elena Laskavaia - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
/**
* Convenience implementation of ILaunchTarget, provides hooks for id, and equals and hashcode methods based on id.
*/
public abstract class AbstractLaunchTarget implements ILaunchTarget {
private final String id;
public AbstractLaunchTarget(String id) {
this.id = id;
}
@Override
public String getId() {
return id;
}
@Override
public String getName() {
return id;
}
@Override
public abstract ILaunchTargetType getType();
@Override
public void setActive() {
// nothing to do
}
@Override
public int hashCode() {
return 7 + getId().hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj.getClass().equals(getClass())))
return false;
ILaunchDescriptorType other = (ILaunchDescriptorType) obj;
if (!getId().equals(other.getId()))
return false;
return true;
}
}

View file

@ -1,62 +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:
* Elena Laskavaia - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
/**
* Convenience implementation of ILaunchTargetType, provides equals and hashcode methods based on id.
*/
public abstract class AbstractLaunchTargetType implements ILaunchTargetType {
private ILaunchBarManager manager;
@Override
public void init(ILaunchBarManager barmanager) {
this.manager = barmanager;
}
public ILaunchBarManager getManager() {
return manager;
}
@Override
public abstract String getId();
@Override
public int hashCode() {
return 7 + getId().hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj.getClass().equals(getClass())))
return false;
ILaunchDescriptorType other = (ILaunchDescriptorType) obj;
if (!getId().equals(other.getId()))
return false;
return true;
}
@Override
public ILaunchTarget getTarget(String id) {
if (id == null)
return null;
ILaunchTarget[] targets = getTargets();
for (int i = 0; i < targets.length; i++) {
ILaunchTarget target = targets[i];
if (target.getId().equals(id))
return target;
}
return null;
}
}

View file

@ -1,84 +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:
* Elena Laskavaia - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
import java.util.HashMap;
import org.eclipse.cdt.launchbar.core.internal.Activator;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
public class ConfigBasedLaunchConfigurationProvider extends AbstractLaunchConfigurationProvider implements
ILaunchConfigurationProvider {
protected HashMap<ILaunchConfiguration, Object> configMap = new HashMap<>();
protected String typeId;
public ConfigBasedLaunchConfigurationProvider(String launchConfigurationTypeId) {
this.typeId = launchConfigurationTypeId;
}
public boolean ownsConfiguration(ILaunchConfiguration element) {
try {
// cannot use getType method when config is deleted, event sent after, no getters work on it
if (configMap.containsKey(element))
return true;
return element.getType().getIdentifier().equals(typeId);
} catch (DebugException e) {
return false; // config does not exists, not point logging
} catch (CoreException e) {
Activator.log(e);
return false;
}
}
@Override
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
if (ownsConfiguration(configuration)) {
rememberConfiguration(configuration);
manager.launchObjectAdded(configuration);
return true;
}
return false;
}
protected void rememberConfiguration(ILaunchConfiguration configuration) {
configMap.put(configuration, null);
}
@Override
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
if (ownsConfiguration(configuration)) {
manager.launchObjectRemoved(configuration);
forgetConfiguration(configuration);
return true;
}
return false;
}
protected void forgetConfiguration(ILaunchConfiguration configuration) {
configMap.remove(configuration);
}
@Override
public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor) throws CoreException {
ILaunchConfigurationType type = super.getLaunchConfigurationType(descriptor);
if (type!=null) return type;
return DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(typeId);
}
@Override
public String toString() {
return "provider for " + typeId;
}
}

View file

@ -1,66 +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:
* Alena Laskavaia - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
import org.eclipse.cdt.launchbar.core.internal.Activator;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
public class ConfigBasedLaunchDescriptor extends AbstractLaunchDescriptor implements ILaunchDescriptorConfigBased {
private final ILaunchDescriptorType type;
private ILaunchConfiguration config;
public ConfigBasedLaunchDescriptor(ILaunchDescriptorType type, ILaunchConfiguration config) {
if (type == null)
throw new NullPointerException();
this.type = type;
this.config = config;
}
@Override
public String getName() {
if (config == null)
return "?";
return config.getName();
}
@Override
public ILaunchDescriptorType getType() {
return type;
}
public ILaunchConfiguration getLaunchConfiguration() {
return config;
}
public ILaunchConfigurationType getLaunchConfigurationType() {
if (config != null)
try {
return config.getType();
} catch (CoreException e) {
Activator.log(e); // can happened when config is deleted XXX hide in this case
}
if (type instanceof ConfigBasedLaunchDescriptorType) {
return ((ConfigBasedLaunchDescriptorType) type).getLaunchConfigurationType();
}
throw new IllegalStateException("Cannot determine configuration type for " + this);
}
@Override
public String toString() {
return "LC/" + getName();
}
public void setLaunchConfiguration(ILaunchConfiguration config) {
this.config = config;
}
}

View file

@ -1,65 +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:
* Elena Laskavaia - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
public class ConfigBasedLaunchDescriptorType extends AbstarctLaunchDescriptorType implements ILaunchDescriptorType {
private String id;
private String typeId;
public ConfigBasedLaunchDescriptorType(String descTypeId, String launchConfigurationTypeId) {
if (launchConfigurationTypeId == null)
throw new NullPointerException();
this.typeId = launchConfigurationTypeId;
this.id = descTypeId != null ? descTypeId : launchConfigurationTypeId;
}
public ConfigBasedLaunchDescriptorType(String launchConfigurationTypeId) {
this(null, launchConfigurationTypeId);
}
public boolean ownsConfiguration(ILaunchConfiguration element) {
try {
return element.getType().getIdentifier().equals(typeId);
} catch (CoreException e) {
return false;
}
}
@Override
public ILaunchDescriptor getDescriptor(Object element) {
return new ConfigBasedLaunchDescriptor(this, (ILaunchConfiguration) element);
}
@Override
public boolean ownsLaunchObject(Object element) {
return element instanceof ILaunchConfiguration
&& ownsConfiguration((ILaunchConfiguration) element);
}
@Override
public String getId() {
return id;
}
public ILaunchConfigurationType getLaunchConfigurationType() {
return DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(typeId);
}
@Override
public String toString() {
return "type for " + typeId;
}
}

View file

@ -11,71 +11,58 @@
package org.eclipse.cdt.launchbar.core; package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.runtime.CoreException; 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 { public interface ILaunchBarManager {
ILaunchDescriptor[] getLaunchDescriptors(); /**
* A launch object has been added. Create a matching launch descriptor if available.
*
* @param element launch object
* @return the launch descriptor that got created, null of none was
* @throws CoreException
*/
ILaunchDescriptor launchObjectAdded(Object launchObject) throws CoreException;
ILaunchDescriptor[] getOpenLaunchDescriptors(); /**
* A launch object has been removed. Remove the associated launch descriptor if there is one.
*
* @param element launch object
* @throws CoreException
*/
void launchObjectRemoved(Object launchObject) throws CoreException;
ILaunchDescriptor getActiveLaunchDescriptor() throws CoreException; /**
* A launch object has changed in some way that affects the launch bar.
void setActiveLaunchDescriptor(ILaunchDescriptor configDesc) throws CoreException; *
* @param launchObject
void updateLaunchDescriptor(ILaunchDescriptor configDesc) throws CoreException; * @throws CoreException
*/
ILaunchMode[] getLaunchModes() throws CoreException; void launchObjectChanged(Object launchObject) throws CoreException;
ILaunchMode getActiveLaunchMode() throws CoreException;
void setActiveLaunchMode(ILaunchMode mode) throws CoreException;
ILaunchTarget[] getLaunchTargets() throws CoreException;
ILaunchTarget getLaunchTarget(String id) throws CoreException;
ILaunchTarget getActiveLaunchTarget() throws CoreException;
void setActiveLaunchTarget(ILaunchTarget target) throws CoreException;
void updateLaunchTarget(ILaunchTarget target) throws CoreException;
/**
* A new launch target has been added.
*
* @param target launch target
* @throws CoreException
*/
void launchTargetAdded(ILaunchTarget target) throws CoreException; void launchTargetAdded(ILaunchTarget target) throws CoreException;
/**
* A launch target has been removed.
*
* @param target launch target
* @throws CoreException
*/
void launchTargetRemoved(ILaunchTarget target) throws CoreException; void launchTargetRemoved(ILaunchTarget target) throws CoreException;
ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException; /**
* The launch target has changed in some way that affects the
* launch bar.
*
* @param target launch target
*/
void launchTargetChanged(ILaunchTarget target);
ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException; // TODO API for adding and removing types.
ILaunchDescriptor launchObjectAdded(Object element) throws CoreException;
void launchObjectRemoved(Object element) throws CoreException;
ILaunchDescriptor launchObjectChanged(Object element) throws CoreException;
ILaunchDescriptor getLaunchDescriptor(Object element);
interface Listener {
void activeConfigurationDescriptorChanged();
void activeLaunchModeChanged();
void activeLaunchTargetChanged();
void launchDescriptorRemoved(ILaunchDescriptor descriptor);
void launchTargetsChanged();
}
void addListener(Listener listener);
void removeListener(Listener listener);
} }

View file

@ -13,36 +13,41 @@ package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchManager;
/**
* The provider of launch configurations of a given type for a given descriptor type
* and a given target type.
*/
public interface ILaunchConfigurationProvider { 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 * 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. * is properly constructed by sending in a launch object to the launch manager.
* And return that object.
* *
* @param configuration * @param configuration
* @return boolean - was the launch configuration added by this provider? * @return launch object that relates to this config
* @throws CoreException * @throws CoreException
*/ */
boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException; Object launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException;
/** /**
* Returns the launch configuration type used to launch the descriptor on this target type. * A launch configuration has been removed.
*
* @param configuration
* @return was the launch configuration removed by this provider?
* @throws CoreException
*/
boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException;
/**
* Returns the launch configuration type for configurations created by this provider.
* *
* @param descriptor
* @param target
* @return launch configuration type * @return launch configuration type
* @throws CoreException * @throws CoreException
*/ */
ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor) throws CoreException; ILaunchConfigurationType getLaunchConfigurationType() throws CoreException;
/** /**
* Create a launch configuration for the descriptor to launch on the target. * Create a launch configuration for the descriptor to launch on the target.
@ -52,15 +57,6 @@ public interface ILaunchConfigurationProvider {
* @return launch configuration * @return launch configuration
* @throws CoreException * @throws CoreException
*/ */
ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor) throws CoreException; ILaunchConfiguration createLaunchConfiguration(ILaunchManager launchManager, ILaunchDescriptor descriptor) throws CoreException;
/**
* A launch configuration has been removed.
*
* @param configuration
* @return boolean - was the launch configuration removed by this provider?
* @throws CoreException
*/
boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException;
} }

View file

@ -10,26 +10,24 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.launchbar.core; package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.runtime.IAdaptable;
/** /**
* Represents a thing that can be launched. * Represents a thing that can be launched.
* It is good practice that the descriptor is adaptable to the launch object
* it is representing.
*/ */
public interface ILaunchDescriptor { public interface ILaunchDescriptor extends IAdaptable {
/** /**
* Name to show in the launch descriptor selector. * Name to show in the launch descriptor selector.
* Names must be unique for all descriptors of a given type.
* *
* @return name of the launch descriptor * @return name of the launch descriptor
*/ */
String getName(); String getName();
/**
* Unique id of the descriptor (globally)
*
* @return the non null string representing id of the launch descriptor
*/
String getId();
/** /**
* The type of launch descriptor. * The type of launch descriptor.
* *
@ -37,9 +35,4 @@ public interface ILaunchDescriptor {
*/ */
ILaunchDescriptorType getType(); ILaunchDescriptorType getType();
/**
* Descriptor considered open when it is visible to user, and closed otherwise
*/
boolean isOpen();
} }

View file

@ -1,31 +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.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
/**
* Interface for descriptors which are based on launch configurations
*/
public interface ILaunchDescriptorConfigBased extends ILaunchDescriptor {
/**
* Return launch configuration on which it is based (can be null)
*/
public ILaunchConfiguration getLaunchConfiguration();
/**
* Return launch configuration type on which it is based (cannot be null)
*
* @NonNull
*/
public ILaunchConfigurationType getLaunchConfigurationType();
}

View file

@ -20,46 +20,26 @@ import org.eclipse.core.runtime.CoreException;
public interface ILaunchDescriptorType { public interface ILaunchDescriptorType {
/** /**
* The id for the provider. * Does this type own this launch object?
* *
* @return provider id * @deprecated this needs to be replaced by enablement to avoid plug-in loading.
*/
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 * @param element
* @return owns element * @return owns element
* @throws CoreException * @throws CoreException
*/ */
boolean ownsLaunchObject(Object element) throws CoreException; boolean ownsLaunchObject(Object launchObject) throws CoreException;
/** /**
* Return a descriptor for the given element. The element can be a launch * Return a descriptor for the given launch object.
* 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 * May return null to essentially eat the element so no other types
* create a descriptor for it. * create a descriptor for it.
* *
* @param descriptor candidate descriptor * @param descriptor launch object for descriptor
* @return the best descriptor * @return the best descriptor
* @throws CoreException * @throws CoreException
*/ */
ILaunchDescriptor getDescriptor(Object element) throws CoreException; ILaunchDescriptor getDescriptor(Object launchObject) throws CoreException;
/**
* Return a handle to the launch bar manager.
*
* @return launchbar manager
*/
ILaunchBarManager getManager();
} }

View file

@ -1,5 +1,7 @@
package org.eclipse.cdt.launchbar.core; package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.runtime.CoreException;
/** /**
* An extension that serves up objects to feed launch descriptors. * An extension that serves up objects to feed launch descriptors.
* *
@ -7,11 +9,12 @@ package org.eclipse.cdt.launchbar.core;
public interface ILaunchObjectProvider { public interface ILaunchObjectProvider {
/** /**
* Add initial launch descriptors and set up listeners. * Add initial launch descriptors and set up for new ones.
* *
* @param launchbar manager * @param launchbar manager
* @throws CoreException
*/ */
void init(ILaunchBarManager manager); void init(ILaunchBarManager manager) throws CoreException;
/** /**
* Shutting down, remove any listeners. * Shutting down, remove any listeners.

View file

@ -10,33 +10,30 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.launchbar.core; package org.eclipse.cdt.launchbar.core;
public interface ILaunchTarget { import org.eclipse.core.runtime.IAdaptable;
public interface ILaunchTarget extends IAdaptable {
/** /**
* Get the id for the target. The id of the active target is * Returns the name of this target.
* stored in the preference store. * Names must be unique across all targets of a given type.
* *
* @return id * @return name of the target
*/
String getId();
/**
* Returns a name to show in the UI for this target.
*
* @return name
*/ */
String getName(); String getName();
/** /**
* Returns the type for this target. * Returns the type for this target.
* *
* @return target type * @return type of the target
*/ */
ILaunchTargetType getType(); ILaunchTargetType getType();
/** /**
* This target has been made active. * The active state of this target has changed.
*
* @param active active state of the target
*/ */
void setActive(); void setActive(boolean active);
} }

View file

@ -10,35 +10,21 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.launchbar.core; package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.runtime.CoreException;
public interface ILaunchTargetType { public interface ILaunchTargetType {
/** /**
* Called by the launchbar manager to initialize and pass a hendle to itself. * Add initial targets and set up any listeners.
* *
* @param manager * @param manager
* @throws CoreException
*/ */
void init(ILaunchBarManager manager); void init(ILaunchBarManager manager) throws CoreException;
/** /**
* The id of the target type. * Shutting down, remove any listeners
*
* @return target type id
*/ */
String getId(); void dispose();
/**
* 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

@ -0,0 +1,77 @@
/*******************************************************************************
* 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.cdt.launchbar.core.internal.Activator;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
/**
* A root class for launch configuration providers. Provides the ability to detect launch
* configurations that it has created.
*/
public abstract class LaunchConfigurationProvider implements ILaunchConfigurationProvider {
// Used to make sure this is the config we've created
protected static final String ORIGINAL_NAME = Activator.PLUGIN_ID + ".originalName";
@Override
public ILaunchConfiguration createLaunchConfiguration(ILaunchManager launchManager, ILaunchDescriptor descriptor) throws CoreException {
String name = launchManager.generateLaunchConfigurationName(getConfigurationName(descriptor));
ILaunchConfigurationWorkingCopy wc = getLaunchConfigurationType().newInstance(null, name);
wc.setAttribute(ORIGINAL_NAME, name);
populateConfiguration(wc, descriptor);
return wc.doSave();
}
/**
* Potential name for new configurations. Names are still put through the launch manager
* to ensure they are unique.
*
* @param descriptor the launch descriptor triggering the configuration creation
* @return candidate configuration name
*/
protected String getConfigurationName(ILaunchDescriptor descriptor) {
// by default, use the descriptor name
return descriptor.getName();
}
/**
* Populate the new configuration with attributes and resources.
*
* @param workingCopy working copy for the new configuration
* @param descriptor the launch descriptor that triggered the new configuration
* @throws CoreException
*/
protected void populateConfiguration(ILaunchConfigurationWorkingCopy workingCopy, ILaunchDescriptor descriptor) throws CoreException {
// by default, nothing to add
}
/**
* Determines if we created this launch configuration. Generally used by the launch configuration
* add handler to determine if the incoming launch configuration is ours.
*
* @param configuration
* @return do we own this launch configuration
* @throws CoreException
*/
protected boolean ownsConfiguration(ILaunchConfiguration configuration) throws CoreException {
// must be the same config type
if (!configuration.getType().equals(getLaunchConfigurationType()))
return false;
// we created it if it has the same name we created it with
return configuration.getAttribute(ORIGINAL_NAME, "").equals(configuration.getName());
}
}

View file

@ -1,46 +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:
* Alena Laskavaia - Initial API and implementationn
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
public abstract class ProjectBasedLaunchConfigurationProvider extends ConfigBasedLaunchConfigurationProvider {
public ProjectBasedLaunchConfigurationProvider(String launchConfigurationTypeId) {
super(launchConfigurationTypeId);
}
@Override
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
if (!super.launchConfigurationAdded(configuration)) return false;
IProject project = getProject(configuration);
getManager().launchObjectChanged(project);
return true;
}
@Override
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
if (!ownsConfiguration(configuration))
return false;
IProject project = (IProject) configMap.get(configuration); // cannot use getters from configuration, it is deleted
if (!super.launchConfigurationRemoved(configuration)) return false;
if (project != null)
getManager().launchObjectChanged(project);
return true;
}
protected void rememberConfiguration(ILaunchConfiguration configuration) {
configMap.put(configuration, getProject(configuration));
}
protected abstract IProject getProject(ILaunchConfiguration llc);
}

View file

@ -1,46 +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:
* Alena Laskavaia - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.resources.IProject;
import org.eclipse.debug.core.ILaunchConfiguration;
public class ProjectBasedLaunchDescriptor extends ConfigBasedLaunchDescriptor implements ILaunchDescriptorProjectBased {
private IProject project;
public ProjectBasedLaunchDescriptor(ILaunchDescriptorType type, IProject p, ILaunchConfiguration lc) {
super(type, lc);
if (p == null)
throw new NullPointerException();
this.project = p;
}
@Override
public String getName() {
ILaunchConfiguration lc = getLaunchConfiguration();
if (lc != null)
return lc.getName();
return project.getName();
}
@Override
public IProject getProject() {
return project;
}
@Override
public String toString() {
ILaunchConfiguration lc = getLaunchConfiguration();
if (lc != null)
return "LC/" + lc.getName();
return "P/" + project.getName();
}
}

View file

@ -1,90 +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:
* Alena Laskavaia - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.resources.IProject;
import org.eclipse.debug.core.ILaunchConfiguration;
public abstract class ProjectBasedLaunchDescriptorType extends ConfigBasedLaunchDescriptorType {
public ProjectBasedLaunchDescriptorType(String descTypeId, String launchConfigTypeId) {
super(descTypeId, launchConfigTypeId);
}
@Override
public boolean ownsLaunchObject(Object element) {
if (super.ownsLaunchObject(element))
return true;
if (element instanceof IProject && ((IProject) element).isOpen() && ownsProject((IProject) element))
return true;
return false;
}
public boolean ownsConfiguration(ILaunchConfiguration element) {
return super.ownsConfiguration(element) && getProject(element) != null;
}
protected boolean ownsLaunchDescriptor(ILaunchDescriptor ld) {
if (!(ld instanceof ProjectBasedLaunchDescriptorType))
return false;
ProjectBasedLaunchDescriptorType other = (ProjectBasedLaunchDescriptorType) ld;
return other.getLaunchConfigurationType().equals(getLaunchConfigurationType());
}
protected abstract boolean ownsProject(IProject element);
@Override
public ILaunchDescriptor getDescriptor(Object element) {
if (element instanceof ILaunchConfiguration) {
ILaunchConfiguration llc = (ILaunchConfiguration) element;
IProject project = getProject(llc);
if (project == null)
return null;
// TODO we need disable project based descriptor here
return new ProjectBasedLaunchDescriptor(this, project, llc);
} else if (element instanceof IProject) {
// this type creates two versions of the descriptor - launch config based
// and project based. Project based do not have a config. If at least one
// launch config created, associated with same project, we don't need descriptor with null config
// anymore so we return null in this case
IProject project = (IProject) element;
ProjectBasedLaunchDescriptor desc = new ProjectBasedLaunchDescriptor(this, project, null);
ILaunchDescriptor[] lds = getManager().getLaunchDescriptors();
for (int i = 0; i < lds.length; i++) {
ILaunchDescriptor ld = lds[i];
if (isBetter(ld, desc)) {
return null;// there is a better descriptor already
}
}
return desc;
}
return null;
}
/**
* Return true is a is better then b (which would eliminate b)
*/
protected boolean isBetter(ILaunchDescriptor a, ILaunchDescriptor b) {
if (a instanceof ProjectBasedLaunchDescriptor && b instanceof ProjectBasedLaunchDescriptor) {
ProjectBasedLaunchDescriptor pa = (ProjectBasedLaunchDescriptor) a;
ProjectBasedLaunchDescriptor pb = (ProjectBasedLaunchDescriptor) b;
if (pb.getProject().equals(pa.getProject())
&& pa.getLaunchConfigurationType().equals(pb.getLaunchConfigurationType())
&& pa.getLaunchConfiguration() != null
&& pb.getLaunchConfiguration() == null) {
// a is for same project and same type, but actually have non-null configuraton
return true;
}
}
return false;
}
protected abstract IProject getProject(ILaunchConfiguration llc);
}

View file

@ -0,0 +1,80 @@
/*******************************************************************************
* 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.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
/**
* A root launch configuration provider that can be used with project launch descriptors.
* Takes ownership of configurations we've created that map to the the project.
*/
public abstract class ProjectLaunchConfigurationProvider extends LaunchConfigurationProvider {
@Override
protected void populateConfiguration(ILaunchConfigurationWorkingCopy workingCopy, ILaunchDescriptor descriptor) throws CoreException {
super.populateConfiguration(workingCopy, descriptor);
// Add our project to the mapped resources
IProject project = (IProject) descriptor.getAdapter(IProject.class);
IResource[] mappedResources = workingCopy.getMappedResources();
if (mappedResources == null || mappedResources.length == 0) {
workingCopy.setMappedResources(new IResource[] { project });
} else {
IResource[] newResources = new IResource[mappedResources.length + 1];
System.arraycopy(mappedResources, 0, newResources, 0, mappedResources.length);
newResources[mappedResources.length] = project;
workingCopy.setMappedResources(newResources);
}
}
/**
* Extract the project from the launch configuration. Used when checking if we own it.
*
* @param configuration
* @return project for launch configuration.
* @throws CoreException
*/
protected IProject getProject(ILaunchConfiguration configuration) throws CoreException {
// by default return the first project in the mapped resources
for (IResource resource : configuration.getMappedResources()) {
if (resource instanceof IProject) {
return (IProject) resource;
}
}
return null;
}
@Override
public Object launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
if (!ownsConfiguration(configuration)) {
return null;
}
IProject project = getProject(configuration);
if (project == null) {
// The user must have changed project. We don't own it any more in that case.
return null;
}
return project;
}
@Override
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
return ownsConfiguration(configuration);
}
}

View file

@ -0,0 +1,48 @@
/*******************************************************************************
* 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.resources.IProject;
import org.eclipse.core.runtime.PlatformObject;
/**
* A reusable descriptor for wrapping projects that can be used by descriptor types
* that map to projects.
*/
public class ProjectLaunchDescriptor extends PlatformObject implements ILaunchDescriptor {
private final ILaunchDescriptorType type;
private final IProject project;
public ProjectLaunchDescriptor(ILaunchDescriptorType type, IProject project) {
this.type = type;
this.project = project;
}
@Override
public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
if (IProject.class.equals(adapter)) {
return project;
}
return super.getAdapter(adapter);
}
@Override
public String getName() {
return project.getName();
}
@Override
public ILaunchDescriptorType getType() {
return type;
}
}

View file

@ -16,49 +16,36 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
public class Activator extends Plugin { public class Activator extends Plugin {
public static final String PLUGIN_ID = "org.eclipse.cdt.launchbar.core"; public static final String PLUGIN_ID = "org.eclipse.cdt.launchbar.core";
private static Plugin plugin; private static Activator plugin;
private LaunchBarManager launchBarManager; private LaunchBarManager launchBarManager;
public void start(BundleContext bundleContext) throws Exception { public void start(BundleContext bundleContext) throws Exception {
super.start(bundleContext); super.start(bundleContext);
plugin = this; plugin = this;
launchBarManager = new LaunchBarManager();
bundleContext.registerService(ILaunchBarManager.class, new ServiceFactory<ILaunchBarManager>() { bundleContext.registerService(ILaunchBarManager.class, launchBarManager, null);
@Override
public synchronized ILaunchBarManager getService(Bundle bundle, ServiceRegistration<ILaunchBarManager> registration) {
if (launchBarManager == null) {
try {
launchBarManager = new LaunchBarManager();
} catch (CoreException e) {
// TODO log
e.printStackTrace();
}
}
return launchBarManager;
}
@Override
public synchronized void ungetService(Bundle bundle,
ServiceRegistration<ILaunchBarManager> registration,
ILaunchBarManager service) {
}
}, null);
} }
public void stop(BundleContext bundleContext) throws Exception { public void stop(BundleContext bundleContext) throws Exception {
super.stop(bundleContext); super.stop(bundleContext);
plugin = null; plugin = null;
launchBarManager.dispose();
launchBarManager = null; launchBarManager = null;
} }
public static Activator getDefault() {
return plugin;
}
public LaunchBarManager getLaunchBarManager() {
return launchBarManager;
}
public static void throwCoreException(Exception e) throws CoreException { public static void throwCoreException(Exception e) throws CoreException {
throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e)); throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e));
} }
@ -75,7 +62,7 @@ public class Activator extends Plugin {
} }
private static final String DEBUG_ONE = private static final String DEBUG_ONE =
PLUGIN_ID + "/debug/launchbar"; PLUGIN_ID + "/debug/launchbar";
public static void trace(String str) { public static void trace(String str) {
if (plugin == null || (plugin.isDebugging() && "true".equalsIgnoreCase(Platform.getDebugOption(DEBUG_ONE)))) if (plugin == null || (plugin.isDebugging() && "true".equalsIgnoreCase(Platform.getDebugOption(DEBUG_ONE))))

View file

@ -1,19 +0,0 @@
package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.cdt.launchbar.core.AbstractLaunchConfigurationProvider;
import org.eclipse.cdt.launchbar.core.ILaunchConfigurationProvider;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
public class DefaultLaunchConfigurationProvider extends AbstractLaunchConfigurationProvider implements ILaunchConfigurationProvider {
@Override
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
// We may own it but return false to let it percolate through to the descriptor type.
return false;
}
@Override
public boolean launchConfigurationRemoved(ILaunchConfiguration configation) throws CoreException {
return false;
}
}

View file

@ -10,14 +10,41 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.launchbar.core.internal; package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.cdt.launchbar.core.ConfigBasedLaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType; import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfiguration;
/**
* A special launch descriptor that managed configurations that aren't owned by other
* descriptors.
*/
public class DefaultLaunchDescriptor extends PlatformObject implements ILaunchDescriptor {
public class DefaultLaunchDescriptor extends ConfigBasedLaunchDescriptor { private final DefaultLaunchDescriptorType type;
private final ILaunchConfiguration configuration;
public DefaultLaunchDescriptor(ILaunchDescriptorType type, ILaunchConfiguration config) { public DefaultLaunchDescriptor(DefaultLaunchDescriptorType type, ILaunchConfiguration configuration) {
super(type, config); this.type = type;
this.configuration = configuration;
} }
@Override
public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
if (ILaunchConfiguration.class.equals(adapter)) {
return configuration;
}
return super.getAdapter(adapter);
}
@Override
public String getName() {
return configuration.getName();
}
@Override
public ILaunchDescriptorType getType() {
return type;
}
} }

View file

@ -1,24 +1,41 @@
package org.eclipse.cdt.launchbar.core.internal; package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.cdt.launchbar.core.AbstarctLaunchDescriptorType; import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType; import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType;
import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfiguration;
public class DefaultLaunchDescriptorType extends AbstarctLaunchDescriptorType implements ILaunchDescriptorType { /**
public static final String ID = "org.eclipse.cdt.launchbar.core.descriptor.default"; * A special descriptor type that managed configurations that aren't owned
* by other descriptor types.
*/
public class DefaultLaunchDescriptorType implements ILaunchDescriptorType {
public static final String ID = Activator.PLUGIN_ID + ".descriptorType.default";
private Map<ILaunchConfiguration, DefaultLaunchDescriptor> descriptors = new HashMap<>();
@Override
public String getId() {
return ID;
}
@Override @Override
public boolean ownsLaunchObject(Object element) { public boolean ownsLaunchObject(Object element) {
return element instanceof ILaunchConfiguration; // This descriptor type doesn't own any launch objects
return false;
} }
@Override @Override
public ILaunchDescriptor getDescriptor(Object element) { public ILaunchDescriptor getDescriptor(Object element) {
return new DefaultLaunchDescriptor(this, (ILaunchConfiguration) element); if (element instanceof ILaunchConfiguration) {
ILaunchConfiguration config = (ILaunchConfiguration) element;
DefaultLaunchDescriptor descriptor = descriptors.get(config);
if (descriptor == null) {
descriptor = new DefaultLaunchDescriptor(this, config);
descriptors.put(config, descriptor);
}
return descriptor;
}
return null;
} }
} }

View file

@ -0,0 +1,53 @@
/*******************************************************************************
* 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.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
/**
* A wrapper class that delays instantiation of classes until they're needed
* to prevent early plug-in loading.
*
* @param <T> the type of the object created
*/
public class ExecutableExtension<T> {
private IConfigurationElement element;
private String propertyName;
private T object;
public ExecutableExtension(IConfigurationElement element, String propertyName) {
this.element = element;
this.propertyName = propertyName;
}
// For testing, pre-populate the object
public ExecutableExtension(T object) {
this.object = object;
}
/**
* Get the object instantiating it if necessary.
* @return object
* @throws CoreException
*/
@SuppressWarnings("unchecked")
public T get() throws CoreException {
if (element != null) {
object = (T) element.createExecutableExtension(propertyName);
element = null;
propertyName = null;
}
return object;
}
}

View file

@ -12,24 +12,22 @@ package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.core.ILaunchTargetType; import org.eclipse.cdt.launchbar.core.ILaunchTargetType;
import org.eclipse.core.runtime.PlatformObject;
public class LocalTarget implements ILaunchTarget { /**
* The launch target representing the machine we're running on.
*/
public class LocalTarget extends PlatformObject implements ILaunchTarget {
private final LocalTargetType type; private final LocalTargetType type;
public LocalTarget(LocalTargetType type) { public LocalTarget(LocalTargetType type) {
this.type = type; this.type = type;
} }
@Override
public String getId() {
// Use the same ID as the type since we're really a singleton
return type.getId();
}
@Override @Override
public String getName() { public String getName() {
return "Local Machine"; // TODO externalize return Messages.LocalTarget_name;
} }
@Override @Override
@ -38,8 +36,8 @@ public class LocalTarget implements ILaunchTarget {
} }
@Override @Override
public void setActive() { public void setActive(boolean active) {
// nothing to do // nothing to do, we have no active state
} }
} }

View file

@ -1,34 +1,25 @@
package org.eclipse.cdt.launchbar.core.internal; package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager; import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.core.ILaunchTargetType; import org.eclipse.cdt.launchbar.core.ILaunchTargetType;
import org.eclipse.core.runtime.CoreException;
/**
* The target type that creates the local target.
*/
public class LocalTargetType implements ILaunchTargetType { public class LocalTargetType implements ILaunchTargetType {
public static final String ID = "org.eclipse.cdt.launchbar.core.target.local"; public static final String ID = Activator.PLUGIN_ID + ".targetType.local";
private LocalTarget localTarget;
@Override @Override
public void init(ILaunchBarManager manager) { public void init(ILaunchBarManager manager) throws CoreException {
localTarget = new LocalTarget(this); // create the local target
} manager.launchTargetAdded(new LocalTarget(this));
@Override
public String getId() {
return ID;
} }
@Override @Override
public ILaunchTarget[] getTargets() { public void dispose() {
return new ILaunchTarget[] { localTarget }; // nothing to do
} }
@Override
public ILaunchTarget getTarget(String id) {
if (ID.equals(id))
return localTarget;
return null;
}
} }

View file

@ -6,18 +6,20 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Alena Laskavaia - Initial API and implementation * Doug Schaefer
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.launchbar.core; package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.core.resources.IProject; import org.eclipse.osgi.util.NLS;
/** public class Messages extends NLS {
* Project Based launch descriptor knows about project it is associated with private static final String BUNDLE_NAME = "org.eclipse.cdt.launchbar.core.internal.messages"; //$NON-NLS-1$
*/ public static String LocalTarget_name;
public interface ILaunchDescriptorProjectBased extends ILaunchDescriptor { static {
/** // initialize resource bundle
* Get associate project NLS.initializeMessages(BUNDLE_NAME, Messages.class);
*/ }
public abstract IProject getProject();
} private Messages() {
}
}

View file

@ -0,0 +1,70 @@
/*******************************************************************************
* 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;
/**
* Yet another implementation for Pair. You'd figure Java would have this out of the box.
* Used in the launch bar mainly for modeling descriptor and target id's which includ both
* type id and the object name.
*
* @param <S> first element
* @param <T> second element
*/
public class Pair<S, T> {
private final S first;
private final T second;
public Pair(S first, T second) {
this.first = first;
this.second = second;
}
public S getFirst() {
return first;
}
public T getSecond() {
return second;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((first == null) ? 0 : first.hashCode());
result = prime * result + ((second == null) ? 0 : second.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
@SuppressWarnings("unchecked") Pair<S, T> other = (Pair<S, T>) obj;
if (first == null) {
if (other.first != null)
return false;
} else if (!first.equals(other.first))
return false;
if (second == null) {
if (other.second != null)
return false;
} else if (!second.equals(other.second))
return false;
return true;
}
}

View file

@ -24,18 +24,18 @@ import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/**
* Injects IProject objects from platform resources into the launch bar model for potential
* project descriptors.
*/
public class ProjectLaunchObjectProvider implements ILaunchObjectProvider, IResourceChangeListener { public class ProjectLaunchObjectProvider implements ILaunchObjectProvider, IResourceChangeListener {
private ILaunchBarManager manager; private ILaunchBarManager manager;
@Override @Override
public void init(ILaunchBarManager manager) { public void init(ILaunchBarManager manager) throws CoreException {
this.manager = manager; this.manager = manager;
try { for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { manager.launchObjectAdded(project);
manager.launchObjectAdded(project);
}
} catch (CoreException e) {
Activator.log(e.getStatus());
} }
ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE); ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
} }

View file

@ -0,0 +1,12 @@
################################################################################
# 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
################################################################################
LocalTarget_name=Local Machine

View file

@ -16,7 +16,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.debug.ui, org.eclipse.debug.ui,
org.eclipse.ui.workbench, org.eclipse.ui.workbench,
org.eclipse.ui.ide, org.eclipse.ui.ide,
org.eclipse.swt org.eclipse.swt,
org.eclipse.ui.navigator
Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin Bundle-Localization: plugin

View file

@ -1,2 +1,3 @@
launchToolBar.label = LaunchBar launchToolBar.label = LaunchBar
targetsView.name = Launch Targets targetsView.name = Launch Targets
targetsContent.name = Launch Targets

View file

@ -11,16 +11,6 @@
class="org.eclipse.cdt.launchbar.ui.internal.LaunchBarInjector"> class="org.eclipse.cdt.launchbar.ui.internal.LaunchBarInjector">
</processor> </processor>
</extension> </extension>
<extension
point="org.eclipse.core.runtime.adapters">
<factory
adaptableType="org.eclipse.cdt.launchbar.core.ILaunchBarManager"
class="org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManagerAdapterFactory">
<adapter
type="org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager">
</adapter>
</factory>
</extension>
<extension <extension
point="org.eclipse.ui.commands"> point="org.eclipse.ui.commands">
<command <command
@ -71,16 +61,6 @@
name="Local Target"> name="Local Target">
</targetUI> </targetUI>
</extension> </extension>
<extension
point="org.eclipse.ui.views">
<view
category="org.eclipse.cdt.ui.views"
class="org.eclipse.cdt.launchbar.ui.internal.targetsView.LaunchTargetsViewPart"
id="org.eclipse.cdt.launchbar.ui.targetsView"
name="%targetsView.name"
restorable="true">
</view>
</extension>
<extension <extension
point="org.eclipse.ui.perspectiveExtensions"> point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension <perspectiveExtension
@ -107,5 +87,62 @@
</enabledWhen> </enabledWhen>
</page> </page>
</extension> </extension>
<extension
point="org.eclipse.ui.views">
<view
category="org.eclipse.cdt.ui.views"
class="org.eclipse.cdt.launchbar.ui.internal.targetsView.LaunchTargetsNavigator"
id="org.eclipse.cdt.launchbar.ui.targetsView"
name="%targetsView.name"
restorable="true">
</view>
</extension>
<extension
point="org.eclipse.ui.navigator.navigatorContent">
<navigatorContent
activeByDefault="true"
contentProvider="org.eclipse.cdt.launchbar.ui.internal.targetsView.LaunchTargetsContentProvider"
id="org.eclipse.cdt.launchbar.ui.targetsViewContent"
labelProvider="org.eclipse.cdt.launchbar.ui.internal.targetsView.LaunchTargetsLabelProvider"
name="%targetsContent.name">
<triggerPoints>
<or>
<instanceof
value="org.eclipse.cdt.launchbar.core.ILaunchBarManager">
</instanceof>
</or>
</triggerPoints>
<possibleChildren>
<or>
<instanceof
value="org.eclipse.cdt.launchbar.core.ILaunchTarget">
</instanceof>
</or>
</possibleChildren>
<actionProvider
class="org.eclipse.cdt.launchbar.ui.internal.targetsView.LaunchTargetsActionProvider">
<enablement>
<instanceof
value="org.eclipse.cdt.launchbar.core.ILaunchTarget">
</instanceof>
</enablement>
</actionProvider>
</navigatorContent>
</extension>
<extension
point="org.eclipse.ui.navigator.viewer">
<viewer
viewerId="org.eclipse.cdt.launchbar.ui.targetsView">
</viewer>
<viewerContentBinding
viewerId="org.eclipse.cdt.launchbar.ui.targetsView">
<includes>
<contentExtension
isRoot="true"
pattern="org.eclipse.cdt.launchbar.ui.targetsViewContent">
</contentExtension>
</includes>
</viewerContentBinding>
</extension>
</plugin> </plugin>

View file

@ -10,6 +10,12 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.launchbar.ui; package org.eclipse.cdt.launchbar.ui;
/**
* An extension to allow different object types to provide fancy hovers.
*
* TODO this does lead to inconsistency when different types provide different hover UI
* which can confuse users. We should provide good UI out of the box.
*/
public interface IHoverProvider { public interface IHoverProvider {
/** /**

View file

@ -10,6 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal; package org.eclipse.cdt.launchbar.ui.internal;
import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager;
import org.eclipse.core.commands.Command; import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.IParameter; import org.eclipse.core.commands.IParameter;
@ -54,7 +55,10 @@ public class Activator extends AbstractUIPlugin {
// The shared instance // The shared instance
private static Activator plugin; private static Activator plugin;
// The cache of the Launch Bar UI Manager Object
private LaunchBarUIManager launchBarUIManager;
/** /**
* The constructor * The constructor
*/ */
@ -64,7 +68,7 @@ public class Activator extends AbstractUIPlugin {
public void start(BundleContext context) throws Exception { public void start(BundleContext context) throws Exception {
super.start(context); super.start(context);
plugin = this; plugin = this;
ImageRegistry imageRegistry = getImageRegistry(); ImageRegistry imageRegistry = getImageRegistry();
imageRegistry.put(IMG_BUTTON_BUILD, imageDescriptorFromPlugin(PLUGIN_ID, "icons/build.png")); imageRegistry.put(IMG_BUTTON_BUILD, imageDescriptorFromPlugin(PLUGIN_ID, "icons/build.png"));
imageRegistry.put(IMG_BUTTON_LAUNCH, imageDescriptorFromPlugin(PLUGIN_ID, "icons/launch.png")); imageRegistry.put(IMG_BUTTON_LAUNCH, imageDescriptorFromPlugin(PLUGIN_ID, "icons/launch.png"));
@ -85,6 +89,14 @@ public class Activator extends AbstractUIPlugin {
return plugin; return plugin;
} }
public LaunchBarUIManager getLaunchBarUIManager() {
if (launchBarUIManager == null) {
LaunchBarManager manager = org.eclipse.cdt.launchbar.core.internal.Activator.getDefault().getLaunchBarManager();
launchBarUIManager = new LaunchBarUIManager(manager);
}
return launchBarUIManager;
}
public Image getImage(String id) { public Image getImage(String id) {
return getImageRegistry().get(id); return getImageRegistry().get(id);
} }

View file

@ -3,10 +3,11 @@ package org.eclipse.cdt.launchbar.ui.internal;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.core.internal.Activator;
import org.eclipse.cdt.launchbar.core.internal.DefaultLaunchDescriptor;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageDescriptor;
@ -28,12 +29,10 @@ public class DefaultDescriptorLabelProvider extends LabelProvider {
@Override @Override
public Image getImage(Object element) { public Image getImage(Object element) {
if (element instanceof ILaunchDescriptor) { if (element instanceof ILaunchDescriptor) {
try { ILaunchConfiguration config = (ILaunchConfiguration) ((ILaunchDescriptor) element).getAdapter(ILaunchConfiguration.class);
ILaunchDescriptor desc = (ILaunchDescriptor) element; if (config != null) {
ILaunchBarManager manager = desc.getType().getManager(); try {
ILaunchTarget target = manager.getActiveLaunchTarget(); ILaunchConfigurationType type = config.getType();
ILaunchConfigurationType type = manager.getLaunchConfigurationType(desc, target);
if (type != null) {
ImageDescriptor imageDescriptor = DebugUITools.getDefaultImageDescriptor(type); ImageDescriptor imageDescriptor = DebugUITools.getDefaultImageDescriptor(type);
if (imageDescriptor != null) { if (imageDescriptor != null) {
Image image = images.get(imageDescriptor); Image image = images.get(imageDescriptor);
@ -43,9 +42,9 @@ public class DefaultDescriptorLabelProvider extends LabelProvider {
} }
return image; return image;
} }
} catch (CoreException e) {
Activator.log(e.getStatus());
} }
} catch (CoreException e) {
Activator.log(e);
} }
} }
return super.getImage(element); return super.getImage(element);

View file

@ -15,9 +15,10 @@ import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.core.internal.ExecutableExtension;
import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager;
import org.eclipse.cdt.launchbar.ui.IHoverProvider; import org.eclipse.cdt.launchbar.ui.IHoverProvider;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
@ -30,14 +31,14 @@ import org.eclipse.swt.graphics.Image;
public class LaunchBarUIManager { public class LaunchBarUIManager {
ILaunchBarManager manager; LaunchBarManager manager;
Map<String, ILabelProvider> descriptorLabelProviders = new HashMap<>(); Map<String, ExecutableExtension<ILabelProvider>> descriptorLabelProviders = new HashMap<>();
Map<String, LaunchBarTargetContribution> targetContributions = new HashMap<>(); Map<String, LaunchBarTargetContribution> targetContributions = new HashMap<>();
private final LaunchBarTargetContribution DEFAULT_CONTRIBUTION = new LaunchBarTargetContribution(null, null, null, null, null, private final LaunchBarTargetContribution DEFAULT_CONTRIBUTION = new LaunchBarTargetContribution(null, null, null, null,
null, null); null, null);
public LaunchBarUIManager(ILaunchBarManager manager) { public LaunchBarUIManager(LaunchBarManager manager) {
this.manager = manager; this.manager = manager;
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchBarUIContributions"); IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchBarUIContributions");
@ -46,58 +47,51 @@ public class LaunchBarUIManager {
for (IConfigurationElement element : extension.getConfigurationElements()) { for (IConfigurationElement element : extension.getConfigurationElements()) {
String elementName = element.getName(); String elementName = element.getName();
if (elementName.equals("descriptorUI")) { if (elementName.equals("descriptorUI")) {
try { String descriptorTypeId = element.getAttribute("descriptorTypeId");
String descriptorTypeId = element.getAttribute("descriptorTypeId"); ExecutableExtension<ILabelProvider> labelProvider = new ExecutableExtension<>(element, "labelProvider");
descriptorLabelProviders.put(descriptorTypeId, labelProvider);
ILabelProvider labelProvider = (ILabelProvider) element.createExecutableExtension("labelProvider");
descriptorLabelProviders.put(descriptorTypeId, labelProvider);
} catch (CoreException e) {
Activator.log(e.getStatus());
}
} else if (elementName.equals("targetUI")) { } else if (elementName.equals("targetUI")) {
try { String targetTypeId = element.getAttribute("targetTypeId");
String targetTypeId = element.getAttribute("targetTypeId"); String targetName = element.getAttribute("name");
String targetName = element.getAttribute("name"); String iconStr = element.getAttribute("icon");
ExecutableExtension<ILabelProvider> labelProvider = new ExecutableExtension<ILabelProvider>(element, "labelProvider");
String iconStr = element.getAttribute("icon"); ExecutableExtension<IHoverProvider> hoverProvider = null;
if (element.getAttribute("hoverProvider") != null) {
ILabelProvider labelProvider = (ILabelProvider) element.createExecutableExtension("labelProvider"); hoverProvider = new ExecutableExtension<IHoverProvider>(element, "hoverProvider");
IHoverProvider hoverProvider = null;
if (element.getAttribute("hoverProvider") != null) {
hoverProvider = (IHoverProvider) element.createExecutableExtension("hoverProvider");
}
String editCommandId = element.getAttribute("editCommandId");
String addNewCommandId = element.getAttribute("addNewTargetCommandId");
targetContributions.put(targetTypeId, new LaunchBarTargetContribution(targetTypeId, targetName, iconStr,
labelProvider, hoverProvider, editCommandId, addNewCommandId));
} catch (CoreException e) {
Activator.log(e.getStatus());
} }
String editCommandId = element.getAttribute("editCommandId");
String addNewCommandId = element.getAttribute("addNewTargetCommandId");
targetContributions.put(targetTypeId, new LaunchBarTargetContribution(targetName, iconStr,
labelProvider, hoverProvider, editCommandId, addNewCommandId));
} }
} }
} }
} }
public ILaunchBarManager getManager() { public LaunchBarManager getManager() {
return manager; return manager;
} }
public ILabelProvider getLabelProvider(ILaunchDescriptor descriptor) { public ILabelProvider getLabelProvider(ILaunchDescriptor descriptor) throws CoreException {
return descriptorLabelProviders.get(descriptor.getType().getId()); ExecutableExtension<ILabelProvider> provider = descriptorLabelProviders.get(manager.getDescriptorTypeId(descriptor.getType()));
return provider != null ? provider.get() : null;
} }
public String getTargetTypeName(ILaunchTarget target) { public String getTargetTypeName(ILaunchTarget target) {
return getContribution(target).name; return getContribution(target).name;
} }
public ILabelProvider getLabelProvider(ILaunchTarget target) { public ILabelProvider getLabelProvider(ILaunchTarget target) throws CoreException {
return getContribution(target).labelProvider; ExecutableExtension<ILabelProvider> provider = getContribution(target).labelProvider;
return provider != null ? provider.get() : null;
} }
public IHoverProvider getHoverProvider(ILaunchTarget target) { public IHoverProvider getHoverProvider(ILaunchTarget target) throws CoreException {
return getContribution(target).hoverProvider; ExecutableExtension<IHoverProvider> hoverProvider = getContribution(target).hoverProvider;
return hoverProvider != null ? hoverProvider.get() : null;
} }
public String getEditCommand(ILaunchTarget target) { public String getEditCommand(ILaunchTarget target) {
@ -129,7 +123,7 @@ public class LaunchBarUIManager {
} }
private LaunchBarTargetContribution getContribution(ILaunchTarget target) { private LaunchBarTargetContribution getContribution(ILaunchTarget target) {
LaunchBarTargetContribution c = targetContributions.get(target.getType().getId()); LaunchBarTargetContribution c = targetContributions.get(manager.getTargetTypeId(target.getType()));
if (c == null) { if (c == null) {
return DEFAULT_CONTRIBUTION; return DEFAULT_CONTRIBUTION;
} }
@ -137,19 +131,18 @@ public class LaunchBarUIManager {
} }
private class LaunchBarTargetContribution { private class LaunchBarTargetContribution {
String id;
String name; String name;
String iconStr; String iconStr;
Image icon; Image icon;
ILabelProvider labelProvider; ExecutableExtension<ILabelProvider> labelProvider;
IHoverProvider hoverProvider; ExecutableExtension<IHoverProvider> hoverProvider;
String editCommandId; String editCommandId;
String addNewCommandId; String addNewCommandId;
LaunchBarTargetContribution(String id, String name, String iconStr, ILabelProvider labelProvider, LaunchBarTargetContribution(String name, String iconStr,
IHoverProvider hoverProvider, String editCommand, String addNewCommand) { ExecutableExtension<ILabelProvider> labelProvider,
this.id = id; ExecutableExtension<IHoverProvider> hoverProvider,
String editCommand, String addNewCommand) {
this.name = name; this.name = name;
this.iconStr = iconStr; this.iconStr = iconStr;
this.icon = null; this.icon = null;

View file

@ -1,42 +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.ui.internal;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.core.runtime.IAdapterFactory;
public class LaunchBarUIManagerAdapterFactory implements IAdapterFactory {
private static Map<ILaunchBarManager, LaunchBarUIManager> uiProvider = new HashMap<>();
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
if (adaptableObject instanceof ILaunchBarManager && adapterType.equals(LaunchBarUIManager.class)) {
ILaunchBarManager manager = (ILaunchBarManager) adaptableObject;
LaunchBarUIManager uiManager = uiProvider.get(manager);
if (uiManager == null) {
uiManager = new LaunchBarUIManager(manager);
uiProvider.put(manager, uiManager);
}
return uiManager;
}
return null;
}
@Override
public Class[] getAdapterList() {
return new Class[] { LaunchBarUIManager.class };
}
}

View file

@ -15,9 +15,9 @@ import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager;
import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionEvent;
@ -51,12 +51,6 @@ import org.eclipse.ui.progress.UIJob;
*/ */
public class BuildActiveCommandHandler extends AbstractHandler { public class BuildActiveCommandHandler extends AbstractHandler {
private final ILaunchBarManager launchBarManager;
public BuildActiveCommandHandler() {
launchBarManager = Activator.getService(ILaunchBarManager.class);
}
@Override @Override
public Object execute(ExecutionEvent event) throws ExecutionException { public Object execute(ExecutionEvent event) throws ExecutionException {
new UIJob(Display.getDefault(), "Building Active Configuration") { new UIJob(Display.getDefault(), "Building Active Configuration") {
@ -67,10 +61,16 @@ public class BuildActiveCommandHandler extends AbstractHandler {
public IStatus runInUIThread(IProgressMonitor monitor) { public IStatus runInUIThread(IProgressMonitor monitor) {
try { try {
LaunchBarManager launchBarManager = Activator.getDefault().getLaunchBarUIManager().getManager();
ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor(); ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor();
ILaunchTarget target = launchBarManager.getActiveLaunchTarget(); ILaunchTarget target = launchBarManager.getActiveLaunchTarget();
ILaunchConfiguration config = launchBarManager.getLaunchConfiguration(desc, target); ILaunchConfiguration config = launchBarManager.getLaunchConfiguration(desc, target);
Collection<IProject> projects = getProjects(config);
if (BuildAction.isSaveAllSet()) {
saveEditors(projects);
}
if (config == null) { if (config == null) {
// Default, build the workspace // Default, build the workspace
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
@ -78,12 +78,6 @@ public class BuildActiveCommandHandler extends AbstractHandler {
} }
ILaunchMode launchMode = launchBarManager.getActiveLaunchMode(); ILaunchMode launchMode = launchBarManager.getActiveLaunchMode();
Collection<IProject> projects = getProjects(config);
if (BuildAction.isSaveAllSet()) {
saveEditors(projects);
}
String mode = launchMode.getIdentifier(); String mode = launchMode.getIdentifier();
Set<String> modes = new HashSet<>(); Set<String> modes = new HashSet<>();
modes.add(mode); modes.add(mode);
@ -113,7 +107,7 @@ public class BuildActiveCommandHandler extends AbstractHandler {
} catch (CoreException e) { } catch (CoreException e) {
return e.getStatus(); return e.getStatus();
} }
return Status.OK_STATUS; return Status.OK_STATUS;
}; };
}.schedule(); }.schedule();
@ -124,22 +118,24 @@ public class BuildActiveCommandHandler extends AbstractHandler {
protected Collection<IProject> getProjects(ILaunchConfiguration config) { protected Collection<IProject> getProjects(ILaunchConfiguration config) {
Set<IProject> projects = new HashSet<>(); Set<IProject> projects = new HashSet<>();
IResource[] mappedResources; if (config != null) {
try { IResource[] mappedResources;
mappedResources = config.getMappedResources(); try {
} catch (CoreException e) { mappedResources = config.getMappedResources();
return projects; } catch (CoreException e) {
} return projects;
if (mappedResources != null) { }
for (IResource resource : mappedResources) { if (mappedResources != null) {
IProject project = resource.getProject(); for (IResource resource : mappedResources) {
if (projects.contains(project)) IProject project = resource.getProject();
continue; if (projects.contains(project))
projects.add(project); continue;
try { projects.add(project);
projects.addAll(Arrays.asList(project.getReferencedProjects())); try {
} catch (CoreException e) { projects.addAll(Arrays.asList(project.getReferencedProjects()));
// skip } catch (CoreException e) {
// skip
}
} }
} }
} }

View file

@ -10,9 +10,9 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal.commands; package org.eclipse.cdt.launchbar.ui.internal.commands;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager;
import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionEvent;
@ -30,15 +30,10 @@ import org.eclipse.ui.handlers.HandlerUtil;
public class ConfigureActiveLaunchHandler extends AbstractHandler { public class ConfigureActiveLaunchHandler extends AbstractHandler {
private final ILaunchBarManager launchBarManager;
public ConfigureActiveLaunchHandler() {
launchBarManager = Activator.getService(ILaunchBarManager.class);
}
@Override @Override
public Object execute(ExecutionEvent event) throws ExecutionException { public Object execute(ExecutionEvent event) throws ExecutionException {
try { try {
LaunchBarManager launchBarManager = Activator.getDefault().getLaunchBarUIManager().getManager();
ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor(); ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor();
ILaunchTarget target = launchBarManager.getActiveLaunchTarget(); ILaunchTarget target = launchBarManager.getActiveLaunchTarget();
ILaunchConfiguration launchConfiguration = launchBarManager.getLaunchConfiguration(desc, target); ILaunchConfiguration launchConfiguration = launchBarManager.getLaunchConfiguration(desc, target);

View file

@ -10,9 +10,9 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.launchbar.ui.internal.commands; package org.eclipse.cdt.launchbar.ui.internal.commands;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager;
import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionEvent;
@ -29,17 +29,12 @@ import org.eclipse.ui.progress.UIJob;
public class LaunchActiveCommandHandler extends AbstractHandler { public class LaunchActiveCommandHandler extends AbstractHandler {
private final ILaunchBarManager launchBarManager;
public LaunchActiveCommandHandler() {
launchBarManager = Activator.getService(ILaunchBarManager.class);
}
@Override @Override
public Object execute(ExecutionEvent event) throws ExecutionException { public Object execute(ExecutionEvent event) throws ExecutionException {
new UIJob(Display.getDefault(), "Launching Active Configuration") { new UIJob(Display.getDefault(), "Launching Active Configuration") {
public IStatus runInUIThread(IProgressMonitor monitor) { public IStatus runInUIThread(IProgressMonitor monitor) {
try { try {
LaunchBarManager launchBarManager = Activator.getDefault().getLaunchBarUIManager().getManager();
ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor(); ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor();
ILaunchTarget target = launchBarManager.getActiveLaunchTarget(); ILaunchTarget target = launchBarManager.getActiveLaunchTarget();
ILaunchConfiguration config = launchBarManager.getLaunchConfiguration(desc, target); ILaunchConfiguration config = launchBarManager.getLaunchConfiguration(desc, target);

View file

@ -13,9 +13,9 @@ package org.eclipse.cdt.launchbar.ui.internal.controls;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager;
import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.cdt.launchbar.ui.internal.DefaultDescriptorLabelProvider; import org.eclipse.cdt.launchbar.ui.internal.DefaultDescriptorLabelProvider;
import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager; import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager;
@ -61,7 +61,7 @@ import org.eclipse.ui.PlatformUI;
@SuppressWarnings("restriction") @SuppressWarnings("restriction")
public class ConfigSelector extends CSelector { public class ConfigSelector extends CSelector {
private LaunchBarUIManager uiManager; private LaunchBarUIManager uiManager = Activator.getDefault().getLaunchBarUIManager();
private DefaultDescriptorLabelProvider defaultProvider; private DefaultDescriptorLabelProvider defaultProvider;
private static final String[] noConfigs = new String[] { "No Launch Configurations" }; private static final String[] noConfigs = new String[] { "No Launch Configurations" };
@ -82,7 +82,7 @@ public class ConfigSelector extends CSelector {
} }
@Override @Override
public Object[] getElements(Object inputElement) { public Object[] getElements(Object inputElement) {
ILaunchDescriptor[] descs = getManager().getOpenLaunchDescriptors(); ILaunchDescriptor[] descs = uiManager.getManager().getLaunchDescriptors();
if (descs.length > 0) { if (descs.length > 0) {
if (descs.length > SEPARATOR_INDEX + 1) { if (descs.length > SEPARATOR_INDEX + 1) {
ILaunchDescriptor[] descsCopy = new ILaunchDescriptor[SEPARATOR_INDEX + descs.length]; ILaunchDescriptor[] descsCopy = new ILaunchDescriptor[SEPARATOR_INDEX + descs.length];
@ -107,12 +107,16 @@ public class ConfigSelector extends CSelector {
@Override @Override
public Image getImage(Object element) { public Image getImage(Object element) {
if (element instanceof ILaunchDescriptor) { if (element instanceof ILaunchDescriptor) {
ILaunchDescriptor configDesc = (ILaunchDescriptor)element; try {
ILabelProvider labelProvider = uiManager.getLabelProvider(configDesc); ILaunchDescriptor configDesc = (ILaunchDescriptor)element;
if (labelProvider != null) { ILabelProvider labelProvider = uiManager.getLabelProvider(configDesc);
Image img = labelProvider.getImage(element); if (labelProvider != null) {
if (img != null) Image img = labelProvider.getImage(element);
return img; if (img != null)
return img;
}
} catch (CoreException e) {
Activator.log(e.getStatus());
} }
} }
return defaultProvider.getImage(element); return defaultProvider.getImage(element);
@ -122,12 +126,16 @@ public class ConfigSelector extends CSelector {
if (element instanceof String) { if (element instanceof String) {
return (String)element; return (String)element;
} else if (element instanceof ILaunchDescriptor) { } else if (element instanceof ILaunchDescriptor) {
ILaunchDescriptor configDesc = (ILaunchDescriptor)element; try {
ILabelProvider labelProvider = uiManager.getLabelProvider(configDesc); ILaunchDescriptor configDesc = (ILaunchDescriptor)element;
if (labelProvider != null) { ILabelProvider labelProvider = uiManager.getLabelProvider(configDesc);
String text = labelProvider.getText(element); if (labelProvider != null) {
if (text != null) String text = labelProvider.getText(element);
return text; if (text != null)
return text;
}
} catch (CoreException e) {
Activator.log(e.getStatus());
} }
} }
return defaultProvider.getText(element); return defaultProvider.getText(element);
@ -144,9 +152,9 @@ public class ConfigSelector extends CSelector {
if (selected instanceof ILaunchDescriptor) { if (selected instanceof ILaunchDescriptor) {
ILaunchDescriptor configDesc = (ILaunchDescriptor) selected; ILaunchDescriptor configDesc = (ILaunchDescriptor) selected;
try { try {
getManager().setActiveLaunchDescriptor(configDesc); uiManager.getManager().setActiveLaunchDescriptor(configDesc);
} catch (CoreException e) { } catch (CoreException e) {
Activator.log(e); Activator.log(e.getStatus());
} }
} }
} }
@ -160,14 +168,15 @@ public class ConfigSelector extends CSelector {
public void handleEdit(Object element) { public void handleEdit(Object element) {
try { try {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
LaunchBarManager manager = uiManager.getManager();
ILaunchDescriptor desc = (ILaunchDescriptor) element; ILaunchDescriptor desc = (ILaunchDescriptor) element;
ILaunchMode mode = getManager().getActiveLaunchMode(); ILaunchMode mode = manager.getActiveLaunchMode();
ILaunchTarget target = getManager().getActiveLaunchTarget(); ILaunchTarget target = manager.getActiveLaunchTarget();
if (target == null) { if (target == null) {
MessageDialog.openError(shell, "No Active Target", "You must create a target to edit this launch configuration."); MessageDialog.openError(shell, "No Active Target", "You must create a target to edit this launch configuration.");
return; return;
} }
ILaunchConfigurationType configType = getManager().getLaunchConfigurationType(desc, target); ILaunchConfigurationType configType = manager.getLaunchConfigurationType(desc, target);
if (configType == null) { if (configType == null) {
MessageDialog.openError(shell, "No launch configuration type", "Cannot edit this configuration"); MessageDialog.openError(shell, "No launch configuration type", "Cannot edit this configuration");
return; return;
@ -175,7 +184,7 @@ public class ConfigSelector extends CSelector {
ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(configType, mode.getIdentifier()); ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(configType, mode.getIdentifier());
LaunchGroupExtension groupExt = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(group.getIdentifier()); LaunchGroupExtension groupExt = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(group.getIdentifier());
if (groupExt != null) { if (groupExt != null) {
ILaunchConfiguration config = getManager().getLaunchConfiguration(desc, target); ILaunchConfiguration config = manager.getLaunchConfiguration(desc, target);
if (config == null) { if (config == null) {
MessageDialog.openError(shell, "No launch configuration", "Cannot edit this configuration"); MessageDialog.openError(shell, "No launch configuration", "Cannot edit this configuration");
return; return;
@ -236,7 +245,7 @@ public class ConfigSelector extends CSelector {
try { try {
wizard.getWorkingCopy().doSave(); wizard.getWorkingCopy().doSave();
ILaunchMode lm = wizard.getLaunchMode(); ILaunchMode lm = wizard.getLaunchMode();
getManager().setActiveLaunchMode(lm); uiManager.getManager().setActiveLaunchMode(lm);
return Status.OK_STATUS; return Status.OK_STATUS;
} catch (CoreException e) { } catch (CoreException e) {
return e.getStatus(); return e.getStatus();
@ -271,16 +280,6 @@ public class ConfigSelector extends CSelector {
return super.computeSize(250, hHint, changed); return super.computeSize(250, hHint, changed);
} }
private ILaunchBarManager getManager() {
return (ILaunchBarManager) getInput();
}
@Override
public void setInput(Object input) {
super.setInput(input);
uiManager = (LaunchBarUIManager) ((ILaunchBarManager) input).getAdapter(LaunchBarUIManager.class);
}
@Override @Override
public void setSelection(Object element) { public void setSelection(Object element) {
if (element == null) if (element == null)

View file

@ -12,14 +12,13 @@ package org.eclipse.cdt.launchbar.ui.internal.controls;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
import javax.inject.Inject;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager;
import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager.Listener;
import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.cdt.launchbar.ui.internal.Messages; import org.eclipse.cdt.launchbar.ui.internal.Messages;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchMode; import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeEvent;
@ -32,13 +31,12 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
public class LaunchBarControl implements ILaunchBarManager.Listener { public class LaunchBarControl implements Listener {
public static final String ID = "org.eclipse.cdt.launchbar"; //$NON-NLS-1$ public static final String ID = "org.eclipse.cdt.launchbar"; //$NON-NLS-1$
public static final String CLASS_URI = "bundleclass://" + Activator.PLUGIN_ID + "/" + LaunchBarControl.class.getName(); //$NON-NLS-1$ //$NON-NLS-2$ public static final String CLASS_URI = "bundleclass://" + Activator.PLUGIN_ID + "/" + LaunchBarControl.class.getName(); //$NON-NLS-1$ //$NON-NLS-2$
@Inject private LaunchBarManager manager = Activator.getDefault().getLaunchBarUIManager().getManager();
private ILaunchBarManager manager;
private ConfigSelector configSelector; private ConfigSelector configSelector;
private ModeSelector modeSelector; private ModeSelector modeSelector;
@ -81,18 +79,14 @@ public class LaunchBarControl implements ILaunchBarManager.Listener {
targetSelector.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); targetSelector.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
targetSelector.setInput(manager); targetSelector.setInput(manager);
try { ILaunchDescriptor configDesc = manager.getActiveLaunchDescriptor();
ILaunchDescriptor configDesc = manager.getActiveLaunchDescriptor(); configSelector.setSelection(configDesc == null ? null : configDesc);
configSelector.setSelection(configDesc == null ? null : configDesc);
ILaunchMode mode = manager.getActiveLaunchMode(); ILaunchMode mode = manager.getActiveLaunchMode();
modeSelector.setSelection(mode == null ? null : mode); modeSelector.setSelection(mode == null ? null : mode);
ILaunchTarget target = manager.getActiveLaunchTarget(); ILaunchTarget target = manager.getActiveLaunchTarget();
targetSelector.setSelection(target == null ? null : target); targetSelector.setSelection(target == null ? null : target);
} catch (CoreException e) {
Activator.log(e.getStatus());
}
} }
@PreDestroy @PreDestroy
@ -118,54 +112,42 @@ public class LaunchBarControl implements ILaunchBarManager.Listener {
@Override @Override
public void activeConfigurationDescriptorChanged() { public void activeConfigurationDescriptorChanged() {
if (configSelector != null && !configSelector.isDisposed()) { if (configSelector != null && !configSelector.isDisposed()) {
try { final ILaunchDescriptor configDesc = manager.getActiveLaunchDescriptor();
final ILaunchDescriptor configDesc = manager.getActiveLaunchDescriptor(); configSelector.getDisplay().asyncExec(new Runnable() {
configSelector.getDisplay().asyncExec(new Runnable() { @Override
@Override public void run() {
public void run() { if (!configSelector.isDisposed())
if (!configSelector.isDisposed()) configSelector.setSelection(configDesc == null ? null : configDesc);
configSelector.setSelection(configDesc == null ? null : configDesc); }
} });
});
} catch (CoreException e) {
Activator.log(e.getStatus());
}
} }
} }
@Override @Override
public void activeLaunchModeChanged() { public void activeLaunchModeChanged() {
if (modeSelector != null && !modeSelector.isDisposed()) { if (modeSelector != null && !modeSelector.isDisposed()) {
try { final ILaunchMode mode = manager.getActiveLaunchMode();
final ILaunchMode mode = manager.getActiveLaunchMode(); modeSelector.getDisplay().asyncExec(new Runnable() {
modeSelector.getDisplay().asyncExec(new Runnable() { @Override
@Override public void run() {
public void run() { if (!modeSelector.isDisposed())
if (!modeSelector.isDisposed()) modeSelector.setSelection(mode == null ? null : mode);
modeSelector.setSelection(mode == null ? null : mode); }
} });
});
} catch (CoreException e) {
Activator.log(e.getStatus());
}
} }
} }
@Override @Override
public void activeLaunchTargetChanged() { public void activeLaunchTargetChanged() {
if (targetSelector != null && !targetSelector.isDisposed()) { if (targetSelector != null && !targetSelector.isDisposed()) {
try { final ILaunchTarget target = manager.getActiveLaunchTarget();
final ILaunchTarget target = manager.getActiveLaunchTarget(); targetSelector.getDisplay().asyncExec(new Runnable() {
targetSelector.getDisplay().asyncExec(new Runnable() { @Override
@Override public void run() {
public void run() { if (!targetSelector.isDisposed())
if (!targetSelector.isDisposed()) targetSelector.setSelection(target == null ? null : target);
targetSelector.setSelection(target == null ? null : target); }
} });
});
} catch (CoreException e) {
Activator.log(e.getStatus());
}
} }
} }

View file

@ -14,7 +14,7 @@ import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager; import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager;
import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationType;
@ -33,7 +33,9 @@ import org.eclipse.swt.widgets.Composite;
public class ModeSelector extends CSelector { public class ModeSelector extends CSelector {
private static final String[] noModes = new String[] { "---" }; private static final String[] noModes = new String[] { "---" };
private final LaunchBarManager manager = Activator.getDefault().getLaunchBarUIManager().getManager();
public ModeSelector(Composite parent, int style) { public ModeSelector(Composite parent, int style) {
super(parent, style); super(parent, style);
@ -49,11 +51,11 @@ public class ModeSelector extends CSelector {
@Override @Override
public Object[] getElements(Object inputElement) { public Object[] getElements(Object inputElement) {
try { try {
ILaunchMode[] modes = getManager().getLaunchModes(); ILaunchMode[] modes = manager.getLaunchModes();
if (modes.length > 0) if (modes.length > 0)
return modes; return modes;
} catch (CoreException e) { } catch (CoreException e) {
Activator.log(e); Activator.log(e.getStatus());
} }
return noModes; return noModes;
} }
@ -72,15 +74,19 @@ public class ModeSelector extends CSelector {
public Image getImage(Object element) { public Image getImage(Object element) {
if (element instanceof ILaunchMode) { if (element instanceof ILaunchMode) {
ILaunchMode mode = (ILaunchMode) element; ILaunchMode mode = (ILaunchMode) element;
ILaunchGroup group = getLaunchGroup(mode.getIdentifier()); try {
if (group != null) { ILaunchGroup group = getLaunchGroup(mode.getIdentifier());
ImageDescriptor imageDesc = group.getImageDescriptor(); if (group != null) {
Image image = images.get(imageDesc); ImageDescriptor imageDesc = group.getImageDescriptor();
if (image == null) { Image image = images.get(imageDesc);
image = imageDesc.createImage(); if (image == null) {
images.put(imageDesc, image); image = imageDesc.createImage();
images.put(imageDesc, image);
}
return image;
} }
return image; } catch (CoreException e) {
Activator.log(e.getStatus());
} }
} }
return super.getImage(element); return super.getImage(element);
@ -89,9 +95,13 @@ public class ModeSelector extends CSelector {
public String getText(Object element) { public String getText(Object element) {
if (element instanceof ILaunchMode) { if (element instanceof ILaunchMode) {
ILaunchMode mode = (ILaunchMode) element; ILaunchMode mode = (ILaunchMode) element;
ILaunchGroup group = getLaunchGroup(mode.getIdentifier()); try {
if (group != null) { ILaunchGroup group = getLaunchGroup(mode.getIdentifier());
return group.getLabel().replace("&", ""); if (group != null) {
return group.getLabel().replace("&", "");
}
} catch (CoreException e) {
Activator.log(e.getStatus());
} }
} }
return super.getText(element); return super.getText(element);
@ -128,16 +138,11 @@ public class ModeSelector extends CSelector {
} }
protected ILaunchGroup getLaunchGroup(String mode) { protected ILaunchGroup getLaunchGroup(String mode) throws CoreException {
try { ILaunchConfigurationType type = manager.getLaunchConfigurationType(manager.getActiveLaunchDescriptor(), manager.getActiveLaunchTarget());
ILaunchConfigurationType type = getManager().getLaunchConfigurationType(getManager().getActiveLaunchDescriptor(), getManager().getActiveLaunchTarget()); if (type == null)
if (type == null) return null;
return null; return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(type, mode);
return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(type, mode);
} catch (CoreException e) {
Activator.log(e.getStatus());
}
return null;
} }
@Override @Override
@ -146,27 +151,23 @@ public class ModeSelector extends CSelector {
if (selected instanceof ILaunchMode) { if (selected instanceof ILaunchMode) {
ILaunchMode mode = (ILaunchMode) selected; ILaunchMode mode = (ILaunchMode) selected;
try { try {
getManager().setActiveLaunchMode(mode); manager.setActiveLaunchMode(mode);
} catch (CoreException e) { } catch (CoreException e) {
Activator.log(e); Activator.log(e.getStatus());
} }
} }
} }
@Override @Override
public Point computeSize(int wHint, int hHint, boolean changed) { public Point computeSize(int wHint, int hHint, boolean changed) {
return super.computeSize(150, hHint, changed); return super.computeSize(150, hHint, changed);
} }
private ILaunchBarManager getManager() {
return (ILaunchBarManager) getInput();
}
@Override @Override
public void setSelection(Object element) { public void setSelection(Object element) {
if (element == null) if (element == null)
element = noModes[0]; element = noModes[0];
super.setSelection(element); super.setSelection(element);
} }
} }

View file

@ -13,7 +13,6 @@ package org.eclipse.cdt.launchbar.ui.internal.controls;
import java.util.Comparator; import java.util.Comparator;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.ui.IHoverProvider; import org.eclipse.cdt.launchbar.ui.IHoverProvider;
import org.eclipse.cdt.launchbar.ui.ILaunchBarUIConstants; import org.eclipse.cdt.launchbar.ui.ILaunchBarUIConstants;
@ -45,16 +44,13 @@ import org.eclipse.ui.dialogs.ListDialog;
public class TargetSelector extends CSelector { public class TargetSelector extends CSelector {
private final LaunchBarUIManager uiManager; private final LaunchBarUIManager uiManager = Activator.getDefault().getLaunchBarUIManager();
private static final String[] noTargets = new String[] { "---" }; private static final String[] noTargets = new String[] { "---" };
public TargetSelector(Composite parent, int style) { public TargetSelector(Composite parent, int style) {
super(parent, style); super(parent, style);
ILaunchBarManager manager = Activator.getService(ILaunchBarManager.class);
uiManager = (LaunchBarUIManager) manager.getAdapter(LaunchBarUIManager.class);
setContentProvider(new IStructuredContentProvider() { setContentProvider(new IStructuredContentProvider() {
@Override @Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
@ -67,7 +63,7 @@ public class TargetSelector extends CSelector {
@Override @Override
public Object[] getElements(Object inputElement) { public Object[] getElements(Object inputElement) {
try { try {
ILaunchTarget[] targets = getManager().getLaunchTargets(); ILaunchTarget[] targets = uiManager.getManager().getLaunchTargets();
if (targets.length > 0) if (targets.length > 0)
return targets; return targets;
} catch (CoreException e) { } catch (CoreException e) {
@ -81,10 +77,14 @@ public class TargetSelector extends CSelector {
@Override @Override
public Image getImage(Object element) { public Image getImage(Object element) {
if (element instanceof ILaunchTarget) { if (element instanceof ILaunchTarget) {
ILaunchTarget target = (ILaunchTarget) element; try {
ILabelProvider labelProvider = uiManager.getLabelProvider(target); ILaunchTarget target = (ILaunchTarget) element;
if (labelProvider != null) { ILabelProvider labelProvider = uiManager.getLabelProvider(target);
return labelProvider.getImage(element); if (labelProvider != null) {
return labelProvider.getImage(element);
}
} catch (CoreException e) {
Activator.log(e.getStatus());
} }
} }
return super.getImage(element); return super.getImage(element);
@ -93,12 +93,16 @@ public class TargetSelector extends CSelector {
@Override @Override
public String getText(Object element) { public String getText(Object element) {
if (element instanceof ILaunchTarget) { if (element instanceof ILaunchTarget) {
ILaunchTarget target = (ILaunchTarget) element; ILaunchTarget target = (ILaunchTarget) element;
ILabelProvider labelProvider = uiManager.getLabelProvider(target); try {
if (labelProvider != null) { ILabelProvider labelProvider = uiManager.getLabelProvider(target);
return labelProvider.getText(element); if (labelProvider != null) {
} return labelProvider.getText(element);
return target.getName(); }
} catch (CoreException e) {
Activator.log(e.getStatus());
}
return target.getName();
} }
return super.getText(element); return super.getText(element);
} }
@ -116,10 +120,14 @@ public class TargetSelector extends CSelector {
@Override @Override
public boolean displayHover(Object element) { public boolean displayHover(Object element) {
if (element instanceof ILaunchTarget) { if (element instanceof ILaunchTarget) {
ILaunchTarget target = (ILaunchTarget) element; try {
IHoverProvider hoverProvider = uiManager.getHoverProvider(target); ILaunchTarget target = (ILaunchTarget) element;
if (hoverProvider != null) { IHoverProvider hoverProvider = uiManager.getHoverProvider(target);
return hoverProvider.displayHover(element); if (hoverProvider != null) {
return hoverProvider.displayHover(element);
}
} catch (CoreException e) {
Activator.log(e.getStatus());
} }
} }
return false; return false;
@ -128,10 +136,14 @@ public class TargetSelector extends CSelector {
@Override @Override
public void dismissHover(Object element, boolean immediate) { public void dismissHover(Object element, boolean immediate) {
if (element instanceof ILaunchTarget) { if (element instanceof ILaunchTarget) {
ILaunchTarget target = (ILaunchTarget) element; try {
IHoverProvider hoverProvider = uiManager.getHoverProvider(target); ILaunchTarget target = (ILaunchTarget) element;
if (hoverProvider != null) { IHoverProvider hoverProvider = uiManager.getHoverProvider(target);
hoverProvider.dismissHover(element, immediate); if (hoverProvider != null) {
hoverProvider.dismissHover(element, immediate);
}
} catch (CoreException e) {
Activator.log(e.getStatus());
} }
} }
} }
@ -261,10 +273,6 @@ public class TargetSelector extends CSelector {
return super.computeSize(200, hHint, changed); return super.computeSize(200, hHint, changed);
} }
private ILaunchBarManager getManager() {
return (ILaunchBarManager) getInput();
}
@Override @Override
public void setSelection(Object element) { public void setSelection(Object element) {
if (element == null) if (element == null)

View file

@ -0,0 +1,26 @@
/*******************************************************************************
* 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.ui.internal.targetsView;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.window.SameShellProvider;
import org.eclipse.ui.dialogs.PropertyDialogAction;
import org.eclipse.ui.navigator.CommonActionProvider;
public class LaunchTargetsActionProvider extends CommonActionProvider {
@Override
public void fillContextMenu(IMenuManager menu) {
menu.add(new PropertyDialogAction(new SameShellProvider(getActionSite().getViewSite().getShell()),
getActionSite().getStructuredViewer()));
}
}

View file

@ -0,0 +1,73 @@
/*******************************************************************************
* 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.ui.internal.targetsView;
import java.util.Arrays;
import java.util.Comparator;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
public class LaunchTargetsContentProvider implements ITreeContentProvider {
private LaunchBarManager manager;
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof LaunchBarManager) {
ILaunchTarget[] targets = ((LaunchBarManager) inputElement).getAllLaunchTargets();
Arrays.sort(targets, new Comparator<ILaunchTarget>() {
@Override
public int compare(ILaunchTarget o1, ILaunchTarget o2) {
return o1.getName().compareTo(o2.getName());
}
});
return targets;
}
return null;
}
@Override
public Object[] getChildren(Object parentElement) {
return new Object[0];
}
@Override
public Object getParent(Object element) {
if (element instanceof ILaunchTarget) {
return manager;
}
return null;
}
@Override
public boolean hasChildren(Object element) {
if (element instanceof LaunchBarManager)
return true;
else if (element instanceof ILaunchTarget)
return false;
return false;
}
@Override
public void dispose() {
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
if (newInput instanceof LaunchBarManager) {
manager = (LaunchBarManager) newInput;
}
}
}

View file

@ -0,0 +1,32 @@
/*******************************************************************************
* 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.ui.internal.targetsView;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
public class LaunchTargetsLabelProvider extends LabelProvider {
@Override
public Image getImage(Object element) {
return super.getImage(element);
}
@Override
public String getText(Object element) {
if (element instanceof ILaunchTarget) {
return ((ILaunchTarget) element).getName();
}
return super.getText(element);
}
}

View file

@ -0,0 +1,55 @@
/*******************************************************************************
* 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.ui.internal.targetsView;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager;
import org.eclipse.ui.navigator.CommonNavigator;
public class LaunchTargetsNavigator extends CommonNavigator {
private final LaunchBarUIManager uiManager = Activator.getDefault().getLaunchBarUIManager();
public LaunchTargetsNavigator() {
uiManager.getManager().addListener(new LaunchBarManager.Listener() {
@Override
public void launchTargetsChanged() {
getSite().getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
getCommonViewer().refresh();
}
});
}
@Override
public void launchDescriptorRemoved(ILaunchDescriptor descriptor) {
}
@Override
public void activeLaunchTargetChanged() {
}
@Override
public void activeLaunchModeChanged() {
}
@Override
public void activeConfigurationDescriptorChanged() {
}
});
}
@Override
protected Object getInitialInput() {
return uiManager.getManager();
}
}

View file

@ -1,157 +0,0 @@
package org.eclipse.cdt.launchbar.ui.internal.targetsView;
import java.util.Arrays;
import java.util.Comparator;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
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.LaunchBarManager;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.dialogs.PropertyDialogAction;
import org.eclipse.ui.part.ViewPart;
public class LaunchTargetsViewPart extends ViewPart {
private TreeViewer treeViewer;
private final LaunchBarUIManager uiManager;
public LaunchTargetsViewPart() {
ILaunchBarManager manager = Activator.getService(ILaunchBarManager.class);
uiManager = (LaunchBarUIManager) manager.getAdapter(LaunchBarUIManager.class);
}
@Override
public void createPartControl(Composite parent) {
treeViewer = new TreeViewer(parent, SWT.NONE);
treeViewer.setContentProvider(new ITreeContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public boolean hasChildren(Object element) {
if (element instanceof LaunchBarManager)
return true;
else if (element instanceof ILaunchTargetType)
return true;
else if (element instanceof ILaunchTarget)
return false;
return false;
}
@Override
public Object getParent(Object element) {
if (element instanceof ILaunchTarget)
return ((ILaunchTarget) element).getType();
return null;
}
@Override
public Object[] getElements(Object inputElement) {
// TODO optionally categorize by launch type, maybe
// return ((LaunchBarManager) inputElement).getLaunchTargetTypes();
return ((LaunchBarManager) inputElement).getAllLaunchTargets();
}
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof ILaunchTargetType)
return ((ILaunchTargetType) parentElement).getTargets();
return new Object[0];
}
});
treeViewer.setSorter(new ViewerSorter() {
@Override
public void sort(Viewer viewer, Object[] elements) {
if (elements instanceof ILaunchTarget[]) {
Arrays.sort((ILaunchTarget[]) elements, new Comparator<ILaunchTarget>() {
@Override
public int compare(ILaunchTarget o1, ILaunchTarget o2) {
return o1.getName().compareTo(o2.getName());
}
});
}
}
});
treeViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof ILaunchTargetType) {
return element.getClass().getSimpleName();
} else if (element instanceof ILaunchTarget) {
ILaunchTarget target = (ILaunchTarget) element;
ILabelProvider targetLabelProvider = uiManager.getLabelProvider(target);
if (targetLabelProvider != null) {
return targetLabelProvider.getText(element);
} else {
return target.getName();
}
} else {
return super.getText(element);
}
}
});
final ILaunchBarManager launchBarManager = Activator.getService(ILaunchBarManager.class);
treeViewer.setInput(launchBarManager);
launchBarManager.addListener(new ILaunchBarManager.Listener() {
@Override
public void launchTargetsChanged() {
treeViewer.getControl().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
treeViewer.setInput(launchBarManager);
}
});
}
@Override
public void launchDescriptorRemoved(ILaunchDescriptor descriptor) {
}
@Override
public void activeLaunchTargetChanged() {
}
@Override
public void activeLaunchModeChanged() {
}
@Override
public void activeConfigurationDescriptorChanged() {
}
});
MenuManager menuManager = new MenuManager();
menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
menuManager.add(new Separator());
menuManager.add(new PropertyDialogAction(getSite(), treeViewer));
Menu menu = menuManager.createContextMenu(treeViewer.getControl());
treeViewer.getControl().setMenu(menu);
getSite().registerContextMenu(menuManager, treeViewer);
getSite().setSelectionProvider(treeViewer);
}
@Override
public void setFocus() {
treeViewer.getControl().setFocus();
}
}

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.ui.internal.targetsView; package org.eclipse.cdt.launchbar.ui.internal.targetsView;
import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.core.ILaunchTarget;
@ -29,20 +39,6 @@ public class TargetPropertyPage extends PropertyPage {
nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
nameText.setText(target.getName()); nameText.setText(target.getName());
Label targetLabel = new Label(comp, SWT.NONE);
targetLabel.setText("Target Id:");
Label targetId = new Label(comp, SWT.NONE);
targetId.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
targetId.setText(target.getId());
Label typeLabel = new Label(comp, SWT.NONE);
typeLabel.setText("Target Type:");
Label typeId = new Label(comp, SWT.NONE);
typeId.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
typeId.setText(target.getType().getId());
return comp; return comp;
} }