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="org.eclipse.cdt.launchbar.core.launchBarContributions">
<descriptorType
class="org.eclipse.cdt.launchbar.core.internal.DefaultLaunchDescriptorType"
id="org.eclipse.cdt.launchbar.core.descriptor.default"
priority="0">
</descriptorType>
<targetType
class="org.eclipse.cdt.launchbar.core.internal.LocalTargetType"
id="org.eclipse.cdt.launchbar.core.target.local">
id="org.eclipse.cdt.launchbar.core.targetType.local">
</targetType>
<configProvider
class="org.eclipse.cdt.launchbar.core.internal.DefaultLaunchConfigurationProvider"
descriptorType="org.eclipse.cdt.launchbar.core.descriptor.default"
isDefault="true"
targetType="org.eclipse.cdt.launchbar.core.target.local">
</configProvider>
<objectProvider
class="org.eclipse.cdt.launchbar.core.internal.ProjectLaunchObjectProvider"
id="org.eclipse.cdt.launchbar.core.objectProvider.project">

View file

@ -20,8 +20,10 @@
<sequence minOccurs="0" maxOccurs="unbounded">
<element ref="descriptorType"/>
<element ref="targetType"/>
<element ref="configType"/>
<element ref="configProvider"/>
<element ref="objectProvider"/>
<element ref="defaultConfigTarget"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
@ -51,6 +53,11 @@
</element>
<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>
<attribute name="id" type="string" use="required">
<annotation>
@ -80,6 +87,11 @@
</element>
<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>
<attribute name="id" type="string" use="required">
<annotation>
@ -101,7 +113,12 @@
</complexType>
</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>
<attribute name="descriptorType" type="string" use="required">
<annotation>
@ -123,13 +140,13 @@
</appinfo>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
<attribute name="launchConfigurationType" type="string" use="required">
<annotation>
<documentation>
</documentation>
<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>
</annotation>
</attribute>
@ -143,11 +160,10 @@
</complexType>
</element>
<element name="defaultConfigProvider">
<element name="configProvider">
<annotation>
<documentation>
default provider provides direct mapping between launch configuration types
and launch objects/types without any extra classes involved. The object for this provider is launch configuration, and descriptor is DefaultLaunchDescriptor
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.
</documentation>
</annotation>
<complexType>
@ -161,13 +177,33 @@ and launch objects/types without any extra classes involved. The object for this
</appinfo>
</annotation>
</attribute>
<attribute name="descriptorType" type="string">
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
</documentation>
<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>
</annotation>
</attribute>
@ -192,6 +228,11 @@ and launch objects/types without any extra classes involved. The object for this
</element>
<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>
<attribute name="id" type="string" use="required">
<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;
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;
void setActiveLaunchDescriptor(ILaunchDescriptor configDesc) throws CoreException;
void updateLaunchDescriptor(ILaunchDescriptor configDesc) throws CoreException;
ILaunchMode[] getLaunchModes() 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 launch object has changed in some way that affects the launch bar.
*
* @param launchObject
* @throws CoreException
*/
void launchObjectChanged(Object launchObject) throws CoreException;
/**
* A new launch target has been added.
*
* @param target launch 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;
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;
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);
// TODO API for adding and removing types.
}

View file

@ -13,36 +13,41 @@ package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
public interface ILaunchConfigurationProvider {
import org.eclipse.debug.core.ILaunchManager;
/**
* Do any initialization.
*
* @param manager
* @throws CoreException
* The provider of launch configurations of a given type for a given descriptor type
* and a given target type.
*/
void init(ILaunchBarManager manager) throws CoreException;
public interface ILaunchConfigurationProvider {
/**
* 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.
* And return that object.
*
* @param configuration
* @return boolean - was the launch configuration added by this provider?
* @return launch object that relates to this config
* @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
* @throws CoreException
*/
ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor) throws CoreException;
ILaunchConfigurationType getLaunchConfigurationType() throws CoreException;
/**
* Create a launch configuration for the descriptor to launch on the target.
@ -52,15 +57,6 @@ public interface ILaunchConfigurationProvider {
* @return launch configuration
* @throws CoreException
*/
ILaunchConfiguration getLaunchConfiguration(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;
ILaunchConfiguration createLaunchConfiguration(ILaunchManager launchManager, ILaunchDescriptor descriptor) throws CoreException;
}

