diff --git a/bundles/org.eclipse.launchbar.core/.classpath b/bundles/org.eclipse.launchbar.core/.classpath index 098194ca4b7..eca7bdba8f0 100644 --- a/bundles/org.eclipse.launchbar.core/.classpath +++ b/bundles/org.eclipse.launchbar.core/.classpath @@ -1,6 +1,6 @@ - + diff --git a/bundles/org.eclipse.launchbar.core/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.launchbar.core/.settings/org.eclipse.jdt.core.prefs index f42de363afa..0c68a61dca8 100644 --- a/bundles/org.eclipse.launchbar.core/.settings/org.eclipse.jdt.core.prefs +++ b/bundles/org.eclipse.launchbar.core/.settings/org.eclipse.jdt.core.prefs @@ -1,7 +1,7 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/org.eclipse.launchbar.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.launchbar.core/META-INF/MANIFEST.MF index ab864804f79..dad42f94192 100644 --- a/bundles/org.eclipse.launchbar.core/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.launchbar.core/META-INF/MANIFEST.MF @@ -2,15 +2,15 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: LaunchBar Core Bundle-SymbolicName: org.eclipse.launchbar.core;singleton:=true -Bundle-Version: 1.0.1.qualifier +Bundle-Version: 2.0.0.qualifier Bundle-Activator: org.eclipse.launchbar.core.internal.Activator Bundle-Vendor: Eclipse CDT Require-Bundle: org.eclipse.core.runtime, org.eclipse.debug.core, - org.eclipse.core.filesystem, - org.eclipse.remote.core;bundle-version="2.0.0", org.eclipse.core.expressions -Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.launchbar.core, - org.eclipse.launchbar.core.internal;x-friends:="org.eclipse.launchbar.core.tests,org.eclipse.launchbar.ui" + org.eclipse.launchbar.core.internal;x-friends:="org.eclipse.launchbar.core.tests,org.eclipse.launchbar.ui", + org.eclipse.launchbar.core.target, + org.eclipse.launchbar.core.target.launch diff --git a/bundles/org.eclipse.launchbar.core/build.properties b/bundles/org.eclipse.launchbar.core/build.properties index 786b1df9364..e34cf111400 100644 --- a/bundles/org.eclipse.launchbar.core/build.properties +++ b/bundles/org.eclipse.launchbar.core/build.properties @@ -3,4 +3,5 @@ output.. = bin/ bin.includes = META-INF/,\ .,\ plugin.xml,\ - about.html + about.html,\ + schema/ diff --git a/bundles/org.eclipse.launchbar.core/plugin.xml b/bundles/org.eclipse.launchbar.core/plugin.xml index dd5ec17e2a7..a85371f601e 100644 --- a/bundles/org.eclipse.launchbar.core/plugin.xml +++ b/bundles/org.eclipse.launchbar.core/plugin.xml @@ -2,6 +2,7 @@ + + + + + diff --git a/bundles/org.eclipse.launchbar.core/pom.xml b/bundles/org.eclipse.launchbar.core/pom.xml index 4f1fe4e0d79..3cf8b86a839 100644 --- a/bundles/org.eclipse.launchbar.core/pom.xml +++ b/bundles/org.eclipse.launchbar.core/pom.xml @@ -12,7 +12,7 @@ org.eclipse.launchbar.core - 1.0.1-SNAPSHOT + 2.0.0-SNAPSHOT eclipse-plugin diff --git a/bundles/org.eclipse.launchbar.core/schema/launchTargetTypes.exsd b/bundles/org.eclipse.launchbar.core/schema/launchTargetTypes.exsd new file mode 100644 index 00000000000..290bf844499 --- /dev/null +++ b/bundles/org.eclipse.launchbar.core/schema/launchTargetTypes.exsd @@ -0,0 +1,109 @@ + + + + + + + + + [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/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/AbstractLaunchConfigProvider.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/AbstractLaunchConfigProvider.java index 3758fabbfb2..6203abb43bc 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/AbstractLaunchConfigProvider.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/AbstractLaunchConfigProvider.java @@ -17,7 +17,7 @@ import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchManager; import org.eclipse.launchbar.core.internal.Activator; -import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.launchbar.core.target.ILaunchTarget; /** * Common launch config provider. Manages creating launch configurations and @@ -28,7 +28,7 @@ public abstract class AbstractLaunchConfigProvider implements ILaunchConfigurati private static final String ATTR_ORIGINAL_NAME = Activator.PLUGIN_ID + ".originalName"; //$NON-NLS-1$ private static final String ATTR_PROVIDER_CLASS = Activator.PLUGIN_ID + ".providerClass"; //$NON-NLS-1$ - protected ILaunchConfiguration createLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target) + protected ILaunchConfiguration createLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); String name = launchManager.generateLaunchConfigurationName(descriptor.getName()); @@ -40,7 +40,7 @@ public abstract class AbstractLaunchConfigProvider implements ILaunchConfigurati return workingCopy.doSave(); } - protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target, + protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target, ILaunchConfigurationWorkingCopy workingCopy) throws CoreException { // Leave our breadcrumb workingCopy.setAttribute(ATTR_ORIGINAL_NAME, workingCopy.getName()); diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/DefaultLaunchConfigProvider.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/DefaultLaunchConfigProvider.java index a1dca878dec..ab26e5e83c7 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/DefaultLaunchConfigProvider.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/DefaultLaunchConfigProvider.java @@ -13,7 +13,8 @@ package org.eclipse.launchbar.core; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; -import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.launchbar.core.target.ILaunchTargetManager; /** * The launch config provider for the default descriptor which is the launch @@ -25,23 +26,19 @@ import org.eclipse.remote.core.IRemoteConnection; public class DefaultLaunchConfigProvider implements ILaunchConfigurationProvider { @Override - public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException { + public boolean supports(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { // Only supports Local connection - if (target != null && target.getConnectionType().getId().equals("org.eclipse.remote.LocalServices")) { //$NON-NLS-1$ - return true; - } else { - return false; - } + return target != null && target.getTypeId().equals(ILaunchTargetManager.localLaunchTargetTypeId); } @Override - public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, IRemoteConnection target) + public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { return descriptor.getAdapter(ILaunchConfiguration.class).getType(); } @Override - public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target) + public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { return descriptor.getAdapter(ILaunchConfiguration.class); } @@ -68,7 +65,7 @@ public class DefaultLaunchConfigProvider implements ILaunchConfigurationProvider } @Override - public void launchTargetRemoved(IRemoteConnection target) throws CoreException { + public void launchTargetRemoved(ILaunchTarget target) throws CoreException { // nothing to do } diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/ILaunchConfigurationProvider.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/ILaunchConfigurationProvider.java index b416f87ea40..ef7c9f473f2 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/ILaunchConfigurationProvider.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/ILaunchConfigurationProvider.java @@ -13,7 +13,7 @@ package org.eclipse.launchbar.core; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; -import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.launchbar.core.target.ILaunchTarget; /** * The provider of launch configurations of a given type for a given descriptor @@ -34,7 +34,7 @@ public interface ILaunchConfigurationProvider { * @param target * @return true if target is supported, false otherwise. */ - boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException; + boolean supports(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException; /** * Return the launch configuation type for the descriptor and target. @@ -45,7 +45,7 @@ public interface ILaunchConfigurationProvider { * @return * @throws CoreException */ - ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, IRemoteConnection target) + ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException; /** @@ -58,7 +58,7 @@ public interface ILaunchConfigurationProvider { * @return launch configuration * @throws CoreException */ - ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target) + ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException; /** @@ -108,6 +108,6 @@ public interface ILaunchConfigurationProvider { * @param target * @throws CoreException */ - void launchTargetRemoved(IRemoteConnection target) throws CoreException; + void launchTargetRemoved(ILaunchTarget target) throws CoreException; } diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/PerTargetLaunchConfigProvider.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/PerTargetLaunchConfigProvider.java index f00e7c2264b..314a17591ee 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/PerTargetLaunchConfigProvider.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/PerTargetLaunchConfigProvider.java @@ -20,10 +20,10 @@ import java.util.Map.Entry; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.launchbar.core.internal.Activator; -import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.launchbar.core.target.ILaunchTarget; public abstract class PerTargetLaunchConfigProvider extends AbstractLaunchConfigProvider { - private final Map> configMap = new HashMap<>(); + private final Map> configMap = new HashMap<>(); private final Map defaultConfigs = new HashMap<>(); private final Collection ownedConfigs = new LinkedHashSet<>(); @@ -32,10 +32,10 @@ public abstract class PerTargetLaunchConfigProvider extends AbstractLaunchConfig } @Override - public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target) + public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { if (target != null) { - Map targetMap = configMap.get(descriptor); + Map targetMap = configMap.get(descriptor); if (targetMap != null) { ILaunchConfiguration config = targetMap.get(target); if (config != null) { @@ -56,7 +56,7 @@ public abstract class PerTargetLaunchConfigProvider extends AbstractLaunchConfig protected abstract ILaunchDescriptor getLaunchDescriptor(ILaunchConfiguration configuration) throws CoreException; - protected abstract IRemoteConnection getLaunchTarget(ILaunchConfiguration configuration) throws CoreException; + protected abstract ILaunchTarget getLaunchTarget(ILaunchConfiguration configuration) throws CoreException; protected boolean providesForNullTarget() { return false; @@ -68,7 +68,7 @@ public abstract class PerTargetLaunchConfigProvider extends AbstractLaunchConfig return false; } - IRemoteConnection target = getLaunchTarget(configuration); + ILaunchTarget target = getLaunchTarget(configuration); if (target == null) { if (providesForNullTarget()) { defaultConfigs.put(desc, configuration); @@ -76,7 +76,7 @@ public abstract class PerTargetLaunchConfigProvider extends AbstractLaunchConfig return false; } } else { - Map targetMap = configMap.get(desc); + Map targetMap = configMap.get(desc); if (targetMap == null) { targetMap = new HashMap<>(); configMap.put(desc, targetMap); @@ -117,8 +117,8 @@ public abstract class PerTargetLaunchConfigProvider extends AbstractLaunchConfig @Override public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException { ownedConfigs.remove(configuration); - for (Entry> descEntry : configMap.entrySet()) { - for (Entry targetEntry : descEntry.getValue().entrySet()) { + for (Entry> descEntry : configMap.entrySet()) { + for (Entry targetEntry : descEntry.getValue().entrySet()) { if (targetEntry.getValue().equals(configuration)) { descEntry.getValue().remove(targetEntry.getKey()); if (descEntry.getValue().isEmpty()) { @@ -133,7 +133,7 @@ public abstract class PerTargetLaunchConfigProvider extends AbstractLaunchConfig @Override public void launchDescriptorRemoved(ILaunchDescriptor descriptor) throws CoreException { - Map map = configMap.remove(descriptor); + Map map = configMap.remove(descriptor); if (map != null) { for (ILaunchConfiguration config : map.values()) { ownedConfigs.remove(config); @@ -150,11 +150,11 @@ public abstract class PerTargetLaunchConfigProvider extends AbstractLaunchConfig } @Override - public void launchTargetRemoved(IRemoteConnection target) throws CoreException { - for (Iterator>> iterator = configMap + public void launchTargetRemoved(ILaunchTarget target) throws CoreException { + for (Iterator>> iterator = configMap .entrySet().iterator(); iterator.hasNext();) { - Entry> descEntry = iterator.next(); - Map map = descEntry.getValue(); + Entry> descEntry = iterator.next(); + Map map = descEntry.getValue(); ILaunchConfiguration config = map.remove(target); if (config != null) { // remove all auto-configs associated with target diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/ProjectPerTargetLaunchConfigProvider.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/ProjectPerTargetLaunchConfigProvider.java index 7eb5116a960..d85961f426a 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/ProjectPerTargetLaunchConfigProvider.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/ProjectPerTargetLaunchConfigProvider.java @@ -16,17 +16,17 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.launchbar.core.internal.Activator; -import org.eclipse.remote.core.IRemoteConnection; +import org.eclipse.launchbar.core.target.ILaunchTarget; public abstract class ProjectPerTargetLaunchConfigProvider extends PerTargetLaunchConfigProvider { @Override - public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException { + public boolean supports(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { return (descriptor.getAdapter(IProject.class) != null); } @Override - protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target, + protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target, ILaunchConfigurationWorkingCopy workingCopy) throws CoreException { super.populateLaunchConfiguration(descriptor, target, workingCopy); diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/Activator.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/Activator.java index e8f1b67aa21..80b6cccacc9 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/Activator.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/Activator.java @@ -16,6 +16,8 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; import org.eclipse.launchbar.core.ILaunchBarManager; +import org.eclipse.launchbar.core.internal.target.LaunchTargetManager; +import org.eclipse.launchbar.core.target.ILaunchTargetManager; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; @@ -27,6 +29,7 @@ public class Activator extends Plugin { public void start(BundleContext bundleContext) throws Exception { super.start(bundleContext); plugin = this; + bundleContext.registerService(ILaunchTargetManager.class, new LaunchTargetManager(), null); bundleContext.registerService(ILaunchBarManager.class, new LaunchBarManager(), null); } @@ -42,7 +45,8 @@ public class Activator extends Plugin { /** * Return the OSGi service with the given service interface. * - * @param service service interface + * @param service + * service interface * @return the specified service or null if it's not registered */ public static T getService(Class service) { @@ -70,8 +74,7 @@ public class Activator extends Plugin { } } - private static final String DEBUG_ONE = - PLUGIN_ID + "/debug/launchbar"; //$NON-NLS-1$ + private static final String DEBUG_ONE = PLUGIN_ID + "/debug/launchbar"; //$NON-NLS-1$ public static void trace(String str) { if (plugin == null || (plugin.isDebugging() && "true".equalsIgnoreCase(Platform.getDebugOption(DEBUG_ONE)))) //$NON-NLS-1$ 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 a982bfe30ef..4fef96cea76 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 @@ -11,6 +11,7 @@ package org.eclipse.launchbar.core.internal; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -40,31 +41,32 @@ import org.eclipse.launchbar.core.ILaunchConfigurationProvider; import org.eclipse.launchbar.core.ILaunchDescriptor; import org.eclipse.launchbar.core.ILaunchDescriptorType; import org.eclipse.launchbar.core.ILaunchObjectProvider; -import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteConnectionChangeListener; -import org.eclipse.remote.core.IRemoteConnectionType; -import org.eclipse.remote.core.IRemoteServicesManager; -import org.eclipse.remote.core.RemoteConnectionChangeEvent; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.launchbar.core.target.ILaunchTargetListener; +import org.eclipse.launchbar.core.target.ILaunchTargetManager; import org.osgi.service.prefs.BackingStoreException; import org.osgi.service.prefs.Preferences; /** * The brains of the launch bar. */ -public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionChangeListener { +public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListener { - // TODO make these more fine grained or break them into more focused - // listeners public interface Listener { - void activeLaunchDescriptorChanged(); + default void activeLaunchDescriptorChanged() { + } - void activeLaunchModeChanged(); + default void activeLaunchModeChanged() { + } - void activeLaunchTargetChanged(); + default void activeLaunchTargetChanged() { + } - void launchDescriptorRemoved(ILaunchDescriptor descriptor); + default void launchDescriptorRemoved(ILaunchDescriptor descriptor) { + } - void launchTargetsChanged(); + default void launchTargetsChanged() { + } } private final List listeners = new LinkedList<>(); @@ -88,11 +90,11 @@ public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionCha // Map of launch objects to launch descriptors private final Map objectDescriptorMap = new HashMap<>(); - private final IRemoteServicesManager remoteServicesManager = getRemoteServicesManager(); + private ILaunchTargetManager launchTargetManager; private ILaunchDescriptor activeLaunchDesc; private ILaunchMode activeLaunchMode; - private IRemoteConnection activeLaunchTarget; + private ILaunchTarget activeLaunchTarget; // private static final String PREF_ACTIVE_CONFIG_DESC = "activeConfigDesc"; private static final String PREF_ACTIVE_LAUNCH_MODE = "activeLaunchMode"; //$NON-NLS-1$ @@ -107,8 +109,8 @@ public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionCha // called from unit tests to ensure everything is inited LaunchBarManager(boolean doInit) { - remoteServicesManager.addRemoteConnectionChangeListener(this); - + launchTargetManager = getLaunchTargetManager(); + launchTargetManager.addListener(this); if (doInit) { new Job(Messages.LaunchBarManager_0) { @Override @@ -124,11 +126,6 @@ public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionCha } } - // To allow override by tests - IRemoteServicesManager getRemoteServicesManager() { - return Activator.getService(IRemoteServicesManager.class); - } - // To allow override by tests IExtensionPoint getExtensionPoint() throws CoreException { return Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchBarContributions"); //$NON-NLS-1$ @@ -139,6 +136,10 @@ public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionCha return DebugPlugin.getDefault().getLaunchManager(); } + ILaunchTargetManager getLaunchTargetManager() { + return Activator.getService(ILaunchTargetManager.class); + } + // When testing, call this after setting up the mocks. void init() throws CoreException { try { @@ -293,8 +294,8 @@ public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionCha return new Pair(getDescriptorTypeId(descriptor.getType()), descriptor.getName()); } - private Pair getTargetId(IRemoteConnection target) { - return new Pair(target.getConnectionType().getId(), target.getName()); + private Pair getTargetId(ILaunchTarget target) { + return new Pair(target.getTypeId(), target.getName()); } private void addDescriptor(Object launchObject, ILaunchDescriptor descriptor) throws CoreException { @@ -303,7 +304,7 @@ public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionCha setActiveLaunchDescriptor(descriptor); } - public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, IRemoteConnection target) + public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { if (descriptor == null) return null; @@ -478,13 +479,10 @@ public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionCha String activeTargetId = getPerDescriptorStore().get(PREF_ACTIVE_LAUNCH_TARGET, null); if (activeTargetId != null) { Pair id = toId(activeTargetId); - IRemoteConnectionType remoteServices = remoteServicesManager.getConnectionType(id.getFirst()); - if (remoteServices != null) { - IRemoteConnection storedTarget = remoteServices.getConnection(id.getSecond()); - if (storedTarget != null && supportsTarget(activeLaunchDesc, storedTarget)) { - setActiveLaunchTarget(storedTarget); - return; - } + ILaunchTarget storedTarget = launchTargetManager.getLaunchTarget(id.getFirst(), id.getSecond()); + if (storedTarget != null && supportsTarget(activeLaunchDesc, storedTarget)) { + setActiveLaunchTarget(storedTarget); + return; } } // default target for descriptor @@ -641,12 +639,12 @@ public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionCha } } - public List getLaunchTargets(ILaunchDescriptor descriptor) throws CoreException { + public List getLaunchTargets(ILaunchDescriptor descriptor) { if (descriptor == null) - return remoteServicesManager.getAllRemoteConnections(); + return Arrays.asList(launchTargetManager.getLaunchTargets()); - List targets = new ArrayList<>(); - for (IRemoteConnection target : remoteServicesManager.getAllRemoteConnections()) { + List targets = new ArrayList<>(); + for (ILaunchTarget target : launchTargetManager.getLaunchTargets()) { if (supportsTarget(descriptor, target)) { targets.add(target); } @@ -655,7 +653,7 @@ public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionCha return targets; } - boolean supportsTarget(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException { + boolean supportsTarget(ILaunchDescriptor descriptor, ILaunchTarget target) { String descriptorTypeId = getDescriptorTypeId(descriptor.getType()); for (LaunchConfigProviderInfo providerInfo : configProviders.get(descriptorTypeId)) { try { @@ -671,7 +669,7 @@ public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionCha return false; } - public IRemoteConnection getActiveLaunchTarget() { + public ILaunchTarget getActiveLaunchTarget() { return activeLaunchTarget; } @@ -682,7 +680,7 @@ public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionCha * @param target * @throws CoreException */ - public void setLaunchTarget(ILaunchDescriptor desc, IRemoteConnection target) throws CoreException { + public void setLaunchTarget(ILaunchDescriptor desc, ILaunchTarget target) throws CoreException { if (desc == activeLaunchDesc) { setActiveLaunchTarget(target); } else { @@ -690,7 +688,7 @@ public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionCha } } - public void setActiveLaunchTarget(IRemoteConnection target) throws CoreException { + public void setActiveLaunchTarget(ILaunchTarget target) throws CoreException { if (activeLaunchTarget == target) { return; } @@ -700,7 +698,7 @@ public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionCha fireActiveLaunchTargetChanged(); // notify listeners } - private void storeLaunchTarget(ILaunchDescriptor desc, IRemoteConnection target) { + private void storeLaunchTarget(ILaunchDescriptor desc, ILaunchTarget target) { if (target == null) { // no point storing null, if stored id is invalid it won't be used // anyway @@ -722,8 +720,8 @@ public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionCha } } - private IRemoteConnection getDefaultLaunchTarget(ILaunchDescriptor descriptor) throws CoreException { - List targets = getLaunchTargets(descriptor); + private ILaunchTarget getDefaultLaunchTarget(ILaunchDescriptor descriptor) { + List targets = getLaunchTargets(descriptor); return targets.isEmpty() ? null : targets.get(0); } @@ -731,7 +729,7 @@ public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionCha return getLaunchConfiguration(activeLaunchDesc, activeLaunchTarget); } - public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target) + public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { if (descriptor == null) { return null; @@ -847,32 +845,6 @@ public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionCha } } - @Override - public void connectionChanged(RemoteConnectionChangeEvent event) { - switch (event.getType()) { - case RemoteConnectionChangeEvent.CONNECTION_ADDED: - try { - launchTargetAdded(event.getConnection()); - } catch (CoreException e) { - Activator.log(e); - } - break; - case RemoteConnectionChangeEvent.CONNECTION_REMOVED: - try { - launchTargetRemoved(event.getConnection()); - } catch (CoreException e) { - Activator.log(e); - } - break; - case RemoteConnectionChangeEvent.CONNECTION_RENAMED: - fireLaunchTargetsChanged(); - break; - default: - fireLaunchTargetsChanged(); - break; - } - } - private void fireLaunchTargetsChanged() { if (!initialized) return; @@ -885,22 +857,32 @@ public class LaunchBarManager implements ILaunchBarManager, IRemoteConnectionCha } } - private void launchTargetAdded(IRemoteConnection target) throws CoreException { + @Override + public void launchTargetAdded(ILaunchTarget target) { if (!initialized) return; fireLaunchTargetsChanged(); // if we added new target we probably want to use it if (activeLaunchDesc == null || supportsTarget(activeLaunchDesc, target)) { - setActiveLaunchTarget(target); + try { + setActiveLaunchTarget(target); + } catch (CoreException e) { + Activator.log(e); + } } } - private void launchTargetRemoved(IRemoteConnection target) throws CoreException { + @Override + public void launchTargetRemoved(ILaunchTarget target) { if (!initialized) return; fireLaunchTargetsChanged(); if (activeLaunchTarget == target) { - setActiveLaunchTarget(getDefaultLaunchTarget(activeLaunchDesc)); + try { + setActiveLaunchTarget(getDefaultLaunchTarget(activeLaunchDesc)); + } catch (CoreException e) { + Activator.log(e); + } } } diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchConfigProviderInfo.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchConfigProviderInfo.java index 46721079320..625b15eff8f 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchConfigProviderInfo.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/LaunchConfigProviderInfo.java @@ -70,19 +70,28 @@ public class LaunchConfigProviderInfo { return priority; } - public ILaunchConfigurationProvider getProvider() throws CoreException { + public ILaunchConfigurationProvider getProvider() { if (provider == null) { - provider = (ILaunchConfigurationProvider) element.createExecutableExtension("class"); //$NON-NLS-1$ - element = null; + try { + provider = (ILaunchConfigurationProvider) element.createExecutableExtension("class"); //$NON-NLS-1$ + element = null; + } catch (CoreException e) { + Activator.log(e); + } } return provider; } - public boolean enabled(Object element) throws CoreException { + public boolean enabled(Object element) { if (expression == null) return true; - EvaluationResult result = expression.evaluate(new EvaluationContext(null, element)); - return (result == EvaluationResult.TRUE); + try { + EvaluationResult result = expression.evaluate(new EvaluationContext(null, element)); + return (result == EvaluationResult.TRUE); + } catch (CoreException e) { + Activator.log(e); + return false; + } } } \ No newline at end of file diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/Messages.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/Messages.java index a4d1e8a221b..aac564aa411 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/Messages.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/Messages.java @@ -18,6 +18,8 @@ public class Messages extends NLS { public static String LaunchBarManager_1; public static String LaunchBarManager_2; public static String LocalTarget_name; + public static String OK; + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/messages.properties b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/messages.properties index f99096c67c2..9d627bf8d9c 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/messages.properties +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/messages.properties @@ -12,4 +12,5 @@ LaunchBarManager_2=Mode is not supported by descriptor ################################################################################ LaunchBarManager_0=Launch Bar Initialization -LocalTarget_name=Local Machine +LocalTarget_name=Local +OK=OK diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LaunchTarget.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LaunchTarget.java new file mode 100644 index 00000000000..49c6e4ef0b3 --- /dev/null +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LaunchTarget.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2015 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 + *******************************************************************************/ +package org.eclipse.launchbar.core.internal.target; + +import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.launchbar.core.target.ILaunchTarget; + +public class LaunchTarget extends PlatformObject implements ILaunchTarget { + + private final String typeId; + private final String name; + + public LaunchTarget(String typeId, String name) { + this.typeId = typeId; + this.name = name; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getTypeId() { + return typeId; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((typeId == null) ? 0 : typeId.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + LaunchTarget other = (LaunchTarget) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (typeId == null) { + if (other.typeId != null) + return false; + } else if (!typeId.equals(other.typeId)) + return false; + return true; + } + +} diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LaunchTargetManager.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LaunchTargetManager.java new file mode 100644 index 00000000000..d08ce033232 --- /dev/null +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LaunchTargetManager.java @@ -0,0 +1,211 @@ +/******************************************************************************* + * Copyright (c) 2015 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 + *******************************************************************************/ +package org.eclipse.launchbar.core.internal.target; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +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.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.launchbar.core.internal.Activator; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.launchbar.core.target.ILaunchTargetListener; +import org.eclipse.launchbar.core.target.ILaunchTargetManager; +import org.eclipse.launchbar.core.target.ILaunchTargetProvider; +import org.eclipse.launchbar.core.target.TargetStatus; +import org.osgi.service.prefs.BackingStoreException; +import org.osgi.service.prefs.Preferences; + +public class LaunchTargetManager implements ILaunchTargetManager { + + private Map> targets; + private Map typeElements; + private Map typeProviders = new HashMap<>(); + private List listeners = new LinkedList<>(); + + private static final String DELIMETER = ","; //$NON-NLS-1$ + + private Preferences getTargetsPref() { + return InstanceScope.INSTANCE.getNode(Activator.getDefault().getBundle().getSymbolicName()) + .node(getClass().getSimpleName()); + } + + private synchronized void initTargets() { + if (targets == null) { + // load target type elements from registry + typeElements = new HashMap<>(); + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint point = registry + .getExtensionPoint(Activator.getDefault().getBundle().getSymbolicName() + ".launchTargetTypes"); //$NON-NLS-1$ + for (IExtension extension : point.getExtensions()) { + for (IConfigurationElement element : extension.getConfigurationElements()) { + String id = element.getAttribute("id"); //$NON-NLS-1$ + if (id != null) { + typeElements.put(id, element); + } + } + } + + // load targets from preference store + targets = new HashMap<>(); + Preferences prefs = getTargetsPref(); + try { + for (String typeId : prefs.keys()) { + Map type = targets.get(typeId); + if (type == null) { + type = new HashMap<>(); + targets.put(typeId, type); + } + + for (String name : prefs.get(typeId, "").split(DELIMETER)) { //$NON-NLS-1$ + type.put(name, new LaunchTarget(typeId, name)); + } + } + } catch (BackingStoreException e) { + Activator.log(e); + } + + // Call the provider's init + // TODO check enablement so we don't call them if we don't need to + for (String typeId : typeElements.keySet()) { + ILaunchTargetProvider provider = getProvider(typeId); + if (provider != null) { + provider.init(this); + } + } + } + } + + private ILaunchTargetProvider getProvider(String typeId) { + ILaunchTargetProvider provider = typeProviders.get(typeId); + if (provider == null) { + IConfigurationElement element = typeElements.get(typeId); + if (element != null) { + try { + provider = (ILaunchTargetProvider) element.createExecutableExtension("provider"); //$NON-NLS-1$ + } catch (CoreException e) { + Activator.log(e); + } + } + + if (provider == null) { + provider = new ILaunchTargetProvider() { + @Override + public void init(ILaunchTargetManager targetManager) { + } + + @Override + public TargetStatus getStatus(ILaunchTarget target) { + return TargetStatus.OK_STATUS; + } + }; + } + } + return provider; + } + + @Override + public ILaunchTarget[] getLaunchTargets() { + initTargets(); + List targetList = new ArrayList<>(); + for (Map type : targets.values()) { + targetList.addAll(type.values()); + } + return targetList.toArray(new ILaunchTarget[targetList.size()]); + } + + @Override + public ILaunchTarget[] getLaunchTargetsOfType(String typeId) { + initTargets(); + Map type = targets.get(typeId); + if (type != null) { + return type.values().toArray(new ILaunchTarget[type.size()]); + } + return new ILaunchTarget[0]; + } + + @Override + public ILaunchTarget getLaunchTarget(String typeId, String name) { + initTargets(); + Map type = targets.get(typeId); + if (type != null) { + return type.get(name); + } + return null; + } + + @Override + public TargetStatus getStatus(ILaunchTarget target) { + return getProvider(target.getTypeId()).getStatus(target); + } + + @Override + public ILaunchTarget addLaunchTarget(String typeId, String name) { + initTargets(); + Map type = targets.get(typeId); + if (type == null) { + type = new HashMap<>(); + targets.put(typeId, type); + } + + ILaunchTarget target = new LaunchTarget(typeId, name); + type.put(name, target); + getTargetsPref().put(typeId, String.join(DELIMETER, type.keySet())); + + for (ILaunchTargetListener listener : listeners) { + listener.launchTargetAdded(target); + } + + return target; + } + + @Override + public void removeLaunchTarget(ILaunchTarget target) { + initTargets(); + Map type = targets.get(target.getTypeId()); + if (type != null) { + type.remove(target.getName()); + if (type.isEmpty()) { + targets.remove(target.getTypeId()); + getTargetsPref().remove(target.getTypeId()); + } else { + getTargetsPref().put(target.getTypeId(), String.join(DELIMETER, type.keySet())); + } + + for (ILaunchTargetListener listener : listeners) { + listener.launchTargetRemoved(target); + } + } + } + + @Override + public void targetStatusChanged(ILaunchTarget target) { + for (ILaunchTargetListener listener : listeners) { + listener.launchTargetStatusChanged(target); + } + } + + @Override + public void addListener(ILaunchTargetListener listener) { + listeners.add(listener); + } + + @Override + public void removeListener(ILaunchTargetListener listener) { + listeners.remove(listener); + } + +} diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LocalLaunchTargetProvider.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LocalLaunchTargetProvider.java new file mode 100644 index 00000000000..eb7c130e6fe --- /dev/null +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/target/LocalLaunchTargetProvider.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2015 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 + *******************************************************************************/ +package org.eclipse.launchbar.core.internal.target; + +import org.eclipse.launchbar.core.internal.Messages; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.launchbar.core.target.ILaunchTargetManager; +import org.eclipse.launchbar.core.target.ILaunchTargetProvider; +import org.eclipse.launchbar.core.target.TargetStatus; + +public class LocalLaunchTargetProvider implements ILaunchTargetProvider { + + @Override + public void init(ILaunchTargetManager targetManager) { + if (targetManager.getLaunchTarget(ILaunchTargetManager.localLaunchTargetTypeId, + Messages.LocalTarget_name) == null) { + targetManager.addLaunchTarget(ILaunchTargetManager.localLaunchTargetTypeId, Messages.LocalTarget_name); + } + } + + @Override + public TargetStatus getStatus(ILaunchTarget target) { + return TargetStatus.OK_STATUS; + } + +} 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 new file mode 100644 index 00000000000..147a9072187 --- /dev/null +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTarget.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2015 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 + *******************************************************************************/ +package org.eclipse.launchbar.core.target; + +import org.eclipse.core.runtime.IAdaptable; + +/** + * 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 { + + /** + * 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.core/src/org/eclipse/launchbar/core/target/ILaunchTargetListener.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTargetListener.java new file mode 100644 index 00000000000..c692370a5fe --- /dev/null +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTargetListener.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2015 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 + *******************************************************************************/ +package org.eclipse.launchbar.core.target; + +/** + * A listener to changes in the list and status of launch targets. + */ +public interface ILaunchTargetListener { + + /** + * A launch target was added. + * + * @param target + * the new launch target + */ + default void launchTargetAdded(ILaunchTarget target) { + } + + /** + * A launch target was removed. + * + * @param target + * the target about to be removed. + */ + default void launchTargetRemoved(ILaunchTarget target) { + } + + /** + * The status of a target has changed. Query the target to find out what the + * new status is. + * + * @param target + * the target whose status has changed + */ + default void launchTargetStatusChanged(ILaunchTarget target) { + } + +} diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTargetManager.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTargetManager.java new file mode 100644 index 00000000000..86dbe5e4ff4 --- /dev/null +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTargetManager.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2015 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 + *******************************************************************************/ +package org.eclipse.launchbar.core.target; + +/** + * The manager for the launch targets. It is registered as an OSGi service. + * + * @noimplement not to be implemented by clients + */ +public interface ILaunchTargetManager { + + /** + * The type id for the local launch target type. It is the default launch + * target type. It represents launching on the underlying machine on which + * we are running. There is only one launch target of this type which + * represents that machine. + */ + final String localLaunchTargetTypeId = "org.eclipse.launchbar.core.launchTargetType.local"; //$NON-NLS-1$ + + /** + * The list of all launch targets. + * + * @return list of launch targets + */ + ILaunchTarget[] getLaunchTargets(); + + /** + * The list of launch targets with a given type id. + * + * @param typeId + * the launch target type id + * @return list of launch targets + */ + ILaunchTarget[] getLaunchTargetsOfType(String typeId); + + /** + * Return the launch target with the given typeId and name + * + * @param typeId + * type of the launch target + * @param name + * name of the launch target + * @return the launch target + */ + ILaunchTarget getLaunchTarget(String typeId, String name); + + /** + * Return the status of the launch target. + * + * @param target + * the launch target + * @return status + */ + TargetStatus getStatus(ILaunchTarget target); + + /** + * Add a launch target with the given typeId and name. + * + * @param typeId + * type id of the launch target + * @param name + * name of the launch target + * @return the created launch target + */ + ILaunchTarget addLaunchTarget(String typeId, String name); + + /** + * Removes a launch target. + * + * @param target + * the launch target to remove + */ + void removeLaunchTarget(ILaunchTarget target); + + /** + * The status of the launch target has changed. + * + * @param target + */ + void targetStatusChanged(ILaunchTarget target); + + /** + * Add a listener. + * + * @param listener + */ + void addListener(ILaunchTargetListener listener); + + /** + * Remove a listener. + * + * @param listener + */ + void removeListener(ILaunchTargetListener listener); + +} diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTargetProvider.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTargetProvider.java new file mode 100644 index 00000000000..62e571766a1 --- /dev/null +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/ILaunchTargetProvider.java @@ -0,0 +1,29 @@ +package org.eclipse.launchbar.core.target; + +/** + * A launch target provider is responsible for managing the list and status of + * launch targets. Providers are associated with launch target types in the + * launchTargetTypes extension point. + */ +public interface ILaunchTargetProvider { + + /** + * Called by the launch target manager when it first sees a target of the + * type. Or on startup if the provider is enabled. It is expected the + * provider will sync the list of targets with it's internal list and alert + * the manager of any non-OK statuses. + * + * @param targetManager + */ + void init(ILaunchTargetManager targetManager); + + /** + * Fetch the status for the launch target. + * + * @param target + * the launch target + * @return status of the launch target + */ + TargetStatus getStatus(ILaunchTarget target); + +} diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/TargetStatus.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/TargetStatus.java new file mode 100644 index 00000000000..bc05387110f --- /dev/null +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/TargetStatus.java @@ -0,0 +1,32 @@ +package org.eclipse.launchbar.core.target; + +import org.eclipse.launchbar.core.internal.Messages; + +/** + * The status for a launch target. + */ +public class TargetStatus { + + public enum Code { + OK, WARNING, ERROR + } + + private final TargetStatus.Code code; + private final String message; + + public static final TargetStatus OK_STATUS = new TargetStatus(Code.OK, Messages.OK); + + public TargetStatus(TargetStatus.Code code, String message) { + this.code = code; + this.message = message; + } + + public TargetStatus.Code getCode() { + return code; + } + + public String getMessage() { + return message; + } + +} \ No newline at end of file diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/launch/ILaunchConfigurationTargetedDelegate.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/launch/ILaunchConfigurationTargetedDelegate.java new file mode 100644 index 00000000000..7707d8a349c --- /dev/null +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/launch/ILaunchConfigurationTargetedDelegate.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2015 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 + *******************************************************************************/ +package org.eclipse.launchbar.core.target.launch; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; +import org.eclipse.launchbar.core.target.ILaunchTarget; + +/** + * An ILaunchConfigurationDelegate2 converted to take ILaunchTarget as an + * additional parameter. + */ +public interface ILaunchConfigurationTargetedDelegate extends ILaunchConfigurationDelegate { + + /** + * Returns a launch object to use when launching the given launch + * configuration in the given mode, or null if a new default + * launch object should be created by the debug platform. If a launch object + * is returned, its launch mode must match that of the mode specified in + * this method call. + * + * @param configuration + * the configuration being launched + * @param mode + * the mode the configuration is being launched in + * @return a launch object or null + * @throws CoreException + * if unable to launch + */ + public ITargetedLaunch getLaunch(ILaunchConfiguration configuration, String mode, ILaunchTarget target) + throws CoreException; + + /** + * Optionally performs any required building before launching the given + * configuration in the specified mode, and returns whether the debug + * platform should perform an incremental workspace build before the launch + * continues. If false is returned the launch will proceed + * without further building, and if true is returned an + * incremental build will be performed on the workspace before launching. + *

+ * This method is only called if the launch is invoked with flag indicating + * building should take place before the launch. This is done via the method + * ILaunchConfiguration.launch(String mode, IProgressMonitor monitor, boolean build) + * . + *

+ * + * @param configuration + * the configuration being launched + * @param mode + * the mode the configuration is being launched in + * @param monitor + * progress monitor, or null. A cancelable progress + * monitor is provided by the Job framework. It should be noted + * that the setCanceled(boolean) method should never be called on + * the provided monitor or the monitor passed to any delegates + * from this method; due to a limitation in the progress monitor + * framework using the setCanceled method can cause entire + * workspace batch jobs to be canceled, as the canceled flag is + * propagated up the top-level parent monitor. The provided + * monitor is not guaranteed to have been started. + * @return whether the debug platform should perform an incremental + * workspace build before the launch + * @throws CoreException + * if an exception occurs while building + */ + public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, ILaunchTarget target, + IProgressMonitor monitor) throws CoreException; + + /** + * Returns whether a launch should proceed. This method is called after + * preLaunchCheck() and buildForLaunch() providing + * a final chance for this launch delegate to abort a launch if required. + * For example, a delegate could cancel a launch if it discovered + * compilation errors that would prevent the launch from succeeding. + * + * @param configuration + * the configuration being launched + * @param mode + * launch mode + * @param monitor + * progress monitor, or null. A cancelable progress + * monitor is provided by the Job framework. It should be noted + * that the setCanceled(boolean) method should never be called on + * the provided monitor or the monitor passed to any delegates + * from this method; due to a limitation in the progress monitor + * framework using the setCanceled method can cause entire + * workspace batch jobs to be canceled, as the canceled flag is + * propagated up the top-level parent monitor. The provided + * monitor is not guaranteed to have been started. + * @return whether the launch should proceed + * @throws CoreException + * if an exception occurs during final checks + */ + public boolean finalLaunchCheck(ILaunchConfiguration configuration, String mode, ILaunchTarget target, + IProgressMonitor monitor) throws CoreException; + + /** + * Returns whether a launch should proceed. This method is called first in + * the launch sequence providing an opportunity for this launch delegate to + * abort the launch. + * + * @param configuration + * configuration being launched + * @param mode + * launch mode + * @param monitor + * progress monitor, or null. A cancelable progress + * monitor is provided by the Job framework. It should be noted + * that the setCanceled(boolean) method should never be called on + * the provided monitor or the monitor passed to any delegates + * from this method; due to a limitation in the progress monitor + * framework using the setCanceled method can cause entire + * workspace batch jobs to be canceled, as the canceled flag is + * propagated up the top-level parent monitor. The provided + * monitor is not guaranteed to have been started. + * @return whether the launch should proceed + * @throws CoreException + * if an exception occurs while performing pre-launch checks + */ + public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, ILaunchTarget target, + IProgressMonitor monitor) throws CoreException; + +} diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/launch/ITargetedLaunch.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/launch/ITargetedLaunch.java new file mode 100644 index 00000000000..cd8c7f92ef6 --- /dev/null +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/target/launch/ITargetedLaunch.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2015 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 + *******************************************************************************/ +package org.eclipse.launchbar.core.target.launch; + +import org.eclipse.debug.core.ILaunch; +import org.eclipse.launchbar.core.target.ILaunchTarget; + +/** + * A launch that knows what target it's running on. + */ +public interface ITargetedLaunch extends ILaunch { + + /** + * The target this launch will or is running on. + * + * @return launch target + */ + ILaunchTarget getLaunchTarget(); + +} diff --git a/bundles/org.eclipse.launchbar.ui/.classpath b/bundles/org.eclipse.launchbar.ui/.classpath index 098194ca4b7..eca7bdba8f0 100644 --- a/bundles/org.eclipse.launchbar.ui/.classpath +++ b/bundles/org.eclipse.launchbar.ui/.classpath @@ -1,6 +1,6 @@ - + diff --git a/bundles/org.eclipse.launchbar.ui/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.launchbar.ui/.settings/org.eclipse.jdt.core.prefs index f42de363afa..0c68a61dca8 100644 --- a/bundles/org.eclipse.launchbar.ui/.settings/org.eclipse.jdt.core.prefs +++ b/bundles/org.eclipse.launchbar.ui/.settings/org.eclipse.jdt.core.prefs @@ -1,7 +1,7 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bundles/org.eclipse.launchbar.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.launchbar.ui/META-INF/MANIFEST.MF index 07287ff698f..0b327d70d39 100644 --- a/bundles/org.eclipse.launchbar.ui/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.launchbar.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: LaunchBar UI Bundle-SymbolicName: org.eclipse.launchbar.ui;singleton:=true -Bundle-Version: 1.0.1.qualifier +Bundle-Version: 2.0.0.qualifier Bundle-Activator: org.eclipse.launchbar.ui.internal.Activator Bundle-Vendor: Eclipse CDT Require-Bundle: org.eclipse.ui, @@ -14,14 +14,9 @@ Require-Bundle: org.eclipse.ui, org.eclipse.osgi.services, org.eclipse.launchbar.core, org.eclipse.debug.ui, - org.eclipse.ui.workbench, org.eclipse.ui.ide, - org.eclipse.swt, - org.eclipse.ui.navigator, - org.eclipse.remote.core;bundle-version="2.0.0", - org.eclipse.remote.ui;bundle-version="1.1.0", org.eclipse.e4.core.contexts -Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Bundle-Localization: plugin Export-Package: org.eclipse.launchbar.ui, diff --git a/bundles/org.eclipse.launchbar.ui/build.properties b/bundles/org.eclipse.launchbar.ui/build.properties index 088f01d1b5a..e106532f226 100644 --- a/bundles/org.eclipse.launchbar.ui/build.properties +++ b/bundles/org.eclipse.launchbar.ui/build.properties @@ -5,4 +5,5 @@ bin.includes = META-INF/,\ plugin.xml,\ icons/,\ plugin.properties,\ - about.html + about.html,\ + schema/ diff --git a/bundles/org.eclipse.launchbar.ui/icons/localTarget.png b/bundles/org.eclipse.launchbar.ui/icons/localTarget.png new file mode 100644 index 00000000000..ca77aee5bca Binary files /dev/null and b/bundles/org.eclipse.launchbar.ui/icons/localTarget.png differ diff --git a/bundles/org.eclipse.launchbar.ui/plugin.xml b/bundles/org.eclipse.launchbar.ui/plugin.xml index 8a63efff54a..2f0617fd581 100644 --- a/bundles/org.eclipse.launchbar.ui/plugin.xml +++ b/bundles/org.eclipse.launchbar.ui/plugin.xml @@ -2,6 +2,7 @@ + diff --git a/bundles/org.eclipse.launchbar.ui/pom.xml b/bundles/org.eclipse.launchbar.ui/pom.xml index 62c18d01f02..56c66dd7a01 100644 --- a/bundles/org.eclipse.launchbar.ui/pom.xml +++ b/bundles/org.eclipse.launchbar.ui/pom.xml @@ -12,7 +12,7 @@ org.eclipse.launchbar.ui - 1.0.1-SNAPSHOT + 2.0.0-SNAPSHOT eclipse-plugin diff --git a/bundles/org.eclipse.launchbar.ui/schema/launchTargetTypeUI.exsd b/bundles/org.eclipse.launchbar.ui/schema/launchTargetTypeUI.exsd new file mode 100644 index 00000000000..23a46f9f733 --- /dev/null +++ b/bundles/org.eclipse.launchbar.ui/schema/launchTargetTypeUI.exsd @@ -0,0 +1,112 @@ + + + + + + + + + [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/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/IHoverProvider.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/IHoverProvider.java deleted file mode 100644 index d7cf839da00..00000000000 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/IHoverProvider.java +++ /dev/null @@ -1,36 +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.launchbar.ui; - -/** - * An extension to allow different object types to provide fancy hovers. - * - * TODO this does lead to inconsistency when different types provide different hover UI - * which can confuse users. We should provide good UI out of the box. - */ -public interface IHoverProvider { - - /** - * Display the hover item. - * - * @return true if hover item was displayed, otherwise false - */ - public abstract boolean displayHover(Object element); - - /** - * Dismiss the hover item. - * - * @param immediate - * if true, the hover item will be immediately dismissed, otherwise it may be be dismissed at a later time. - */ - public abstract void dismissHover(Object element, boolean immediate); - -} diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Activator.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Activator.java index f5164f7cd7a..267458300cc 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Activator.java +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Activator.java @@ -24,6 +24,8 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.launchbar.core.ILaunchBarManager; import org.eclipse.launchbar.core.internal.LaunchBarManager; +import org.eclipse.launchbar.ui.internal.target.LaunchTargetUIManager; +import org.eclipse.launchbar.ui.target.ILaunchTargetUIManager; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Event; import org.eclipse.ui.PlatformUI; @@ -45,6 +47,7 @@ public class Activator extends AbstractUIPlugin { public static final String IMG_BUTTON_BUILD = "build"; //$NON-NLS-1$ public static final String IMG_BUTTON_LAUNCH = "launch"; //$NON-NLS-1$ public static final String IMG_BUTTON_STOP = "stop"; //$NON-NLS-1$ + public static final String IMG_LOCAL_TARGET = "localTarget"; //$NON-NLS-1$ // Command ids public static final String CMD_BUILD = PLUGIN_ID + ".command.buildActive"; //$NON-NLS-1$ @@ -61,7 +64,7 @@ public class Activator extends AbstractUIPlugin { private static Activator plugin; // The cache of the Launch Bar UI Manager Object - private LaunchBarUIManager launchBarUIManager; + private LaunchBarUIManager launchBarUIManager; /** * The constructor @@ -77,6 +80,9 @@ public class Activator extends AbstractUIPlugin { imageRegistry.put(IMG_BUTTON_BUILD, imageDescriptorFromPlugin(PLUGIN_ID, "icons/build.png")); //$NON-NLS-1$ imageRegistry.put(IMG_BUTTON_LAUNCH, imageDescriptorFromPlugin(PLUGIN_ID, "icons/launch.png")); //$NON-NLS-1$ imageRegistry.put(IMG_BUTTON_STOP, imageDescriptorFromPlugin(PLUGIN_ID, "icons/stop.png")); //$NON-NLS-1$ + imageRegistry.put(IMG_LOCAL_TARGET, imageDescriptorFromPlugin(PLUGIN_ID, "icons/localTarget.png")); //$NON-NLS-1$ + + context.registerService(ILaunchTargetUIManager.class, new LaunchTargetUIManager(), null); } public void stop(BundleContext context) throws Exception { diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Messages.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Messages.java index 1621a8ce5f8..7aef26870a3 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Messages.java +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Messages.java @@ -58,8 +58,9 @@ public class Messages extends NLS { public static String NewLaunchConfigWizard_0; public static String StopActiveCommandHandler_0; public static String StopActiveCommandHandler_1; + public static String TargetSelector_ToolTipPrefix; public static String TargetSelector_CreateNewTarget; - + public static String DescriptorMustNotBeNull; public static String DescriptorMustNotBeNullDesc; public static String NoActiveTarget; @@ -72,9 +73,7 @@ public class Messages extends NLS { public static String LaunchConfigurationNotFoundDesc; public static String NoLaunchTabsDefined; public static String NoLaunchTabsDefinedDesc; - - - + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/commands/ConfigureActiveLaunchHandler.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/commands/ConfigureActiveLaunchHandler.java index f11b404c9a0..346d32d4c65 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/commands/ConfigureActiveLaunchHandler.java +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/commands/ConfigureActiveLaunchHandler.java @@ -28,10 +28,10 @@ import org.eclipse.debug.ui.ILaunchGroup; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.launchbar.core.ILaunchDescriptor; import org.eclipse.launchbar.core.internal.LaunchBarManager; +import org.eclipse.launchbar.core.target.ILaunchTarget; import org.eclipse.launchbar.ui.internal.Activator; import org.eclipse.launchbar.ui.internal.Messages; import org.eclipse.launchbar.ui.internal.dialogs.LaunchConfigurationEditDialog; -import org.eclipse.remote.core.IRemoteConnection; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; @@ -46,83 +46,97 @@ public class ConfigureActiveLaunchHandler extends AbstractHandler { return Status.OK_STATUS; } - public static IStatus canOpenConfigurationEditor(ILaunchDescriptor desc) { if (desc == null) - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.DescriptorMustNotBeNull, new Exception(Messages.DescriptorMustNotBeNullDesc)); + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.DescriptorMustNotBeNull, + new Exception(Messages.DescriptorMustNotBeNullDesc)); LaunchBarManager manager = Activator.getDefault().getLaunchBarUIManager().getManager(); ILaunchMode mode = manager.getActiveLaunchMode(); - IRemoteConnection target = manager.getActiveLaunchTarget(); + ILaunchTarget target = manager.getActiveLaunchTarget(); if (target == null) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NoActiveTarget, new Exception(Messages.NoActiveTargetDesc)); + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NoActiveTarget, + new Exception(Messages.NoActiveTargetDesc)); } - + ILaunchConfigurationType configType = null; try { configType = manager.getLaunchConfigurationType(desc, target); - } catch(CoreException ce) {/* ignore */ }; + } catch (CoreException ce) { + /* ignore */ } + ; if (configType == null) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NoLaunchConfigType, new Exception(Messages.CannotEditLaunchConfiguration)); + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NoLaunchConfigType, + new Exception(Messages.CannotEditLaunchConfiguration)); } - - if( mode == null ) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NoLaunchModeSelected, new Exception(Messages.NoLaunchModeSelected)); + + if (mode == null) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NoLaunchModeSelected, + new Exception(Messages.NoLaunchModeSelected)); } - - ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(configType, mode.getIdentifier()); - if( group == null ) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NoLaunchGroupSelected, new Exception(Messages.NoLaunchGroupSelected)); + + ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(configType, + mode.getIdentifier()); + if (group == null) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NoLaunchGroupSelected, + new Exception(Messages.NoLaunchGroupSelected)); } - + String mode2 = group.getMode(); - if( mode2 == null ) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NoLaunchModeSelected, new Exception(Messages.CannotEditLaunchConfiguration)); + if (mode2 == null) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NoLaunchModeSelected, + new Exception(Messages.CannotEditLaunchConfiguration)); } - - LaunchGroupExtension groupExt = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(group.getIdentifier()); + + LaunchGroupExtension groupExt = DebugUIPlugin.getDefault().getLaunchConfigurationManager() + .getLaunchGroup(group.getIdentifier()); if (groupExt != null) { ILaunchConfiguration config = null; try { config = manager.getLaunchConfiguration(desc, target); - } catch(CoreException ce) { + } catch (CoreException ce) { // Ignore } if (config == null) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LaunchConfigurationNotFound, new Exception(Messages.LaunchConfigurationNotFoundDesc)); + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LaunchConfigurationNotFound, + new Exception(Messages.LaunchConfigurationNotFoundDesc)); } try { LaunchConfigurationPresentationManager mgr = LaunchConfigurationPresentationManager.getDefault(); ILaunchConfigurationTabGroup tabgroup = mgr.getTabGroup(config, mode.getIdentifier()); - } catch(CoreException ce) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID,Messages.NoLaunchTabsDefined, new Exception(Messages.NoLaunchTabsDefinedDesc)); + } catch (CoreException ce) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NoLaunchTabsDefined, + new Exception(Messages.NoLaunchTabsDefinedDesc)); } } else { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CannotEditLaunchConfiguration, new Exception(Messages.CannotEditLaunchConfiguration)); + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CannotEditLaunchConfiguration, + new Exception(Messages.CannotEditLaunchConfiguration)); } return Status.OK_STATUS; } - - + public static void openConfigurationEditor(ILaunchDescriptor desc) { if (desc == null) return; - + // Display the error message Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); IStatus s = canOpenConfigurationEditor(desc); - if( !s.isOK()) { - MessageDialog.openError(shell, s.getMessage(), s.getException() == null ? s.getMessage() : s.getException().getMessage()); + if (!s.isOK()) { + MessageDialog.openError(shell, s.getMessage(), + s.getException() == null ? s.getMessage() : s.getException().getMessage()); return; } - - // At this point, no error handling should be needed. + + // At this point, no error handling should be needed. try { LaunchBarManager manager = Activator.getDefault().getLaunchBarUIManager().getManager(); ILaunchMode mode = manager.getActiveLaunchMode(); - IRemoteConnection target = manager.getActiveLaunchTarget(); + ILaunchTarget target = manager.getActiveLaunchTarget(); ILaunchConfigurationType configType = manager.getLaunchConfigurationType(desc, target); - ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(configType, mode.getIdentifier()); - LaunchGroupExtension groupExt = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(group.getIdentifier()); + ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(configType, + mode.getIdentifier()); + LaunchGroupExtension groupExt = DebugUIPlugin.getDefault().getLaunchConfigurationManager() + .getLaunchGroup(group.getIdentifier()); ILaunchConfiguration config = manager.getLaunchConfiguration(desc, target); if (config.isWorkingCopy() && ((ILaunchConfigurationWorkingCopy) config).isDirty()) { config = ((ILaunchConfigurationWorkingCopy) config).doSave(); diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/controls/CSelector.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/controls/CSelector.java index 3b790248664..b98b5ccc911 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/controls/CSelector.java +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/controls/CSelector.java @@ -23,7 +23,6 @@ import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.launchbar.ui.IHoverProvider; import org.eclipse.launchbar.ui.internal.Activator; import org.eclipse.launchbar.ui.internal.Messages; import org.eclipse.swt.SWT; @@ -32,7 +31,6 @@ import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseListener; -import org.eclipse.swt.events.MouseTrackListener; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.events.SelectionAdapter; @@ -57,13 +55,10 @@ import org.eclipse.ui.PlatformUI; public abstract class CSelector extends Composite { private IStructuredContentProvider contentProvider; private ILabelProvider labelProvider; - private IHoverProvider hoverProvider; private Comparator sorter; private Comparator sorterTop; private Object input; private Composite buttonComposite; - private String toolTipText; - private boolean toolTipWasModified; // Used for the hover provider private static final int arrowMax = 2; private Transition arrowTransition; private Object selection; @@ -77,51 +72,7 @@ public abstract class CSelector extends Composite { private Shell popup; private LaunchBarListViewer listViewer; private Job delayJob; - private MouseTrackListener mouseTrackListener = new MouseTrackListener() { - @Override - public void mouseEnter(MouseEvent e) { - if (!mouseOver) { - mouseOver = true; - redraw(); - if (toolTipWasModified) { - buttonComposite.setToolTipText(toolTipText); - if (currentLabel != null) { - currentLabel.setToolTipText(toolTipText); - } - if (currentIcon != null) { - currentIcon.setToolTipText(toolTipText); - } - } - } - } - @Override - public void mouseHover(MouseEvent e) { - if (hoverProvider != null && (popup == null || popup.isDisposed())) { - final Object eventSource = e.getSource(); - if ((eventSource == currentLabel || eventSource == buttonComposite || eventSource == currentIcon)) { - if (hoverProvider.displayHover(selection)) { - buttonComposite.setToolTipText(""); //$NON-NLS-1$ - if (currentLabel != null) { - currentLabel.setToolTipText(""); //$NON-NLS-1$ - } - if (currentIcon != null) { - currentIcon.setToolTipText(""); //$NON-NLS-1$ - } - toolTipWasModified = true; - } - } - } - } - - @Override - public void mouseExit(MouseEvent e) { - if (mouseOver) { - mouseOver = false; - redraw(); - } - } - }; private MouseListener mouseListener = new MouseAdapter() { @Override public void mouseUp(MouseEvent event) { @@ -159,8 +110,10 @@ public abstract class CSelector extends Composite { break; case SWT.FocusOut: if (isPopUpInFocus()) { - // we about to loose focus from popup children, but it may go - // to another child, lets schedule a job to wait before we close + // we about to loose focus from popup children, but it may + // go + // to another child, lets schedule a job to wait before we + // close if (closingJob != null) closingJob.cancel(); closingJob = new Job(Messages.CSelector_0) { @@ -212,7 +165,6 @@ public abstract class CSelector extends Composite { } }); addMouseListener(mouseListener); - addMouseTrackListener(mouseTrackListener); } private boolean isPopUpInFocus() { @@ -260,7 +212,7 @@ public abstract class CSelector extends Composite { this.selection = element; if (buttonComposite != null) buttonComposite.dispose(); - toolTipText = getToolTipText(); + String toolTipText = getToolTipText(); boolean editable = false; int columns = 2; Image image = labelProvider.getImage(element); @@ -276,19 +228,16 @@ public abstract class CSelector extends Composite { buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); buttonComposite.setBackground(backgroundColor); buttonComposite.addMouseListener(mouseListener); - buttonComposite.addMouseTrackListener(mouseTrackListener); buttonComposite.setToolTipText(toolTipText); if (element != null) { if (image != null) { Label icon = createImage(buttonComposite, image); icon.addMouseListener(mouseListener); - icon.addMouseTrackListener(mouseTrackListener); currentIcon = icon; currentIcon.setToolTipText(toolTipText); } Label label = createLabel(buttonComposite, element); label.addMouseListener(mouseListener); - label.addMouseTrackListener(mouseTrackListener); currentLabel = label; currentLabel.setToolTipText(toolTipText); } else { @@ -318,15 +267,11 @@ public abstract class CSelector extends Composite { Rectangle bounds = arrow.getBounds(); int arrowWidth = bounds.width - hPadding * 2; int current = arrowTransition.getCurrent(); - gc.drawPolyline(new int[] { hPadding, - bounds.height / 2 - current, - hPadding + (arrowWidth / 2), - bounds.height / 2 + current, hPadding + arrowWidth, - bounds.height / 2 - current }); + gc.drawPolyline(new int[] { hPadding, bounds.height / 2 - current, hPadding + (arrowWidth / 2), + bounds.height / 2 + current, hPadding + arrowWidth, bounds.height / 2 - current }); } }); arrow.addMouseListener(mouseListener); - arrow.addMouseTrackListener(mouseTrackListener); if (editable) { final EditButton editButton = new EditButton(buttonComposite, SWT.NONE); editButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true)); @@ -359,10 +304,6 @@ public abstract class CSelector extends Composite { return mouseListener; } - public MouseTrackListener getMouseTrackListener() { - return mouseTrackListener; - } - protected void openPopup() { Object[] elements = contentProvider.getElements(input); if (elements.length == 0 && !hasActionArea()) @@ -374,7 +315,6 @@ public abstract class CSelector extends Composite { popup = new Shell(getShell(), SWT.TOOL | SWT.ON_TOP | SWT.RESIZE); popup.setLayout(GridLayoutFactory.fillDefaults().spacing(0, 0).create()); - listViewer = new LaunchBarListViewer(popup); initializeListViewer(listViewer); listViewer.setFilterVisible(elements.length > 7); @@ -395,8 +335,7 @@ public abstract class CSelector extends Composite { if (hasActionArea()) createActionArea(popup); Rectangle buttonBounds = getBounds(); - Point popupLocation = popup.getDisplay().map(this, null, 0, - buttonBounds.height); + Point popupLocation = popup.getDisplay().map(this, null, 0, buttonBounds.height); popup.setLocation(popupLocation.x, popupLocation.y + 5); restoreShellSize(); @@ -415,9 +354,6 @@ public abstract class CSelector extends Composite { } }); - if (hoverProvider != null) { - hoverProvider.dismissHover(selection != null ? selection : null, true); - } } protected String getDialogPreferencePrefix() { @@ -432,8 +368,8 @@ public abstract class CSelector extends Composite { try { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); String prefName = getDialogPreferencePrefix(); - int w = store.getInt(prefName + ".shell.w"); - int h = store.getInt(prefName + ".shell.h"); + int w = store.getInt(prefName + ".shell.w"); //$NON-NLS-1$ + int h = store.getInt(prefName + ".shell.h"); //$NON-NLS-1$ size.x = Math.max(size.x, w); size.y = Math.max(size.y, h); } catch (Exception e) { @@ -446,8 +382,8 @@ public abstract class CSelector extends Composite { Point size = popup.getSize(); IPreferenceStore store = Activator.getDefault().getPreferenceStore(); String prefName = getDialogPreferencePrefix(); - store.setValue(prefName + ".shell.w", size.x); - store.setValue(prefName + ".shell.h", size.y); + store.setValue(prefName + ".shell.w", size.x); //$NON-NLS-1$ + store.setValue(prefName + ".shell.h", size.y); //$NON-NLS-1$ } protected void initializeListViewer(LaunchBarListViewer listViewer) { @@ -478,8 +414,7 @@ public abstract class CSelector extends Composite { GC gc = new GC(buttonImage); gc.setAntialias(SWT.ON); gc.setInterpolation(SWT.HIGH); - gc.drawImage(image, 0, 0, image.getBounds().width, - image.getBounds().height, 0, 0, 16, 16); + gc.drawImage(image, 0, 0, image.getBounds().width, image.getBounds().height, 0, 0, 16, 16); gc.dispose(); image = buttonImage; disposeImage = true; @@ -523,12 +458,18 @@ public abstract class CSelector extends Composite { return labelProvider; } - public void setHoverProvider(IHoverProvider hoverProvider) { - this.hoverProvider = hoverProvider; - } - - public IHoverProvider getHoverProvider() { - return hoverProvider; + @Override + public void setToolTipText(String toolTipText) { + super.setToolTipText(toolTipText); + if (buttonComposite != null) { + buttonComposite.setToolTipText(toolTipText); + } + if (currentLabel != null) { + currentLabel.setToolTipText(toolTipText); + } + if (currentIcon != null) { + currentIcon.setToolTipText(toolTipText); + } } /** @@ -561,7 +502,8 @@ public abstract class CSelector extends Composite { PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { @Override public void run() { - update(selection); // update current selection - name or icon may have changed + update(selection); // update current selection - name or icon + // may have changed if (popup != null && !popup.isDisposed()) { listViewer.refresh(true); // update all labels in the popup } diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/controls/LaunchBarControl.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/controls/LaunchBarControl.java index b527c1329bc..8a481f1316c 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/controls/LaunchBarControl.java +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/controls/LaunchBarControl.java @@ -19,9 +19,9 @@ import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.launchbar.core.ILaunchDescriptor; import org.eclipse.launchbar.core.internal.LaunchBarManager; import org.eclipse.launchbar.core.internal.LaunchBarManager.Listener; +import org.eclipse.launchbar.core.target.ILaunchTarget; import org.eclipse.launchbar.ui.internal.Activator; import org.eclipse.launchbar.ui.internal.Messages; -import org.eclipse.remote.core.IRemoteConnection; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; @@ -36,7 +36,8 @@ import org.eclipse.swt.widgets.ToolItem; public class LaunchBarControl implements Listener { public static final String ID = "org.eclipse.launchbar"; //$NON-NLS-1$ - public static final String CLASS_URI = "bundleclass://" + Activator.PLUGIN_ID + "/" + LaunchBarControl.class.getName(); //$NON-NLS-1$ //$NON-NLS-2$ + public static final String CLASS_URI = "bundleclass://" + Activator.PLUGIN_ID + "/" //$NON-NLS-1$ //$NON-NLS-2$ + + LaunchBarControl.class.getName(); private LaunchBarManager manager = Activator.getDefault().getLaunchBarUIManager().getManager(); @@ -82,7 +83,7 @@ public class LaunchBarControl implements Listener { Label label = new Label(container, SWT.NONE); label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); label.setText(Messages.LaunchBarControl_0 + ":"); //$NON-NLS-1$ - + targetSelector = new TargetSelector(container, SWT.NONE); targetSelector.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); targetSelector.setInput(manager); @@ -107,9 +108,10 @@ public class LaunchBarControl implements Listener { private void createButton(Composite parent, String imageName, String toolTipText, final String command) { ToolItem button = new ToolItem((ToolBar) parent, SWT.FLAT); - //button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + // button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); Image srcImage = Activator.getDefault().getImage(imageName); - //Image image = new Image(parent.getDisplay(), srcImage, SWT.IMAGE_COPY); + // Image image = new Image(parent.getDisplay(), srcImage, + // SWT.IMAGE_COPY); button.setImage(srcImage); button.setToolTipText(toolTipText); button.addSelectionListener(new SelectionAdapter() { @@ -139,7 +141,7 @@ public class LaunchBarControl implements Listener { @Override public void activeLaunchTargetChanged() { if (targetSelector != null) { - final IRemoteConnection target = manager.getActiveLaunchTarget(); + final ILaunchTarget target = manager.getActiveLaunchTarget(); targetSelector.setDelayedSelection(target, SELECTION_DELAY); } } @@ -152,7 +154,7 @@ public class LaunchBarControl implements Listener { @Override public void launchTargetsChanged() { - if (targetSelector!=null){ + if (targetSelector != null) { targetSelector.refresh(); } } diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/controls/ModeSelector.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/controls/ModeSelector.java index 6543f7fa7f7..1a46006323f 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/controls/ModeSelector.java +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/controls/ModeSelector.java @@ -48,9 +48,11 @@ public class ModeSelector extends CSelector { @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } + @Override public void dispose() { - } + } + @Override public Object[] getElements(Object inputElement) { try { @@ -66,6 +68,7 @@ public class ModeSelector extends CSelector { setLabelProvider(new LabelProvider() { private Map images = new HashMap<>(); + @Override public void dispose() { super.dispose(); @@ -73,13 +76,14 @@ public class ModeSelector extends CSelector { image.dispose(); } } + @Override public Image getImage(Object element) { if (element instanceof ILaunchMode) { ILaunchMode mode = (ILaunchMode) element; try { ILaunchGroup group = getLaunchGroup(mode.getIdentifier()); - if( group == null ) { + if (group == null) { group = getDefaultLaunchGroup(mode.getIdentifier()); } if (group != null) { @@ -99,13 +103,14 @@ public class ModeSelector extends CSelector { } return super.getImage(element); } + @Override public String getText(Object element) { if (element instanceof ILaunchMode) { ILaunchMode mode = (ILaunchMode) element; try { ILaunchGroup group = getLaunchGroup(mode.getIdentifier()); - if( group == null ) { + if (group == null) { group = getDefaultLaunchGroup(mode.getIdentifier()); } if (group != null) { @@ -123,8 +128,8 @@ public class ModeSelector extends CSelector { @Override public int compare(Object o1, Object o2) { if (o1 instanceof ILaunchMode && o2 instanceof ILaunchMode) { - String mode1 = ((ILaunchMode)o1).getIdentifier(); - String mode2 = ((ILaunchMode)o2).getIdentifier(); + String mode1 = ((ILaunchMode) o1).getIdentifier(); + String mode2 = ((ILaunchMode) o2).getIdentifier(); // run comes first, then debug, then the rest if (mode1.equals("run")) { //$NON-NLS-1$ if (mode2.equals("run")) //$NON-NLS-1$ @@ -152,18 +157,19 @@ public class ModeSelector extends CSelector { String groupId = null; if (mode.equals(ILaunchManager.DEBUG_MODE)) { groupId = IDebugUIConstants.ID_DEBUG_LAUNCH_GROUP; - } else if( mode.equals(ILaunchManager.PROFILE_MODE)) { + } else if (mode.equals(ILaunchManager.PROFILE_MODE)) { groupId = IDebugUIConstants.ID_PROFILE_LAUNCH_GROUP; } else { groupId = IDebugUIConstants.ID_RUN_LAUNCH_GROUP; } - if( groupId != null ) + if (groupId != null) return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(groupId); return null; } - + protected ILaunchGroup getLaunchGroup(String mode) throws CoreException { - ILaunchConfigurationType type = manager.getLaunchConfigurationType(manager.getActiveLaunchDescriptor(), manager.getActiveLaunchTarget()); + ILaunchConfigurationType type = manager.getLaunchConfigurationType(manager.getActiveLaunchDescriptor(), + manager.getActiveLaunchTarget()); if (type == null) return null; return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(type, mode); @@ -179,7 +185,8 @@ public class ModeSelector extends CSelector { } catch (CoreException e) { Activator.log(e.getStatus()); } catch (Exception e) { - // manager can throw illegal state exception hopefully we never get it + // manager can throw illegal state exception hopefully we never + // get it Activator.log(e); } } 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 f8a72c3684c..eacbac7f41d 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 @@ -13,54 +13,49 @@ package org.eclipse.launchbar.ui.internal.controls; import java.util.Comparator; import java.util.List; -import org.eclipse.core.commands.Command; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.NotEnabledException; -import org.eclipse.core.commands.NotHandledException; -import org.eclipse.core.commands.common.NotDefinedException; import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.resource.CompositeImageDescriptor; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.window.SameShellProvider; import org.eclipse.launchbar.core.internal.LaunchBarManager; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.launchbar.core.target.ILaunchTargetListener; +import org.eclipse.launchbar.core.target.ILaunchTargetManager; +import org.eclipse.launchbar.core.target.TargetStatus; +import org.eclipse.launchbar.core.target.TargetStatus.Code; import org.eclipse.launchbar.ui.internal.Activator; import org.eclipse.launchbar.ui.internal.LaunchBarUIManager; import org.eclipse.launchbar.ui.internal.Messages; -import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.ui.IRemoteUIConnectionService; -import org.eclipse.remote.ui.RemoteConnectionsLabelProvider; -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; -import org.eclipse.swt.events.PaintListener; -import org.eclipse.swt.graphics.GC; +import org.eclipse.launchbar.ui.target.ILaunchTargetUIManager; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.dialogs.PropertyDialogAction; -public class TargetSelector extends CSelector { +public class TargetSelector extends CSelector implements ILaunchTargetListener { private final LaunchBarUIManager uiManager = Activator.getDefault().getLaunchBarUIManager(); + 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$ public TargetSelector(Composite parent, int style) { super(parent, style); + targetManager.addListener(this); + setContentProvider(new IStructuredContentProvider() { @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { @@ -73,19 +68,69 @@ public class TargetSelector extends CSelector { @Override public Object[] getElements(Object inputElement) { LaunchBarManager manager = uiManager.getManager(); - try { - List targets = manager.getLaunchTargets(manager.getActiveLaunchDescriptor()); - if (!targets.isEmpty()) { - return targets.toArray(); - } - } catch (CoreException e) { - Activator.log(e); + List targets = manager.getLaunchTargets(manager.getActiveLaunchDescriptor()); + if (!targets.isEmpty()) { + return targets.toArray(); } return noTargets; } }); - setLabelProvider(new RemoteConnectionsLabelProvider()); + setLabelProvider(new LabelProvider() { + @Override + public String getText(Object element) { + if (element instanceof ILaunchTarget) { + ILaunchTarget target = (ILaunchTarget) element; + ILabelProvider provider = targetUIManager.getLabelProvider(target); + return provider != null ? provider.getText(target) : target.getName(); + } + return super.getText(element); + } + + @Override + public Image getImage(Object element) { + if (element instanceof ILaunchTarget) { + // TODO apply a status overlay + ILaunchTarget target = (ILaunchTarget) element; + ILabelProvider provider = targetUIManager.getLabelProvider(target); + if (provider != null) { + final Image baseImage = provider.getImage(target); + final TargetStatus status = targetManager.getStatus(target); + if (status.getCode() == Code.OK) { + return baseImage; + } else { + String compId = target.getTypeId() + + (status.getCode() == Code.ERROR ? ".error" : ".warning"); //$NON-NLS-1$ //$NON-NLS-2$ + Image image = Activator.getDefault().getImageRegistry().get(compId); + if (image == null) { + ImageDescriptor desc = new CompositeImageDescriptor() { + @Override + protected Point getSize() { + Rectangle bounds = baseImage.getBounds(); + return new Point(bounds.width, bounds.height); + } + + @Override + protected void drawCompositeImage(int width, int height) { + Image overlay = PlatformUI.getWorkbench().getSharedImages() + .getImage(status.getCode() == Code.ERROR + ? ISharedImages.IMG_DEC_FIELD_ERROR + : ISharedImages.IMG_DEC_FIELD_WARNING); + drawImage(baseImage.getImageData(), 0, 0); + int y = baseImage.getBounds().height - overlay.getBounds().height; + drawImage(overlay.getImageData(), 0, y); + } + }; + image = desc.createImage(); + Activator.getDefault().getImageRegistry().put(compId, image); + } + return image; + } + } + } + return super.getImage(element); + } + }); setSorter(new Comparator() { @Override @@ -100,11 +145,10 @@ public class TargetSelector extends CSelector { @Override public boolean isEditable(Object element) { - return true; } - private ISelectionProvider getSelectionProvider(){ + private ISelectionProvider getSelectionProvider() { return new ISelectionProvider() { @Override public void setSelection(ISelection selection) { @@ -127,83 +171,18 @@ public class TargetSelector extends CSelector { } }; } + @Override public void handleEdit(Object element) { // opens property dialog on a selected target - new PropertyDialogAction(new SameShellProvider(getShell()), getSelectionProvider()).run(); - } - - @Override - public boolean hasActionArea() { - return true; - } - - @Override - public void createActionArea(final Composite parent) { - Composite actionArea = new Composite(parent, SWT.NONE); - GridLayout actionLayout = new GridLayout(); - actionLayout.marginWidth = actionLayout.marginHeight = 0; - actionArea.setLayout(actionLayout); - actionArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - - final Composite createButton = new Composite(actionArea, SWT.NONE); - createButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - GridLayout buttonLayout = new GridLayout(); - buttonLayout.marginWidth = buttonLayout.marginHeight = 7; - createButton.setLayout(buttonLayout); - createButton.setBackground(backgroundColor); - createButton.addPaintListener(new PaintListener() { - @Override - public void paintControl(PaintEvent e) { - Point size = createButton.getSize(); - GC gc = e.gc; - gc.setForeground(outlineColor); - gc.drawLine(0, 0, size.x, 0); - } - }); - - final Label createLabel = new Label(createButton, SWT.None); - createLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - createLabel.setText(Messages.TargetSelector_CreateNewTarget); - createLabel.setBackground(backgroundColor); - - MouseListener mouseListener = new MouseAdapter() { - @Override - public void mouseUp(org.eclipse.swt.events.MouseEvent event) { - try { - ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class); - Command newConnectionCmd = commandService.getCommand(IRemoteUIConnectionService.NEW_CONNECTION_COMMAND); - newConnectionCmd.executeWithChecks(new ExecutionEvent()); - } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) { - Activator.log(e); - } - } - }; - - createButton.addMouseListener(mouseListener); - createLabel.addMouseListener(mouseListener); - - MouseTrackListener mouseTrackListener = new MouseTrackAdapter() { - @Override - public void mouseEnter(MouseEvent e) { - createButton.setBackground(highlightColor); - createLabel.setBackground(highlightColor); - } - @Override - public void mouseExit(MouseEvent e) { - createButton.setBackground(white); - createLabel.setBackground(white); - } - }; - createButton.addMouseTrackListener(mouseTrackListener); - createLabel.addMouseTrackListener(mouseTrackListener); + new PropertyDialogAction(new SameShellProvider(getShell()), getSelectionProvider()).run(); } @Override protected void fireSelectionChanged() { Object selection = getSelection(); - if (selection instanceof IRemoteConnection) { - IRemoteConnection target = (IRemoteConnection) selection; + if (selection instanceof ILaunchTarget) { + ILaunchTarget target = (ILaunchTarget) selection; try { uiManager.getManager().setActiveLaunchTarget(target); } catch (CoreException e) { @@ -212,6 +191,11 @@ public class TargetSelector extends CSelector { } } + public void setToolTipText(ILaunchTarget target) { + String text = Messages.TargetSelector_ToolTipPrefix + ": " + targetManager.getStatus(target).getMessage(); //$NON-NLS-1$ + setToolTipText(text); + } + @Override public Point computeSize(int wHint, int hHint, boolean changed) { return super.computeSize(200, hHint, changed); @@ -219,9 +203,35 @@ public class TargetSelector extends CSelector { @Override public void setSelection(Object element) { - if (element == null) + if (element == null) { element = noTargets[0]; + } else if (element instanceof ILaunchTarget) { + setToolTipText((ILaunchTarget) element); + } super.setSelection(element); } + @Override + public void dispose() { + super.dispose(); + targetManager.removeListener(this); + } + + @Override + public void update(Object element) { + super.update(element); + if (element != null && element instanceof ILaunchTarget) { + setToolTipText((ILaunchTarget) element); + } else { + setToolTipText(Messages.TargetSelector_ToolTipPrefix); + } + } + + @Override + public void launchTargetStatusChanged(ILaunchTarget target) { + if (target.equals(uiManager.getManager().getActiveLaunchTarget())) { + refresh(); + } + } + } diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/messages.properties b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/messages.properties index d1d335eb26f..2e57068198c 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/messages.properties +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/messages.properties @@ -41,6 +41,7 @@ NewLaunchConfigTypePage_2=Select the type of launch configuration to create. NewLaunchConfigWizard_0=Create Launch Configuration StopActiveCommandHandler_0=Stopping launches StopActiveCommandHandler_1=Stopping build +TargetSelector_ToolTipPrefix=Launch Target TargetSelector_CreateNewTarget=Create New Connection... DescriptorMustNotBeNull=Descriptor must not be null diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/target/LaunchTargetUIManager.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/target/LaunchTargetUIManager.java new file mode 100644 index 00000000000..751064e6c28 --- /dev/null +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/target/LaunchTargetUIManager.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2015 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 + *******************************************************************************/ +package org.eclipse.launchbar.ui.internal.target; + +import java.util.HashMap; +import java.util.Map; + +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.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.launchbar.ui.internal.Activator; +import org.eclipse.launchbar.ui.target.ILaunchTargetUIManager; +import org.eclipse.swt.graphics.Image; + +public class LaunchTargetUIManager implements ILaunchTargetUIManager { + + private Map typeElements; + private Map labelProviders = new HashMap<>(); + + @Override + public ILabelProvider getLabelProvider(ILaunchTarget target) { + if (typeElements == null) { + // Load them up + typeElements = new HashMap<>(); + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint point = registry + .getExtensionPoint(Activator.getDefault().getBundle().getSymbolicName() + ".launchTargetTypeUI"); //$NON-NLS-1$ + for (IExtension extension : point.getExtensions()) { + for (IConfigurationElement element : extension.getConfigurationElements()) { + String id = element.getAttribute("id"); //$NON-NLS-1$ + if (id != null) { + typeElements.put(id, element); + } + } + } + } + + String typeId = target.getTypeId(); + ILabelProvider labelProvider = labelProviders.get(typeId); + if (labelProvider == null) { + IConfigurationElement element = typeElements.get(typeId); + if (element != null) { + try { + labelProvider = (ILabelProvider) element.createExecutableExtension("labelProvider"); //$NON-NLS-1$ + } catch (CoreException e) { + Activator.log(e); + } + } + + if (labelProvider == null) { + labelProvider = new LabelProvider() { + public String getText(Object element) { + if (element instanceof ILaunchTarget) { + return ((ILaunchTarget) element).getName(); + } + return super.getText(element); + } + + @Override + public Image getImage(Object element) { + if (element instanceof ILaunchTarget) { + return Activator.getDefault().getImage(Activator.IMG_LOCAL_TARGET); + } + return super.getImage(element); + } + + }; + } + + } + return labelProvider; + } + +} diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/target/ILaunchTargetUIManager.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/target/ILaunchTargetUIManager.java new file mode 100644 index 00000000000..6cd2a5726d2 --- /dev/null +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/target/ILaunchTargetUIManager.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2015 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 + *******************************************************************************/ +package org.eclipse.launchbar.ui.target; + +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.launchbar.core.target.ILaunchTarget; + +/** + * A manager for the launch target UI. + */ +public interface ILaunchTargetUIManager { + + /** + * Return a label provider that gives the test and image for the target. + * + * @param target + * the launch target + * @return the label provider for the launch target + */ + ILabelProvider getLabelProvider(ILaunchTarget target); + +} diff --git a/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/PerTargetLaunchConfigProviderTest.java b/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/PerTargetLaunchConfigProviderTest.java index 9f59c4d140a..f1211ff6627 100644 --- a/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/PerTargetLaunchConfigProviderTest.java +++ b/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/PerTargetLaunchConfigProviderTest.java @@ -18,7 +18,6 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import org.eclipse.core.runtime.CoreException; @@ -29,9 +28,8 @@ import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchManager; import org.eclipse.launchbar.core.internal.Activator; import org.eclipse.launchbar.core.internal.LaunchBarManager2Test; -import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteConnectionType; -import org.eclipse.remote.core.IRemoteServicesManager; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.launchbar.core.target.ILaunchTargetManager; import org.junit.After; import org.junit.Before; import org.junit.FixMethodOrder; @@ -41,10 +39,9 @@ import org.junit.runners.MethodSorters; @SuppressWarnings("nls") @FixMethodOrder(MethodSorters.JVM) public class PerTargetLaunchConfigProviderTest { - private IRemoteServicesManager remoteServiceManager; - private IRemoteConnection localTarget; + private ILaunchTarget localTarget; private String launchName; - private IRemoteConnection otherTarget; + private ILaunchTarget otherTarget; private ILaunchConfigurationType launchConfigType; private ILaunchDescriptorType descriptorType; private ILaunchDescriptor descriptor; @@ -52,14 +49,24 @@ public class PerTargetLaunchConfigProviderTest { @Before public void basicSetupOnly() throws CoreException { - remoteServiceManager = spy(Activator.getService(IRemoteServicesManager.class)); - localTarget = remoteServiceManager.getLocalConnectionType().getConnections().get(0); + ILaunchTargetManager targetManager = mock(ILaunchTargetManager.class); + Activator.getDefault().getBundle().getBundleContext().registerService(ILaunchTargetManager.class, targetManager, + null); + + localTarget = mock(ILaunchTarget.class); + doReturn("Local").when(localTarget).getName(); + doReturn(ILaunchTargetManager.localLaunchTargetTypeId).when(localTarget).getTypeId(); + doReturn(localTarget).when(targetManager).getLaunchTarget(ILaunchTargetManager.localLaunchTargetTypeId, + "Local"); + // other mocked remote connections - otherTarget = mock(IRemoteConnection.class); - IRemoteConnectionType rtype = mock(IRemoteConnectionType.class); - doReturn(rtype).when(otherTarget).getConnectionType(); - doReturn("otherTargetType").when(rtype).getId(); + otherTarget = mock(ILaunchTarget.class); + doReturn("otherTargetType").when(otherTarget).getTypeId(); doReturn("otherTarget").when(otherTarget).getName(); + doReturn(otherTarget).when(targetManager).getLaunchTarget("otherTargetType", "otherTarget"); + + doReturn(new ILaunchTarget[] { localTarget, otherTarget }).when(targetManager).getLaunchTargets(); + // launch stuff launchName = "test"; // launch config type @@ -90,18 +97,18 @@ public class PerTargetLaunchConfigProviderTest { private ILaunchBarManager manager; @Override - public boolean supports(ILaunchDescriptor descriptor, IRemoteConnection target) throws CoreException { + public boolean supports(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { return true; } @Override - public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, - IRemoteConnection target) throws CoreException { + public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) + throws CoreException { return launchConfigType; } @Override - protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target, + protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target, ILaunchConfigurationWorkingCopy workingCopy) throws CoreException { super.populateLaunchConfiguration(descriptor, target, workingCopy); workingCopy.setAttribute(CONNECTION_NAME_ATTR, target.getName()); @@ -113,7 +120,7 @@ public class PerTargetLaunchConfigProviderTest { } @Override - protected IRemoteConnection getLaunchTarget(ILaunchConfiguration configuration) throws CoreException { + protected ILaunchTarget getLaunchTarget(ILaunchConfiguration configuration) throws CoreException { String name = configuration.getAttribute(CONNECTION_NAME_ATTR, ""); if (localTarget.getName().equals(name)) { return localTarget; @@ -133,7 +140,7 @@ public class PerTargetLaunchConfigProviderTest { } @Override - public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, IRemoteConnection target) + public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { ILaunchConfiguration config = super.getLaunchConfiguration(descriptor, target); // Since this provider isn't hooked in properly, need to manually diff --git a/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/internal/LaunchBarManager2Test.java b/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/internal/LaunchBarManager2Test.java index 08842f3311d..b5833ecd082 100644 --- a/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/internal/LaunchBarManager2Test.java +++ b/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/internal/LaunchBarManager2Test.java @@ -23,7 +23,6 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; @@ -57,9 +56,8 @@ import org.eclipse.launchbar.core.ILaunchDescriptorType; import org.eclipse.launchbar.core.ProjectLaunchDescriptor; import org.eclipse.launchbar.core.ProjectPerTargetLaunchConfigProvider; import org.eclipse.launchbar.core.internal.LaunchBarManager.Listener; -import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteConnectionType; -import org.eclipse.remote.core.IRemoteServicesManager; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.launchbar.core.target.ILaunchTargetManager; import org.junit.Before; import org.junit.FixMethodOrder; import org.junit.Test; @@ -81,13 +79,12 @@ public class LaunchBarManager2Test { IEclipsePreferences store = new EclipsePreferences(); private ArrayList elements; private IExtension extension; - private static final String localTargetTypeId = "org.eclipse.remote.LocalServices"; private String descriptorTypeId; - private IRemoteConnection localTarget; + private ILaunchTargetManager targetManager; + private ILaunchTarget localTarget; private String launchObject; - private IRemoteServicesManager remoteServiceManager; - private IRemoteConnection otherTarget; - private List targets; + private ILaunchTarget otherTarget; + private ILaunchTarget[] targets; public class FixedLaunchBarManager extends LaunchBarManager { public FixedLaunchBarManager() throws CoreException { @@ -110,8 +107,8 @@ public class LaunchBarManager2Test { } @Override - IRemoteServicesManager getRemoteServicesManager() { - return remoteServiceManager; + ILaunchTargetManager getLaunchTargetManager() { + return targetManager; } }; @@ -129,7 +126,7 @@ public class LaunchBarManager2Test { } protected ILaunchConfigurationProvider mockConfigProviderElement(String descriptorTypeId, int priority, - ILaunchDescriptor descriptor, IRemoteConnection target, ILaunchConfiguration config, Object launchObj) + ILaunchDescriptor descriptor, ILaunchTarget target, ILaunchConfiguration config, Object launchObj) throws CoreException { ILaunchConfigurationProvider provider = mock(ILaunchConfigurationProvider.class); mockProviderElement(descriptorTypeId, priority, provider); @@ -166,7 +163,7 @@ public class LaunchBarManager2Test { protected void init() throws CoreException { doReturn(elements.toArray(new IConfigurationElement[0])).when(extension).getConfigurationElements(); - doReturn(targets).when(remoteServiceManager).getAllRemoteConnections(); + doReturn(targets).when(targetManager).getLaunchTargets(); manager.init(); } @@ -219,13 +216,10 @@ public class LaunchBarManager2Test { * @param t2 * @return */ - private IRemoteConnection mockRemoteConnection(String t2) { - IRemoteConnection target = mock(IRemoteConnection.class); - IRemoteConnectionType type = mock(IRemoteConnectionType.class); - doReturn(t2).when(type).getName(); - doReturn(t2).when(type).getId(); + private ILaunchTarget mockRemoteConnection(String t2) { + ILaunchTarget target = mock(ILaunchTarget.class); + doReturn(t2).when(target).getTypeId(); doReturn(t2 + ".target").when(target).getName(); - doReturn(type).when(target).getConnectionType(); return target; } @@ -270,17 +264,18 @@ public class LaunchBarManager2Test { lman = mock(ILaunchManager.class); doReturn(globalmodes.toArray(new ILaunchMode[globalmodes.size()])).when(lman).getLaunchModes(); doReturn(new ILaunchConfiguration[] {}).when(lman).getLaunchConfigurations(); - remoteServiceManager = spy(Activator.getService(IRemoteServicesManager.class)); + targetManager = mock(ILaunchTargetManager.class); manager = new FixedLaunchBarManager(); - localTarget = manager.getRemoteServicesManager().getLocalConnectionType().getConnections().get(0); + localTarget = mock(ILaunchTarget.class); + doReturn(ILaunchTargetManager.localLaunchTargetTypeId).when(localTarget).getTypeId(); + doReturn("Local").when(localTarget).getName(); // mock launchObject = "test"; // remote connections - otherTarget = mock(IRemoteConnection.class); - IRemoteConnectionType rtype = mock(IRemoteConnectionType.class); - doReturn(rtype).when(otherTarget).getConnectionType(); - doReturn("otherTargetType").when(rtype).getId(); - targets = Arrays.asList(new IRemoteConnection[] { otherTarget, localTarget }); + otherTarget = mock(ILaunchTarget.class); + doReturn("otherTargetType").when(otherTarget).getTypeId(); + doReturn("otherTarget").when(otherTarget).getName(); + targets = new ILaunchTarget[] { otherTarget, localTarget }; // lc String launchConfigTypeId = "lctype1"; launchConfigType = mockLCType(launchConfigTypeId); @@ -329,7 +324,7 @@ public class LaunchBarManager2Test { @Test public void testAddConfigMappingTwo() throws CoreException { basicSetupOnly(); - IRemoteConnection target = mockRemoteConnection("t2"); + ILaunchTarget target = mockRemoteConnection("t2"); mockConfigProviderElement(descriptorTypeId, 10, descriptor, target, launchConfig, launchObject); // now create another lc type, which is not registered in config type ILaunchConfigurationType lctype2 = mockLCType("lctypeid2"); @@ -346,7 +341,7 @@ public class LaunchBarManager2Test { @Test public void testAddConfigProviderTwo2() throws CoreException { basicSetupOnly(); - IRemoteConnection target = mockRemoteConnection("t2"); + ILaunchTarget target = mockRemoteConnection("t2"); mockConfigProviderElement(descriptorTypeId, 15, descriptor, target, launchConfig, launchObject); ILaunchConfigurationType lctype2 = mockLCType("lctypeid2"); ILaunchConfiguration lc2 = mockLC("lc2", lctype2); @@ -360,7 +355,7 @@ public class LaunchBarManager2Test { public void testGetLaunchTargets() throws CoreException { manager.launchObjectAdded(launchObject); manager.setActiveLaunchDescriptor(descriptor); - List launchTargets = manager.getLaunchTargets(descriptor); + List launchTargets = manager.getLaunchTargets(descriptor); assertEquals(1, launchTargets.size()); assertEquals(otherTarget, launchTargets.get(0)); } @@ -374,7 +369,7 @@ public class LaunchBarManager2Test { init(); manager.launchObjectAdded(launchObject); ILaunchDescriptor desc = manager.getActiveLaunchDescriptor(); - List launchTargets = manager.getLaunchTargets(desc); + List launchTargets = manager.getLaunchTargets(desc); assertEquals(1, launchTargets.size()); } @@ -387,7 +382,7 @@ public class LaunchBarManager2Test { init(); manager.launchObjectAdded(launchObject); ILaunchDescriptor desc = manager.getActiveLaunchDescriptor(); - List launchTargets = manager.getLaunchTargets(desc); + List launchTargets = manager.getLaunchTargets(desc); assertEquals(1, launchTargets.size()); } @@ -577,7 +572,7 @@ public class LaunchBarManager2Test { provider = new ProjectPerTargetLaunchConfigProvider() { @Override public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, - IRemoteConnection target) throws CoreException { + ILaunchTarget target) throws CoreException { return launchConfigType; } @@ -592,7 +587,7 @@ public class LaunchBarManager2Test { } @Override - protected IRemoteConnection getLaunchTarget(ILaunchConfiguration configuration) throws CoreException { + protected ILaunchTarget getLaunchTarget(ILaunchConfiguration configuration) throws CoreException { return localTarget; } }; @@ -835,14 +830,6 @@ public class LaunchBarManager2Test { assertEquals(localTarget, manager.getActiveLaunchTarget()); } - @Test - public void testGetLaunchTarget() throws CoreException { - IRemoteConnectionType targetType = remoteServiceManager.getConnectionType(localTargetTypeId); - final List list = targetType.getConnections(); - assertEquals(1, list.size()); - assertEquals(localTarget, list.get(0)); - } - @Test public void testGetLaunchConfigurationType() throws CoreException { manager.launchObjectAdded(launchObject); diff --git a/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/internal/LaunchBarManagerTest.java b/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/internal/LaunchBarManagerTest.java index 33105f6351a..af557564acf 100644 --- a/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/internal/LaunchBarManagerTest.java +++ b/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/internal/LaunchBarManagerTest.java @@ -34,9 +34,8 @@ import org.eclipse.debug.core.ILaunchMode; import org.eclipse.launchbar.core.ILaunchConfigurationProvider; import org.eclipse.launchbar.core.ILaunchDescriptor; import org.eclipse.launchbar.core.ILaunchDescriptorType; -import org.eclipse.remote.core.IRemoteConnection; -import org.eclipse.remote.core.IRemoteConnectionType; -import org.eclipse.remote.core.IRemoteServicesManager; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.launchbar.core.target.ILaunchTargetManager; import org.junit.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -73,8 +72,18 @@ public class LaunchBarManagerTest { doReturn(true).when(launchConfigType).supportsMode("run"); doReturn(true).when(launchConfigType).supportsMode("debug"); + final ILaunchTargetManager targetManager = mock(ILaunchTargetManager.class); + ILaunchTarget localTarget = mock(ILaunchTarget.class); + doReturn(ILaunchTargetManager.localLaunchTargetTypeId).when(localTarget).getTypeId(); + doReturn("Local").when(localTarget).getName(); + doReturn(new ILaunchTarget[] { localTarget }).when(targetManager).getLaunchTargets(); + // Inject the launch config LaunchBarManager manager = new LaunchBarManager(false) { + @Override + ILaunchTargetManager getLaunchTargetManager() { + return targetManager; + } }; manager.init(); manager.launchConfigurationAdded(launchConfig); @@ -83,11 +92,9 @@ public class LaunchBarManagerTest { assertNotNull(manager.getActiveLaunchDescriptor()); assertEquals(launchConfig, manager.getActiveLaunchDescriptor().getAdapter(ILaunchConfiguration.class)); - IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class); - IRemoteConnectionType localServices = remoteManager.getLocalConnectionType(); - IRemoteConnection localConnection = localServices.getConnections().get(0); assertNotNull(manager.getActiveLaunchTarget()); - assertEquals(localConnection, manager.getActiveLaunchTarget()); + assertEquals(ILaunchTargetManager.localLaunchTargetTypeId, manager.getActiveLaunchTarget().getTypeId()); + assertEquals("Local", manager.getActiveLaunchTarget().getName()); assertNotNull(manager.getActiveLaunchMode()); assertEquals("run", manager.getActiveLaunchMode().getIdentifier()); @@ -156,18 +163,23 @@ public class LaunchBarManagerTest { ILaunchConfigurationProvider configProvider = mock(ILaunchConfigurationProvider.class); doReturn(configProvider).when(element).createExecutableExtension("class"); + final ILaunchTargetManager targetManager = mock(ILaunchTargetManager.class); + ILaunchTarget localTarget = mock(ILaunchTarget.class); + doReturn(ILaunchTargetManager.localLaunchTargetTypeId).when(localTarget).getTypeId(); + doReturn("Local").when(localTarget).getName(); + doReturn(new ILaunchTarget[] { localTarget }).when(targetManager).getLaunchTargets(); + ILaunchConfiguration launchConfig = mock(ILaunchConfiguration.class); - doReturn(launchConfig).when(configProvider).getLaunchConfiguration(eq(descriptor), - any(IRemoteConnection.class)); + doReturn(launchConfig).when(configProvider).getLaunchConfiguration(eq(descriptor), any(ILaunchTarget.class)); doReturn(launchConfigType).when(configProvider).getLaunchConfigurationType(any(ILaunchDescriptor.class), - any(IRemoteConnection.class)); + any(ILaunchTarget.class)); doAnswer(new Answer() { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { - IRemoteConnection target = (IRemoteConnection) invocation.getArguments()[1]; - return target.getConnectionType().getId().equals("org.eclipse.remote.LocalServices"); + ILaunchTarget target = (ILaunchTarget) invocation.getArguments()[1]; + return target.getTypeId().equals(ILaunchTargetManager.localLaunchTargetTypeId); } - }).when(configProvider).supports(eq(descriptor), any(IRemoteConnection.class)); + }).when(configProvider).supports(eq(descriptor), any(ILaunchTarget.class)); doReturn(elements.toArray(new IConfigurationElement[0])).when(extension).getConfigurationElements(); @@ -182,17 +194,20 @@ public class LaunchBarManagerTest { ILaunchManager getLaunchManager() { return launchManager; } + + @Override + ILaunchTargetManager getLaunchTargetManager() { + return targetManager; + } + }; manager.init(); manager.launchObjectAdded(launchObject); assertEquals(descriptor, manager.getActiveLaunchDescriptor()); assertEquals(runMode, manager.getActiveLaunchMode()); - IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class); - IRemoteConnectionType localServices = remoteManager.getLocalConnectionType(); - IRemoteConnection localConnection = localServices.getConnections().get(0); - assertNotNull(localConnection); - assertEquals(localConnection, manager.getActiveLaunchTarget()); + assertEquals(ILaunchTargetManager.localLaunchTargetTypeId, manager.getActiveLaunchTarget().getTypeId()); + assertEquals("Local", manager.getActiveLaunchTarget().getName()); assertEquals(launchConfig, manager.getActiveLaunchConfiguration()); }