From b318ffaedb8f4879e22efa9cfab13ca2f70fe247 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Sun, 13 Jul 2014 14:25:12 -0400 Subject: [PATCH] Bug 437392 - Add support for multiple target types per launch thing. Introduces a whole lot new concepts that will be documented in the wiki. Change-Id: Idd05d5232b88be7ac1d400e5b9618cf08716abf4 Reviewed-on: https://git.eclipse.org/r/29849 Tested-by: Hudson CI Reviewed-by: Doug Schaefer --- .../plugin.xml | 8 - .../cdt/core/internal/Activator.java | 12 + .../internal/CDTLaunchConfigDescriptor.java | 128 ----- .../internal/CDTLaunchConfigProvider.java | 24 - .../org.eclipse.cdt.launchbar.core/plugin.xml | 24 +- .../schema/launchBarContributions.exsd | 205 ++++++++ .../schema/launchConfigProvider.exsd | 109 ---- .../cdt/launchbar/core/ILaunchBarManager.java | 51 +- .../core/ILaunchConfigurationDescriptor.java | 92 ---- .../core/ILaunchConfigurationProvider.java | 65 +++ .../cdt/launchbar/core/ILaunchDescriptor.java | 33 ++ .../launchbar/core/ILaunchDescriptorType.java | 64 +++ .../launchbar/core/ILaunchObjectProvider.java | 21 + .../cdt/launchbar/core/ILaunchTarget.java | 13 + ...nsProvider.java => ILaunchTargetType.java} | 34 +- .../DefaultLaunchConfigurationDescriptor.java | 96 ---- .../DefaultLaunchConfigurationProvider.java | 44 ++ .../internal/DefaultLaunchDescriptor.java | 41 ++ .../internal/DefaultLaunchDescriptorType.java | 39 ++ .../core/internal/LaunchBarManager.java | 491 +++++++++++------- .../launchbar/core/internal/LocalTarget.java | 20 +- .../core/internal/LocalTargetType.java | 34 ++ .../internal/ProjectLaunchObjectProvider.java | 67 +++ .../META-INF/MANIFEST.MF | 1 + .../org.eclipse.cdt.launchbar.ui/plugin.xml | 12 + .../schema/launchBarUIContributions.exsd | 168 ++++++ .../launchbar/ui/ILaunchBarUIConstants.java | 3 + .../cdt/launchbar/ui/internal/Activator.java | 6 +- .../DefaultDescriptorLabelProvider.java | 60 +++ .../ui/internal/LaunchBarUIManager.java | 81 ++- .../ui/internal/LocalTargetLabelProvider.java | 16 + .../commands/BuildActiveCommandHandler.java | 112 ++-- .../ConfigureActiveLaunchHandler.java | 29 +- .../commands/LaunchActiveCommandHandler.java | 54 +- .../commands/StopActiveCommandHandler.java | 37 +- .../ui/internal/controls/ConfigSelector.java | 77 +-- .../internal/controls/LaunchBarControl.java | 89 ++-- .../ui/internal/controls/ModeSelector.java | 15 +- .../ui/internal/controls/TargetSelector.java | 46 +- 39 files changed, 1546 insertions(+), 975 deletions(-) delete mode 100644 launch/org.eclipse.cdt.launchbar.cdt.core/src/org/eclipse/cdt/launchbar/cdt/core/internal/CDTLaunchConfigDescriptor.java delete mode 100644 launch/org.eclipse.cdt.launchbar.cdt.core/src/org/eclipse/cdt/launchbar/cdt/core/internal/CDTLaunchConfigProvider.java create mode 100644 launch/org.eclipse.cdt.launchbar.core/schema/launchBarContributions.exsd delete mode 100644 launch/org.eclipse.cdt.launchbar.core/schema/launchConfigProvider.exsd delete mode 100644 launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchConfigurationDescriptor.java create mode 100644 launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchConfigurationProvider.java create mode 100644 launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptor.java create mode 100644 launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorType.java create mode 100644 launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchObjectProvider.java rename launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/{ILaunchConfigurationsProvider.java => ILaunchTargetType.java} (52%) delete mode 100644 launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchConfigurationDescriptor.java create mode 100644 launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchConfigurationProvider.java create mode 100644 launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptor.java create mode 100644 launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptorType.java create mode 100644 launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LocalTargetType.java create mode 100644 launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/ProjectLaunchObjectProvider.java create mode 100644 launch/org.eclipse.cdt.launchbar.ui/schema/launchBarUIContributions.exsd create mode 100644 launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/DefaultDescriptorLabelProvider.java create mode 100644 launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/LocalTargetLabelProvider.java diff --git a/launch/org.eclipse.cdt.launchbar.cdt.core/plugin.xml b/launch/org.eclipse.cdt.launchbar.cdt.core/plugin.xml index ae90a5929e7..5535690d377 100644 --- a/launch/org.eclipse.cdt.launchbar.cdt.core/plugin.xml +++ b/launch/org.eclipse.cdt.launchbar.cdt.core/plugin.xml @@ -1,13 +1,5 @@ - - - diff --git a/launch/org.eclipse.cdt.launchbar.cdt.core/src/org/eclipse/cdt/launchbar/cdt/core/internal/Activator.java b/launch/org.eclipse.cdt.launchbar.cdt.core/src/org/eclipse/cdt/launchbar/cdt/core/internal/Activator.java index 1ef410fd26f..2ee76bf841d 100644 --- a/launch/org.eclipse.cdt.launchbar.cdt.core/src/org/eclipse/cdt/launchbar/cdt/core/internal/Activator.java +++ b/launch/org.eclipse.cdt.launchbar.cdt.core/src/org/eclipse/cdt/launchbar/cdt/core/internal/Activator.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2014 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Doug Schaefer + *******************************************************************************/ package org.eclipse.cdt.launchbar.cdt.core.internal; import org.osgi.framework.BundleActivator; @@ -5,6 +15,8 @@ import org.osgi.framework.BundleContext; public class Activator implements BundleActivator { + public static final String ID = "org.eclipse.cdt.launchbar.cdt.core"; + private static BundleContext context; static BundleContext getContext() { diff --git a/launch/org.eclipse.cdt.launchbar.cdt.core/src/org/eclipse/cdt/launchbar/cdt/core/internal/CDTLaunchConfigDescriptor.java b/launch/org.eclipse.cdt.launchbar.cdt.core/src/org/eclipse/cdt/launchbar/cdt/core/internal/CDTLaunchConfigDescriptor.java deleted file mode 100644 index 8b3f571755c..00000000000 --- a/launch/org.eclipse.cdt.launchbar.cdt.core/src/org/eclipse/cdt/launchbar/cdt/core/internal/CDTLaunchConfigDescriptor.java +++ /dev/null @@ -1,128 +0,0 @@ -package org.eclipse.cdt.launchbar.cdt.core.internal; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; -import org.eclipse.cdt.launchbar.core.ILaunchBarManager; -import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor; -import org.eclipse.cdt.launchbar.core.ILaunchTarget; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchConfigurationType; -import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; -import org.eclipse.debug.core.ILaunchManager; -import org.eclipse.debug.core.ILaunchMode; - -public class CDTLaunchConfigDescriptor implements ILaunchConfigurationDescriptor { - - private final ILaunchBarManager manager; - private String projectName; - private ILaunchConfiguration config; - private ILaunchMode[] launchModes; - - public CDTLaunchConfigDescriptor(ILaunchBarManager manager, IProject project) { - this.manager = manager; - this.projectName = project.getName(); - } - - public CDTLaunchConfigDescriptor(ILaunchBarManager manager, ILaunchConfiguration config) { - this.manager = manager; - this.config = config; - } - - @Override - public String getName() { - if (config != null) - return config.getName(); - else - return projectName; - } - - private ILaunchManager getLaunchManager() { - return DebugPlugin.getDefault().getLaunchManager(); - } - - private IProject getProject() { - return ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); - } - - @Override - public ILaunchConfiguration getLaunchConfiguration() throws CoreException { - if (config == null) { - ILaunchConfigurationType configType = config.getType(); - ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateLaunchConfigurationName(projectName)); - wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName); - wc.setMappedResources(new IResource[] { getProject() }); - wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null); - - // TODO finish this off - - config = wc.doSave(); - } - return config; - } - - @Override - public boolean matches(ILaunchConfiguration launchConfiguration) throws CoreException { - if (config == launchConfiguration) - return true; - - String pname = launchConfiguration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); - return pname.equals(projectName); - } - - @Override - public ILaunchTarget[] getLaunchTargets() { - return new ILaunchTarget[] { manager.getLocalLaunchTarget() }; - } - - @Override - public ILaunchTarget getLaunchTarget(String id) { - ILaunchTarget localTarget = manager.getLocalLaunchTarget(); - if (localTarget.getId().equals(id)) - return localTarget; - return null; - } - - @Override - public void setActiveLaunchTarget(ILaunchTarget target) { - // TODO Auto-generated method stub - - } - - @Override - public ILaunchMode[] getLaunchModes() throws CoreException { - if (launchModes == null) { - List mymodes = new ArrayList<>(); - ILaunchConfigurationType type = config.getType(); - ILaunchMode[] modes = DebugPlugin.getDefault().getLaunchManager().getLaunchModes(); - for (ILaunchMode mode : modes) { - if (type.supportsMode(mode.getIdentifier())) { - mymodes.add(mode); - } - } - launchModes = mymodes.toArray(new ILaunchMode[mymodes.size()]); - } - return launchModes; - } - - @Override - public ILaunchMode getLaunchMode(String id) throws CoreException { - for (ILaunchMode mode : getLaunchModes()) - if (mode.getIdentifier().equals(id)) - return mode; - return null; - } - - @Override - public void setActiveLaunchMode(ILaunchMode mode) { - // TODO Auto-generated method stub - - } - -} diff --git a/launch/org.eclipse.cdt.launchbar.cdt.core/src/org/eclipse/cdt/launchbar/cdt/core/internal/CDTLaunchConfigProvider.java b/launch/org.eclipse.cdt.launchbar.cdt.core/src/org/eclipse/cdt/launchbar/cdt/core/internal/CDTLaunchConfigProvider.java deleted file mode 100644 index 523615a1f0f..00000000000 --- a/launch/org.eclipse.cdt.launchbar.cdt.core/src/org/eclipse/cdt/launchbar/cdt/core/internal/CDTLaunchConfigProvider.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.eclipse.cdt.launchbar.cdt.core.internal; - -import org.eclipse.cdt.launchbar.core.ILaunchBarManager; -import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor; -import org.eclipse.cdt.launchbar.core.ILaunchConfigurationsProvider; - -public class CDTLaunchConfigProvider implements ILaunchConfigurationsProvider { - - public CDTLaunchConfigProvider() { - // TODO Auto-generated constructor stub - } - - @Override - public void init(ILaunchBarManager manager) { - // TODO Auto-generated method stub - - } - - @Override - public ILaunchConfigurationDescriptor filterDescriptor(ILaunchBarManager manager, ILaunchConfigurationDescriptor descriptor) { - return descriptor; - } - -} diff --git a/launch/org.eclipse.cdt.launchbar.core/plugin.xml b/launch/org.eclipse.cdt.launchbar.core/plugin.xml index 4ccd1a4a5ba..fc378e9d598 100644 --- a/launch/org.eclipse.cdt.launchbar.core/plugin.xml +++ b/launch/org.eclipse.cdt.launchbar.core/plugin.xml @@ -1,6 +1,28 @@ - + + + + + + + + + + + diff --git a/launch/org.eclipse.cdt.launchbar.core/schema/launchBarContributions.exsd b/launch/org.eclipse.cdt.launchbar.core/schema/launchBarContributions.exsd new file mode 100644 index 00000000000..78b8e1abdfe --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.core/schema/launchBarContributions.exsd @@ -0,0 +1,205 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Is this the default target type for this descriptor type. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/launch/org.eclipse.cdt.launchbar.core/schema/launchConfigProvider.exsd b/launch/org.eclipse.cdt.launchbar.core/schema/launchConfigProvider.exsd deleted file mode 100644 index 6fba0084105..00000000000 --- a/launch/org.eclipse.cdt.launchbar.core/schema/launchConfigProvider.exsd +++ /dev/null @@ -1,109 +0,0 @@ - - - - - - - - - [Enter description of this extension point.] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [Enter the first release in which this extension point appears.] - - - - - - - - - [Enter extension point usage example here.] - - - - - - - - - [Enter API information here.] - - - - - - - - - [Enter information about supplied implementation of this extension point.] - - - - - diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchBarManager.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchBarManager.java index 157ef144c3d..da5faf23330 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchBarManager.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchBarManager.java @@ -13,48 +13,53 @@ package org.eclipse.cdt.launchbar.core; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchMode; public interface ILaunchBarManager extends IAdaptable { - ILaunchConfigurationDescriptor[] getLaunchConfigurationDescriptors(); + ILaunchDescriptor[] getLaunchDescriptors() throws CoreException; - ILaunchConfigurationDescriptor getActiveLaunchConfigurationDescriptor(); + ILaunchDescriptor getActiveLaunchDescriptor() throws CoreException; - void setActiveLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc) throws CoreException; - - void addLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc) throws CoreException; - - void removeLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc); - - ILaunchConfigurationDescriptor getLaunchConfigurationDescriptor(ILaunchConfiguration configuration) throws CoreException; + void setActiveLaunchDescriptor(ILaunchDescriptor configDesc) throws CoreException; - ILaunchMode getActiveLaunchMode(); + ILaunchMode[] getLaunchModes() throws CoreException; + + ILaunchMode getActiveLaunchMode() throws CoreException; + + void setActiveLaunchMode(ILaunchMode mode) throws CoreException; + + ILaunchTarget[] getLaunchTargets() throws CoreException; - void setActiveLaunchMode(ILaunchMode mode); - - ILaunchTarget getActiveLaunchTarget(); - - void setActiveLaunchTarget(ILaunchTarget target); - - void addLaunchTarget(ILaunchTarget target); - - void removeLaunchTarget(ILaunchTarget target); - - ILaunchTarget getLocalLaunchTarget(); + ILaunchTarget getLaunchTarget(String id) throws CoreException; + + ILaunchTarget getActiveLaunchTarget() throws CoreException; + + void setActiveLaunchTarget(ILaunchTarget target) throws CoreException; + + ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException; + + ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException; + + ILaunchDescriptor launchObjectAdded(Object element) throws CoreException; + + void launchObjectRemoved(Object element) throws CoreException; interface Listener { void activeConfigurationDescriptorChanged(); void activeLaunchModeChanged(); - + void activeLaunchTargetChanged(); + void launchDescriptorRemoved(ILaunchDescriptor descriptor); + } void addListener(Listener listener); - + void removeListener(Listener listener); } diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchConfigurationDescriptor.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchConfigurationDescriptor.java deleted file mode 100644 index 3d8a2603d4f..00000000000 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchConfigurationDescriptor.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Doug Schaefer - *******************************************************************************/ -package org.eclipse.cdt.launchbar.core; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchMode; - -public interface ILaunchConfigurationDescriptor { - - /** - * Name to show in the launch configuration selector. - * - * @return name of the launch configuration - */ - String getName(); - - /** - * The corresponding launch configuration. - * If this launch config hasn't been created yet, it will be - * - * @return the corresponding launch configuration - * @throws CoreException - */ - ILaunchConfiguration getLaunchConfiguration() throws CoreException; - - /** - * Is this launch configuration managed by this descriptor. - * - * @param launchConfiguration - * @return - * @throws CoreException - */ - boolean matches(ILaunchConfiguration launchConfiguration) throws CoreException; - - /** - * Return the list of launch targets this configuration can launcht to. - * - * @return launch targets - */ - ILaunchTarget[] getLaunchTargets(); - - /** - * Return the launch target with the given id. - * - * @param id id of target - * @return launch target - */ - ILaunchTarget getLaunchTarget(String id); - - /** - * Set the active launch target. Allows the descriptor to prepare for - * a launch on that target. - * - * @param target the new active launch target - */ - void setActiveLaunchTarget(ILaunchTarget target); - - /** - * Return the launch modes supported by this descriptor. - * - * @return launch modes - * @throws CoreException - */ - ILaunchMode[] getLaunchModes() throws CoreException; - - /** - * Returns the launch mode with the given identifier. - * - * @param id - * @return launch mode with id - * @throws CoreException - */ - ILaunchMode getLaunchMode(String id) throws CoreException; - - /** - * Set the active launch mode. Allows the descriptor to prepare for a - * launch in that mode. - * - * @param mode the new active launch mode - */ - void setActiveLaunchMode(ILaunchMode mode); - -} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchConfigurationProvider.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchConfigurationProvider.java new file mode 100644 index 00000000000..a028221c710 --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchConfigurationProvider.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2014 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Doug Schaefer + *******************************************************************************/ +package org.eclipse.cdt.launchbar.core; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; + +public interface ILaunchConfigurationProvider { + + /** + * Do any initialization. + * + * @param manager + * @throws CoreException + */ + void init(ILaunchBarManager manager) throws CoreException; + + /** + * Does this provider own this launch configuration. If so, make sure the launch descriptor + * is properly constructed by sending in a launch object to the launch manager. + * + * @param configuration + * @return + * @throws CoreException + */ + boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException; + + /** + * Returns the launch configuration type used to launch the descriptor on this target type. + * + * @param descriptor + * @param target + * @return launch configuration type + * @throws CoreException + */ + ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor) throws CoreException; + + /** + * Create a launch configuration for the descriptor to launch on the target. + * + * @param descriptor + * @param target + * @return launch configuration + * @throws CoreException + */ + ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor) throws CoreException; + + /** + * A launch configuration has been removed. + * + * @param configuration + * @throws CoreException + */ + void launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException; + +} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptor.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptor.java new file mode 100644 index 00000000000..9fde3bdac57 --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptor.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2014 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Doug Schaefer + *******************************************************************************/ +package org.eclipse.cdt.launchbar.core; + + +/** + * Represents a thing that can be launched. + */ +public interface ILaunchDescriptor { + + /** + * Name to show in the launch descriptor selector. + * + * @return name of the launch descriptor + */ + String getName(); + + /** + * The type of launch descriptor. + * + * @return provider + */ + ILaunchDescriptorType getType(); + +} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorType.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorType.java new file mode 100644 index 00000000000..11b3fc5feeb --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorType.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2014 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Doug Schaefer + *******************************************************************************/ +package org.eclipse.cdt.launchbar.core; + +import org.eclipse.core.runtime.CoreException; + +/** + * Provides the list of launch configurations + * + */ +public interface ILaunchDescriptorType { + + /** + * The id for the provider. + * + * @return provider id + */ + String getId(); + + /** + * Called after existing launch configs have been added. The provider + * can now add any more that they'd like to have. + */ + void init(ILaunchBarManager manager); + + /** + * Does this type own this launch element. + * + * @param element + * @return owns element + * @throws CoreException + */ + boolean ownsLaunchObject(Object element) throws CoreException; + + /** + * Return a descriptor for the given element. The element can be a launch + * configuration, a project, or anything else that gets fed to the + * launch bar manager. + * + * May return null to essentially eat the element so no other types + * create a descriptor for it. + * + * @param descriptor candidate descriptor + * @return the best descriptor + * @throws CoreException + */ + ILaunchDescriptor getDescriptor(Object element) throws CoreException; + + /** + * Return a handle to the launch bar manager. + * + * @return launchbar manager + */ + ILaunchBarManager getManager(); + +} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchObjectProvider.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchObjectProvider.java new file mode 100644 index 00000000000..82520fb027f --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchObjectProvider.java @@ -0,0 +1,21 @@ +package org.eclipse.cdt.launchbar.core; + +/** + * An extension that serves up objects to feed launch descriptors. + * + */ +public interface ILaunchObjectProvider { + + /** + * Add initial launch descriptors and set up listeners. + * + * @param launchbar manager + */ + void init(ILaunchBarManager manager); + + /** + * Shutting down, remove any listeners. + */ + void dispose(); + +} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchTarget.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchTarget.java index c45dd0499f9..d6899a084d6 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchTarget.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchTarget.java @@ -26,4 +26,17 @@ public interface ILaunchTarget { * @return name */ String getName(); + + /** + * Returns the type for this target. + * + * @return target type + */ + ILaunchTargetType getType(); + + /** + * This target has been made active. + */ + void setActive(); + } diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchConfigurationsProvider.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchTargetType.java similarity index 52% rename from launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchConfigurationsProvider.java rename to launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchTargetType.java index 116d5828a76..f292a929faf 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchConfigurationsProvider.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchTargetType.java @@ -10,25 +10,35 @@ *******************************************************************************/ package org.eclipse.cdt.launchbar.core; -/** - * Provides the list of launch configurations - * - */ -public interface ILaunchConfigurationsProvider { +public interface ILaunchTargetType { /** - * Called after existing launch configs have been added. The provider - * can now add any more that they'd like to have. + * Called by the launchbar manager to initialize and pass a hendle to itself. + * + * @param manager */ void init(ILaunchBarManager manager); /** - * If the provider has a better descriptor than the suggested one, return a better one. - * Otherwise, return the one that was passed in. + * The id of the target type. * - * @param descriptor candidate descriptor - * @return the best descriptor + * @return target type id */ - ILaunchConfigurationDescriptor filterDescriptor(ILaunchBarManager manager, ILaunchConfigurationDescriptor descriptor); + String getId(); + + /** + * Return the list of targets for this type. + * + * @return targets + */ + ILaunchTarget[] getTargets(); + + /** + * Return the target with the specified id. + * + * @param id + * @return target + */ + ILaunchTarget getTarget(String id); } diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchConfigurationDescriptor.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchConfigurationDescriptor.java deleted file mode 100644 index 3a4bc13107b..00000000000 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchConfigurationDescriptor.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Doug Schaefer - *******************************************************************************/ -package org.eclipse.cdt.launchbar.core.internal; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.cdt.launchbar.core.ILaunchBarManager; -import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor; -import org.eclipse.cdt.launchbar.core.ILaunchTarget; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchConfigurationType; -import org.eclipse.debug.core.ILaunchMode; - -public class DefaultLaunchConfigurationDescriptor implements ILaunchConfigurationDescriptor { - - private final ILaunchBarManager manager; - private ILaunchConfiguration config; - private ILaunchMode[] launchModes; - - public DefaultLaunchConfigurationDescriptor(ILaunchBarManager manager, ILaunchConfiguration config) { - this.manager = manager; - this.config = config; - } - - @Override - public String getName() { - return config.getName(); - } - - @Override - public ILaunchConfiguration getLaunchConfiguration() throws CoreException { - return config; - } - - @Override - public boolean matches(ILaunchConfiguration launchConfiguration) { - return config.equals(launchConfiguration); - } - - @Override - public ILaunchTarget getLaunchTarget(String id) { - return LocalTarget.ID.equals(id) ? manager.getLocalLaunchTarget() : null; - } - - @Override - public ILaunchTarget[] getLaunchTargets() { - return new ILaunchTarget[] { manager.getLocalLaunchTarget() }; - } - - @Override - public void setActiveLaunchTarget(ILaunchTarget target) { - // nothing to do - } - - @Override - public ILaunchMode[] getLaunchModes() throws CoreException { - if (launchModes == null) { - List mymodes = new ArrayList<>(); - ILaunchConfigurationType type = config.getType(); - ILaunchMode[] modes = DebugPlugin.getDefault().getLaunchManager().getLaunchModes(); - for (ILaunchMode mode : modes) { - if (type.supportsMode(mode.getIdentifier())) { - mymodes.add(mode); - } - } - launchModes = mymodes.toArray(new ILaunchMode[mymodes.size()]); - } - return launchModes; - } - - @Override - public ILaunchMode getLaunchMode(String id) throws CoreException { - for (ILaunchMode mode : getLaunchModes()) { - if (mode.getIdentifier().equals(id)) - return mode; - } - return null; - } - - @Override - public void setActiveLaunchMode(ILaunchMode mode) { - // nothing to do - } - -} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchConfigurationProvider.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchConfigurationProvider.java new file mode 100644 index 00000000000..83bbce1cec3 --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchConfigurationProvider.java @@ -0,0 +1,44 @@ +package org.eclipse.cdt.launchbar.core.internal; + +import org.eclipse.cdt.launchbar.core.ILaunchBarManager; +import org.eclipse.cdt.launchbar.core.ILaunchConfigurationProvider; +import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; + +public class DefaultLaunchConfigurationProvider implements ILaunchConfigurationProvider { + + @Override + public void init(ILaunchBarManager manager) throws CoreException { + // nothing to do + } + + @Override + public boolean ownsLaunchConfiguration(ILaunchConfiguration configuration) throws CoreException { + // We may own it but return false to let it percolate through to the descriptor type. + return false; + } + + @Override + public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor) throws CoreException { + if (descriptor instanceof DefaultLaunchDescriptor) { + return ((DefaultLaunchDescriptor) descriptor).getConfig(); + } + return null; + } + + @Override + public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor) throws CoreException { + if (descriptor instanceof DefaultLaunchDescriptor) { + return ((DefaultLaunchDescriptor) descriptor).getConfig().getType(); + } + return null; + } + + @Override + public void launchConfigurationRemoved(ILaunchConfiguration configation) throws CoreException { + // The descriptor will handle the remove. + } + +} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptor.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptor.java new file mode 100644 index 00000000000..ebd779f3380 --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptor.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2014 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Doug Schaefer + *******************************************************************************/ +package org.eclipse.cdt.launchbar.core.internal; + +import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; +import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType; +import org.eclipse.debug.core.ILaunchConfiguration; + +public class DefaultLaunchDescriptor implements ILaunchDescriptor { + + private final DefaultLaunchDescriptorType type; + private final ILaunchConfiguration config; + + public DefaultLaunchDescriptor(DefaultLaunchDescriptorType type, ILaunchConfiguration config) { + this.type = type; + this.config = config; + } + + @Override + public String getName() { + return config.getName(); + } + + @Override + public ILaunchDescriptorType getType() { + return type; + } + + public ILaunchConfiguration getConfig() { + return config; + } + +} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptorType.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptorType.java new file mode 100644 index 00000000000..f9c76bb891d --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptorType.java @@ -0,0 +1,39 @@ +package org.eclipse.cdt.launchbar.core.internal; + +import org.eclipse.cdt.launchbar.core.ILaunchBarManager; +import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; +import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType; +import org.eclipse.debug.core.ILaunchConfiguration; + +public class DefaultLaunchDescriptorType implements ILaunchDescriptorType { + + public static final String ID = "org.eclipse.cdt.launchbar.core.descriptor.default"; + + private ILaunchBarManager manager; + + @Override + public String getId() { + return ID; + } + + @Override + public void init(ILaunchBarManager manager) { + this.manager = manager; + } + + @Override + public boolean ownsLaunchObject(Object element) { + return element instanceof ILaunchConfiguration; + } + + @Override + public ILaunchDescriptor getDescriptor(Object element) { + return new DefaultLaunchDescriptor(this, (ILaunchConfiguration) element); + } + + @Override + public ILaunchBarManager getManager() { + return manager; + } + +} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManager.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManager.java index 3a7c19348df..adc6a14c65c 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManager.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManager.java @@ -20,9 +20,12 @@ import java.util.List; import java.util.Map; import org.eclipse.cdt.launchbar.core.ILaunchBarManager; -import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor; -import org.eclipse.cdt.launchbar.core.ILaunchConfigurationsProvider; +import org.eclipse.cdt.launchbar.core.ILaunchConfigurationProvider; +import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; +import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType; +import org.eclipse.cdt.launchbar.core.ILaunchObjectProvider; import org.eclipse.cdt.launchbar.core.ILaunchTarget; +import org.eclipse.cdt.launchbar.core.ILaunchTargetType; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; @@ -34,6 +37,7 @@ import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationListener; +import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.ILaunchMode; import org.osgi.service.prefs.BackingStoreException; @@ -42,142 +46,183 @@ import org.osgi.service.prefs.Preferences; public class LaunchBarManager extends PlatformObject implements ILaunchBarManager, ILaunchConfigurationListener { private List listeners = new LinkedList<>(); - private List providers = new ArrayList<>(); - private Map configDescs = new HashMap<>(); - private ILaunchConfigurationDescriptor lastConfigDesc; - - private ILaunchConfigurationDescriptor activeConfigDesc; + private Map targetTypes = new HashMap<>(); + private List descriptorTypes = new ArrayList<>(); + private Map descriptors = new HashMap<>(); + private List objectProviders = new ArrayList<>(); + // Map descriptor type to target type to provider + private Map> configProviders = new HashMap<>(); + // Map descriptor type to target type + private Map defaultTargetTypes = new HashMap<>(); + private Map objectDescriptorMap = new HashMap<>(); + + private ILaunchDescriptor activeLaunchDesc; private ILaunchMode activeLaunchMode; private ILaunchTarget activeLaunchTarget; - private static final LocalTarget localLaunchTarget = new LocalTarget(); + private ILaunchDescriptor lastLaunchDesc; private static final String PREF_ACTIVE_CONFIG_DESC = "activeConfigDesc"; private static final String PREF_ACTIVE_LAUNCH_MODE = "activeLaunchMode"; private static final String PREF_ACTIVE_LAUNCH_TARGET = "activeLaunchTarget"; - private class ProviderExtensionDescriptor { - private ILaunchConfigurationsProvider provider; - private int priority; - - public ProviderExtensionDescriptor(ILaunchConfigurationsProvider provider, int priority) { - super(); - this.provider = provider; - this.priority = priority; - } - - public ILaunchConfigurationsProvider getProvider() { - return provider; - } - - public int getPriority() { - return priority; - } - - } - public LaunchBarManager() throws CoreException { - IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchConfigProvider"); + final Map typePriorities = new HashMap<>(); + + IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchBarContributions"); IExtension[] extensions = point.getExtensions(); for (IExtension extension : extensions) { - // provider is manditory - IConfigurationElement element = extension.getConfigurationElements()[0]; - ILaunchConfigurationsProvider provider = (ILaunchConfigurationsProvider) element.createExecutableExtension("class"); - String priorityString = element.getAttribute("priority"); - int priority = 100; - if (priorityString != null) { - try { - priority = Integer.parseInt(priorityString); - } catch (NumberFormatException e) { - // Log it but keep going with the default - Activator.log(e); + for (IConfigurationElement element : extension.getConfigurationElements()) { + String elementName = element.getName(); + if (elementName.equals("descriptorType")) { + String id = element.getAttribute("id"); + String priorityStr = element.getAttribute("priority"); + ILaunchDescriptorType type = (ILaunchDescriptorType) element.createExecutableExtension("class"); + + assert id.equals(type.getId()); + descriptorTypes.add(type); + + int priority = 1; + if (priorityStr != null) { + try { + priority = Integer.parseInt(priorityStr); + } catch (NumberFormatException e) { + // Log it but keep going with the default + Activator.log(e); + } + } + typePriorities.put(type, priority); + } else if (elementName.equals("targetType")) { + String id = element.getAttribute("id"); + ILaunchTargetType targetType = (ILaunchTargetType) element.createExecutableExtension("class"); + + assert id.equals(targetType.getId()); + targetTypes.put(id, targetType); + } else if (elementName.equals("objectProvider")) { + ILaunchObjectProvider objectProvider = (ILaunchObjectProvider) element.createExecutableExtension("class"); + objectProviders.add(objectProvider); + } else if (elementName.equals("configProvider")) { + String descriptorType = element.getAttribute("descriptorType"); + String targetType = element.getAttribute("targetType"); + // TODO don't instantiate this until we need it + ILaunchConfigurationProvider configProvider = (ILaunchConfigurationProvider) element.createExecutableExtension("class"); + + Map targetTypes = configProviders.get(descriptorType); + if (targetTypes == null) { + targetTypes = new HashMap<>(); + configProviders.put(descriptorType, targetTypes); + } + targetTypes.put(targetType, configProvider); + + String isDefault = element.getAttribute("isDefault"); + if (isDefault != null && Boolean.valueOf(isDefault)) { + defaultTargetTypes.put(descriptorType, targetType); + } } } - providers.add(new ProviderExtensionDescriptor(provider, priority)); } - Collections.sort(providers, new Comparator() { + Collections.sort(descriptorTypes, new Comparator() { @Override - public int compare(ProviderExtensionDescriptor o1, ProviderExtensionDescriptor o2) { - int p1 = o1.getPriority(); - int p2 = o2.getPriority(); - if (p1 > p2) + public int compare(ILaunchDescriptorType o1, ILaunchDescriptorType o2) { + int p1 = typePriorities.get(o1); + int p2 = typePriorities.get(o2); + // Reverse order, highest priority first + if (p1 < p2) return 1; - else if (p1 < p2) + else if (p1 > p2) return -1; else return 0; } }); + for (ILaunchDescriptorType descriptorType : descriptorTypes) { + descriptorType.init(this); + } + + for (ILaunchTargetType targetType : targetTypes.values()) { + targetType.init(this); + } + + for (ILaunchObjectProvider objectProvider : objectProviders) { + objectProvider.init(this); + } + + for (Map targetMap : configProviders.values()) { + for (ILaunchConfigurationProvider configProvider : targetMap.values()) { + configProvider.init(this); + } + } + + // Hook up the existing launch configurations and listen ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); for (ILaunchConfiguration configuration : launchManager.getLaunchConfigurations()) { - ILaunchConfigurationDescriptor configDesc = new DefaultLaunchConfigurationDescriptor(this, configuration); - - - for (ProviderExtensionDescriptor provider : providers) { - configDesc = provider.getProvider().filterDescriptor(this, configDesc); - } - configDescs.put(configDesc.getName(), configDesc); + launchConfigurationAdded(configuration); } - - for (ProviderExtensionDescriptor providerDesc : providers) { - providerDesc.getProvider().init(this); - } - launchManager.addLaunchConfigurationListener(this); // Load up the active from the preferences or pick reasonable defaults IEclipsePreferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID); String activeConfigDescName = store.get(PREF_ACTIVE_CONFIG_DESC, null); - if (activeConfigDescName == null && !configDescs.isEmpty()) { - activeConfigDescName = configDescs.values().iterator().next().getName(); + if (activeConfigDescName == null && !descriptors.isEmpty()) { + activeConfigDescName = descriptors.values().iterator().next().getName(); } if (activeConfigDescName != null) { - ILaunchConfigurationDescriptor configDesc = configDescs.get(activeConfigDescName); + ILaunchDescriptor configDesc = descriptors.get(activeConfigDescName); if (configDesc != null) { - setActiveLaunchConfigurationDescriptor(configDesc); + setActiveLaunchDescriptor(configDesc); } } } @Override - public void launchConfigurationAdded(ILaunchConfiguration configuration) { - ILaunchConfigurationDescriptor configDesc = new DefaultLaunchConfigurationDescriptor(this, configuration); - for (ProviderExtensionDescriptor provider : providers) { - configDesc = provider.getProvider().filterDescriptor(this, configDesc); + public ILaunchDescriptor launchObjectAdded(Object element) { + ILaunchDescriptor desc = objectDescriptorMap.get(element); + if (desc != null) + return desc; + + for (ILaunchDescriptorType descriptorType : descriptorTypes) { + try { + if (descriptorType.ownsLaunchObject(element)) { + desc = descriptorType.getDescriptor(element); + if (desc != null) { + descriptors.put(desc.getName(), desc); + objectDescriptorMap.put(element, desc); + setActiveLaunchDescriptor(desc); + return desc; + } + break; + } + } catch (CoreException e) { + Activator.log(e.getStatus()); + } } - try { - addLaunchConfigurationDescriptor(configDesc); - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + return null; + } + + @Override + public void launchObjectRemoved(Object element) throws CoreException { + ILaunchDescriptor desc = objectDescriptorMap.get(element); + if (desc != null) { + descriptors.remove(desc.getName()); + objectDescriptorMap.remove(element); + if (desc.equals(activeLaunchDesc)) { + // Roll back to the last one and make sure we don't come back + ILaunchDescriptor nextDesc = lastLaunchDesc; + activeLaunchDesc = null; + setActiveLaunchDescriptor(nextDesc); + } } } @Override - public void launchConfigurationChanged(ILaunchConfiguration configuration) { - // TODO Auto-generated method stub - } - - @Override - public void launchConfigurationRemoved(ILaunchConfiguration configuration) { - try { - ILaunchConfigurationDescriptor configDesc = getLaunchConfigurationDescriptor(configuration); - if (configDesc != null) - removeLaunchConfigurationDescriptor(configDesc); - } catch (CoreException e) { - Activator.log(e.getStatus()); - } - } - - @Override - public ILaunchConfigurationDescriptor[] getLaunchConfigurationDescriptors() { - ILaunchConfigurationDescriptor[] descs = configDescs.values().toArray(new ILaunchConfigurationDescriptor[configDescs.size()]); - Arrays.sort(descs, new Comparator() { + public ILaunchDescriptor[] getLaunchDescriptors() { + ILaunchDescriptor[] descs = descriptors.values().toArray(new ILaunchDescriptor[descriptors.size()]); + Arrays.sort(descs, new Comparator() { @Override - public int compare(ILaunchConfigurationDescriptor o1, ILaunchConfigurationDescriptor o2) { + public int compare(ILaunchDescriptor o1, ILaunchDescriptor o2) { return o1.getName().compareTo(o2.getName()); } }); @@ -185,51 +230,27 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage } @Override - public ILaunchConfigurationDescriptor getActiveLaunchConfigurationDescriptor() { - return activeConfigDesc; + public ILaunchDescriptor getActiveLaunchDescriptor() { + return activeLaunchDesc; } @Override - public ILaunchConfigurationDescriptor getLaunchConfigurationDescriptor(ILaunchConfiguration configuration) throws CoreException { - // Check by name - ILaunchConfigurationDescriptor configDesc = configDescs.get(configuration.getName()); - if (configDesc.matches(configuration)) - return configDesc; - - // Nope, try all descs - for (ILaunchConfigurationDescriptor cd : configDescs.values()) { - if (cd.matches(configuration)) - return cd; - } - - // nothing, weird - return null; - } - - @Override - public void setActiveLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc) throws CoreException { - if (activeConfigDesc == configDesc) + public void setActiveLaunchDescriptor(ILaunchDescriptor configDesc) throws CoreException { + if (activeLaunchDesc != null && activeLaunchDesc == configDesc) return; - lastConfigDesc = activeConfigDesc; - activeConfigDesc = configDesc; + lastLaunchDesc = activeLaunchDesc; + activeLaunchDesc = configDesc; IEclipsePreferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID); - if (activeConfigDesc != null) { - store.put(PREF_ACTIVE_CONFIG_DESC, activeConfigDesc.getName()); + if (activeLaunchDesc != null) { + store.put(PREF_ACTIVE_CONFIG_DESC, activeLaunchDesc.getName()); } else { store.remove(PREF_ACTIVE_CONFIG_DESC); } try { store.flush(); } catch (BackingStoreException e) { - // TODO log - e.printStackTrace(); - } - - if (activeConfigDesc == null) { - setActiveLaunchMode(null); - setActiveLaunchTarget(null); - return; + Activator.log(e); } // Send notifications @@ -237,76 +258,58 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage listener.activeConfigurationDescriptorChanged(); } - // Set active mode - String activeModeName = store.node(activeConfigDesc.getName()).get(PREF_ACTIVE_LAUNCH_MODE, null); - ILaunchMode[] launchModes = activeConfigDesc.getLaunchModes(); - boolean foundMode = false; - if (activeModeName != null) { - for (ILaunchMode mode : launchModes) { - if (activeModeName.equals(mode.getIdentifier())) { - setActiveLaunchMode(mode); - foundMode = true; - break; - } - } - } - if (!foundMode) { - if (launchModes.length > 0) { - ILaunchMode mode = activeConfigDesc.getLaunchMode("debug"); - if (mode == null) { - mode = activeConfigDesc.getLaunchMode("run"); - } - if (mode == null) { - mode = launchModes[0]; - } - setActiveLaunchMode(mode); - } else { - setActiveLaunchMode(null); - } + if (activeLaunchDesc == null) { + setActiveLaunchMode(null); + setActiveLaunchTarget(null); + return; } // Set active target - String activeTargetId = store.node(activeConfigDesc.getName()).get(PREF_ACTIVE_LAUNCH_TARGET, null); + String activeTargetId = store.node(activeLaunchDesc.getName()).get(PREF_ACTIVE_LAUNCH_TARGET, null); ILaunchTarget target = null; if (activeTargetId != null) { - target = activeConfigDesc.getLaunchTarget(activeTargetId); + target = getLaunchTarget(activeTargetId); } if (target == null) { - ILaunchTarget[] targets = activeConfigDesc.getLaunchTargets(); + ILaunchTarget[] targets = getLaunchTargets(); if (targets.length > 0) { target = targets[0]; } } setActiveLaunchTarget(target); + + // Set active mode + String activeModeName = store.node(activeLaunchDesc.getName()).get(PREF_ACTIVE_LAUNCH_MODE, null); + ILaunchConfigurationType configType = getLaunchConfigurationType(activeLaunchDesc, activeLaunchTarget); + ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); + ILaunchMode foundMode = null; + if (activeModeName != null && configType.supportsMode(activeModeName)) { + foundMode = launchManager.getLaunchMode(activeModeName); + } + if (foundMode == null && configType.supportsMode("debug")) { + foundMode = launchManager.getLaunchMode("debug"); + } + if (foundMode == null && configType.supportsMode("run")) { + foundMode = launchManager.getLaunchMode("run"); + } + setActiveLaunchMode(foundMode); } @Override - public void addLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc) throws CoreException { - configDescs.put(configDesc.getName(), configDesc); - setActiveLaunchConfigurationDescriptor(configDesc); - } + public ILaunchMode[] getLaunchModes() throws CoreException { + ILaunchConfigurationType configType = getLaunchConfigurationType(activeLaunchDesc, activeLaunchTarget); + if (configType == null) + return new ILaunchMode[0]; - @Override - public void removeLaunchConfigurationDescriptor(ILaunchConfigurationDescriptor configDesc) { - configDescs.remove(configDesc.getName()); - - // Fix up the active config if this one was it - if (activeConfigDesc.equals(configDesc)) { - try { - if (configDescs.isEmpty()) { - setActiveLaunchConfigurationDescriptor(null); - } else if (lastConfigDesc != null) { - setActiveLaunchConfigurationDescriptor(lastConfigDesc); - // Clear out the last desc since we just used it - lastConfigDesc = null; - } else { - setActiveLaunchConfigurationDescriptor(configDescs.values().iterator().next()); - } - } catch (CoreException e) { - // TODO log - e.printStackTrace(); + List modeList = new ArrayList<>(); + ILaunchMode[] modes = DebugPlugin.getDefault().getLaunchManager().getLaunchModes(); + for (ILaunchMode mode : modes) { + if (configType.supportsMode(mode.getIdentifier())) { + modeList.add(mode); } } + + return modeList.toArray(new ILaunchMode[modeList.size()]); } @Override @@ -320,10 +323,13 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage return; activeLaunchMode = mode; - if (activeConfigDesc == null) + for (Listener listener : listeners) + listener.activeLaunchModeChanged(); + + if (activeLaunchDesc == null) return; - - Preferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).node(activeConfigDesc.getName()); + + Preferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).node(activeLaunchDesc.getName()); if (mode != null) { store.put(PREF_ACTIVE_LAUNCH_MODE, mode.getIdentifier()); } else { @@ -335,10 +341,27 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage // TODO log e.printStackTrace(); } + } - activeConfigDesc.setActiveLaunchMode(mode); - for (Listener listener : listeners) - listener.activeLaunchModeChanged(); + @Override + public ILaunchTarget[] getLaunchTargets() { + if (activeLaunchDesc == null) + return new ILaunchTarget[0]; + + List targetList = new ArrayList<>(); + Map targetMap = configProviders.get(activeLaunchDesc.getType().getId()); + if (targetMap != null) { + for (String id : targetMap.keySet()) { + ILaunchTargetType type = targetTypes.get(id); + if (type != null) { + ILaunchTarget[] targets = type.getTargets(); + for (ILaunchTarget target : targets) { + targetList.add(target); + } + } + } + } + return targetList.toArray(new ILaunchTarget[targetList.size()]); } @Override @@ -349,13 +372,16 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage @Override public void setActiveLaunchTarget(ILaunchTarget target) { if (activeLaunchTarget == target) return; - + activeLaunchTarget = target; - - if (activeConfigDesc == null) + + for (Listener listener : listeners) + listener.activeLaunchTargetChanged(); + + if (activeLaunchDesc == null) return; - Preferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).node(activeConfigDesc.getName()); + Preferences store = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).node(activeLaunchDesc.getName()); if (target != null) { store.put(PREF_ACTIVE_LAUNCH_TARGET, target.getId()); } else { @@ -368,25 +394,51 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage e.printStackTrace(); } - activeConfigDesc.setActiveLaunchTarget(target); - for (Listener listener : listeners) - listener.activeLaunchTargetChanged(); - } - - public LocalTarget getLocalLaunchTarget() { - return localLaunchTarget; - } - - @Override - public void addLaunchTarget(ILaunchTarget target) { - // TODO Auto-generated method stub - + target.setActive(); } @Override - public void removeLaunchTarget(ILaunchTarget target) { - // TODO Auto-generated method stub + public ILaunchTarget getLaunchTarget(String id) { + for (ILaunchTargetType type : targetTypes.values()) { + ILaunchTarget target = type.getTarget(id); + if (target != null) + return target; + } + return null; + } + @Override + public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { + if (descriptor == null) + return null; + + String descriptorTypeId = descriptor.getType().getId(); + Map targetMap = configProviders.get(descriptorTypeId); + if (targetMap != null) { + String targetTypeId = target != null ? target.getType().getId() : defaultTargetTypes.get(descriptorTypeId); + if (targetTypeId != null) { + ILaunchConfigurationProvider configProvider = targetMap.get(targetTypeId); + if (configProvider != null) { + return configProvider.getLaunchConfigurationType(descriptor); + } + } + } + return null; + } + + @Override + public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { + if (activeLaunchDesc == null) + return null; + + Map targetMap = configProviders.get(descriptor.getType().getId()); + if (targetMap != null) { + ILaunchConfigurationProvider configProvider = targetMap.get(target.getType().getId()); + if (configProvider != null) { + return configProvider.getLaunchConfiguration(descriptor); + } + } + return null; } @Override @@ -399,4 +451,39 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage listeners.remove(listener); } + @Override + public void launchConfigurationAdded(ILaunchConfiguration configuration) { + try { + boolean owned = false; + // TODO filter by launch configuration type + + for (Map targetMap : configProviders.values()) { + for (ILaunchConfigurationProvider configProvider : targetMap.values()) { + if (configProvider.ownsLaunchConfiguration(configuration)) { + owned = true; + break; + } + } + } + + if (!owned) { + launchObjectAdded(configuration); + } + } catch (CoreException e) { + Activator.log(e.getStatus()); + } + } + + @Override + public void launchConfigurationChanged(ILaunchConfiguration configuration) { + // TODO Auto-generated method stub + + } + + @Override + public void launchConfigurationRemoved(ILaunchConfiguration configuration) { + // TODO Auto-generated method stub + + } + } diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LocalTarget.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LocalTarget.java index 43c79ffb6cb..ab572df9fd7 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LocalTarget.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LocalTarget.java @@ -11,19 +11,35 @@ package org.eclipse.cdt.launchbar.core.internal; import org.eclipse.cdt.launchbar.core.ILaunchTarget; +import org.eclipse.cdt.launchbar.core.ILaunchTargetType; public class LocalTarget implements ILaunchTarget { - public static final String ID = "org.eclipse.cdt.local"; + private final LocalTargetType type; + + public LocalTarget(LocalTargetType type) { + this.type = type; + } @Override public String getId() { - return ID; + // Use the same ID as the type since we're really a singleton + return type.getId(); } @Override public String getName() { return "Local Machine"; // TODO externalize } + + @Override + public ILaunchTargetType getType() { + return type; + } + + @Override + public void setActive() { + // nothing to do + } } diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LocalTargetType.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LocalTargetType.java new file mode 100644 index 00000000000..68bbcb0cc4a --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LocalTargetType.java @@ -0,0 +1,34 @@ +package org.eclipse.cdt.launchbar.core.internal; + +import org.eclipse.cdt.launchbar.core.ILaunchBarManager; +import org.eclipse.cdt.launchbar.core.ILaunchTarget; +import org.eclipse.cdt.launchbar.core.ILaunchTargetType; + +public class LocalTargetType implements ILaunchTargetType { + + public static final String ID = "org.eclipse.cdt.launchbar.core.target.local"; + private LocalTarget localTarget; + + @Override + public void init(ILaunchBarManager manager) { + localTarget = new LocalTarget(this); + } + + @Override + public String getId() { + return ID; + } + + @Override + public ILaunchTarget[] getTargets() { + return new ILaunchTarget[] { localTarget }; + } + + @Override + public ILaunchTarget getTarget(String id) { + if (ID.equals(id)) + return localTarget; + return null; + } + +} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/ProjectLaunchObjectProvider.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/ProjectLaunchObjectProvider.java new file mode 100644 index 00000000000..8d06be2c25f --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/ProjectLaunchObjectProvider.java @@ -0,0 +1,67 @@ +package org.eclipse.cdt.launchbar.core.internal; + +import org.eclipse.cdt.launchbar.core.ILaunchBarManager; +import org.eclipse.cdt.launchbar.core.ILaunchObjectProvider; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.resources.IResourceDeltaVisitor; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; + +public class ProjectLaunchObjectProvider implements ILaunchObjectProvider, IResourceChangeListener { + + private ILaunchBarManager manager; + + @Override + public void init(ILaunchBarManager manager) { + this.manager = manager; + + try { + for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { + manager.launchObjectAdded(project); + } + } catch (CoreException e) { + Activator.log(e.getStatus()); + } + + ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE); + } + + @Override + public void dispose() { + ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); + } + + @Override + public void resourceChanged(IResourceChangeEvent event) { + try { + event.getDelta().accept(new IResourceDeltaVisitor() { + @Override + public boolean visit(IResourceDelta delta) throws CoreException { + IResource res = delta.getResource(); + if (res instanceof IProject) { + IProject project = (IProject) delta.getResource(); + int kind = delta.getKind(); + if ((kind & IResourceDelta.ADDED) != 0) { + manager.launchObjectAdded(project); + } else if ((kind & IResourceDelta.REMOVED) != 0) { + manager.launchObjectRemoved(project); + } + return false; + } else if (res instanceof IFile || res instanceof IFolder) { + return false; + } + return true; + } + }); + } catch (CoreException e) { + Activator.log(e.getStatus()); + } + } + +} diff --git a/launch/org.eclipse.cdt.launchbar.ui/META-INF/MANIFEST.MF b/launch/org.eclipse.cdt.launchbar.ui/META-INF/MANIFEST.MF index a457822e466..adbf1079f4a 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/META-INF/MANIFEST.MF +++ b/launch/org.eclipse.cdt.launchbar.ui/META-INF/MANIFEST.MF @@ -19,3 +19,4 @@ Require-Bundle: org.eclipse.ui, Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-ActivationPolicy: lazy Bundle-Localization: plugin +Export-Package: org.eclipse.cdt.launchbar.ui diff --git a/launch/org.eclipse.cdt.launchbar.ui/plugin.xml b/launch/org.eclipse.cdt.launchbar.ui/plugin.xml index a0c63afd83c..b6a2643b00e 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/plugin.xml +++ b/launch/org.eclipse.cdt.launchbar.ui/plugin.xml @@ -1,6 +1,7 @@ + @@ -58,5 +59,16 @@ name="Launch Bar"> + + + + + + diff --git a/launch/org.eclipse.cdt.launchbar.ui/schema/launchBarUIContributions.exsd b/launch/org.eclipse.cdt.launchbar.ui/schema/launchBarUIContributions.exsd new file mode 100644 index 00000000000..7cc1eef571e --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.ui/schema/launchBarUIContributions.exsd @@ -0,0 +1,168 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/ILaunchBarUIConstants.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/ILaunchBarUIConstants.java index 62dac23c719..daf746cfadb 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/ILaunchBarUIConstants.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/ILaunchBarUIConstants.java @@ -12,6 +12,9 @@ package org.eclipse.cdt.launchbar.ui; public interface ILaunchBarUIConstants { + /** + * Parameter name for the edit target command. + */ public static final String TARGET_NAME = "targetName"; } diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/Activator.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/Activator.java index e377f4ac085..dabd2844d62 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/Activator.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/Activator.java @@ -125,11 +125,13 @@ public class Activator extends AbstractUIPlugin { } } - public static void log(CoreException e) { - plugin.getLog().log(e.getStatus()); + public static void log(IStatus status) { + plugin.getLog().log(status); } public static void log(Exception e) { + if (e instanceof CoreException) + log(((CoreException) e).getStatus()); plugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e)); } diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/DefaultDescriptorLabelProvider.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/DefaultDescriptorLabelProvider.java new file mode 100644 index 00000000000..20246cf6f66 --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/DefaultDescriptorLabelProvider.java @@ -0,0 +1,60 @@ +package org.eclipse.cdt.launchbar.ui.internal; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.cdt.launchbar.core.ILaunchBarManager; +import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; +import org.eclipse.cdt.launchbar.core.ILaunchTarget; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; + +public class DefaultDescriptorLabelProvider extends LabelProvider { + + private Map images = new HashMap<>(); + + @Override + public void dispose() { + super.dispose(); + for (Image image : images.values()) { + image.dispose(); + } + } + + @Override + public Image getImage(Object element) { + if (element instanceof ILaunchDescriptor) { + try { + ILaunchDescriptor desc = (ILaunchDescriptor) element; + ILaunchBarManager manager = desc.getType().getManager(); + ILaunchTarget target = manager.getActiveLaunchTarget(); + ILaunchConfigurationType type = manager.getLaunchConfigurationType(desc, target); + ImageDescriptor imageDescriptor = DebugUITools.getDefaultImageDescriptor(type); + if (imageDescriptor != null) { + Image image = images.get(imageDescriptor); + if (image == null) { + image = imageDescriptor.createImage(); + images.put(imageDescriptor, image); + } + return image; + } + } catch (CoreException e) { + Activator.log(e); + } + } + return super.getImage(element); + } + + @Override + public String getText(Object element) { + if (element instanceof ILaunchDescriptor) { + return ((ILaunchDescriptor) element).getName(); + } + return super.getText(element); + } + +} diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/LaunchBarUIManager.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/LaunchBarUIManager.java index f100adf44fb..e55acd2dcbe 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/LaunchBarUIManager.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/LaunchBarUIManager.java @@ -10,46 +10,95 @@ *******************************************************************************/ package org.eclipse.cdt.launchbar.ui.internal; +import java.util.HashMap; +import java.util.Map; + import org.eclipse.cdt.launchbar.core.ILaunchBarManager; -import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor; +import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchTarget; +import org.eclipse.cdt.launchbar.core.ILaunchTargetType; +import org.eclipse.cdt.launchbar.core.internal.Activator; import org.eclipse.cdt.launchbar.ui.IHoverProvider; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.Platform; import org.eclipse.jface.viewers.ILabelProvider; public class LaunchBarUIManager { ILaunchBarManager manager; + Map descriptorLabelProviders = new HashMap<>(); + Map targetLabelProviders = new HashMap<>(); + Map targetHoverProviders = new HashMap<>(); + Map targetEditCommandIds = new HashMap<>(); + Map targetAddNewCommandIds = new HashMap<>(); public LaunchBarUIManager(ILaunchBarManager manager) { this.manager = manager; + + IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchBarContributions"); + IExtension[] extensions = point.getExtensions(); + for (IExtension extension : extensions) { + for (IConfigurationElement element : extension.getConfigurationElements()) { + String elementName = element.getName(); + if (elementName.equals("descriptorUI")) { + try { + String descriptorTypeId = element.getAttribute("descriptorTypeId"); + + ILabelProvider labelProvider = (ILabelProvider) element.createExecutableExtension("labelProvider"); + descriptorLabelProviders.put(descriptorTypeId, labelProvider); + } catch (CoreException e) { + Activator.log(e.getStatus()); + } + } else if (elementName.equals("targetUI")) { + try { + String targetTypeId = element.getAttribute("targetTypeId"); + + ILabelProvider labelProvider = (ILabelProvider) element.createExecutableExtension("labelProvider"); + targetLabelProviders.put(targetTypeId, labelProvider); + + IHoverProvider hoverProvider = (IHoverProvider) element.createExecutableExtension("hoverProvider"); + if (hoverProvider != null) + targetHoverProviders.put(targetTypeId, hoverProvider); + + String editCommandId = element.getAttribute("editCommandId"); + if (editCommandId != null && editCommandId.length() > 0) + targetEditCommandIds.put(targetTypeId, editCommandId); + + String addNewCommandId = element.getAttribute("addNewTargetCommandId"); + if (addNewCommandId != null && addNewCommandId.length() > 0) + targetAddNewCommandIds.put(targetTypeId, addNewCommandId); + } catch (CoreException e) { + Activator.log(e.getStatus()); + } + } + } + } } public ILaunchBarManager getManager() { return manager; } - public ILabelProvider getLabelProvider(ILaunchConfigurationDescriptor configDesc) { - // TODO - return null; + public ILabelProvider getLabelProvider(ILaunchDescriptor descriptor) { + return descriptorLabelProviders.get(descriptor.getType().getId()); } public ILabelProvider getLabelProvider(ILaunchTarget target) { - // TODO - return null; - } - - public String getEditCommand(ILaunchTarget target) { - // TODO - return null; + return targetLabelProviders.get(target.getType().getId()); } public IHoverProvider getHoverProvider(ILaunchTarget target) { - // TODO - return null; + return targetHoverProviders.get(target.getType().getId()); } - public String getAddTargetCommand(ILaunchConfigurationDescriptor configDesc) { - // TODO - return null; + public String getEditCommand(ILaunchTarget target) { + return targetEditCommandIds.get(target.getType().getId()); + } + + public String getAddTargetCommand(ILaunchTargetType targetType) { + return targetAddNewCommandIds.get(targetType.getId()); } } diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/LocalTargetLabelProvider.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/LocalTargetLabelProvider.java new file mode 100644 index 00000000000..f687bee406b --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/LocalTargetLabelProvider.java @@ -0,0 +1,16 @@ +package org.eclipse.cdt.launchbar.ui.internal; +import org.eclipse.cdt.launchbar.core.ILaunchTarget; +import org.eclipse.jface.viewers.LabelProvider; + + +public class LocalTargetLabelProvider extends LabelProvider { + + @Override + public String getText(Object element) { + if (element instanceof ILaunchTarget) { + return ((ILaunchTarget) element).getName(); + } + return super.getText(element); + } + +} diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/BuildActiveCommandHandler.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/BuildActiveCommandHandler.java index 0659fcb8c4f..301c7827d7b 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/BuildActiveCommandHandler.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/BuildActiveCommandHandler.java @@ -16,7 +16,8 @@ import java.util.HashSet; import java.util.Set; import org.eclipse.cdt.launchbar.core.ILaunchBarManager; -import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor; +import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; +import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -31,7 +32,6 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchDelegate; import org.eclipse.debug.core.ILaunchMode; @@ -60,70 +60,60 @@ public class BuildActiveCommandHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { new UIJob(Display.getDefault(), "Building Active Configuration") { + @Override + public boolean belongsTo(Object family) { + return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family); + } + public IStatus runInUIThread(IProgressMonitor monitor) { - final ILaunchConfigurationDescriptor desc = launchBarManager.getActiveLaunchConfigurationDescriptor(); + try { + ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor(); + ILaunchTarget target = launchBarManager.getActiveLaunchTarget(); + ILaunchConfiguration config = launchBarManager.getLaunchConfiguration(desc, target); - if (desc == null) { - // popout - No launch configuration -// showConfigurationErrorCallOut(NLS.bind("{0}\n{1}", Messages.RunActiveCommandHandler_No_Launch_Configuration_Selected, -// Messages.RunActiveCommandHanlder_Create_Launch_Configuration)); - } - - new Job("Building Active Configuration") { - @Override - public boolean belongsTo(Object family) { - return ResourcesPlugin.FAMILY_MANUAL_BUILD.equals(family); - } - - protected IStatus run(IProgressMonitor monitor) { - try { - if (desc == null) { - ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); - return Status.OK_STATUS; - } - - ILaunchMode launchMode = launchBarManager.getActiveLaunchMode(); - - ILaunchConfiguration config = desc.getLaunchConfiguration(); - Collection projects = getProjects(config); - - if (BuildAction.isSaveAllSet()) { - saveEditors(projects); - } - - String mode = launchMode.getIdentifier(); - Set modes = new HashSet<>(); - modes.add(mode); - ILaunchDelegate delegate = config.getType().getPreferredDelegate(modes); - if (delegate == null) - delegate = config.getType().getDelegates(modes)[0]; - ILaunchConfigurationDelegate configDel = delegate.getDelegate(); - if (configDel instanceof ILaunchConfigurationDelegate2) { - ILaunchConfigurationDelegate2 configDel2 = (ILaunchConfigurationDelegate2)configDel; - boolean ret; - ret = configDel2.preLaunchCheck(config, mode, monitor); - if (!ret) - return Status.CANCEL_STATUS; - if (!configDel2.buildForLaunch(config, mode, monitor)) - return Status.OK_STATUS; - } - - // Fall through, do a normal build - if (projects.isEmpty()) { - ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); - } else { - Collection buildConfigs = getBuildConfigs(projects); - ResourcesPlugin.getWorkspace().build(buildConfigs.toArray(new IBuildConfiguration[buildConfigs.size()]), - IncrementalProjectBuilder.INCREMENTAL_BUILD, true, monitor); - // TODO, may need to get the buildReferences argument from the descriptor - } - } catch (CoreException e) { - return e.getStatus(); - } + if (config == null) { + // Default, build the workspace + ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); return Status.OK_STATUS; } - }.schedule(); + ILaunchMode launchMode = launchBarManager.getActiveLaunchMode(); + + Collection projects = getProjects(config); + if (BuildAction.isSaveAllSet()) { + saveEditors(projects); + } + + String mode = launchMode.getIdentifier(); + Set modes = new HashSet<>(); + modes.add(mode); + ILaunchDelegate delegate = config.getType().getPreferredDelegate(modes); + if (delegate == null) + delegate = config.getType().getDelegates(modes)[0]; + ILaunchConfigurationDelegate configDel = delegate.getDelegate(); + if (configDel instanceof ILaunchConfigurationDelegate2) { + ILaunchConfigurationDelegate2 configDel2 = (ILaunchConfigurationDelegate2)configDel; + boolean ret; + ret = configDel2.preLaunchCheck(config, mode, monitor); + if (!ret) + return Status.CANCEL_STATUS; + if (!configDel2.buildForLaunch(config, mode, monitor)) + return Status.OK_STATUS; + } + + // Fall through, do a normal build + if (projects.isEmpty()) { + ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); + } else { + Collection buildConfigs = getBuildConfigs(projects); + ResourcesPlugin.getWorkspace().build(buildConfigs.toArray(new IBuildConfiguration[buildConfigs.size()]), + IncrementalProjectBuilder.INCREMENTAL_BUILD, true, monitor); + // TODO, may need to get the buildReferences argument from the descriptor + } + } catch (CoreException e) { + return e.getStatus(); + } + return Status.OK_STATUS; }; }.schedule(); diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/ConfigureActiveLaunchHandler.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/ConfigureActiveLaunchHandler.java index 16b87bb28f6..1c5d4f70f40 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/ConfigureActiveLaunchHandler.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/ConfigureActiveLaunchHandler.java @@ -11,7 +11,8 @@ package org.eclipse.cdt.launchbar.ui.internal.commands; import org.eclipse.cdt.launchbar.core.ILaunchBarManager; -import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor; +import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; +import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -37,22 +38,15 @@ public class ConfigureActiveLaunchHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { - ILaunchConfigurationDescriptor activeLaunchConfiguration = launchBarManager.getActiveLaunchConfigurationDescriptor(); - ILaunchMode activeLaunchMode = launchBarManager.getActiveLaunchMode(); - - if (activeLaunchConfiguration == null) - return Status.OK_STATUS; - - ILaunchConfiguration launchConfiguration; - try { - launchConfiguration = activeLaunchConfiguration.getLaunchConfiguration(); - } catch (CoreException e1) { - return e1.getStatus(); - } - try { + ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor(); + ILaunchTarget target = launchBarManager.getActiveLaunchTarget(); + ILaunchConfiguration launchConfiguration = launchBarManager.getLaunchConfiguration(desc, target); + if (launchConfiguration == null) + return Status.OK_STATUS; ILaunchConfigurationWorkingCopy wc = launchConfiguration.getWorkingCopy(); - // TODO, gah, this is internal. Get it added to DebugUIUtil + + ILaunchMode activeLaunchMode = launchBarManager.getActiveLaunchMode(); ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(launchConfiguration.getType(), activeLaunchMode.getIdentifier()); if (DebugUITools.openLaunchConfigurationPropertiesDialog(HandlerUtil.getActiveShell(event), wc, group.getIdentifier()) == Window.OK) @@ -60,11 +54,6 @@ public class ConfigureActiveLaunchHandler extends AbstractHandler { } catch (CoreException e) { return e.getStatus(); } - return Status.OK_STATUS; } - - protected String getMode() { - return "config"; //$NON-NLS-1$ - } } diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/LaunchActiveCommandHandler.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/LaunchActiveCommandHandler.java index d28002cc4f9..aa3e54544fa 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/LaunchActiveCommandHandler.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/LaunchActiveCommandHandler.java @@ -11,7 +11,7 @@ package org.eclipse.cdt.launchbar.ui.internal.commands; import org.eclipse.cdt.launchbar.core.ILaunchBarManager; -import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor; +import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.core.commands.AbstractHandler; @@ -21,50 +21,32 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchMode; import org.eclipse.debug.ui.DebugUITools; -import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.progress.UIJob; public class LaunchActiveCommandHandler extends AbstractHandler { private final ILaunchBarManager launchBarManager; - + public LaunchActiveCommandHandler() { launchBarManager = Activator.getService(ILaunchBarManager.class); } - + @Override public Object execute(ExecutionEvent event) throws ExecutionException { new UIJob(Display.getDefault(), "Launching Active Configuration") { public IStatus runInUIThread(IProgressMonitor monitor) { try { - ILaunchConfigurationDescriptor desc = launchBarManager.getActiveLaunchConfigurationDescriptor(); - - if (desc == null) { - // popout - No launch configuration -// showConfigurationErrorCallOut(NLS.bind("{0}\n{1}", Messages.RunActiveCommandHandler_No_Launch_Configuration_Selected, -// Messages.RunActiveCommandHanlder_Create_Launch_Configuration)); - return Status.OK_STATUS; - } - - ILaunchMode launchMode = launchBarManager.getActiveLaunchMode(); + ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor(); ILaunchTarget target = launchBarManager.getActiveLaunchTarget(); - - if (target == null) { - // popout - No target -// if (TargetCorePlugin.getDefault().getTargetRegistry().getTargets().length == 1) { -// showTargetErrorCallOut(NLS.bind("{0}{1}", Messages.RunActiveCommandHandler_Cannot, getMode(launchMode)), -// DeviceErrors.Error.NO_DEVICES, Messages.RunActiveCommandHandler_Select_Manage_Devices); -// } else { // Don't think this can occur. Leaving just in case. -// showTargetErrorCallOut(NLS.bind("{0}{1}", Messages.RunActiveCommandHandler_Cannot, getMode(launchMode)), -// DeviceErrors.Error.NO_ACTIVE, Messages.RunActiveCommandHandler_Select_Device_Or_Simulator); -// } + ILaunchConfiguration config = launchBarManager.getLaunchConfiguration(desc, target); + if (config == null) return Status.OK_STATUS; - } - - DebugUITools.launch(desc.getLaunchConfiguration(), launchMode.getIdentifier()); + ILaunchMode launchMode = launchBarManager.getActiveLaunchMode(); + DebugUITools.launch(config, launchMode.getIdentifier()); } catch (CoreException e) { return e.getStatus(); } @@ -75,24 +57,6 @@ public class LaunchActiveCommandHandler extends AbstractHandler { return Status.OK_STATUS; } - protected void showConfigurationErrorCallOut(final String error) { -// Control activeProjectControl = LaunchToolBar.getInstance().getActiveConfigurationControl(); -// showErrorToolTipOnControl(error, activeProjectControl); - } - -// protected void showTargetErrorCallOut(final String title, DeviceErrors.Error e, String action) { -// Control activeTargetControl = LaunchToolBar.getInstance().getActiveTargetControl(); -// DeviceErrors.showCallOutErrorOnControl(activeTargetControl, title, e, action); -// } - - public static void showErrorToolTipOnControl(final String error, Control activeProjectControl) { -// CalloutError tip = new CalloutError(); -// tip.setTarget(activeProjectControl); -// tip.setHook(Position.BOTTOM_CENTER, Position.TOP_CENTER, new Point(0, 0)); -// tip.setData(error); -// tip.show(); - } - protected String getMode(ILaunchMode launchMode) { return launchMode.getIdentifier(); //$NON-NLS-1$ } diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/StopActiveCommandHandler.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/StopActiveCommandHandler.java index 695081c9e54..6e81501c907 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/StopActiveCommandHandler.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/StopActiveCommandHandler.java @@ -11,13 +11,11 @@ package org.eclipse.cdt.launchbar.ui.internal.commands; import org.eclipse.cdt.launchbar.core.ILaunchBarManager; -import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor; import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -26,7 +24,6 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; -import org.eclipse.debug.core.ILaunchConfiguration; public class StopActiveCommandHandler extends AbstractHandler { private ILaunchBarManager launchBarManager; @@ -47,39 +44,25 @@ public class StopActiveCommandHandler extends AbstractHandler { } protected void stopActiveLaunches() { - ILaunch[] activeLaunches = DebugPlugin.getDefault().getLaunchManager().getLaunches(); - ILaunchConfigurationDescriptor desc = launchBarManager.getActiveLaunchConfigurationDescriptor(); - ILaunchConfiguration activeLaunchConfiguration; - try { - activeLaunchConfiguration = desc.getLaunchConfiguration(); - } catch (CoreException e) { - Activator.log(e); - return; - } - for (int i = 0; i < activeLaunches.length; i++) { - final ILaunch launch = activeLaunches[i]; - if (!launch.isTerminated() && activeLaunchConfiguration != null - && matches(activeLaunchConfiguration, launch.getLaunchConfiguration())) { - Job job = new Job("Stopping " + activeLaunchConfiguration.getName()) { - @Override - protected IStatus run(IProgressMonitor monitor) { + final ILaunch[] activeLaunches = DebugPlugin.getDefault().getLaunchManager().getLaunches(); + if (activeLaunches != null && activeLaunches.length > 0) { + new Job("Stopping launches") { + protected IStatus run(IProgressMonitor monitor) { + // TODO only stop the launches for the active launch descriptor + // Not sure we have the API to map that out yet. + for (ILaunch launch : activeLaunches) { try { launch.terminate(); } catch (DebugException e) { - Activator.log(e); + return e.getStatus(); } - return Status.OK_STATUS; } + return Status.OK_STATUS; }; - job.schedule(); - } + }.schedule(); } } - protected boolean matches(ILaunchConfiguration activeLaunchConfiguration, ILaunchConfiguration launchConfiguration) { - return activeLaunchConfiguration.getName().equals(launchConfiguration.getName()); // just name for now - } - protected void stopBuild() { Job job = new Job("Stopping build") { @Override diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/ConfigSelector.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/ConfigSelector.java index 115250a0f7c..2b0a4ddbeca 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/ConfigSelector.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/ConfigSelector.java @@ -11,12 +11,10 @@ package org.eclipse.cdt.launchbar.ui.internal.controls; import java.util.Comparator; -import java.util.HashMap; -import java.util.Map; import org.eclipse.cdt.launchbar.core.ILaunchBarManager; -import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor; -import org.eclipse.cdt.launchbar.core.internal.DefaultLaunchConfigurationDescriptor; +import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; +import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager; import org.eclipse.cdt.launchbar.ui.internal.dialogs.LaunchConfigurationEditDialog; @@ -26,13 +24,12 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchMode; import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension; -import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.ILaunchGroup; -import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.LabelProvider; @@ -78,58 +75,35 @@ public class ConfigSelector extends CSelector { } @Override public Object[] getElements(Object inputElement) { - ILaunchConfigurationDescriptor[] descs = getManager().getLaunchConfigurationDescriptors(); - if (descs.length > 0) - return descs; + try { + ILaunchDescriptor[] descs = getManager().getLaunchDescriptors(); + if (descs.length > 0) + return descs; + } catch (CoreException e) { + Activator.log(e.getStatus()); + } return noConfigs; } }); setLabelProvider(new LabelProvider() { - private Map images = new HashMap<>(); - @Override - public void dispose() { - super.dispose(); - for (Image image : images.values()) { - image.dispose(); - } - } @Override public Image getImage(Object element) { - if (element instanceof ILaunchConfigurationDescriptor) { - ILaunchConfigurationDescriptor configDesc = (ILaunchConfigurationDescriptor)element; + if (element instanceof ILaunchDescriptor) { + ILaunchDescriptor configDesc = (ILaunchDescriptor)element; ILabelProvider labelProvider = uiManager.getLabelProvider(configDesc); if (labelProvider != null) { return labelProvider.getImage(element); } - - // Default - if (element instanceof DefaultLaunchConfigurationDescriptor) { - try { - ILaunchConfigurationType type = configDesc.getLaunchConfiguration().getType(); - ImageDescriptor imageDescriptor = DebugUITools.getDefaultImageDescriptor(type); - if (imageDescriptor != null) { - Image image = images.get(imageDescriptor); - if (image == null) { - image = imageDescriptor.createImage(); - images.put(imageDescriptor, image); - } - return image; - } - } catch (CoreException e) { - Activator.log(e); - } - } } - // Default - return null; + return super.getImage(element); } @Override public String getText(Object element) { if (element instanceof String) { return (String)element; - } else if (element instanceof ILaunchConfigurationDescriptor) { - ILaunchConfigurationDescriptor configDesc = (ILaunchConfigurationDescriptor)element; + } else if (element instanceof ILaunchDescriptor) { + ILaunchDescriptor configDesc = (ILaunchDescriptor)element; ILabelProvider labelProvider = uiManager.getLabelProvider(configDesc); if (labelProvider != null) { return labelProvider.getText(element); @@ -137,8 +111,7 @@ public class ConfigSelector extends CSelector { // Default return configDesc.getName(); } - - return null; + return super.getText(element); } }); @@ -155,10 +128,10 @@ public class ConfigSelector extends CSelector { @Override protected void fireSelectionChanged() { Object selected = getSelection(); - if (selected instanceof ILaunchConfigurationDescriptor) { - ILaunchConfigurationDescriptor configDesc = (ILaunchConfigurationDescriptor) selected; + if (selected instanceof ILaunchDescriptor) { + ILaunchDescriptor configDesc = (ILaunchDescriptor) selected; try { - getManager().setActiveLaunchConfigurationDescriptor(configDesc); + getManager().setActiveLaunchDescriptor(configDesc); } catch (CoreException e) { Activator.log(e); } @@ -167,20 +140,22 @@ public class ConfigSelector extends CSelector { @Override public boolean isEditable(Object element) { - return element instanceof ILaunchConfigurationDescriptor; + return element instanceof ILaunchDescriptor; } @Override public void handleEdit(Object element) { try { - ILaunchConfigurationDescriptor config = (ILaunchConfigurationDescriptor) element; + ILaunchDescriptor desc = (ILaunchDescriptor) element; ILaunchMode mode = getManager().getActiveLaunchMode(); - ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager() - .getLaunchGroup(config.getLaunchConfiguration().getType(), mode.getIdentifier()); + ILaunchTarget target = getManager().getActiveLaunchTarget(); + ILaunchConfigurationType configType = getManager().getLaunchConfigurationType(desc, target); + ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(configType, mode.getIdentifier()); Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); LaunchGroupExtension groupExt = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(group.getIdentifier()); if (groupExt != null) { - final LaunchConfigurationEditDialog dialog = new LaunchConfigurationEditDialog(shell, config.getLaunchConfiguration(), groupExt); + ILaunchConfiguration config = getManager().getLaunchConfiguration(desc, target); + final LaunchConfigurationEditDialog dialog = new LaunchConfigurationEditDialog(shell, config, groupExt); dialog.setInitialStatus(Status.OK_STATUS); dialog.open(); } diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/LaunchBarControl.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/LaunchBarControl.java index e2fb17953d4..f9e9bb2104c 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/LaunchBarControl.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/LaunchBarControl.java @@ -15,10 +15,11 @@ import javax.annotation.PreDestroy; import javax.inject.Inject; import org.eclipse.cdt.launchbar.core.ILaunchBarManager; -import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor; +import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.cdt.launchbar.ui.internal.Messages; +import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunchMode; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; @@ -80,14 +81,18 @@ public class LaunchBarControl implements ILaunchBarManager.Listener { targetSelector.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); targetSelector.setInput(manager); - ILaunchConfigurationDescriptor configDesc = manager.getActiveLaunchConfigurationDescriptor(); - configSelector.setSelection(configDesc == null ? null : configDesc); - - ILaunchMode mode = manager.getActiveLaunchMode(); - modeSelector.setSelection(mode == null ? null : mode); - - ILaunchTarget target = manager.getActiveLaunchTarget(); - targetSelector.setSelection(target == null ? null : target); + try { + ILaunchDescriptor configDesc = manager.getActiveLaunchDescriptor(); + configSelector.setSelection(configDesc == null ? null : configDesc); + + ILaunchMode mode = manager.getActiveLaunchMode(); + modeSelector.setSelection(mode == null ? null : mode); + + ILaunchTarget target = manager.getActiveLaunchTarget(); + targetSelector.setSelection(target == null ? null : target); + } catch (CoreException e) { + Activator.log(e.getStatus()); + } } @PreDestroy @@ -113,43 +118,61 @@ public class LaunchBarControl implements ILaunchBarManager.Listener { @Override public void activeConfigurationDescriptorChanged() { if (configSelector != null && !configSelector.isDisposed()) { - final ILaunchConfigurationDescriptor configDesc = manager.getActiveLaunchConfigurationDescriptor(); - configSelector.getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - if (!configSelector.isDisposed()) - configSelector.setSelection(configDesc == null ? null : configDesc); - } - }); + try { + final ILaunchDescriptor configDesc = manager.getActiveLaunchDescriptor(); + configSelector.getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + if (!configSelector.isDisposed()) + configSelector.setSelection(configDesc == null ? null : configDesc); + } + }); + } catch (CoreException e) { + Activator.log(e.getStatus()); + } } } @Override public void activeLaunchModeChanged() { if (modeSelector != null && !modeSelector.isDisposed()) { - final ILaunchMode mode = manager.getActiveLaunchMode(); - modeSelector.getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - if (!modeSelector.isDisposed()) - modeSelector.setSelection(mode == null ? null : mode); - } - }); + try { + final ILaunchMode mode = manager.getActiveLaunchMode(); + modeSelector.getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + if (!modeSelector.isDisposed()) + modeSelector.setSelection(mode == null ? null : mode); + } + }); + } catch (CoreException e) { + Activator.log(e.getStatus()); + } } } @Override public void activeLaunchTargetChanged() { if (targetSelector != null && !targetSelector.isDisposed()) { - final ILaunchTarget target = manager.getActiveLaunchTarget(); - targetSelector.getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - if (!targetSelector.isDisposed()) - targetSelector.setSelection(target == null ? null : target); - } - }); + try { + final ILaunchTarget target = manager.getActiveLaunchTarget(); + targetSelector.getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + if (!targetSelector.isDisposed()) + targetSelector.setSelection(target == null ? null : target); + } + }); + } catch (CoreException e) { + Activator.log(e.getStatus()); + } } } + @Override + public void launchDescriptorRemoved(ILaunchDescriptor descriptor) { + // TODO Auto-generated method stub + + } + } diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/ModeSelector.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/ModeSelector.java index d24da7bbd36..ef6c9a54567 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/ModeSelector.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/ModeSelector.java @@ -15,7 +15,6 @@ import java.util.HashMap; import java.util.Map; import org.eclipse.cdt.launchbar.core.ILaunchBarManager; -import org.eclipse.cdt.launchbar.core.ILaunchConfigurationDescriptor; import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunchMode; @@ -49,7 +48,7 @@ public class ModeSelector extends CSelector { @Override public Object[] getElements(Object inputElement) { try { - ILaunchMode[] modes = getManager().getActiveLaunchConfigurationDescriptor().getLaunchModes(); + ILaunchMode[] modes = getManager().getLaunchModes(); if (modes.length > 0) return modes; } catch (CoreException e) { @@ -70,8 +69,7 @@ public class ModeSelector extends CSelector { } @Override public Image getImage(Object element) { - ILaunchConfigurationDescriptor config = getManager().getActiveLaunchConfigurationDescriptor(); - if (config != null && element instanceof ILaunchMode) { + if (element instanceof ILaunchMode) { ILaunchMode mode = (ILaunchMode) element; ILaunchGroup group = getLaunchGroup(mode.getIdentifier()); if (group != null) { @@ -88,8 +86,7 @@ public class ModeSelector extends CSelector { } @Override public String getText(Object element) { - ILaunchConfigurationDescriptor config = getManager().getActiveLaunchConfigurationDescriptor(); - if (config != null && element instanceof ILaunchMode) { + if (element instanceof ILaunchMode) { ILaunchMode mode = (ILaunchMode) element; ILaunchGroup group = getLaunchGroup(mode.getIdentifier()); if (group != null) { @@ -147,7 +144,11 @@ public class ModeSelector extends CSelector { Object selected = getSelection(); if (selected instanceof ILaunchMode) { ILaunchMode mode = (ILaunchMode) selected; - getManager().setActiveLaunchMode(mode); + try { + getManager().setActiveLaunchMode(mode); + } catch (CoreException e) { + Activator.log(e); + } } } diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/TargetSelector.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/TargetSelector.java index e19f47782b8..d885f99daad 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/TargetSelector.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/TargetSelector.java @@ -18,14 +18,13 @@ import org.eclipse.cdt.launchbar.ui.IHoverProvider; import org.eclipse.cdt.launchbar.ui.ILaunchBarUIConstants; import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager; +import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.events.MouseTrackAdapter; import org.eclipse.swt.events.MouseTrackListener; import org.eclipse.swt.events.PaintEvent; @@ -63,9 +62,13 @@ public class TargetSelector extends CSelector { @Override public Object[] getElements(Object inputElement) { - ILaunchTarget[] targets = getManager().getActiveLaunchConfigurationDescriptor().getLaunchTargets(); - if (targets.length > 0) - return targets; + try { + ILaunchTarget[] targets = getManager().getLaunchTargets(); + if (targets.length > 0) + return targets; + } catch (CoreException e) { + Activator.log(e.getStatus()); + } return noTargets; } }); @@ -151,7 +154,10 @@ public class TargetSelector extends CSelector { @Override public boolean hasActionArea() { - return uiManager.getAddTargetCommand(getManager().getActiveLaunchConfigurationDescriptor()) != null; + // TODO need an add target command similar to the add configuration that allows the user + // to select the target type. +// return uiManager.getAddTargetCommand(getManager().getActiveLaunchDescriptor()) != null; + return false; } @Override @@ -184,15 +190,19 @@ public class TargetSelector extends CSelector { createLabel.setText("Add New Target..."); createLabel.setBackground(white); - final String command = uiManager.getAddTargetCommand(getManager().getActiveLaunchConfigurationDescriptor()); - MouseListener mouseListener = new MouseAdapter() { - public void mouseUp(org.eclipse.swt.events.MouseEvent e) { - Activator.runCommand(command); - } - }; - - createButton.addMouseListener(mouseListener); - createLabel.addMouseListener(mouseListener); +// try { +// final String command = uiManager.getAddTargetCommand(getManager().getActiveLaunchDescriptor()); +// MouseListener mouseListener = new MouseAdapter() { +// public void mouseUp(org.eclipse.swt.events.MouseEvent e) { +// Activator.runCommand(command); +// } +// }; +// +// createButton.addMouseListener(mouseListener); +// createLabel.addMouseListener(mouseListener); +// } catch (CoreException e) { +// Activator.log(e.getStatus()); +// } MouseTrackListener mouseTrackListener = new MouseTrackAdapter() { @Override @@ -216,7 +226,11 @@ public class TargetSelector extends CSelector { Object selection = getSelection(); if (selection instanceof ILaunchTarget) { ILaunchTarget target = (ILaunchTarget) selection; - uiManager.getManager().setActiveLaunchTarget(target); + try { + uiManager.getManager().setActiveLaunchTarget(target); + } catch (CoreException e) { + Activator.log(e.getStatus()); + } } }