From d5c63d386c130cfaf4495122cf055e6d4e46c24c Mon Sep 17 00:00:00 2001 From: Alena Laskavaia Date: Mon, 9 Nov 2015 10:27:07 -0500 Subject: [PATCH] [launchbar] Support launching without a target - we should not make assumption about the target and let delegate deal with it. For example if no targets are created and you run for the first time, delegate can offer to create a target - also if launch bar participants don't care about targets at all we should be able to still show modes, etc - so I removed filters on null target and let participant deal with it (note null target is not the same as Local). To avoid NPEs null target is actually an object ILaunchTarget.NULL_TARGET Change-Id: Ie2a4d3430284adbb137a4565d9976a0ba554d41f --- .../launchbar/core/internal/LaunchBarManager.java | 11 +++++------ .../eclipse/launchbar/core/target/ILaunchTarget.java | 8 +++++--- .../ui/internal/controls/TargetSelector.java | 5 ++++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java index 4fef96cea76..312dd7e4940 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchBarManager.java @@ -490,7 +490,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene } private void syncActiveMode() throws CoreException { - if (activeLaunchDesc == null || activeLaunchTarget == null) { + if (activeLaunchDesc == null) { setActiveLaunchMode(null); return; } @@ -574,9 +574,6 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene } public ILaunchMode[] getLaunchModes() throws CoreException { - if (activeLaunchTarget == null) { - return new ILaunchMode[0]; - } ILaunchConfigurationType configType = getLaunchConfigurationType(activeLaunchDesc, activeLaunchTarget); if (configType == null) return new ILaunchMode[0]; @@ -689,6 +686,8 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene } public void setActiveLaunchTarget(ILaunchTarget target) throws CoreException { + if (target == null) + target = ILaunchTarget.NULL_TARGET; if (activeLaunchTarget == target) { return; } @@ -699,7 +698,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene } private void storeLaunchTarget(ILaunchDescriptor desc, ILaunchTarget target) { - if (target == null) { + if (target == null || target == ILaunchTarget.NULL_TARGET) { // no point storing null, if stored id is invalid it won't be used // anyway return; @@ -722,7 +721,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene private ILaunchTarget getDefaultLaunchTarget(ILaunchDescriptor descriptor) { List targets = getLaunchTargets(descriptor); - return targets.isEmpty() ? null : targets.get(0); + return targets.isEmpty() ? ILaunchTarget.NULL_TARGET : targets.get(0); } public ILaunchConfiguration getActiveLaunchConfiguration() throws CoreException { diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTarget.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTarget.java index 147a9072187..99817fc4689 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTarget.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTarget.java @@ -8,26 +8,28 @@ package org.eclipse.launchbar.core.target; import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.launchbar.core.internal.target.LaunchTarget; /** * A launch target is a thing that a launch will run on. Launch targets are * simple objects with the intention that the launch delegates and launches will * adapt this object to an object that will assist in performing the launch. - * + * * @noimplement not to be implemented by clients */ public interface ILaunchTarget extends IAdaptable { + public static final ILaunchTarget NULL_TARGET = new LaunchTarget("null", "---"); /** * The name of the target. - * + * * @return name of the target */ String getName(); /** * The type of the target. - * + * * @return type of the target */ String getTypeId(); diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/controls/TargetSelector.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/controls/TargetSelector.java index eacbac7f41d..cbbf39ebd6b 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/controls/TargetSelector.java +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/controls/TargetSelector.java @@ -49,7 +49,7 @@ public class TargetSelector extends CSelector implements ILaunchTargetListener { private final ILaunchTargetUIManager targetUIManager = Activator.getService(ILaunchTargetUIManager.class); private final ILaunchTargetManager targetManager = Activator.getService(ILaunchTargetManager.class); - private static final String[] noTargets = new String[] { "---" }; //$NON-NLS-1$ + private static final ILaunchTarget[] noTargets = new ILaunchTarget[] { ILaunchTarget.NULL_TARGET }; public TargetSelector(Composite parent, int style) { super(parent, style); @@ -89,6 +89,9 @@ public class TargetSelector extends CSelector implements ILaunchTargetListener { @Override public Image getImage(Object element) { + if (element == ILaunchTarget.NULL_TARGET) { + return null; + } if (element instanceof ILaunchTarget) { // TODO apply a status overlay ILaunchTarget target = (ILaunchTarget) element;