View file

@ -10,26 +10,24 @@
*******************************************************************************/
package org.eclipse.cdt.launchbar.core;
import org.eclipse.core.runtime.IAdaptable;
/**
* 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.
* Names must be unique for all descriptors of a given type.
*
* @return name of the launch descriptor
*/
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.
*
@ -37,9 +35,4 @@ public interface ILaunchDescriptor {
*/
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 {
/**
* The id for the provider.
* Does this type own this launch object?
*
* @return provider id
*/
String getId();
/**
* Called after existing launch configs have been added. The provider
* can now add any more that they'd like to have.
*/
void init(ILaunchBarManager manager);
/**
* Does this type own this launch element.
* @deprecated this needs to be replaced by enablement to avoid plug-in loading.
*
* @param element
* @return owns element
* @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
* configuration, a project, or anything else that gets fed to the
* launch bar manager.
* Return a descriptor for the given launch object.
*
* May return null to essentially eat the element so no other types
* create a descriptor for it.
*
* @param descriptor candidate descriptor
* @param descriptor launch object for descriptor
* @return the best descriptor
* @throws CoreException
*/
ILaunchDescriptor getDescriptor(Object element) throws CoreException;
/**
* Return a handle to the launch bar manager.
*
* @return launchbar manager
*/
ILaunchBarManager getManager();
ILaunchDescriptor getDescriptor(Object launchObject) throws CoreException;
}

View file

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

View file

@ -10,33 +10,30 @@
*******************************************************************************/
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
* stored in the preference store.
* Returns the name of this target.
* Names must be unique across all targets of a given type.
*
* @return id
*/
String getId();
/**
* Returns a name to show in the UI for this target.
*
* @return name
* @return name of the target
*/
String getName();
/**
* Returns the type for this target.
*
* @return target type
* @return type of the target
*/
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;
import org.eclipse.core.runtime.CoreException;
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
* @throws CoreException
*/
void init(ILaunchBarManager manager);
void init(ILaunchBarManager manager) throws CoreException;
/**
* The id of the target type.
*
* @return target type id
* Shutting down, remove any listeners
*/
String getId();
/**
* Return the list of targets for this type.
*
* @return targets
*/
ILaunchTarget[] getTargets();
/**
* Return the target with the specified id.
*
* @param id
* @return target
*/
ILaunchTarget getTarget(String id);
void dispose();
}

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.Plugin;
import org.eclipse.core.runtime.Status;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
public class Activator extends Plugin {
public static final String PLUGIN_ID = "org.eclipse.cdt.launchbar.core";
private static Plugin plugin;
private static Activator plugin;
private LaunchBarManager launchBarManager;
public void start(BundleContext bundleContext) throws Exception {
super.start(bundleContext);
plugin = this;
bundleContext.registerService(ILaunchBarManager.class, new ServiceFactory<ILaunchBarManager>() {
@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);
bundleContext.registerService(ILaunchBarManager.class, launchBarManager, null);
}
public void stop(BundleContext bundleContext) throws Exception {
super.stop(bundleContext);
plugin = null;
launchBarManager.dispose();
launchBarManager = null;
}
public static Activator getDefault() {
return plugin;
}
public LaunchBarManager getLaunchBarManager() {
return launchBarManager;
}
public static void throwCoreException(Exception e) throws CoreException {
throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e));
}

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;
import org.eclipse.cdt.launchbar.core.ConfigBasedLaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType;
import org.eclipse.core.runtime.PlatformObject;
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) {
super(type, config);
public DefaultLaunchDescriptor(DefaultLaunchDescriptorType type, ILaunchConfiguration configuration) {
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;
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.ILaunchDescriptorType;
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
public boolean ownsLaunchObject(Object element) {
return element instanceof ILaunchConfiguration;
// This descriptor type doesn't own any launch objects
return false;
}
@Override
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,8 +12,12 @@ package org.eclipse.cdt.launchbar.core.internal;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
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;
@ -21,15 +25,9 @@ public class LocalTarget implements ILaunchTarget {
this.type = type;
}
@Override
public String getId() {
// Use the same ID as the type since we're really a singleton
return type.getId();
}
@Override
public String getName() {
return "Local Machine"; // TODO externalize
return Messages.LocalTarget_name;
}
@Override
@ -38,8 +36,8 @@ public class LocalTarget implements ILaunchTarget {
}
@Override
public void setActive() {
// nothing to do
public void setActive(boolean active) {
// nothing to do, we have no active state
}
}

View file

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

View file

@ -6,18 +6,20 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* 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;
/**
* Project Based launch descriptor knows about project it is associated with
*/
public interface ILaunchDescriptorProjectBased extends ILaunchDescriptor {
/**
* Get associate project
*/
public abstract IProject getProject();
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.launchbar.core.internal.messages"; //$NON-NLS-1$
public static String LocalTarget_name;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}
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,19 +24,19 @@ import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.ResourcesPlugin;
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 {
private ILaunchBarManager manager;
@Override
public void init(ILaunchBarManager manager) {
public void init(ILaunchBarManager manager) throws CoreException {
this.manager = manager;
try {
for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
manager.launchObjectAdded(project);
}
} catch (CoreException e) {
Activator.log(e.getStatus());
}
ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
}

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.ui.workbench,
org.eclipse.ui.ide,
org.eclipse.swt
org.eclipse.swt,
org.eclipse.ui.navigator
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin

View file

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

View file

@ -11,16 +11,6 @@
class="org.eclipse.cdt.launchbar.ui.internal.LaunchBarInjector">
</processor>
</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
point="org.eclipse.ui.commands">
<command
@ -71,16 +61,6 @@
name="Local Target">
</targetUI>
</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
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
@ -107,5 +87,62 @@
</enabledWhen>
</page>
</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>

View file

@ -10,6 +10,12 @@
*******************************************************************************/
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 {
/**

View file

@ -10,6 +10,7 @@
*******************************************************************************/
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.ExecutionEvent;
import org.eclipse.core.commands.IParameter;
@ -55,6 +56,9 @@ public class Activator extends AbstractUIPlugin {
// The shared instance
private static Activator plugin;
// The cache of the Launch Bar UI Manager Object
private LaunchBarUIManager launchBarUIManager;
/**
* The constructor
*/
@ -85,6 +89,14 @@ public class Activator extends AbstractUIPlugin {
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) {
return getImageRegistry().get(id);
}

View file

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

View file

@ -15,9 +15,10 @@ import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.launchbar.core.ILaunchBarManager;
import org.eclipse.cdt.launchbar.core.ILaunchDescriptor;
import org.eclipse.cdt.launchbar.core.ILaunchTarget;
import org.eclipse.cdt.launchbar.core.internal.ExecutableExtension;
import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager;
import org.eclipse.cdt.launchbar.ui.IHoverProvider;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
@ -30,14 +31,14 @@ import org.eclipse.swt.graphics.Image;
public class LaunchBarUIManager {
ILaunchBarManager manager;
Map<String, ILabelProvider> descriptorLabelProviders = new HashMap<>();
LaunchBarManager manager;
Map<String, ExecutableExtension<ILabelProvider>> descriptorLabelProviders = 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);
public LaunchBarUIManager(ILaunchBarManager manager) {
public LaunchBarUIManager(LaunchBarManager manager) {
this.manager = manager;
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchBarUIContributions");
@ -46,58 +47,51 @@ public class LaunchBarUIManager {
for (IConfigurationElement element : extension.getConfigurationElements()) {
String elementName = element.getName();
if (elementName.equals("descriptorUI")) {
try {
String descriptorTypeId = element.getAttribute("descriptorTypeId");
ILabelProvider labelProvider = (ILabelProvider) element.createExecutableExtension("labelProvider");
ExecutableExtension<ILabelProvider> labelProvider = new ExecutableExtension<>(element, "labelProvider");
descriptorLabelProviders.put(descriptorTypeId, labelProvider);
} catch (CoreException e) {
Activator.log(e.getStatus());
}
} else if (elementName.equals("targetUI")) {
try {
String targetTypeId = element.getAttribute("targetTypeId");
String targetName = element.getAttribute("name");
String iconStr = element.getAttribute("icon");
ExecutableExtension<ILabelProvider> labelProvider = new ExecutableExtension<ILabelProvider>(element, "labelProvider");
ILabelProvider labelProvider = (ILabelProvider) element.createExecutableExtension("labelProvider");
IHoverProvider hoverProvider = null;
ExecutableExtension<IHoverProvider> hoverProvider = null;
if (element.getAttribute("hoverProvider") != null) {
hoverProvider = (IHoverProvider) element.createExecutableExtension("hoverProvider");
hoverProvider = new ExecutableExtension<IHoverProvider>(element, "hoverProvider");
}
String editCommandId = element.getAttribute("editCommandId");
String addNewCommandId = element.getAttribute("addNewTargetCommandId");
targetContributions.put(targetTypeId, new LaunchBarTargetContribution(targetTypeId, targetName, iconStr,
targetContributions.put(targetTypeId, new LaunchBarTargetContribution(targetName, iconStr,
labelProvider, hoverProvider, editCommandId, addNewCommandId));
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
}
}
}
public ILaunchBarManager getManager() {
public LaunchBarManager getManager() {
return manager;
}
public ILabelProvider getLabelProvider(ILaunchDescriptor descriptor) {
return descriptorLabelProviders.get(descriptor.getType().getId());
public ILabelProvider getLabelProvider(ILaunchDescriptor descriptor) throws CoreException {
ExecutableExtension<ILabelProvider> provider = descriptorLabelProviders.get(manager.getDescriptorTypeId(descriptor.getType()));
return provider != null ? provider.get() : null;
}
public String getTargetTypeName(ILaunchTarget target) {
return getContribution(target).name;
}
public ILabelProvider getLabelProvider(ILaunchTarget target) {
return getContribution(target).labelProvider;
public ILabelProvider getLabelProvider(ILaunchTarget target) throws CoreException {
ExecutableExtension<ILabelProvider> provider = getContribution(target).labelProvider;
return provider != null ? provider.get() : null;
}
public IHoverProvider getHoverProvider(ILaunchTarget target) {
return getContribution(target).hoverProvider;
public IHoverProvider getHoverProvider(ILaunchTarget target) throws CoreException {
ExecutableExtension<IHoverProvider> hoverProvider = getContribution(target).hoverProvider;
return hoverProvider != null ? hoverProvider.get() : null;
}
public String getEditCommand(ILaunchTarget target) {
@ -129,7 +123,7 @@ public class LaunchBarUIManager {
}
private LaunchBarTargetContribution getContribution(ILaunchTarget target) {
LaunchBarTargetContribution c = targetContributions.get(target.getType().getId());
LaunchBarTargetContribution c = targetContributions.get(manager.getTargetTypeId(target.getType()));
if (c == null) {
return DEFAULT_CONTRIBUTION;
}
@ -137,19 +131,18 @@ public class LaunchBarUIManager {
}
private class LaunchBarTargetContribution {
String id;
String name;
String iconStr;
Image icon;
ILabelProvider labelProvider;
IHoverProvider hoverProvider;
ExecutableExtension<ILabelProvider> labelProvider;
ExecutableExtension<IHoverProvider> hoverProvider;
String editCommandId;
String addNewCommandId;
LaunchBarTargetContribution(String id, String name, String iconStr, ILabelProvider labelProvider,
IHoverProvider hoverProvider, String editCommand, String addNewCommand) {
this.id = id;
LaunchBarTargetContribution(String name, String iconStr,
ExecutableExtension<ILabelProvider> labelProvider,
ExecutableExtension<IHoverProvider> hoverProvider,
String editCommand, String addNewCommand) {
this.name = name;
this.iconStr = iconStr;
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.Set;
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.internal.LaunchBarManager;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
@ -51,12 +51,6 @@ import org.eclipse.ui.progress.UIJob;
*/
public class BuildActiveCommandHandler extends AbstractHandler {
private final ILaunchBarManager launchBarManager;
public BuildActiveCommandHandler() {
launchBarManager = Activator.getService(ILaunchBarManager.class);
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
new UIJob(Display.getDefault(), "Building Active Configuration") {
@ -67,10 +61,16 @@ public class BuildActiveCommandHandler extends AbstractHandler {
public IStatus runInUIThread(IProgressMonitor monitor) {
try {
LaunchBarManager launchBarManager = Activator.getDefault().getLaunchBarUIManager().getManager();
ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor();
ILaunchTarget target = launchBarManager.getActiveLaunchTarget();
ILaunchConfiguration config = launchBarManager.getLaunchConfiguration(desc, target);
Collection<IProject> projects = getProjects(config);
if (BuildAction.isSaveAllSet()) {
saveEditors(projects);
}
if (config == null) {
// Default, build the workspace
ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
@ -78,12 +78,6 @@ public class BuildActiveCommandHandler extends AbstractHandler {
}
ILaunchMode launchMode = launchBarManager.getActiveLaunchMode();
Collection<IProject> projects = getProjects(config);
if (BuildAction.isSaveAllSet()) {
saveEditors(projects);
}
String mode = launchMode.getIdentifier();
Set<String> modes = new HashSet<>();
modes.add(mode);
@ -124,6 +118,7 @@ public class BuildActiveCommandHandler extends AbstractHandler {
protected Collection<IProject> getProjects(ILaunchConfiguration config) {
Set<IProject> projects = new HashSet<>();
if (config != null) {
IResource[] mappedResources;
try {
mappedResources = config.getMappedResources();
@ -143,6 +138,7 @@ public class BuildActiveCommandHandler extends AbstractHandler {
}
}
}
}
return projects;
}

View file

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

View file

@ -10,9 +10,9 @@
*******************************************************************************/
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.ILaunchTarget;
import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
@ -29,17 +29,12 @@ import org.eclipse.ui.progress.UIJob;
public class LaunchActiveCommandHandler extends AbstractHandler {
private final ILaunchBarManager launchBarManager;
public LaunchActiveCommandHandler() {
launchBarManager = Activator.getService(ILaunchBarManager.class);
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
new UIJob(Display.getDefault(), "Launching Active Configuration") {
public IStatus runInUIThread(IProgressMonitor monitor) {
try {
LaunchBarManager launchBarManager = Activator.getDefault().getLaunchBarUIManager().getManager();
ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor();
ILaunchTarget target = launchBarManager.getActiveLaunchTarget();
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.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.internal.LaunchBarManager;
import org.eclipse.cdt.launchbar.ui.internal.Activator;
import org.eclipse.cdt.launchbar.ui.internal.DefaultDescriptorLabelProvider;
import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager;
@ -61,7 +61,7 @@ import org.eclipse.ui.PlatformUI;
@SuppressWarnings("restriction")
public class ConfigSelector extends CSelector {
private LaunchBarUIManager uiManager;
private LaunchBarUIManager uiManager = Activator.getDefault().getLaunchBarUIManager();
private DefaultDescriptorLabelProvider defaultProvider;
private static final String[] noConfigs = new String[] { "No Launch Configurations" };
@ -82,7 +82,7 @@ public class ConfigSelector extends CSelector {
}
@Override
public Object[] getElements(Object inputElement) {
ILaunchDescriptor[] descs = getManager().getOpenLaunchDescriptors();
ILaunchDescriptor[] descs = uiManager.getManager().getLaunchDescriptors();
if (descs.length > 0) {
if (descs.length > SEPARATOR_INDEX + 1) {
ILaunchDescriptor[] descsCopy = new ILaunchDescriptor[SEPARATOR_INDEX + descs.length];
@ -107,6 +107,7 @@ public class ConfigSelector extends CSelector {
@Override
public Image getImage(Object element) {
if (element instanceof ILaunchDescriptor) {
try {
ILaunchDescriptor configDesc = (ILaunchDescriptor)element;
ILabelProvider labelProvider = uiManager.getLabelProvider(configDesc);
if (labelProvider != null) {
@ -114,6 +115,9 @@ public class ConfigSelector extends CSelector {
if (img != null)
return img;
}
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
return defaultProvider.getImage(element);
}
@ -122,6 +126,7 @@ public class ConfigSelector extends CSelector {
if (element instanceof String) {
return (String)element;
} else if (element instanceof ILaunchDescriptor) {
try {
ILaunchDescriptor configDesc = (ILaunchDescriptor)element;
ILabelProvider labelProvider = uiManager.getLabelProvider(configDesc);
if (labelProvider != null) {
@ -129,6 +134,9 @@ public class ConfigSelector extends CSelector {
if (text != null)
return text;
}
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
return defaultProvider.getText(element);
}
@ -144,9 +152,9 @@ public class ConfigSelector extends CSelector {
if (selected instanceof ILaunchDescriptor) {
ILaunchDescriptor configDesc = (ILaunchDescriptor) selected;
try {
getManager().setActiveLaunchDescriptor(configDesc);
uiManager.getManager().setActiveLaunchDescriptor(configDesc);
} catch (CoreException e) {
Activator.log(e);
Activator.log(e.getStatus());
}
}
}
@ -160,14 +168,15 @@ public class ConfigSelector extends CSelector {
public void handleEdit(Object element) {
try {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
LaunchBarManager manager = uiManager.getManager();
ILaunchDescriptor desc = (ILaunchDescriptor) element;
ILaunchMode mode = getManager().getActiveLaunchMode();
ILaunchTarget target = getManager().getActiveLaunchTarget();
ILaunchMode mode = manager.getActiveLaunchMode();
ILaunchTarget target = manager.getActiveLaunchTarget();
if (target == null) {
MessageDialog.openError(shell, "No Active Target", "You must create a target to edit this launch configuration.");
return;
}
ILaunchConfigurationType configType = getManager().getLaunchConfigurationType(desc, target);
ILaunchConfigurationType configType = manager.getLaunchConfigurationType(desc, target);
if (configType == null) {
MessageDialog.openError(shell, "No launch configuration type", "Cannot edit this configuration");
return;
@ -175,7 +184,7 @@ public class ConfigSelector extends CSelector {
ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(configType, mode.getIdentifier());
LaunchGroupExtension groupExt = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(group.getIdentifier());
if (groupExt != null) {
ILaunchConfiguration config = getManager().getLaunchConfiguration(desc, target);
ILaunchConfiguration config = manager.getLaunchConfiguration(desc, target);
if (config == null) {
MessageDialog.openError(shell, "No launch configuration", "Cannot edit this configuration");
return;
@ -236,7 +245,7 @@ public class ConfigSelector extends CSelector {
try {
wizard.getWorkingCopy().doSave();
ILaunchMode lm = wizard.getLaunchMode();
getManager().setActiveLaunchMode(lm);
uiManager.getManager().setActiveLaunchMode(lm);
return Status.OK_STATUS;
} catch (CoreException e) {
return e.getStatus();
@ -271,16 +280,6 @@ public class ConfigSelector extends CSelector {
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
public void setSelection(Object element) {
if (element == null)

View file

@ -12,14 +12,13 @@ package org.eclipse.cdt.launchbar.ui.internal.controls;
import javax.annotation.PostConstruct;
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.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.Messages;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.swt.SWT;
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.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 CLASS_URI = "bundleclass://" + Activator.PLUGIN_ID + "/" + LaunchBarControl.class.getName(); //$NON-NLS-1$ //$NON-NLS-2$
@Inject
private ILaunchBarManager manager;
private LaunchBarManager manager = Activator.getDefault().getLaunchBarUIManager().getManager();
private ConfigSelector configSelector;
private ModeSelector modeSelector;
@ -81,7 +79,6 @@ public class LaunchBarControl implements ILaunchBarManager.Listener {
targetSelector.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
targetSelector.setInput(manager);
try {
ILaunchDescriptor configDesc = manager.getActiveLaunchDescriptor();
configSelector.setSelection(configDesc == null ? null : configDesc);
@ -90,9 +87,6 @@ public class LaunchBarControl implements ILaunchBarManager.Listener {
ILaunchTarget target = manager.getActiveLaunchTarget();
targetSelector.setSelection(target == null ? null : target);
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
@PreDestroy
@ -118,7 +112,6 @@ public class LaunchBarControl implements ILaunchBarManager.Listener {
@Override
public void activeConfigurationDescriptorChanged() {
if (configSelector != null && !configSelector.isDisposed()) {
try {
final ILaunchDescriptor configDesc = manager.getActiveLaunchDescriptor();
configSelector.getDisplay().asyncExec(new Runnable() {
@Override
@ -127,16 +120,12 @@ public class LaunchBarControl implements ILaunchBarManager.Listener {
configSelector.setSelection(configDesc == null ? null : configDesc);
}
});
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
}
@Override
public void activeLaunchModeChanged() {
if (modeSelector != null && !modeSelector.isDisposed()) {
try {
final ILaunchMode mode = manager.getActiveLaunchMode();
modeSelector.getDisplay().asyncExec(new Runnable() {
@Override
@ -145,16 +134,12 @@ public class LaunchBarControl implements ILaunchBarManager.Listener {
modeSelector.setSelection(mode == null ? null : mode);
}
});
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
}
@Override
public void activeLaunchTargetChanged() {
if (targetSelector != null && !targetSelector.isDisposed()) {
try {
final ILaunchTarget target = manager.getActiveLaunchTarget();
targetSelector.getDisplay().asyncExec(new Runnable() {
@Override
@ -163,9 +148,6 @@ public class LaunchBarControl implements ILaunchBarManager.Listener {
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.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.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfigurationType;
@ -34,6 +34,8 @@ public class ModeSelector extends CSelector {
private static final String[] noModes = new String[] { "---" };
private final LaunchBarManager manager = Activator.getDefault().getLaunchBarUIManager().getManager();
public ModeSelector(Composite parent, int style) {
super(parent, style);
@ -49,11 +51,11 @@ public class ModeSelector extends CSelector {
@Override
public Object[] getElements(Object inputElement) {
try {
ILaunchMode[] modes = getManager().getLaunchModes();
ILaunchMode[] modes = manager.getLaunchModes();
if (modes.length > 0)
return modes;
} catch (CoreException e) {
Activator.log(e);
Activator.log(e.getStatus());
}
return noModes;
}
@ -72,6 +74,7 @@ public class ModeSelector extends CSelector {
public Image getImage(Object element) {
if (element instanceof ILaunchMode) {
ILaunchMode mode = (ILaunchMode) element;
try {
ILaunchGroup group = getLaunchGroup(mode.getIdentifier());
if (group != null) {
ImageDescriptor imageDesc = group.getImageDescriptor();
@ -82,6 +85,9 @@ public class ModeSelector extends CSelector {
}
return image;
}
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
return super.getImage(element);
}
@ -89,10 +95,14 @@ public class ModeSelector extends CSelector {
public String getText(Object element) {
if (element instanceof ILaunchMode) {
ILaunchMode mode = (ILaunchMode) element;
try {
ILaunchGroup group = getLaunchGroup(mode.getIdentifier());
if (group != null) {
return group.getLabel().replace("&", "");
}
} catch (CoreException e) {
Activator.log(e.getStatus());
}
}
return super.getText(element);
}
@ -128,16 +138,11 @@ public class ModeSelector extends CSelector {
}
protected ILaunchGroup getLaunchGroup(String mode) {
try {
ILaunchConfigurationType type = getManager().getLaunchConfigurationType(getManager().getActiveLaunchDescriptor(), getManager().getActiveLaunchTarget());
protected ILaunchGroup getLaunchGroup(String mode) throws CoreException {
ILaunchConfigurationType type = manager.getLaunchConfigurationType(manager.getActiveLaunchDescriptor(), manager.getActiveLaunchTarget());
if (type == null)
return null;
return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(type, mode);
} catch (CoreException e) {
Activator.log(e.getStatus());
}
return null;
}
@Override
@ -146,9 +151,9 @@ public class ModeSelector extends CSelector {
if (selected instanceof ILaunchMode) {
ILaunchMode mode = (ILaunchMode) selected;
try {
getManager().setActiveLaunchMode(mode);
manager.setActiveLaunchMode(mode);
} catch (CoreException e) {
Activator.log(e);
Activator.log(e.getStatus());
}
}
}
@ -158,10 +163,6 @@ public class ModeSelector extends CSelector {
return super.computeSize(150, hHint, changed);
}
private ILaunchBarManager getManager() {
return (ILaunchBarManager) getInput();
}
@Override
public void setSelection(Object element) {
if (element == null)

View file

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