diff --git a/launch/org.eclipse.cdt.launchbar.core.tests/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManagerTest.java b/launch/org.eclipse.cdt.launchbar.core.tests/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManagerTest.java index b73140e253a..18492295be2 100644 --- a/launch/org.eclipse.cdt.launchbar.core.tests/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManagerTest.java +++ b/launch/org.eclipse.cdt.launchbar.core.tests/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManagerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 QNX Software Systems. All Rights Reserved. +> * Copyright (c) 2014 QNX Software Systems. All Rights Reserved. * * You must obtain a written license from and pay applicable license fees to QNX * Software Systems before you may reproduce, modify or distribute this software, @@ -14,47 +14,32 @@ *******************************************************************************/ package org.eclipse.cdt.launchbar.core.internal; -import static org.junit.Assert.assertNotEquals; -import static org.mockito.Matchers.*; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; +import java.util.List; import junit.framework.TestCase; -import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; -import org.eclipse.cdt.launchbar.core.AbstarctLaunchDescriptorType; -import org.eclipse.cdt.launchbar.core.AbstractLaunchConfigurationProvider; -import org.eclipse.cdt.launchbar.core.AbstractLaunchDescriptor; -import org.eclipse.cdt.launchbar.core.AbstractLaunchTarget; -import org.eclipse.cdt.launchbar.core.AbstractLaunchTargetType; -import org.eclipse.cdt.launchbar.core.ConfigBasedLaunchConfigurationProvider; -import org.eclipse.cdt.launchbar.core.ConfigBasedLaunchDescriptor; -import org.eclipse.cdt.launchbar.core.ConfigBasedLaunchDescriptorType; -import org.eclipse.cdt.launchbar.core.ILaunchBarManager.Listener; -import org.eclipse.cdt.launchbar.core.ILaunchConfigurationProvider; +import org.eclipse.cdt.launchbar.core.ILaunchBarManager; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType; +import org.eclipse.cdt.launchbar.core.ILaunchObjectProvider; import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.core.ILaunchTargetType; -import org.eclipse.cdt.launchbar.core.ProjectBasedLaunchConfigurationProvider; -import org.eclipse.cdt.launchbar.core.ProjectBasedLaunchDescriptorType; +import org.eclipse.cdt.launchbar.core.LaunchConfigurationProvider; import org.eclipse.core.internal.preferences.EclipsePreferences; -import org.eclipse.core.internal.resources.Project; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; 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.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.ILaunchMode; import org.junit.Test; @@ -64,998 +49,707 @@ import org.junit.Test; * */ public class LaunchBarManagerTest extends TestCase { - private LaunchBarManager manager; - private ILaunchConfigurationProvider provider; - private ILaunchDescriptor desc; - ILaunchDescriptorType descType; - private ILaunchConfigurationType lctype; - private ILaunchConfiguration lc; - public class TargetType extends AbstractLaunchTargetType { - private String id; - ArrayList targets = new ArrayList<>(); + // default type ids + private static final String DEFAULT_CONFIG_TYPE_ID = "configType.test"; + private static final String DEFAULT_TARGET_TYPE_ID = "targetType.test"; + private static final String DEFAULT_DESCRIPTOR_TYPE_ID = "descriptorType.test"; - public TargetType(String id) { + private IEclipsePreferences prefs; + private ILaunchManager launchManager; + + public class TestLaunchBarManager extends LaunchBarManager { + private ILaunchMode[] defaultLaunchModes; + + public TestLaunchBarManager() throws CoreException { + super(); + } + + @Override + public IExtensionPoint getExtensionPoint() throws CoreException { + // default things + IExtensionPoint point = mock(IExtensionPoint.class); + + IExtension extension = mock(IExtension.class); + doReturn(new IExtension[] { extension }).when(point).getExtensions(); + + List elements = new ArrayList<>(); + + IConfigurationElement element; + + // The local target + element = mock(IConfigurationElement.class); + elements.add(element); + doReturn("targetType").when(element).getName(); + doReturn(LocalTargetType.ID).when(element).getAttribute("id"); + doReturn(new LocalTargetType()).when(element).createExecutableExtension("class"); + + // Test targets + for (TestLaunchTargetType targetType : getTestTargetTypes()) { + element = mock(IConfigurationElement.class); + elements.add(element); + doReturn("targetType").when(element).getName(); + doReturn(targetType.id).when(element).getAttribute("id"); + doReturn(targetType).when(element).createExecutableExtension("class"); + } + + // Test descriptors + for (TestLaunchDescriptorType descType : getTestDescriptorTypes()) { + element = mock(IConfigurationElement.class); + elements.add(element); + doReturn("descriptorType").when(element).getName(); + doReturn(descType.id).when(element).getAttribute("id"); + doReturn(Integer.toString(descType.priority)).when(element).getAttribute("priority"); + doReturn(descType).when(element).createExecutableExtension("class"); + } + + // Test config types + for (TestLaunchConfigurationProvider provider : getTestConfigProviders()) { + element = mock(IConfigurationElement.class); + elements.add(element); + doReturn("configType").when(element).getName(); + doReturn(provider.descTypeId).when(element).getAttribute("descriptorType"); + doReturn(provider.targetTypeId).when(element).getAttribute("targetType"); + doReturn(provider.configType.getIdentifier()).when(element).getAttribute("launchConfigurationType"); + doReturn(Boolean.toString(provider.isDefault)).when(element).getAttribute("isDefault"); + + element = mock(IConfigurationElement.class); + elements.add(element); + doReturn("configProvider").when(element).getName(); + doReturn(provider.configType.getIdentifier()).when(element).getAttribute("launchConfigurationType"); + doReturn(provider).when(element).createExecutableExtension("class"); + } + + // test object providers + for (TestLaunchObjectProvider objectProvider : getTestObjectProviders()) { + element = mock(IConfigurationElement.class); + elements.add(element); + doReturn("objectProvider").when(element).getName(); + doReturn(objectProvider).when(element).createExecutableExtension("class"); + } + + doReturn(elements.toArray(new IConfigurationElement[0])).when(extension).getConfigurationElements(); + + return point; + } + + protected TestLaunchTargetType[] getTestTargetTypes() { + return new TestLaunchTargetType[] { + new TestLaunchTargetType(DEFAULT_TARGET_TYPE_ID) + }; + } + + protected TestLaunchDescriptorType[] getTestDescriptorTypes() { + return new TestLaunchDescriptorType[] { + new TestLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID, 5) + }; + } + + protected TestLaunchConfigurationProvider[] getTestConfigProviders() { + ILaunchConfigurationType configType = mockLaunchConfigurationType(DEFAULT_CONFIG_TYPE_ID); + return new TestLaunchConfigurationProvider[] { + new TestLaunchConfigurationProvider(DEFAULT_DESCRIPTOR_TYPE_ID, DEFAULT_TARGET_TYPE_ID, configType, true, this) + }; + } + + protected TestLaunchObjectProvider[] getTestObjectProviders() { + return new TestLaunchObjectProvider[0]; + } + + @Override + protected ILaunchManager getLaunchManager() { + return launchManager; + } + + @Override + protected IEclipsePreferences getPreferenceStore() { + return prefs; + } + }; + + public static class TestLaunchTargetType implements ILaunchTargetType { + final String id; + + public TestLaunchTargetType(String id) { this.id = id; } @Override - public ILaunchTarget[] getTargets() { - return targets.toArray(new ILaunchTarget[targets.size()]); + public void init(ILaunchBarManager manager) throws CoreException { + // override if you want to add targets } @Override - public String getId() { - return id; + public void dispose() { } } - private TargetType targetType = new TargetType("target_type1"); - class LaunchTarget extends AbstractLaunchTarget { + public static class TestLaunchTarget extends PlatformObject implements ILaunchTarget { private ILaunchTargetType type; + private String name; - public LaunchTarget(String id, ILaunchTargetType type) { - super(id); + public TestLaunchTarget(String name, ILaunchTargetType type) { + this.name = name; this.type = type; } public ILaunchTargetType getType() { return type; } + + @Override + public String getName() { + return name; + } + + @Override + public void setActive(boolean active) { + } } - private ILaunchTarget mytarget = new LaunchTarget("target_1", targetType); - private ILaunchManager lman; - private IProject aaa; - private ArrayList globalmodes = new ArrayList<>(); - IExtensionPoint point; - IEclipsePreferences store = new EclipsePreferences(); - private LocalTargetType localTargetType; - public class FixedLaunchBarManager extends LaunchBarManager { - public FixedLaunchBarManager() throws CoreException { - super(); + public static class TestLaunchObject { + final String name; + final ILaunchDescriptorType descType; + + public TestLaunchObject(String name, ILaunchDescriptorType descType) { + this.name = name; + this.descType = descType; } @Override - public IExtensionPoint getExtensionPoint() { - return point; + public boolean equals(Object obj) { + if (obj instanceof TestLaunchObject) { + return name.equals(((TestLaunchObject) obj).name); + } + return super.equals(obj); } @Override - protected ILaunchManager getLaunchManager() { - return lman; + public int hashCode() { + return name.hashCode(); + } + } + + public static class TestLaunchDescriptor extends PlatformObject implements ILaunchDescriptor { + private final TestLaunchObject object; + private final TestLaunchDescriptorType type; + + public TestLaunchDescriptor(TestLaunchDescriptorType type, TestLaunchObject object) { + this.object = object; + this.type = type; } @Override - protected IEclipsePreferences getPreferenceStore() { - return store; + public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { + if (TestLaunchObject.class.equals(adapter)) { + return object; + } + return super.getAdapter(adapter); } - }; + + @Override + public String getName() { + return object.name; + } + + @Override + public ILaunchDescriptorType getType() { + return type; + } + } + + public static class TestLaunchDescriptorType implements ILaunchDescriptorType { + final String id; + final int priority; + + public TestLaunchDescriptorType(String id, int priority) { + this.id = id; + this.priority = priority; + } + + @Override + public boolean ownsLaunchObject(Object launchObject) throws CoreException { + if (!(launchObject instanceof TestLaunchObject)) { + return false; + } + return ((TestLaunchObject) launchObject).descType.equals(this); + } + + @Override + public ILaunchDescriptor getDescriptor(Object launchObject) throws CoreException { + return new TestLaunchDescriptor(this, (TestLaunchObject) launchObject); + } + } + + public static class TestLaunchConfigurationProvider extends LaunchConfigurationProvider { + final String descTypeId; + final String targetTypeId; + final ILaunchConfigurationType configType; + final boolean isDefault; + final LaunchBarManager manager; + + private static final String OBJECT_NAME = "testObject.objectName"; + private static final String DESC_TYPE = "testObject.descType"; + + public TestLaunchConfigurationProvider(String descTypeId, String targetTypeId, ILaunchConfigurationType configType, boolean isDefault, LaunchBarManager manager) { + this.descTypeId = descTypeId; + this.targetTypeId = targetTypeId; + this.configType = configType; + this.isDefault = isDefault; + this.manager = manager; + } + + @Override + public ILaunchConfigurationType getLaunchConfigurationType() throws CoreException { + return configType; + } + + @Override + public ILaunchConfiguration createLaunchConfiguration(ILaunchManager launchManager, ILaunchDescriptor descriptor) throws CoreException { + String name = launchManager.generateLaunchConfigurationName(getConfigurationName(descriptor)); + ILaunchConfigurationWorkingCopy workingCopy = getLaunchConfigurationType().newInstance(null, name); + doReturn(name).when(workingCopy).getAttribute(ORIGINAL_NAME, ""); + + TestLaunchObject launchObject = (TestLaunchObject) descriptor.getAdapter(TestLaunchObject.class); + doReturn(launchObject.name).when(workingCopy).getAttribute(OBJECT_NAME, ""); + doReturn(manager.getDescriptorTypeId(launchObject.descType)).when(workingCopy).getAttribute(DESC_TYPE, ""); + return workingCopy.doSave(); + } + + @Override + protected void populateConfiguration(ILaunchConfigurationWorkingCopy workingCopy, ILaunchDescriptor descriptor) throws CoreException { + super.populateConfiguration(workingCopy, descriptor); + + } + + @Override + public Object launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException { + if (ownsConfiguration(configuration)) { + String objectName = configuration.getAttribute(OBJECT_NAME, ""); + String descTypeId = configuration.getAttribute(DESC_TYPE, ""); + if (!objectName.isEmpty() && !descTypeId.isEmpty()) { + return new TestLaunchObject(objectName, manager.getLaunchDescriptorType(descTypeId)); + } + } + return null; + } + + @Override + public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException { + if (ownsConfiguration(configuration)) { + return true; + } + return false; + } + + } + + public abstract class TestLaunchObjectProvider implements ILaunchObjectProvider { + @Override + public void dispose() { + // nothing by default + } + } + + protected ILaunchConfigurationType mockLaunchConfigurationType(String id) { + return mockLaunchConfigurationType(id, launchManager.getLaunchModes()); + } + + protected ILaunchConfigurationType mockLaunchConfigurationType(String id, ILaunchMode[] modes) { + ILaunchConfigurationType type = mock(ILaunchConfigurationType.class); + doReturn(id).when(type).getIdentifier(); + doReturn(type).when(launchManager).getLaunchConfigurationType(id); + + // mock for supportsMode + for (ILaunchMode mode : modes) { + String modeid = mode.getIdentifier(); + doReturn(true).when(type).supportsMode(modeid); + } + + return type; + } + + protected ILaunchConfigurationWorkingCopy mockLaunchConfiguration(String name, ILaunchConfigurationType type) throws CoreException { + ILaunchConfigurationWorkingCopy wc = mock(ILaunchConfigurationWorkingCopy.class); + doReturn(name).when(wc).getName(); + doReturn(type).when(wc).getType(); + doReturn(wc).when(wc).doSave(); + doReturn(name).when(launchManager).generateLaunchConfigurationName(name); + doReturn(wc).when(type).newInstance(null, name); + return wc; + } + + // + // Now that we have all the setup, + // Actual tests :) + // @Override protected void setUp() throws Exception { - point = mock(IExtensionPoint.class); - doReturn(new IExtension[] {}).when(point).getExtensions(); - lman = mock(ILaunchManager.class); - doReturn(new ILaunchConfiguration[] {}).when(lman).getLaunchConfigurations(); - doReturn(globalmodes.toArray(new ILaunchMode[globalmodes.size()])).when(lman).getLaunchModes(); - manager = new FixedLaunchBarManager(); - // mock - // lc - lctype = mockLCType("lctype1"); - lc = mockLC("bla", lctype); - // other init - provider = new ConfigBasedLaunchConfigurationProvider(lctype.getIdentifier()); - descType = new ConfigBasedLaunchDescriptorType("desctype1", lctype.getIdentifier()); - desc = new ConfigBasedLaunchDescriptor(descType, lc); - } + // Prefs are shared across an entire test + prefs = new EclipsePreferences(); - protected void basicSetup() { - // setup some stuff - manager.addTargetType(targetType); - targetType.targets.add(mytarget); - manager.addDescriptorType(descType, 5); - manager.addConfigProvider(descType.getId(), targetType.getId(), false, provider); - } - - private ILaunchConfiguration mockLC(String string, ILaunchConfigurationType lctype2) throws CoreException { - ILaunchConfiguration lc = mock(ILaunchConfiguration.class); - doReturn(string).when(lc).getName(); - doReturn(lctype2).when(lc).getType(); - return lc; - } - - protected ILaunchConfigurationType mockLCType(String id) { - ILaunchConfigurationType lctype = mock(ILaunchConfigurationType.class); - doReturn(id).when(lctype).getIdentifier(); - return lctype; - } - - protected ILaunchMode[] mockLaunchModes(ILaunchConfigurationType type, String... modes) { - ILaunchMode res[] = new ILaunchMode[modes.length]; - for (int i = 0; i < modes.length; i++) { - String modeId = modes[i]; - doReturn(true).when(type).supportsMode(modeId); - ILaunchMode mode = mock(ILaunchMode.class); - res[i] = mode; - doReturn(modeId).when(mode).getIdentifier(); - doReturn(mode).when(lman).getLaunchMode(modeId); - globalmodes.add(mode); + // launch manager and default modes + launchManager = mock(ILaunchManager.class); + try { + doReturn(new ILaunchConfiguration[] {}).when(launchManager).getLaunchConfigurations(); + } catch (CoreException e) { + fail(e.getMessage()); } - doReturn(new HashSet<>(Arrays.asList(modes))).when(type).getSupportedModes(); - doReturn(globalmodes.toArray(new ILaunchMode[globalmodes.size()])).when(lman).getLaunchModes(); - return res; + + ILaunchMode runMode = mock(ILaunchMode.class); + doReturn("run").when(runMode).getIdentifier(); + doReturn("Run").when(runMode).getLabel(); + doReturn("Run As...").when(runMode).getLaunchAsLabel(); + doReturn(runMode).when(launchManager).getLaunchMode("run"); + + ILaunchMode debugMode = mock(ILaunchMode.class); + doReturn("debug").when(debugMode).getIdentifier(); + doReturn("Debug").when(debugMode).getLabel(); + doReturn("Debug As...").when(debugMode).getLaunchAsLabel(); + doReturn(debugMode).when(launchManager).getLaunchMode("debug"); + + doReturn(new ILaunchMode[] { runMode, debugMode }).when(launchManager).getLaunchModes(); } - public void testLaunchBarManager() { + @Test + public void testLaunchBarManager() throws Exception { + TestLaunchBarManager manager = new TestLaunchBarManager(); assertNull(manager.getActiveLaunchDescriptor()); assertNull(manager.getActiveLaunchTarget()); assertNull(manager.getActiveLaunchMode()); } @Test - public void testAddConfigProvider() { - manager.addTargetType(targetType); - manager.addDescriptorType(descType, 5); - manager.addConfigProvider(descType.getId(), targetType.getId(), false, provider); + public void testSuccessPath() throws Exception { + TestLaunchBarManager manager = new TestLaunchBarManager(); + + // mock out the launch config that will be created + String name = "testConfig"; + ILaunchConfigurationType configType = manager.getLaunchManager().getLaunchConfigurationType(DEFAULT_CONFIG_TYPE_ID); + assertNotNull(configType); + ILaunchConfigurationWorkingCopy wc = mockLaunchConfiguration(name, configType); + + // fire in launch object and target + ILaunchDescriptorType descType = manager.getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID); + assertNotNull(descType); + TestLaunchObject launchObject = new TestLaunchObject(name, descType); + manager.launchObjectAdded(launchObject); + + // check our state + assertEquals(manager.getLaunchDescriptor(launchObject), manager.getActiveLaunchDescriptor()); + assertNull(manager.getActiveLaunchTarget()); + assertNotNull(manager.getActiveLaunchMode()); + + ILaunchTargetType targetType = manager.getLaunchTargetType(DEFAULT_TARGET_TYPE_ID); + assertNotNull(targetType); + manager.launchTargetAdded(new TestLaunchTarget("testTarget", targetType)); + + // verify that our launch config got created and saved + assertNotNull(manager.getActiveLaunchMode()); + assertEquals(wc, manager.getActiveLaunchConfiguration()); + verify(wc).doSave(); + + // now remove the launch object and make sure everything resets + manager.launchObjectRemoved(launchObject); + assertNull(manager.getActiveLaunchDescriptor()); + assertNull(manager.getActiveLaunchTarget()); + assertNull(manager.getActiveLaunchMode()); + verify(wc).delete(); } @Test - public void testAddConfigProviderBad() throws CoreException { - provider = spy(provider); - doThrow(new NullPointerException()).when(provider).init(manager); - manager.addTargetType(targetType); - manager.addDescriptorType(descType, 5); - manager.addConfigProvider(descType.getId(), targetType.getId(), false, provider); - verify(provider).init(manager); + public void testWrongObject() throws Exception { + TestLaunchBarManager manager = new TestLaunchBarManager(); + + // mock out the launch config that will be created + String name = "testConfig"; + ILaunchConfigurationType configType = manager.getLaunchManager().getLaunchConfigurationType(DEFAULT_CONFIG_TYPE_ID); + mockLaunchConfiguration(name, configType); + + // fire in launch target but object with no descriptor + manager.launchObjectAdded(new Object()); + manager.launchTargetAdded(new TestLaunchTarget("testTarget", manager.getLaunchTargetType(DEFAULT_TARGET_TYPE_ID))); + + // verify that there are no launch configs + assertNull(manager.getActiveLaunchConfiguration()); } @Test - public void testAddDescriptorTypeBad() throws CoreException { - descType = spy(descType); - doThrow(new NullPointerException()).when(descType).init(manager); - manager.addDescriptorType(descType, 5); - verify(descType).init(manager); + public void testNoTarget() throws Exception { + TestLaunchBarManager manager = new TestLaunchBarManager(); + + // mock out the launch config that will be created + String name = "testConfig"; + ILaunchConfigurationType configType = manager.getLaunchManager().getLaunchConfigurationType(DEFAULT_CONFIG_TYPE_ID); + ILaunchConfigurationWorkingCopy wc = mockLaunchConfiguration(name, configType); + + // create descriptor and target + manager.launchObjectAdded(new TestLaunchObject(name, manager.getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID))); + + // verify that our launch config got created and saved even though the default config type + assertEquals(wc, manager.getActiveLaunchConfiguration()); + verify(wc).doSave(); } @Test - public void testAddConfigProviderNoTarget() { - try { - manager.addDescriptorType(descType, 5); - manager.addConfigProvider(descType.getId(), targetType.getId(), false, provider); - fail("Expecting exctpion because target is not registered"); - } catch (Exception e) { - // pass + public void testDefaultDescriptor() throws Exception { + TestLaunchBarManager manager = new TestLaunchBarManager(); + + ILaunchConfigurationType configType = mockLaunchConfigurationType("configType.default"); + ILaunchConfiguration config = mockLaunchConfiguration("defaultConfig", configType); + manager.launchConfigurationAdded(config); + assertEquals(config, manager.getActiveLaunchConfiguration()); + + manager.launchConfigurationRemoved(config); + assertNull(manager.getActiveLaunchConfiguration()); + } + + @Test + public void testSetActiveDescriptor() throws Exception { + TestLaunchBarManager manager = new TestLaunchBarManager(); + + // descriptor for the test descriptor + String name = "test1"; + ILaunchConfigurationType configType = manager.getLaunchManager().getLaunchConfigurationType(DEFAULT_CONFIG_TYPE_ID); + ILaunchConfigurationWorkingCopy wc = mockLaunchConfiguration(name, configType); + + ILaunchDescriptorType descType = manager.getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID); + TestLaunchObject testObject1 = new TestLaunchObject(name, descType); + manager.launchObjectAdded(testObject1); + ILaunchDescriptor test1 = manager.getLaunchDescriptor(testObject1); + assertNotNull(test1); + + // descriptor for the default descriptor + ILaunchConfigurationType defaultConfigType = mockLaunchConfigurationType("configType.default"); + ILaunchConfiguration config = mockLaunchConfiguration("test2", defaultConfigType); + manager.launchConfigurationAdded(config); + ILaunchDescriptor test2 = manager.getLaunchDescriptor(config); + assertNotNull(test2); + assertNotSame(test1, test2); + + // test2 should be active by default since it was created last + assertEquals(test2, manager.getActiveLaunchDescriptor()); + assertEquals(config, manager.getActiveLaunchConfiguration()); + + // flip to test1 + manager.setActiveLaunchDescriptor(test1); + assertEquals(test1, manager.getActiveLaunchDescriptor()); + assertEquals(wc, manager.getActiveLaunchConfiguration()); + + // and back to test2 + manager.setActiveLaunchDescriptor(test2); + assertEquals(test2, manager.getActiveLaunchDescriptor()); + assertEquals(config, manager.getActiveLaunchConfiguration()); + } + + @Test + public void testSetActiveMode() throws Exception { + TestLaunchBarManager manager = new TestLaunchBarManager(); + ILaunchMode runMode = launchManager.getLaunchMode("run"); + ILaunchMode debugMode = launchManager.getLaunchMode("debug"); + + String name = "test"; + ILaunchConfigurationType testConfigType = manager.getLaunchManager().getLaunchConfigurationType(DEFAULT_CONFIG_TYPE_ID); + mockLaunchConfiguration(name, testConfigType); + + ILaunchDescriptorType descType = manager.getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID); + TestLaunchObject testObject = new TestLaunchObject(name, descType); + manager.launchObjectAdded(testObject); + assertNotNull(manager.getActiveLaunchConfiguration()); + + // The default launch mode is debug (that may change) + assertEquals(debugMode, manager.getActiveLaunchMode()); + + // Set to run + manager.setActiveLaunchMode(runMode); + assertEquals(runMode, manager.getActiveLaunchMode()); + + // and back to debug + manager.setActiveLaunchMode(debugMode); + assertEquals(debugMode, manager.getActiveLaunchMode()); + } + + @Test + public void testSetActiveTarget() throws Exception { + // create separate target types and provider types for each one + final ILaunchConfigurationType configType1 = mockLaunchConfigurationType("configType.test1"); + final ILaunchConfigurationType configType2 = mockLaunchConfigurationType("configType.test2"); + final TestLaunchTargetType targetType1 = new TestLaunchTargetType("targetType.test1"); + final TestLaunchTargetType targetType2 = new TestLaunchTargetType("targetType.test2"); + + TestLaunchBarManager manager = new TestLaunchBarManager() { + @Override + protected TestLaunchTargetType[] getTestTargetTypes() { + return new TestLaunchTargetType[] { targetType1, targetType2 }; + } + @Override + protected TestLaunchConfigurationProvider[] getTestConfigProviders() { + TestLaunchConfigurationProvider provider1 = new TestLaunchConfigurationProvider( + DEFAULT_DESCRIPTOR_TYPE_ID, targetType1.id, configType1, true, this); + TestLaunchConfigurationProvider provider2 = new TestLaunchConfigurationProvider( + DEFAULT_DESCRIPTOR_TYPE_ID, targetType2.id, configType2, true, this); + return new TestLaunchConfigurationProvider[] { provider1, provider2 }; + } + }; + + // Target 1 + ILaunchConfiguration config1 = mockLaunchConfiguration("test1", configType1); + TestLaunchTarget target1 = new TestLaunchTarget("testTarget1", targetType1); + manager.launchTargetAdded(target1); + + // add in our object + manager.launchObjectAdded(new TestLaunchObject("test1", manager.getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID))); + + // launch config and target should be the default one + assertEquals(target1, manager.getActiveLaunchTarget()); + assertEquals(config1, manager.getActiveLaunchConfiguration()); + + // switching to second target type should create a new config, but it needs a new name + ILaunchManager launchManager = manager.getLaunchManager(); + doReturn("test2").when(launchManager).generateLaunchConfigurationName("test1"); + ILaunchConfiguration config2 = mockLaunchConfiguration("test2", configType2); + TestLaunchTarget target2 = new TestLaunchTarget("testTarget2", targetType2); + manager.setActiveLaunchTarget(target2); + + assertEquals(target2, manager.getActiveLaunchTarget()); + assertEquals(config2, manager.getActiveLaunchConfiguration()); + assertEquals("test2", manager.getActiveLaunchConfiguration().getName()); + } + + public class TestRestartLaunchBarManager extends TestLaunchBarManager { + public TestRestartLaunchBarManager() throws CoreException { + super(); + } + + @Override + protected TestLaunchTargetType[] getTestTargetTypes() { + TestLaunchTargetType targetType = new TestLaunchTargetType(DEFAULT_TARGET_TYPE_ID) { + public void init(ILaunchBarManager manager) throws CoreException { + manager.launchTargetAdded(new TestLaunchTarget("testTarget1", this)); + manager.launchTargetAdded(new TestLaunchTarget("testTarget2", this)); + } + }; + return new TestLaunchTargetType[] { targetType }; + } + + @Override + protected TestLaunchObjectProvider[] getTestObjectProviders() { + TestLaunchObjectProvider provider = new TestLaunchObjectProvider() { + @Override + public void init(ILaunchBarManager manager) throws CoreException { + mockLaunchConfiguration("test1", launchManager.getLaunchConfigurationType(DEFAULT_CONFIG_TYPE_ID)); + manager.launchObjectAdded(new TestLaunchObject("test1", getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID))); + mockLaunchConfiguration("test2", launchManager.getLaunchConfigurationType(DEFAULT_CONFIG_TYPE_ID)); + manager.launchObjectAdded(new TestLaunchObject("test2", getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID))); + } + }; + return new TestLaunchObjectProvider[] { provider }; } } @Test - public void testAddConfigProviderNoDesc() { - try { - manager.addTargetType(targetType); - manager.addConfigProvider(descType.getId(), targetType.getId(), false, provider); - fail("Expecting exctpion because target is not registered"); - } catch (Exception e) { - // pass - } + public void testRestart() throws Exception { + // create two over everything, set second active, and make sure it's remembered in a second manager + TestLaunchBarManager manager = new TestRestartLaunchBarManager(); + ILaunchMode runMode = launchManager.getLaunchMode("run"); + ILaunchMode debugMode = launchManager.getLaunchMode("debug"); + assertNotNull(runMode); + + // get our targets + ILaunchTarget target1 = manager.getLaunchTarget(new Pair(DEFAULT_TARGET_TYPE_ID, "testTarget1")); + assertNotNull(target1); + ILaunchTarget target2 = manager.getLaunchTarget(new Pair(DEFAULT_TARGET_TYPE_ID, "testTarget2")); + assertNotNull(target2); + + // get our descriptors + ILaunchDescriptor desc1 = manager.getLaunchDescriptor(new Pair(DEFAULT_DESCRIPTOR_TYPE_ID, "test1")); + assertNotNull(desc1); + ILaunchDescriptor desc2 = manager.getLaunchDescriptor(new Pair(DEFAULT_DESCRIPTOR_TYPE_ID, "test2")); + assertNotNull(desc2); + + // Set the actives one way + manager.setActiveLaunchDescriptor(desc1); + manager.setActiveLaunchTarget(target1); + manager.setActiveLaunchMode(runMode); + + // Create a new manager and check they are the same + manager = new TestRestartLaunchBarManager(); + desc1 = manager.getLaunchDescriptor(new Pair(DEFAULT_DESCRIPTOR_TYPE_ID, "test1")); + assertNotNull(desc1); + desc2 = manager.getLaunchDescriptor(new Pair(DEFAULT_DESCRIPTOR_TYPE_ID, "test2")); + assertNotNull(desc2); + assertEquals(desc1, manager.getActiveLaunchDescriptor()); + + target1 = manager.getLaunchTarget(new Pair(DEFAULT_TARGET_TYPE_ID, "testTarget1")); + assertNotNull(target1); + target2 = manager.getLaunchTarget(new Pair(DEFAULT_TARGET_TYPE_ID, "testTarget2")); + assertNotNull(target2); + assertEquals(target1, manager.getActiveLaunchTarget()); + assertEquals(runMode, manager.getActiveLaunchMode()); + + // Set them the other way + manager.setActiveLaunchDescriptor(desc2); + manager.setActiveLaunchTarget(target2); + manager.setActiveLaunchMode(debugMode); + + // Create a new manager and check they stuck + manager = new TestRestartLaunchBarManager(); + desc2 = manager.getLaunchDescriptor(new Pair(DEFAULT_DESCRIPTOR_TYPE_ID, "test2")); + assertNotNull(desc2); + assertEquals(desc2, manager.getActiveLaunchDescriptor()); + target2 = manager.getLaunchTarget(new Pair(DEFAULT_TARGET_TYPE_ID, "testTarget2")); + assertNotNull(target2); + assertEquals(target2, manager.getActiveLaunchTarget()); + assertEquals(debugMode, manager.getActiveLaunchMode()); } @Test - public void testAddConfigProviderTwo() throws CoreException { - basicSetup(); - TargetType targetType2 = new TargetType("t2"); - manager.addTargetType(targetType2); - ILaunchConfigurationProvider provider2 = new ConfigBasedLaunchConfigurationProvider("type2"); - manager.addConfigProvider(descType.getId(), targetType2.getId(), true, provider2); - ILaunchConfigurationType lctype2 = mockLCType("lctypeid2"); - ILaunchConfiguration lc2 = mockLC("bla2", lctype2); - ConfigBasedLaunchDescriptor desc2 = new ConfigBasedLaunchDescriptor(descType, lc2); - assertEquals(lctype2, manager.getLaunchConfigurationType(desc2, null)); - } - - @Test - public void testAddConfigProviderTwo2() throws CoreException { - manager.addTargetType(targetType); - manager.addDescriptorType(descType, 5); - ILaunchConfigurationProvider provider2 = new ConfigBasedLaunchConfigurationProvider("type2"); - manager.addConfigProvider(descType.getId(), targetType.getId(), true, provider2); - TargetType targetType2 = new TargetType("t2"); - manager.addTargetType(targetType2); - manager.addConfigProvider(descType.getId(), targetType2.getId(), false, provider); - ILaunchConfigurationType lctype2 = mockLCType("lctypeid2"); - ILaunchConfiguration lc2 = mockLC("bla2", lctype2); - ConfigBasedLaunchDescriptor desc2 = new ConfigBasedLaunchDescriptor(descType, lc2); - assertEquals(lctype2, manager.getLaunchConfigurationType(desc2, null)); - } - - @Test - public void testGetLaunchTargets() throws CoreException { - basicSetup(); - manager.launchObjectAdded(lc); - manager.setActiveLaunchDescriptor(desc); - ILaunchTarget[] launchTargets = manager.getLaunchTargets(); - assertEquals(1, launchTargets.length); - assertEquals(mytarget, launchTargets[0]); - } - - @Test - public void testGetLaunchTargetsNoProvider() throws CoreException { - manager.addTargetType(targetType); - targetType.targets.add(mytarget); - manager.addDescriptorType(descType, 5); - manager.launchObjectAdded(lc); - ILaunchTarget[] launchTargets = manager.getLaunchTargets(); - assertEquals(0, launchTargets.length); - } - - @Test - public void testGetOpenLaunchDescriptorsNull() { - ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors(); - assertEquals(0, launchDescriptors.length); - } - - public void testGetOpenLaunchDescriptors() { - basicSetup(); - manager.launchObjectAdded(lc); - ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors(); - assertEquals(1, launchDescriptors.length); - } - - public void testGetOpenLaunchDescriptorsSort() { - final ILaunchDescriptor res[] = new ILaunchDescriptor[1]; - manager.addTargetType(targetType); - ConfigBasedLaunchDescriptorType descType1 = new ConfigBasedLaunchDescriptorType("id1", lctype.getIdentifier()); - ConfigBasedLaunchDescriptorType descType2 = new ConfigBasedLaunchDescriptorType("id2", lctype.getIdentifier()) { - @Override - public ILaunchDescriptor getDescriptor(Object element) { - return res[0] = super.getDescriptor(element); + public void testLaunchConfigCapture() throws Exception { + final ILaunchConfigurationType configType = mockLaunchConfigurationType(DEFAULT_CONFIG_TYPE_ID); + TestLaunchBarManager manager = new TestLaunchBarManager() { + protected TestLaunchConfigurationProvider[] getTestConfigProviders() { + return new TestLaunchConfigurationProvider[] { + new TestLaunchConfigurationProvider(DEFAULT_DESCRIPTOR_TYPE_ID, DEFAULT_TARGET_TYPE_ID, configType, true, this) + }; } }; - ConfigBasedLaunchDescriptorType descType3 = new ConfigBasedLaunchDescriptorType("id3", lctype.getIdentifier()); - manager.addDescriptorType(descType1, 3); - manager.addDescriptorType(descType2, 5); - manager.addDescriptorType(descType3, 1); - manager.addConfigProvider(descType1.getId(), targetType.getId(), true, provider); - manager.addConfigProvider(descType2.getId(), targetType.getId(), true, provider); - manager.addConfigProvider(descType3.getId(), targetType.getId(), true, provider); - targetType.targets.add(mytarget); - manager.launchObjectAdded(lc); - ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors(); - assertEquals(1, launchDescriptors.length); - assertNotNull(launchDescriptors[0]); - assertSame(res[0], launchDescriptors[0]); - } - @Test - public void testLaunchObjectAdded() throws CoreException { - basicSetup(); - manager.launchObjectAdded(lc); - ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors(); - assertEquals(1, launchDescriptors.length); - assertNotNull(launchDescriptors[0]); - assertEquals(lc.getName(), launchDescriptors[0].getName()); - } + ILaunchConfiguration config = mockLaunchConfiguration("test", configType); + manager.launchObjectAdded(new TestLaunchObject("test", manager.getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID))); + String activeDescId = manager.toString(manager.getDescriptorId(manager.getActiveLaunchDescriptor())); + assertEquals(manager.getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID), manager.getActiveLaunchDescriptor().getType()); + assertEquals(config, manager.getActiveLaunchConfiguration()); - @Test - public void testLaunchObjectAdded2() throws CoreException { - basicSetup(); - manager.launchObjectAdded(lc); - ILaunchConfiguration lc2 = mockLC("lc2", lctype); - manager.launchObjectAdded(lc2); - assertEquals(2, manager.getOpenLaunchDescriptors().length); - } - - @Test - public void testLaunchObjectChanged() throws CoreException { - basicSetup(); - assertNull(manager.launchObjectChanged(lc)); - manager.launchObjectAdded(lc); - assertEquals(1, manager.getOpenLaunchDescriptors().length); - assertNotNull(manager.launchObjectChanged(lc)); - } - - public IProject mockProject(String projectName) { - IProject project = mock(Project.class); - when(project.getAdapter(IResource.class)).thenReturn(project); - when(project.getProject()).thenReturn(project); - when(project.getName()).thenReturn(projectName); - IPath path = new Path(projectName); - when(project.getFullPath()).thenReturn(path); - when(project.getType()).thenReturn(IResource.PROJECT); - when(project.isOpen()).thenReturn(true); - return project; - } - - public ILaunchConfiguration mockLCProject(ILaunchConfiguration lc, String projectName) { - mockLCAttribute(lc, ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName); - return lc; - } - - public ILaunchConfiguration mockLCBinary(ILaunchConfiguration lc, String binname) { - mockLCAttribute(lc, ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, binname); - return lc; - } - - public ILaunchConfiguration mockLCAttribute(ILaunchConfiguration lc, String attr, String value) { - try { - when(lc.getAttribute(eq(attr), anyString())).thenReturn(value); - } catch (CoreException e) { - throw new RuntimeException(e); - } - return lc; - } - - protected String getProjectName(ILaunchConfiguration llc) { - try { - return llc.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); - } catch (CoreException e) { - // - } - return ""; - } - - IProject getProjectByName(String p) { - if (p.equals("aaa")) - return aaa; - return mockProject(p); - } - - /** - * This scenario when provider will change mapping element->descriptor, depending on other objects involved - */ - @Test - public void testLaunchObjectAddedRemapping() throws CoreException { - projectMappingSetup(); - // user created a project - manager.launchObjectAdded(aaa); - assertEquals(1, manager.getOpenLaunchDescriptors().length); - assertTrue(manager.getOpenLaunchDescriptors()[0].getName().startsWith(aaa.getName())); - // user clicked on descriptor geer to edit lc, new lc is created - manager.launchConfigurationAdded(lc); - assertEquals(1, manager.getOpenLaunchDescriptors().length); - assertEquals(lc.getName(), manager.getOpenLaunchDescriptors()[0].getName()); - // user cloned lc and changed some settings - ILaunchConfiguration lc2 = mockLC("lc2", lctype); - mockLCProject(lc2, aaa.getName()); - manager.launchConfigurationAdded(lc2); - assertEquals(2, manager.getOpenLaunchDescriptors().length); - // user deleted lc - userDeletesLC(lc2); - assertEquals(1, manager.getOpenLaunchDescriptors().length); - // user deleted last lc, now we back to project default - userDeletesLC(lc); - assertEquals(1, manager.getOpenLaunchDescriptors().length); - } - - protected void userDeletesLC(ILaunchConfiguration lc2) { - String string = lc2.getName(); - reset(lc2); - doReturn(string).when(lc2).getName(); - manager.launchConfigurationRemoved(lc2); - } - - protected void projectMappingSetup() { - descType = new ProjectBasedLaunchDescriptorType("desc2", lctype.getIdentifier()) { - protected IProject getProject(ILaunchConfiguration llc) { - return getProjectByName(getProjectName(llc)); + // restart and make sure the same descriptor is selected and new one new ones created + doReturn(new ILaunchConfiguration[] { config }).when(launchManager).getLaunchConfigurations(); + manager = new TestLaunchBarManager() { + protected TestLaunchConfigurationProvider[] getTestConfigProviders() { + return new TestLaunchConfigurationProvider[] { + new TestLaunchConfigurationProvider(DEFAULT_DESCRIPTOR_TYPE_ID, DEFAULT_TARGET_TYPE_ID, configType, true, this) + }; } - @Override - protected boolean ownsProject(IProject element) { - return true; - } - - @Override - public ILaunchConfigurationType getLaunchConfigurationType() { - return lctype; + protected TestLaunchObjectProvider[] getTestObjectProviders() { + return new TestLaunchObjectProvider[] { + new TestLaunchObjectProvider() { + @Override + public void init(ILaunchBarManager manager) throws CoreException { + manager.launchObjectAdded( + new TestLaunchObject("test", + getLaunchDescriptorType(DEFAULT_DESCRIPTOR_TYPE_ID)));; + } + } + }; } }; - provider = new ProjectBasedLaunchConfigurationProvider(lctype.getIdentifier()) { - protected IProject getProject(ILaunchConfiguration llc) { - return getProjectByName(getProjectName(llc)); - } - }; - desc = null; - basicSetup(); - aaa = mockProject("aaa"); - mockLCProject(lc, aaa.getName()); - assertEquals(0, manager.getOpenLaunchDescriptors().length); + String newActiveDescId = manager.toString(manager.getDescriptorId(manager.getActiveLaunchDescriptor())); + assertEquals(activeDescId, newActiveDescId); + assertEquals(1, manager.getLaunchDescriptors().length); } - public void testLaunchObjectAddedRemapping2() throws CoreException { - projectMappingSetup(); - // test unmapping - manager.launchObjectAdded(aaa); - assertEquals(1, manager.getOpenLaunchDescriptors().length); - manager.launchObjectAdded(lc); - assertEquals(2, manager.getOpenLaunchDescriptors().length); // XXX should be 1 - manager.launchObjectChanged(aaa); - assertEquals(1, manager.getOpenLaunchDescriptors().length); - assertEquals(lc.getName(), manager.getOpenLaunchDescriptors()[0].getName()); - manager.launchObjectRemoved(lc); - assertEquals(0, manager.getOpenLaunchDescriptors().length); // XXX should be 1 - } + // TODO - test that two target types that map to the same desc type and config type share configs + // TODO - test duplicating a config. make sure it's default desc and same targets + // TODO - test project descriptors and stuff - @Test - public void testLaunchObjectAddedBadDescriptor() throws CoreException { - descType = spy(descType); - basicSetup(); - doThrow(new NullPointerException()).when(descType).ownsLaunchObject(any()); - // check events - manager.launchObjectAdded(lc); - verify(descType).ownsLaunchObject(lc); - } - - @Test - public void testLaunchObjectRemoveBadDescriptor() throws CoreException { - descType = spy(descType); - basicSetup(); - doThrow(new NullPointerException()).when(descType).ownsLaunchObject(any()); - // check events - manager.launchObjectRemoved(lc); - } - - @Test - public void testLaunchObjectRemoved() throws CoreException { - basicSetup(); - manager.launchObjectAdded(lc); - assertEquals(1, manager.getOpenLaunchDescriptors().length); - manager.launchObjectRemoved(lc); - assertEquals(0, manager.getOpenLaunchDescriptors().length); - } - - @Test - public void testGetActiveLaunchDescriptor() throws CoreException { - basicSetup(); - Listener lis = mock(Listener.class); - manager.addListener(lis); - manager.launchObjectAdded(lc); - // manager.setActiveLaunchDescriptor(desc); - assertEquals(desc, manager.getActiveLaunchDescriptor()); - verify(lis).activeConfigurationDescriptorChanged(); - } - - @Test - public void testSetActiveLaunchDescriptorUnkn() throws CoreException { - basicSetup(); - try { - manager.setActiveLaunchDescriptor(desc); - fail(); - } catch (Exception e) { - // pass - } - } - - @Test - public void testSetActiveLaunchDescriptorNullBad() throws CoreException { - basicSetup(); - manager.launchObjectAdded(lc); - manager.setActiveLaunchDescriptor(null); - assertEquals(desc, manager.getActiveLaunchDescriptor()); - } - - @Test - public void testSetActiveLaunchDescriptorLisBad() throws CoreException { - basicSetup(); - Listener lis = mock(Listener.class); - manager.addListener(lis); - doThrow(new NullPointerException()).when(lis).activeConfigurationDescriptorChanged(); - manager.launchConfigurationAdded(lc); - verify(lis).activeConfigurationDescriptorChanged(); - } - - @Test - public void testSetActiveLaunchDescriptorNull() throws CoreException { - basicSetup(); - manager.launchObjectAdded(lc); - manager.launchObjectRemoved(lc); - manager.setActiveLaunchDescriptor(null); - } - - @Test - public void testGetLaunchModes() throws CoreException { - ILaunchMode[] launchModes = manager.getLaunchModes(); - assertEquals(0, launchModes.length); - } - - @Test - public void testGetLaunchModesFew() throws CoreException { - basicSetup(); - ILaunchConfigurationType lctype2 = mockLCType("lctype2"); - mockLaunchModes(lctype2, "modex"); - mockLaunchModes(lctype, "run", "debug", "foo"); - manager.launchConfigurationAdded(lc); - ILaunchMode[] launchModes = manager.getLaunchModes(); - assertEquals(3, launchModes.length); - } - - @Test - public void testSetActiveLaunchMode() { - ILaunchMode mode = mock(ILaunchMode.class); - doReturn("bla").when(mode).getIdentifier(); - doReturn("Bla").when(mode).getLabel(); - manager.setActiveLaunchMode(mode); - assertEquals(mode, manager.getActiveLaunchMode()); - } - - @Test - public void testSetActiveLaunchModeNull() { - manager.setActiveLaunchMode(null); - assertEquals(null, manager.getActiveLaunchMode()); - } - - @Test - public void testSetActiveLaunchModeNull2() { - ILaunchMode modes[] = mockLaunchModes(lctype, "run", "debug", "foo"); - manager.setActiveLaunchMode(modes[0]); - manager.setActiveLaunchMode(null); - assertEquals(null, manager.getActiveLaunchMode()); - } - - @Test - public void testSetActiveLaunchModeUnsupported() { - basicSetup(); - ILaunchConfigurationType lctype2 = mockLCType("lctype2"); - ILaunchMode mode = mockLaunchModes(lctype2, "modex")[0]; - mockLaunchModes(lctype, "run", "debug", "foo"); - manager.launchConfigurationAdded(lc); - try { - manager.setActiveLaunchMode(mode); - fail(); - } catch (Exception e) { - // works - assertNotEquals(mode, manager.getActiveLaunchMode()); - } - } - - @Test - public void testSetActiveLaunchModeLis() { - ILaunchMode mode = mock(ILaunchMode.class); - doReturn("bla").when(mode).getIdentifier(); - Listener lis = mock(Listener.class); - manager.addListener(lis); - manager.setActiveLaunchMode(mode); - manager.setActiveLaunchMode(null); - verify(lis, times(2)).activeLaunchModeChanged(); - } - - @Test - public void testSetActiveLaunchModeLisBad() { - ILaunchMode mode = mock(ILaunchMode.class); - doReturn("bla").when(mode).getIdentifier(); - Listener lis = mock(Listener.class); - manager.addListener(lis); - doThrow(new NullPointerException()).when(lis).activeLaunchModeChanged(); - manager.setActiveLaunchMode(mode); - verify(lis).activeLaunchModeChanged(); - } - - @Test - public void testGetActiveLaunchModeFromDesc() throws CoreException { - basicSetup(); - mockLaunchModes(lctype, "run"); - manager.launchObjectAdded(lc); - manager.setActiveLaunchDescriptor(desc); - ILaunchMode resmode = manager.getActiveLaunchMode(); - assertNotNull(resmode); - assertEquals("run", resmode.getIdentifier()); - } - - @Test - public void testGetActiveLaunchModeFromDescDebug() throws CoreException { - basicSetup(); - mockLaunchModes(lctype, "run", "debug"); - manager.launchObjectAdded(lc); - manager.setActiveLaunchDescriptor(desc); - ILaunchMode resmode = manager.getActiveLaunchMode(); - assertNotNull(resmode); - assertEquals("debug", resmode.getIdentifier()); - } - - @Test - public void testGetActiveLaunchModeFromDescActive() throws CoreException { - basicSetup(); - mockLaunchModes(lctype, "run"); - ILaunchMode mode = mockLaunchModes(lctype, "foo")[0]; - manager.launchObjectAdded(lc); - manager.setActiveLaunchMode(mode); - manager.setActiveLaunchDescriptor(desc); - ILaunchMode resmode = manager.getActiveLaunchMode(); - assertNotNull(resmode); - assertEquals("foo", resmode.getIdentifier()); - } - - @Test - public void testGetActiveLaunchTarget() { - manager.addTargetType(targetType); - targetType.targets.add(mytarget); - manager.setActiveLaunchTarget(mytarget); - assertEquals(mytarget, manager.getActiveLaunchTarget()); - } - - @Test - public void testAddTargetTypeBad() { - targetType = spy(targetType); - doThrow(new NullPointerException()).when(targetType).init(manager); - manager.addTargetType(targetType); - targetType.targets.add(mytarget); - assertEquals(mytarget, manager.getLaunchTarget(mytarget.getId())); - verify(targetType).init(manager); - } - - @Test - public void testGetLaunchTarget() { - manager.addTargetType(targetType); - targetType.targets.add(mytarget); - assertEquals(mytarget, manager.getLaunchTarget(mytarget.getId())); - } - - @Test - public void testGetLaunchTargetNone() { - manager.addTargetType(targetType); - assertNull(manager.getLaunchTarget(mytarget.getId())); - } - - @Test - public void testGetLaunchConfigurationType() throws CoreException { - assertNotNull(manager.getLaunchConfigurationType(desc, mytarget)); - } - - @Test - public void testGetLaunchConfigurationTypeSet() throws CoreException { - basicSetup(); - assertNotNull(manager.getLaunchConfigurationType(desc, mytarget)); - } - - @Test - public void testGetLaunchConfigurationTypeSet2() throws CoreException { - - descType = new AbstarctLaunchDescriptorType() { - @Override - public boolean ownsLaunchObject(Object element) throws CoreException { - // TODO Auto-generated method stub - return element.equals("bla"); - } - - @Override - public ILaunchDescriptor getDescriptor(Object element) throws CoreException { - return desc; - } - - @Override - public String getId() { - return "bla"; - } - }; - desc = new AbstractLaunchDescriptor() { - @Override - public ILaunchDescriptorType getType() { - return descType; - } - - @Override - public String getName() { - return "bla"; - } - }; - provider = new AbstractLaunchConfigurationProvider() { - @Override - public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException { - return false; - } - - @Override - public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException { - return false; - } - - @Override - public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor) throws CoreException { - return lc; - } - - @Override - public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor) throws CoreException { - return lctype; - } - }; - manager.addTargetType(targetType); - manager.addDescriptorType(descType, 5); - assertEquals(null, manager.getLaunchConfigurationType(desc, null)); - manager.addConfigProvider(descType.getId(), targetType.getId(), false, provider); - assertEquals(lctype, manager.getLaunchConfigurationType(desc, mytarget)); - assertEquals(lctype, manager.getLaunchConfigurationType(desc, null)); - } - - @Test - public void testGetLaunchConfigurationNull() throws CoreException { - assertNull(manager.getLaunchConfiguration(null, mytarget)); - } - - @Test - public void testGetLaunchConfigurationNull2() throws CoreException { - assertNull(manager.getLaunchConfiguration(desc, null)); - } - - @Test - public void testGetLaunchConfigurationDummy() throws CoreException { - assertNull(manager.getLaunchConfiguration(desc, mytarget)); - } - - public void testGetLaunchConfigurationLocal() throws CoreException { - basicSetup(); - addDefaultProvider(); - assertFalse(manager.supportsTargetType(desc, localTargetType)); - assertNull(manager.getLaunchConfiguration(desc, localTargetType.getTargets()[0])); - } - - public void testGetLaunchConfiguration() throws CoreException { - basicSetup(); - assertTrue(manager.supportsTargetType(desc, targetType)); - assertNotNull(manager.getLaunchConfiguration(desc, mytarget)); - } - - @Test - public void testAddListener() throws CoreException { - Listener lis = mock(Listener.class); - manager.addListener(lis); - basicSetup(); - // check events - manager.launchObjectAdded(lc); - manager.setActiveLaunchDescriptor(desc); - verify(lis).activeLaunchTargetChanged(); - } - - @Test - public void testAddListenerBad() throws CoreException { - Listener lis = mock(Listener.class); - manager.addListener(lis); - doThrow(new NullPointerException()).when(lis).activeLaunchTargetChanged(); - basicSetup(); - // check events - manager.launchObjectAdded(lc); - manager.setActiveLaunchDescriptor(desc); - verify(lis).activeLaunchTargetChanged(); - } - - @Test - public void testRemoveListener() { - basicSetup(); - Listener lis = mock(Listener.class); - manager.addListener(lis); - manager.removeListener(lis); - verifyZeroInteractions(lis); - } - - @Test - public void testLaunchConfigurationAdded() throws CoreException { - provider = spy(provider); - basicSetup(); - ILaunchMode mode = mockLaunchModes(lctype, "foo")[0]; - manager.launchConfigurationAdded(lc); - verify(provider).launchConfigurationAdded(lc); - ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors(); - assertEquals(1, launchDescriptors.length); - assertNotNull(launchDescriptors[0]); - assertEquals(lc.getName(), launchDescriptors[0].getName()); - manager.setActiveLaunchDescriptor(desc); - assertEquals(mytarget, manager.getActiveLaunchTarget()); - assertEquals(mode, manager.getActiveLaunchMode()); - } - - public void testLaunchConfigurationAddedDefault() throws CoreException { - provider = spy(provider); - basicSetup(); - // emulate default type (if running not from plugin) - DefaultLaunchDescriptorType type = addDefaultProvider(); - // another lc not covered by provider - ILaunchConfigurationType lctype2 = mockLCType("lctype2"); - ILaunchConfiguration lc2 = mockLC("lc2", lctype2); - manager.launchConfigurationAdded(lc2); - verify(provider).launchConfigurationAdded(lc2); - ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors(); - assertEquals(1, launchDescriptors.length); - assertNotNull(launchDescriptors[0]); - assertEquals(lc2.getName(), launchDescriptors[0].getName()); - manager.setActiveLaunchDescriptor(type.getDescriptor(lc2)); - assertEquals(localTargetType.getTargets()[0], manager.getActiveLaunchTarget()); - } - - @Test - public void testLaunchConfigurationAddedBad() throws CoreException { - provider = spy(provider); - basicSetup(); - doThrow(new NullPointerException()).when(provider).launchConfigurationAdded(any(ILaunchConfiguration.class)); - manager.launchConfigurationAdded(lc); - verify(provider).launchConfigurationAdded(lc); - } - - public DefaultLaunchDescriptorType addDefaultProvider() { - localTargetType = new LocalTargetType(); - manager.addTargetType(localTargetType); - DefaultLaunchDescriptorType type = new DefaultLaunchDescriptorType(); - manager.addDescriptorType(type, 1); - manager.addConfigProvider(type.getId(), localTargetType.getId(), false, new DefaultLaunchConfigurationProvider()); - return type; - } - - @Test - public void testLaunchConfigurationRemoved() throws CoreException { - provider = spy(provider); - basicSetup(); - manager.launchConfigurationRemoved(lc); - verify(provider).launchConfigurationRemoved(lc); - } - - @Test - public void testLaunchConfigurationRemovedNoClaim() throws CoreException { - manager = spy(manager); - addDefaultProvider(); - manager.launchConfigurationAdded(lc); - manager.launchConfigurationRemoved(lc); - verify(manager).launchObjectRemoved(lc); - } - - @Test - public void testLaunchConfigurationRemovedBad() throws CoreException { - provider = spy(provider); - basicSetup(); - doThrow(new NullPointerException()).when(provider).launchConfigurationRemoved(any(ILaunchConfiguration.class)); - manager.launchConfigurationRemoved(lc); - verify(provider).launchConfigurationRemoved(lc); - } - - public void testExtensionConfigDefaultProvider() throws CoreException { - IExtension extension = mock(IExtension.class); - doReturn(new IExtension[] { extension }).when(point).getExtensions(); - IConfigurationElement element = mock(IConfigurationElement.class); - IConfigurationElement targetElement = mock(IConfigurationElement.class); - mockTargetElement(targetElement, targetType); - doReturn("defaultConfigProvider").when(element).getName(); - doReturn(new IConfigurationElement[] { element, targetElement }).when(extension).getConfigurationElements(); - doReturn(targetType.getId()).when(element).getAttribute("targetType"); - doReturn(lctype.getIdentifier()).when(element).getAttribute("launchConfigurationType"); - manager = new FixedLaunchBarManager(); - targetType.targets.add(mytarget); - manager.launchObjectAdded(lc); - ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors(); - assertEquals(1, launchDescriptors.length); - assertNotNull(launchDescriptors[0]); - assertEquals(lc.getName(), launchDescriptors[0].getName()); - assertEquals(mytarget, manager.getActiveLaunchTarget()); - } - - private void mockTargetElement(IConfigurationElement element, TargetType targetType2) throws CoreException { - doReturn("targetType").when(element).getName(); - doReturn(targetType.getId()).when(element).getAttribute("id"); - doReturn(targetType).when(element).createExecutableExtension("class"); - } - - public void testExtensionDescriptorType() throws CoreException { - IExtension extension = mock(IExtension.class); - doReturn(new IExtension[] { extension }).when(point).getExtensions(); - IConfigurationElement element = mock(IConfigurationElement.class); - doReturn(new IConfigurationElement[] { element }).when(extension).getConfigurationElements(); - descType = spy(descType); - mockDescType(element, descType); - doReturn(new ILaunchConfiguration[] { lc }).when(lman).getLaunchConfigurations(); - store.put("activeConfigDesc", desc.getId()); - manager = new FixedLaunchBarManager(); - verify(descType).getDescriptor(lc); - ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors(); - assertEquals(1, launchDescriptors.length); - assertEquals(desc, launchDescriptors[0]); - // assertEquals(desc, descriptor); - } - - protected void mockDescType(IConfigurationElement element, ILaunchDescriptorType descType) throws CoreException { - doReturn("descriptorType").when(element).getName(); - doReturn(descType.getId()).when(element).getAttribute("id"); - doReturn("5").when(element).getAttribute("priority"); - doReturn(descType).when(element).createExecutableExtension("class"); - } - - public void testExtensionDescriptorTypeBad() throws CoreException { - IExtension extension = mock(IExtension.class); - doReturn(new IExtension[] { extension }).when(point).getExtensions(); - IConfigurationElement element = mock(IConfigurationElement.class); - doReturn(new IConfigurationElement[] { element }).when(extension).getConfigurationElements(); - descType = spy(descType); - mockDescType(element, descType); - doThrow(new CoreException(new Status(1, "a", "n"))).when(element).createExecutableExtension("class"); - doReturn(new ILaunchConfiguration[] { lc }).when(lman).getLaunchConfigurations(); - manager = new FixedLaunchBarManager(); - ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors(); - assertEquals(0, launchDescriptors.length); - } - - public void testExtensionDescriptorTypeBadId() throws CoreException { - IExtension extension = mock(IExtension.class); - doReturn(new IExtension[] { extension }).when(point).getExtensions(); - IConfigurationElement element = mock(IConfigurationElement.class); - doReturn(new IConfigurationElement[] { element }).when(extension).getConfigurationElements(); - descType = spy(descType); - mockDescType(element, descType); - doReturn(descType.getId() + "somestuff").when(element).getAttribute("id"); - doReturn(new ILaunchConfiguration[] { lc }).when(lman).getLaunchConfigurations(); - manager = new FixedLaunchBarManager(); - ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors(); - assertEquals(0, launchDescriptors.length); - } - - public void testExtensionDescriptorTypeBadPrio() throws CoreException { - IExtension extension = mock(IExtension.class); - doReturn(new IExtension[] { extension }).when(point).getExtensions(); - IConfigurationElement element = mock(IConfigurationElement.class); - doReturn(new IConfigurationElement[] { element }).when(extension).getConfigurationElements(); - descType = spy(descType); - mockDescType(element, descType); - - doReturn("5a").when(element).getAttribute("priority"); - doReturn(new ILaunchConfiguration[] { lc }).when(lman).getLaunchConfigurations(); - manager = new FixedLaunchBarManager(); - verify(descType).getDescriptor(lc); - assertEquals(desc, manager.getOpenLaunchDescriptors()[0]); - } - - public void testExtensionDescriptorTypeNoPrio() throws CoreException { - IExtension extension = mock(IExtension.class); - doReturn(new IExtension[] { extension }).when(point).getExtensions(); - IConfigurationElement element = mock(IConfigurationElement.class); - doReturn(new IConfigurationElement[] { element }).when(extension).getConfigurationElements(); - descType = spy(descType); - mockDescType(element, descType); - doReturn(null).when(element).getAttribute("priority"); - doReturn(new ILaunchConfiguration[] { lc }).when(lman).getLaunchConfigurations(); - manager = new FixedLaunchBarManager(); - verify(descType).getDescriptor(lc); - assertEquals(desc, manager.getOpenLaunchDescriptors()[0]); - } - - public void testExtensionTargetType() throws CoreException { - IExtension extension = mock(IExtension.class); - doReturn(new IExtension[] { extension }).when(point).getExtensions(); - IConfigurationElement targetElement = mock(IConfigurationElement.class); - mockTargetElement(targetElement, targetType); - doReturn(new IConfigurationElement[] { targetElement }).when(extension).getConfigurationElements(); - manager = new FixedLaunchBarManager(); - targetType.targets.add(mytarget); - ILaunchTarget launchTarget = manager.getLaunchTarget(mytarget.getId()); - assertEquals(mytarget, launchTarget); - } - - public void testExtensionTargetTypeBad() throws CoreException { - IExtension extension = mock(IExtension.class); - doReturn(new IExtension[] { extension }).when(point).getExtensions(); - IConfigurationElement targetElement = mock(IConfigurationElement.class); - mockTargetElement(targetElement, targetType); - doReturn(targetType.getId() + "some").when(targetElement).getAttribute("id"); - doReturn(new IConfigurationElement[] { targetElement }).when(extension).getConfigurationElements(); - manager = new FixedLaunchBarManager(); - targetType.targets.add(mytarget); - ILaunchTarget launchTarget = manager.getLaunchTarget(mytarget.getId()); - assertNull(launchTarget); - } - - public void testExtensionConfigProvider() throws CoreException { - IExtension extension = mock(IExtension.class); - doReturn(new IExtension[] { extension }).when(point).getExtensions(); - IConfigurationElement element = mock(IConfigurationElement.class); - IConfigurationElement targetElement = mock(IConfigurationElement.class); - IConfigurationElement descElement = mock(IConfigurationElement.class); - mockTargetElement(targetElement, targetType); - mockDescType(descElement, descType); - doReturn(new IConfigurationElement[] { element, targetElement, descElement }).when(extension).getConfigurationElements(); - doReturn("configProvider").when(element).getName(); - doReturn(targetType.getId()).when(element).getAttribute("targetType"); - doReturn(descType.getId()).when(element).getAttribute("descriptorType"); - doReturn(provider).when(element).createExecutableExtension("class"); - doReturn(new ILaunchConfiguration[] { lc }).when(lman).getLaunchConfigurations(); - targetType.targets.add(mytarget); - manager = new FixedLaunchBarManager(); - ILaunchDescriptor[] launchDescriptors = manager.getOpenLaunchDescriptors(); - assertEquals(1, launchDescriptors.length); - assertEquals(desc, launchDescriptors[0]); - assertEquals(mytarget, manager.getActiveLaunchTarget()); - } } diff --git a/launch/org.eclipse.cdt.launchbar.core/plugin.xml b/launch/org.eclipse.cdt.launchbar.core/plugin.xml index fc378e9d598..5d13b58ee97 100644 --- a/launch/org.eclipse.cdt.launchbar.core/plugin.xml +++ b/launch/org.eclipse.cdt.launchbar.core/plugin.xml @@ -4,21 +4,10 @@ - - + id="org.eclipse.cdt.launchbar.core.targetType.local"> - - diff --git a/launch/org.eclipse.cdt.launchbar.core/schema/launchBarContributions.exsd b/launch/org.eclipse.cdt.launchbar.core/schema/launchBarContributions.exsd index f9c33b79d68..36e5548a98a 100644 --- a/launch/org.eclipse.cdt.launchbar.core/schema/launchBarContributions.exsd +++ b/launch/org.eclipse.cdt.launchbar.core/schema/launchBarContributions.exsd @@ -20,8 +20,10 @@ + + @@ -51,6 +53,11 @@ + + + A descriptor represents an object that can be converted into a launch configuration. The typical example is IProject. Launch configurations can be created that launch the build output of the project. + + @@ -80,6 +87,11 @@ + + + A target is the machine you launch on. Typical examples include the local machine we are running on, or remote embedded or server targets. + + @@ -101,7 +113,12 @@ - + + + + Descriptor types and target types map to a launch configuration type. Configurations of that type knows how to launch for the desciptor on targets of that type. + + @@ -123,13 +140,13 @@ - + - + @@ -143,11 +160,10 @@ - + - default provider provides direct mapping between launch configuration types -and launch objects/types without any extra classes involved. The object for this provider is launch configuration, and descriptor is DefaultLaunchDescriptor + The config provider knows how to create launch configurations from descriptors. It tracks which configs it has created so that they don't show up as descriptors on their own. @@ -161,13 +177,33 @@ and launch objects/types without any extra classes involved. The object for this - + - + + + + + + + + + + + The default config provider is brought in when no other config providers claim a given launch configuration. This entry associates a target type with the launch configuration so that it can be launched on targets of that type. + + + + + + + + + + @@ -192,6 +228,11 @@ and launch objects/types without any extra classes involved. The object for this + + + Object providers pump launch objects into the model as they are created and removed. These are used to create descriptors for these objects. + + diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstarctLaunchDescriptorType.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstarctLaunchDescriptorType.java deleted file mode 100644 index 1c1891f01f0..00000000000 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstarctLaunchDescriptorType.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Elena Laskavaia - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.launchbar.core; - -/** - * Abstract launch descriptor type provide convenience methods to implement hashcode, equals and store lanch bar manager object. It - * is recommended to use this method instead of implementing interface - */ -public abstract class AbstarctLaunchDescriptorType implements ILaunchDescriptorType { - private ILaunchBarManager manager; - - @Override - public abstract String getId(); - - - @Override - public void init(ILaunchBarManager barmanager) { - this.manager = barmanager; - } - - @Override - public ILaunchBarManager getManager() { - return manager; - } - - @Override - public int hashCode() { - return 37 + getId().hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj.getClass().equals(getClass()))) - return false; - ILaunchDescriptorType other = (ILaunchDescriptorType) obj; - if (!getId().equals(other.getId())) - return false; - return true; - } - - @Override - public String toString() { - return getId(); - } -} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchConfigurationProvider.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchConfigurationProvider.java deleted file mode 100644 index acc54d03844..00000000000 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchConfigurationProvider.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Elena Laskavaia - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.launchbar.core; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchConfigurationType; - -/** - * Abstract provider can work with any ILaunchDescriptorConfigBased to provide launch configurations - */ -public abstract class AbstractLaunchConfigurationProvider implements ILaunchConfigurationProvider { - protected ILaunchBarManager manager; - - @Override - public void init(ILaunchBarManager manager) throws CoreException { - this.manager = manager; - } - - public ILaunchBarManager getManager() { - return manager; - } - - @Override - public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor) throws CoreException { - if (descriptor instanceof ILaunchDescriptorConfigBased) { - return ((ILaunchDescriptorConfigBased) descriptor).getLaunchConfiguration(); - } - return null; - } - - @Override - public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor) throws CoreException { - if (descriptor instanceof ILaunchDescriptorConfigBased) { - return ((ILaunchDescriptorConfigBased) descriptor).getLaunchConfigurationType(); - } - return null; - } - -} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchDescriptor.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchDescriptor.java deleted file mode 100644 index 10fee5686b1..00000000000 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchDescriptor.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Elena Laskavaia - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.launchbar.core; - -/** - * Convenience implementation of ILaunchDescriptor - */ -public abstract class AbstractLaunchDescriptor implements ILaunchDescriptor { - private boolean open = true; - - @Override - public abstract String getName(); - - @Override - public abstract ILaunchDescriptorType getType(); - - public String getId() { - return getName() + "." + getType().getId(); - } - - @Override - public int hashCode() { - return 17 + getId().hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof AbstractLaunchDescriptor)) - return false; - AbstractLaunchDescriptor other = (AbstractLaunchDescriptor) obj; - if (!getId().equals(other.getId())) - return false; - return true; - } - - @Override - public boolean isOpen() { - return open; - } - - public void setOpen(boolean open) { - this.open = open; - } -} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchTarget.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchTarget.java deleted file mode 100644 index 4046199d25c..00000000000 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchTarget.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Elena Laskavaia - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.launchbar.core; - -/** - * Convenience implementation of ILaunchTarget, provides hooks for id, and equals and hashcode methods based on id. - */ -public abstract class AbstractLaunchTarget implements ILaunchTarget { - private final String id; - - public AbstractLaunchTarget(String id) { - this.id = id; - } - - @Override - public String getId() { - return id; - } - - @Override - public String getName() { - return id; - } - - @Override - public abstract ILaunchTargetType getType(); - - @Override - public void setActive() { - // nothing to do - } - - @Override - public int hashCode() { - return 7 + getId().hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj.getClass().equals(getClass()))) - return false; - ILaunchDescriptorType other = (ILaunchDescriptorType) obj; - if (!getId().equals(other.getId())) - return false; - return true; - } -} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchTargetType.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchTargetType.java deleted file mode 100644 index e2a75132f72..00000000000 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/AbstractLaunchTargetType.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Elena Laskavaia - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.launchbar.core; - -/** - * Convenience implementation of ILaunchTargetType, provides equals and hashcode methods based on id. - */ -public abstract class AbstractLaunchTargetType implements ILaunchTargetType { - private ILaunchBarManager manager; - - @Override - public void init(ILaunchBarManager barmanager) { - this.manager = barmanager; - } - - public ILaunchBarManager getManager() { - return manager; - } - - @Override - public abstract String getId(); - - @Override - public int hashCode() { - return 7 + getId().hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj.getClass().equals(getClass()))) - return false; - ILaunchDescriptorType other = (ILaunchDescriptorType) obj; - if (!getId().equals(other.getId())) - return false; - return true; - } - - @Override - public ILaunchTarget getTarget(String id) { - if (id == null) - return null; - ILaunchTarget[] targets = getTargets(); - for (int i = 0; i < targets.length; i++) { - ILaunchTarget target = targets[i]; - if (target.getId().equals(id)) - return target; - } - return null; - } -} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchConfigurationProvider.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchConfigurationProvider.java deleted file mode 100644 index ca88f6afa7c..00000000000 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchConfigurationProvider.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Elena Laskavaia - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.launchbar.core; - -import java.util.HashMap; - -import org.eclipse.cdt.launchbar.core.internal.Activator; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchConfigurationType; - -public class ConfigBasedLaunchConfigurationProvider extends AbstractLaunchConfigurationProvider implements - ILaunchConfigurationProvider { - protected HashMap configMap = new HashMap<>(); - protected String typeId; - - public ConfigBasedLaunchConfigurationProvider(String launchConfigurationTypeId) { - this.typeId = launchConfigurationTypeId; - } - - public boolean ownsConfiguration(ILaunchConfiguration element) { - try { - // cannot use getType method when config is deleted, event sent after, no getters work on it - if (configMap.containsKey(element)) - return true; - return element.getType().getIdentifier().equals(typeId); - } catch (DebugException e) { - return false; // config does not exists, not point logging - } catch (CoreException e) { - Activator.log(e); - return false; - } - } - - @Override - public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException { - if (ownsConfiguration(configuration)) { - rememberConfiguration(configuration); - manager.launchObjectAdded(configuration); - return true; - } - return false; - } - - protected void rememberConfiguration(ILaunchConfiguration configuration) { - configMap.put(configuration, null); - } - - @Override - public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException { - if (ownsConfiguration(configuration)) { - manager.launchObjectRemoved(configuration); - forgetConfiguration(configuration); - return true; - } - return false; - } - - protected void forgetConfiguration(ILaunchConfiguration configuration) { - configMap.remove(configuration); - } - - @Override - public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor) throws CoreException { - ILaunchConfigurationType type = super.getLaunchConfigurationType(descriptor); - if (type!=null) return type; - return DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(typeId); - } - - @Override - public String toString() { - return "provider for " + typeId; - } -} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchDescriptor.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchDescriptor.java deleted file mode 100644 index 0c9c47e1825..00000000000 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchDescriptor.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alena Laskavaia - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.launchbar.core; - -import org.eclipse.cdt.launchbar.core.internal.Activator; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchConfigurationType; - -public class ConfigBasedLaunchDescriptor extends AbstractLaunchDescriptor implements ILaunchDescriptorConfigBased { - private final ILaunchDescriptorType type; - private ILaunchConfiguration config; - - public ConfigBasedLaunchDescriptor(ILaunchDescriptorType type, ILaunchConfiguration config) { - if (type == null) - throw new NullPointerException(); - this.type = type; - this.config = config; - } - - @Override - public String getName() { - if (config == null) - return "?"; - return config.getName(); - } - - @Override - public ILaunchDescriptorType getType() { - return type; - } - - public ILaunchConfiguration getLaunchConfiguration() { - return config; - } - - public ILaunchConfigurationType getLaunchConfigurationType() { - if (config != null) - try { - return config.getType(); - } catch (CoreException e) { - Activator.log(e); // can happened when config is deleted XXX hide in this case - } - if (type instanceof ConfigBasedLaunchDescriptorType) { - return ((ConfigBasedLaunchDescriptorType) type).getLaunchConfigurationType(); - } - throw new IllegalStateException("Cannot determine configuration type for " + this); - } - - @Override - public String toString() { - return "LC/" + getName(); - } - - public void setLaunchConfiguration(ILaunchConfiguration config) { - this.config = config; - } -} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchDescriptorType.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchDescriptorType.java deleted file mode 100644 index e02b1967054..00000000000 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ConfigBasedLaunchDescriptorType.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Elena Laskavaia - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.launchbar.core; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchConfigurationType; - -public class ConfigBasedLaunchDescriptorType extends AbstarctLaunchDescriptorType implements ILaunchDescriptorType { - private String id; - private String typeId; - - public ConfigBasedLaunchDescriptorType(String descTypeId, String launchConfigurationTypeId) { - if (launchConfigurationTypeId == null) - throw new NullPointerException(); - this.typeId = launchConfigurationTypeId; - this.id = descTypeId != null ? descTypeId : launchConfigurationTypeId; - } - - public ConfigBasedLaunchDescriptorType(String launchConfigurationTypeId) { - this(null, launchConfigurationTypeId); - } - - public boolean ownsConfiguration(ILaunchConfiguration element) { - try { - return element.getType().getIdentifier().equals(typeId); - } catch (CoreException e) { - return false; - } - } - - @Override - public ILaunchDescriptor getDescriptor(Object element) { - return new ConfigBasedLaunchDescriptor(this, (ILaunchConfiguration) element); - } - - @Override - public boolean ownsLaunchObject(Object element) { - return element instanceof ILaunchConfiguration - && ownsConfiguration((ILaunchConfiguration) element); - } - - @Override - public String getId() { - return id; - } - - public ILaunchConfigurationType getLaunchConfigurationType() { - return DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(typeId); - } - - @Override - public String toString() { - return "type for " + typeId; - } -} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchBarManager.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchBarManager.java index 36d30a1aee7..ac5bbe0d3bc 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchBarManager.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchBarManager.java @@ -11,71 +11,58 @@ package org.eclipse.cdt.launchbar.core; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchConfigurationType; -import org.eclipse.debug.core.ILaunchMode; -public interface ILaunchBarManager extends IAdaptable { +public interface ILaunchBarManager { - ILaunchDescriptor[] getLaunchDescriptors(); + /** + * A launch object has been added. Create a matching launch descriptor if available. + * + * @param element launch object + * @return the launch descriptor that got created, null of none was + * @throws CoreException + */ + ILaunchDescriptor launchObjectAdded(Object launchObject) throws CoreException; - ILaunchDescriptor[] getOpenLaunchDescriptors(); + /** + * A launch object has been removed. Remove the associated launch descriptor if there is one. + * + * @param element launch object + * @throws CoreException + */ + void launchObjectRemoved(Object launchObject) throws CoreException; - ILaunchDescriptor getActiveLaunchDescriptor() throws CoreException; - - void setActiveLaunchDescriptor(ILaunchDescriptor configDesc) throws CoreException; - - void updateLaunchDescriptor(ILaunchDescriptor configDesc) throws CoreException; - - ILaunchMode[] getLaunchModes() throws CoreException; - - ILaunchMode getActiveLaunchMode() throws CoreException; - - void setActiveLaunchMode(ILaunchMode mode) throws CoreException; - - ILaunchTarget[] getLaunchTargets() throws CoreException; - - ILaunchTarget getLaunchTarget(String id) throws CoreException; - - ILaunchTarget getActiveLaunchTarget() throws CoreException; - - void setActiveLaunchTarget(ILaunchTarget target) throws CoreException; - - void updateLaunchTarget(ILaunchTarget target) throws CoreException; + /** + * A launch object has changed in some way that affects the launch bar. + * + * @param launchObject + * @throws CoreException + */ + void launchObjectChanged(Object launchObject) throws CoreException; + /** + * A new launch target has been added. + * + * @param target launch target + * @throws CoreException + */ void launchTargetAdded(ILaunchTarget target) throws CoreException; + /** + * A launch target has been removed. + * + * @param target launch target + * @throws CoreException + */ void launchTargetRemoved(ILaunchTarget target) throws CoreException; - ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException; + /** + * The launch target has changed in some way that affects the + * launch bar. + * + * @param target launch target + */ + void launchTargetChanged(ILaunchTarget target); - ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException; - - ILaunchDescriptor launchObjectAdded(Object element) throws CoreException; - - void launchObjectRemoved(Object element) throws CoreException; - - ILaunchDescriptor launchObjectChanged(Object element) throws CoreException; - - ILaunchDescriptor getLaunchDescriptor(Object element); - - interface Listener { - - void activeConfigurationDescriptorChanged(); - - void activeLaunchModeChanged(); - - void activeLaunchTargetChanged(); - - void launchDescriptorRemoved(ILaunchDescriptor descriptor); - - void launchTargetsChanged(); - - } - - void addListener(Listener listener); - - void removeListener(Listener listener); + // TODO API for adding and removing types. } diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchConfigurationProvider.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchConfigurationProvider.java index 52c12c60295..f2910fb2445 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchConfigurationProvider.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchConfigurationProvider.java @@ -13,36 +13,41 @@ package org.eclipse.cdt.launchbar.core; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchManager; +/** + * The provider of launch configurations of a given type for a given descriptor type + * and a given target type. + */ public interface ILaunchConfigurationProvider { - /** - * Do any initialization. - * - * @param manager - * @throws CoreException - */ - void init(ILaunchBarManager manager) throws CoreException; - /** * Does this provider own this launch configuration. If so, make sure the launch descriptor * is properly constructed by sending in a launch object to the launch manager. + * And return that object. * * @param configuration - * @return boolean - was the launch configuration added by this provider? + * @return launch object that relates to this config * @throws CoreException */ - boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException; - + Object launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException; + /** - * Returns the launch configuration type used to launch the descriptor on this target type. + * A launch configuration has been removed. + * + * @param configuration + * @return was the launch configuration removed by this provider? + * @throws CoreException + */ + boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException; + + /** + * Returns the launch configuration type for configurations created by this provider. * - * @param descriptor - * @param target * @return launch configuration type * @throws CoreException */ - ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor) throws CoreException; + ILaunchConfigurationType getLaunchConfigurationType() throws CoreException; /** * Create a launch configuration for the descriptor to launch on the target. @@ -52,15 +57,6 @@ public interface ILaunchConfigurationProvider { * @return launch configuration * @throws CoreException */ - ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor) throws CoreException; - - /** - * A launch configuration has been removed. - * - * @param configuration - * @return boolean - was the launch configuration removed by this provider? - * @throws CoreException - */ - boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException; + ILaunchConfiguration createLaunchConfiguration(ILaunchManager launchManager, ILaunchDescriptor descriptor) throws CoreException; } diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptor.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptor.java index d0969afda04..b5d6f7fb2c9 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptor.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptor.java @@ -10,26 +10,24 @@ *******************************************************************************/ package org.eclipse.cdt.launchbar.core; +import org.eclipse.core.runtime.IAdaptable; + /** * Represents a thing that can be launched. + * It is good practice that the descriptor is adaptable to the launch object + * it is representing. */ -public interface ILaunchDescriptor { +public interface ILaunchDescriptor extends IAdaptable { /** * Name to show in the launch descriptor selector. + * Names must be unique for all descriptors of a given type. * * @return name of the launch descriptor */ String getName(); - /** - * Unique id of the descriptor (globally) - * - * @return the non null string representing id of the launch descriptor - */ - String getId(); - /** * The type of launch descriptor. * @@ -37,9 +35,4 @@ public interface ILaunchDescriptor { */ ILaunchDescriptorType getType(); - /** - * Descriptor considered open when it is visible to user, and closed otherwise - */ - boolean isOpen(); - } diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorConfigBased.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorConfigBased.java deleted file mode 100644 index 5fe878b6bb0..00000000000 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorConfigBased.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Doug Schaefer - *******************************************************************************/ -package org.eclipse.cdt.launchbar.core; - -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchConfigurationType; - -/** - * Interface for descriptors which are based on launch configurations - */ -public interface ILaunchDescriptorConfigBased extends ILaunchDescriptor { - /** - * Return launch configuration on which it is based (can be null) - */ - public ILaunchConfiguration getLaunchConfiguration(); - - /** - * Return launch configuration type on which it is based (cannot be null) - * - * @NonNull - */ - public ILaunchConfigurationType getLaunchConfigurationType(); -} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorType.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorType.java index 98e1f9b2cd5..564aee33129 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorType.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorType.java @@ -20,46 +20,26 @@ import org.eclipse.core.runtime.CoreException; public interface ILaunchDescriptorType { /** - * The id for the provider. + * Does this type own this launch object? * - * @return provider id - */ - String getId(); - - /** - * Called after existing launch configs have been added. The provider - * can now add any more that they'd like to have. - */ - void init(ILaunchBarManager manager); - - /** - * Does this type own this launch element. + * @deprecated this needs to be replaced by enablement to avoid plug-in loading. * * @param element * @return owns element * @throws CoreException */ - boolean ownsLaunchObject(Object element) throws CoreException; - + boolean ownsLaunchObject(Object launchObject) throws CoreException; + /** - * Return a descriptor for the given element. The element can be a launch - * configuration, a project, or anything else that gets fed to the - * launch bar manager. + * Return a descriptor for the given launch object. * * May return null to essentially eat the element so no other types * create a descriptor for it. * - * @param descriptor candidate descriptor + * @param descriptor launch object for descriptor * @return the best descriptor * @throws CoreException */ - ILaunchDescriptor getDescriptor(Object element) throws CoreException; - - /** - * Return a handle to the launch bar manager. - * - * @return launchbar manager - */ - ILaunchBarManager getManager(); + ILaunchDescriptor getDescriptor(Object launchObject) throws CoreException; } diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchObjectProvider.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchObjectProvider.java index 82520fb027f..25426ea2ad9 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchObjectProvider.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchObjectProvider.java @@ -1,5 +1,7 @@ package org.eclipse.cdt.launchbar.core; +import org.eclipse.core.runtime.CoreException; + /** * An extension that serves up objects to feed launch descriptors. * @@ -7,11 +9,12 @@ package org.eclipse.cdt.launchbar.core; public interface ILaunchObjectProvider { /** - * Add initial launch descriptors and set up listeners. + * Add initial launch descriptors and set up for new ones. * * @param launchbar manager + * @throws CoreException */ - void init(ILaunchBarManager manager); + void init(ILaunchBarManager manager) throws CoreException; /** * Shutting down, remove any listeners. diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchTarget.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchTarget.java index d6899a084d6..d5f01c1d661 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchTarget.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchTarget.java @@ -10,33 +10,30 @@ *******************************************************************************/ package org.eclipse.cdt.launchbar.core; -public interface ILaunchTarget { +import org.eclipse.core.runtime.IAdaptable; + +public interface ILaunchTarget extends IAdaptable { /** - * Get the id for the target. The id of the active target is - * stored in the preference store. + * Returns the name of this target. + * Names must be unique across all targets of a given type. * - * @return id - */ - String getId(); - - /** - * Returns a name to show in the UI for this target. - * - * @return name + * @return name of the target */ String getName(); /** * Returns the type for this target. * - * @return target type + * @return type of the target */ ILaunchTargetType getType(); /** - * This target has been made active. + * The active state of this target has changed. + * + * @param active active state of the target */ - void setActive(); + void setActive(boolean active); } diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchTargetType.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchTargetType.java index f292a929faf..361f8b210f5 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchTargetType.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchTargetType.java @@ -10,35 +10,21 @@ *******************************************************************************/ package org.eclipse.cdt.launchbar.core; +import org.eclipse.core.runtime.CoreException; + public interface ILaunchTargetType { /** - * Called by the launchbar manager to initialize and pass a hendle to itself. + * Add initial targets and set up any listeners. * * @param manager + * @throws CoreException */ - void init(ILaunchBarManager manager); + void init(ILaunchBarManager manager) throws CoreException; /** - * The id of the target type. - * - * @return target type id + * Shutting down, remove any listeners */ - String getId(); - - /** - * Return the list of targets for this type. - * - * @return targets - */ - ILaunchTarget[] getTargets(); - - /** - * Return the target with the specified id. - * - * @param id - * @return target - */ - ILaunchTarget getTarget(String id); + void dispose(); } diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/LaunchConfigurationProvider.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/LaunchConfigurationProvider.java new file mode 100644 index 00000000000..9fa3cf3e202 --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/LaunchConfigurationProvider.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2014 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Doug Schaefer + *******************************************************************************/ +package org.eclipse.cdt.launchbar.core; + +import org.eclipse.cdt.launchbar.core.internal.Activator; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.ILaunchManager; + +/** + * A root class for launch configuration providers. Provides the ability to detect launch + * configurations that it has created. + */ +public abstract class LaunchConfigurationProvider implements ILaunchConfigurationProvider { + + // Used to make sure this is the config we've created + protected static final String ORIGINAL_NAME = Activator.PLUGIN_ID + ".originalName"; + + @Override + public ILaunchConfiguration createLaunchConfiguration(ILaunchManager launchManager, ILaunchDescriptor descriptor) throws CoreException { + String name = launchManager.generateLaunchConfigurationName(getConfigurationName(descriptor)); + ILaunchConfigurationWorkingCopy wc = getLaunchConfigurationType().newInstance(null, name); + wc.setAttribute(ORIGINAL_NAME, name); + populateConfiguration(wc, descriptor); + return wc.doSave(); + } + + /** + * Potential name for new configurations. Names are still put through the launch manager + * to ensure they are unique. + * + * @param descriptor the launch descriptor triggering the configuration creation + * @return candidate configuration name + */ + protected String getConfigurationName(ILaunchDescriptor descriptor) { + // by default, use the descriptor name + return descriptor.getName(); + } + + /** + * Populate the new configuration with attributes and resources. + * + * @param workingCopy working copy for the new configuration + * @param descriptor the launch descriptor that triggered the new configuration + * @throws CoreException + */ + protected void populateConfiguration(ILaunchConfigurationWorkingCopy workingCopy, ILaunchDescriptor descriptor) throws CoreException { + // by default, nothing to add + } + + /** + * Determines if we created this launch configuration. Generally used by the launch configuration + * add handler to determine if the incoming launch configuration is ours. + * + * @param configuration + * @return do we own this launch configuration + * @throws CoreException + */ + protected boolean ownsConfiguration(ILaunchConfiguration configuration) throws CoreException { + // must be the same config type + if (!configuration.getType().equals(getLaunchConfigurationType())) + return false; + + // we created it if it has the same name we created it with + return configuration.getAttribute(ORIGINAL_NAME, "").equals(configuration.getName()); + } + +} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ProjectBasedLaunchConfigurationProvider.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ProjectBasedLaunchConfigurationProvider.java deleted file mode 100644 index 429e2ddb545..00000000000 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ProjectBasedLaunchConfigurationProvider.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alena Laskavaia - Initial API and implementationn - *******************************************************************************/ -package org.eclipse.cdt.launchbar.core; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.ILaunchConfiguration; - -public abstract class ProjectBasedLaunchConfigurationProvider extends ConfigBasedLaunchConfigurationProvider { - public ProjectBasedLaunchConfigurationProvider(String launchConfigurationTypeId) { - super(launchConfigurationTypeId); - } - - @Override - public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException { - if (!super.launchConfigurationAdded(configuration)) return false; - IProject project = getProject(configuration); - getManager().launchObjectChanged(project); - return true; - } - - @Override - public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException { - if (!ownsConfiguration(configuration)) - return false; - IProject project = (IProject) configMap.get(configuration); // cannot use getters from configuration, it is deleted - if (!super.launchConfigurationRemoved(configuration)) return false; - if (project != null) - getManager().launchObjectChanged(project); - return true; - } - - protected void rememberConfiguration(ILaunchConfiguration configuration) { - configMap.put(configuration, getProject(configuration)); - } - - protected abstract IProject getProject(ILaunchConfiguration llc); -} \ No newline at end of file diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ProjectBasedLaunchDescriptor.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ProjectBasedLaunchDescriptor.java deleted file mode 100644 index 4768b8e873b..00000000000 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ProjectBasedLaunchDescriptor.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alena Laskavaia - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.launchbar.core; - -import org.eclipse.core.resources.IProject; -import org.eclipse.debug.core.ILaunchConfiguration; - -public class ProjectBasedLaunchDescriptor extends ConfigBasedLaunchDescriptor implements ILaunchDescriptorProjectBased { - private IProject project; - - public ProjectBasedLaunchDescriptor(ILaunchDescriptorType type, IProject p, ILaunchConfiguration lc) { - super(type, lc); - if (p == null) - throw new NullPointerException(); - this.project = p; - } - - @Override - public String getName() { - ILaunchConfiguration lc = getLaunchConfiguration(); - if (lc != null) - return lc.getName(); - return project.getName(); - } - - @Override - public IProject getProject() { - return project; - } - - @Override - public String toString() { - ILaunchConfiguration lc = getLaunchConfiguration(); - if (lc != null) - return "LC/" + lc.getName(); - return "P/" + project.getName(); - } -} \ No newline at end of file diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ProjectBasedLaunchDescriptorType.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ProjectBasedLaunchDescriptorType.java deleted file mode 100644 index c1f087e36e4..00000000000 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ProjectBasedLaunchDescriptorType.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alena Laskavaia - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.launchbar.core; - -import org.eclipse.core.resources.IProject; -import org.eclipse.debug.core.ILaunchConfiguration; - -public abstract class ProjectBasedLaunchDescriptorType extends ConfigBasedLaunchDescriptorType { - public ProjectBasedLaunchDescriptorType(String descTypeId, String launchConfigTypeId) { - super(descTypeId, launchConfigTypeId); - } - - @Override - public boolean ownsLaunchObject(Object element) { - if (super.ownsLaunchObject(element)) - return true; - if (element instanceof IProject && ((IProject) element).isOpen() && ownsProject((IProject) element)) - return true; - return false; - } - - public boolean ownsConfiguration(ILaunchConfiguration element) { - return super.ownsConfiguration(element) && getProject(element) != null; - } - - protected boolean ownsLaunchDescriptor(ILaunchDescriptor ld) { - if (!(ld instanceof ProjectBasedLaunchDescriptorType)) - return false; - ProjectBasedLaunchDescriptorType other = (ProjectBasedLaunchDescriptorType) ld; - return other.getLaunchConfigurationType().equals(getLaunchConfigurationType()); - } - - protected abstract boolean ownsProject(IProject element); - - @Override - public ILaunchDescriptor getDescriptor(Object element) { - if (element instanceof ILaunchConfiguration) { - ILaunchConfiguration llc = (ILaunchConfiguration) element; - IProject project = getProject(llc); - if (project == null) - return null; - // TODO we need disable project based descriptor here - return new ProjectBasedLaunchDescriptor(this, project, llc); - } else if (element instanceof IProject) { - // this type creates two versions of the descriptor - launch config based - // and project based. Project based do not have a config. If at least one - // launch config created, associated with same project, we don't need descriptor with null config - // anymore so we return null in this case - IProject project = (IProject) element; - ProjectBasedLaunchDescriptor desc = new ProjectBasedLaunchDescriptor(this, project, null); - ILaunchDescriptor[] lds = getManager().getLaunchDescriptors(); - for (int i = 0; i < lds.length; i++) { - ILaunchDescriptor ld = lds[i]; - if (isBetter(ld, desc)) { - return null;// there is a better descriptor already - } - } - return desc; - } - return null; - } - - /** - * Return true is a is better then b (which would eliminate b) - */ - protected boolean isBetter(ILaunchDescriptor a, ILaunchDescriptor b) { - if (a instanceof ProjectBasedLaunchDescriptor && b instanceof ProjectBasedLaunchDescriptor) { - ProjectBasedLaunchDescriptor pa = (ProjectBasedLaunchDescriptor) a; - ProjectBasedLaunchDescriptor pb = (ProjectBasedLaunchDescriptor) b; - if (pb.getProject().equals(pa.getProject()) - && pa.getLaunchConfigurationType().equals(pb.getLaunchConfigurationType()) - && pa.getLaunchConfiguration() != null - && pb.getLaunchConfiguration() == null) { - // a is for same project and same type, but actually have non-null configuraton - return true; - } - } - return false; - } - - protected abstract IProject getProject(ILaunchConfiguration llc); -} \ No newline at end of file diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ProjectLaunchConfigurationProvider.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ProjectLaunchConfigurationProvider.java new file mode 100644 index 00000000000..38aa0203a5b --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ProjectLaunchConfigurationProvider.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2014 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Doug Schaefer + *******************************************************************************/ +package org.eclipse.cdt.launchbar.core; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; + +/** + * A root launch configuration provider that can be used with project launch descriptors. + * Takes ownership of configurations we've created that map to the the project. + */ +public abstract class ProjectLaunchConfigurationProvider extends LaunchConfigurationProvider { + + @Override + protected void populateConfiguration(ILaunchConfigurationWorkingCopy workingCopy, ILaunchDescriptor descriptor) throws CoreException { + super.populateConfiguration(workingCopy, descriptor); + + // Add our project to the mapped resources + IProject project = (IProject) descriptor.getAdapter(IProject.class); + IResource[] mappedResources = workingCopy.getMappedResources(); + if (mappedResources == null || mappedResources.length == 0) { + workingCopy.setMappedResources(new IResource[] { project }); + } else { + IResource[] newResources = new IResource[mappedResources.length + 1]; + System.arraycopy(mappedResources, 0, newResources, 0, mappedResources.length); + newResources[mappedResources.length] = project; + workingCopy.setMappedResources(newResources); + } + } + + /** + * Extract the project from the launch configuration. Used when checking if we own it. + * + * @param configuration + * @return project for launch configuration. + * @throws CoreException + */ + protected IProject getProject(ILaunchConfiguration configuration) throws CoreException { + // by default return the first project in the mapped resources + for (IResource resource : configuration.getMappedResources()) { + if (resource instanceof IProject) { + return (IProject) resource; + } + } + + return null; + } + + @Override + public Object launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException { + if (!ownsConfiguration(configuration)) { + return null; + } + + IProject project = getProject(configuration); + if (project == null) { + // The user must have changed project. We don't own it any more in that case. + return null; + } + + return project; + } + + @Override + public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException { + return ownsConfiguration(configuration); + } + +} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ProjectLaunchDescriptor.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ProjectLaunchDescriptor.java new file mode 100644 index 00000000000..9d9fc1dd408 --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ProjectLaunchDescriptor.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2014 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Doug Schaefer + *******************************************************************************/ +package org.eclipse.cdt.launchbar.core; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.PlatformObject; + +/** + * A reusable descriptor for wrapping projects that can be used by descriptor types + * that map to projects. + */ +public class ProjectLaunchDescriptor extends PlatformObject implements ILaunchDescriptor { + + private final ILaunchDescriptorType type; + private final IProject project; + + public ProjectLaunchDescriptor(ILaunchDescriptorType type, IProject project) { + this.type = type; + this.project = project; + } + + @Override + public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { + if (IProject.class.equals(adapter)) { + return project; + } + return super.getAdapter(adapter); + } + + @Override + public String getName() { + return project.getName(); + } + + @Override + public ILaunchDescriptorType getType() { + return type; + } + +} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/Activator.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/Activator.java index 5efa65a6d29..0352d6240d5 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/Activator.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/Activator.java @@ -16,49 +16,36 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; -import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceFactory; -import org.osgi.framework.ServiceRegistration; public class Activator extends Plugin { public static final String PLUGIN_ID = "org.eclipse.cdt.launchbar.core"; - private static Plugin plugin; + private static Activator plugin; private LaunchBarManager launchBarManager; public void start(BundleContext bundleContext) throws Exception { super.start(bundleContext); plugin = this; - - bundleContext.registerService(ILaunchBarManager.class, new ServiceFactory() { - @Override - public synchronized ILaunchBarManager getService(Bundle bundle, ServiceRegistration registration) { - if (launchBarManager == null) { - try { - launchBarManager = new LaunchBarManager(); - } catch (CoreException e) { - // TODO log - e.printStackTrace(); - } - } - return launchBarManager; - } - - @Override - public synchronized void ungetService(Bundle bundle, - ServiceRegistration registration, - ILaunchBarManager service) { - } - }, null); + launchBarManager = new LaunchBarManager(); + bundleContext.registerService(ILaunchBarManager.class, launchBarManager, null); } public void stop(BundleContext bundleContext) throws Exception { super.stop(bundleContext); plugin = null; + launchBarManager.dispose(); launchBarManager = null; } + public static Activator getDefault() { + return plugin; + } + + public LaunchBarManager getLaunchBarManager() { + return launchBarManager; + } + public static void throwCoreException(Exception e) throws CoreException { throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e)); } @@ -75,7 +62,7 @@ public class Activator extends Plugin { } private static final String DEBUG_ONE = - PLUGIN_ID + "/debug/launchbar"; + PLUGIN_ID + "/debug/launchbar"; public static void trace(String str) { if (plugin == null || (plugin.isDebugging() && "true".equalsIgnoreCase(Platform.getDebugOption(DEBUG_ONE)))) diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchConfigurationProvider.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchConfigurationProvider.java deleted file mode 100644 index 01a7d827282..00000000000 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchConfigurationProvider.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.eclipse.cdt.launchbar.core.internal; - -import org.eclipse.cdt.launchbar.core.AbstractLaunchConfigurationProvider; -import org.eclipse.cdt.launchbar.core.ILaunchConfigurationProvider; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.ILaunchConfiguration; - -public class DefaultLaunchConfigurationProvider extends AbstractLaunchConfigurationProvider implements ILaunchConfigurationProvider { - @Override - public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException { - // We may own it but return false to let it percolate through to the descriptor type. - return false; - } - - @Override - public boolean launchConfigurationRemoved(ILaunchConfiguration configation) throws CoreException { - return false; - } -} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptor.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptor.java index 18377e25dc5..5038eff773e 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptor.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptor.java @@ -10,14 +10,41 @@ *******************************************************************************/ package org.eclipse.cdt.launchbar.core.internal; -import org.eclipse.cdt.launchbar.core.ConfigBasedLaunchDescriptor; +import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType; +import org.eclipse.core.runtime.PlatformObject; import org.eclipse.debug.core.ILaunchConfiguration; +/** + * A special launch descriptor that managed configurations that aren't owned by other + * descriptors. + */ +public class DefaultLaunchDescriptor extends PlatformObject implements ILaunchDescriptor { -public class DefaultLaunchDescriptor extends ConfigBasedLaunchDescriptor { + private final DefaultLaunchDescriptorType type; + private final ILaunchConfiguration configuration; - public DefaultLaunchDescriptor(ILaunchDescriptorType type, ILaunchConfiguration config) { - super(type, config); + public DefaultLaunchDescriptor(DefaultLaunchDescriptorType type, ILaunchConfiguration configuration) { + this.type = type; + this.configuration = configuration; } + + @Override + public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { + if (ILaunchConfiguration.class.equals(adapter)) { + return configuration; + } + return super.getAdapter(adapter); + } + + @Override + public String getName() { + return configuration.getName(); + } + + @Override + public ILaunchDescriptorType getType() { + return type; + } + } diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptorType.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptorType.java index c5d4ee8c5a5..79dd1c318c2 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptorType.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/DefaultLaunchDescriptorType.java @@ -1,24 +1,41 @@ package org.eclipse.cdt.launchbar.core.internal; -import org.eclipse.cdt.launchbar.core.AbstarctLaunchDescriptorType; +import java.util.HashMap; +import java.util.Map; + import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType; import org.eclipse.debug.core.ILaunchConfiguration; -public class DefaultLaunchDescriptorType extends AbstarctLaunchDescriptorType implements ILaunchDescriptorType { - public static final String ID = "org.eclipse.cdt.launchbar.core.descriptor.default"; +/** + * A special descriptor type that managed configurations that aren't owned + * by other descriptor types. + */ +public class DefaultLaunchDescriptorType implements ILaunchDescriptorType { + + public static final String ID = Activator.PLUGIN_ID + ".descriptorType.default"; + + private Map descriptors = new HashMap<>(); - @Override - public String getId() { - return ID; - } @Override public boolean ownsLaunchObject(Object element) { - return element instanceof ILaunchConfiguration; + // This descriptor type doesn't own any launch objects + return false; } @Override public ILaunchDescriptor getDescriptor(Object element) { - return new DefaultLaunchDescriptor(this, (ILaunchConfiguration) element); + if (element instanceof ILaunchConfiguration) { + ILaunchConfiguration config = (ILaunchConfiguration) element; + DefaultLaunchDescriptor descriptor = descriptors.get(config); + if (descriptor == null) { + descriptor = new DefaultLaunchDescriptor(this, config); + descriptors.put(config, descriptor); + } + return descriptor; + } + + return null; } + } diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/ExecutableExtension.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/ExecutableExtension.java new file mode 100644 index 00000000000..594fdef9175 --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/ExecutableExtension.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2014 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Doug Schaefer + *******************************************************************************/ +package org.eclipse.cdt.launchbar.core.internal; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; + +/** + * A wrapper class that delays instantiation of classes until they're needed + * to prevent early plug-in loading. + * + * @param the type of the object created + */ +public class ExecutableExtension { + + private IConfigurationElement element; + private String propertyName; + private T object; + + public ExecutableExtension(IConfigurationElement element, String propertyName) { + this.element = element; + this.propertyName = propertyName; + } + + // For testing, pre-populate the object + public ExecutableExtension(T object) { + this.object = object; + } + + /** + * Get the object instantiating it if necessary. + * @return object + * @throws CoreException + */ + @SuppressWarnings("unchecked") + public T get() throws CoreException { + if (element != null) { + object = (T) element.createExecutableExtension(propertyName); + element = null; + propertyName = null; + } + return object; + } + +} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManager.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManager.java index 01f4e238d3b..69fc1614db9 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManager.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LaunchBarManager.java @@ -12,20 +12,19 @@ package org.eclipse.cdt.launchbar.core.internal; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; -import org.eclipse.cdt.launchbar.core.ConfigBasedLaunchConfigurationProvider; -import org.eclipse.cdt.launchbar.core.ConfigBasedLaunchDescriptorType; import org.eclipse.cdt.launchbar.core.ILaunchBarManager; import org.eclipse.cdt.launchbar.core.ILaunchConfigurationProvider; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; -import org.eclipse.cdt.launchbar.core.ILaunchDescriptorConfigBased; import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType; import org.eclipse.cdt.launchbar.core.ILaunchObjectProvider; import org.eclipse.cdt.launchbar.core.ILaunchTarget; @@ -34,8 +33,9 @@ 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.ISafeRunnable; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.core.runtime.SafeRunner; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.debug.core.DebugPlugin; @@ -47,54 +47,241 @@ import org.eclipse.debug.core.ILaunchMode; import org.osgi.service.prefs.BackingStoreException; import org.osgi.service.prefs.Preferences; -public class LaunchBarManager extends PlatformObject implements ILaunchBarManager, ILaunchConfigurationListener { - private List listeners = new LinkedList<>(); - private Map targetTypes = new HashMap<>(); - private LinkedHashMap descriptorTypes = new LinkedHashMap<>(); - private final Map descriptors = new LinkedHashMap<>(); - private List objectProviders = new ArrayList<>(); - // Map descriptor type to target type to provider - private Map> configProviders = new HashMap<>(); - // Map descriptor type to target type - private Map defaultTargetTypes = new HashMap<>(); - private Map objectDescriptorMap = new HashMap<>(); +/** + * The brains of the launch bar. + */ +public class LaunchBarManager implements ILaunchBarManager, ILaunchConfigurationListener { + + // TODO make these more fine grained or break them into more focused listeners + public interface Listener { + void activeConfigurationDescriptorChanged(); + void activeLaunchModeChanged(); + void activeLaunchTargetChanged(); + void launchDescriptorRemoved(ILaunchDescriptor descriptor); + void launchTargetsChanged(); + } + + public static class LaunchTargetTypeInfo { + private final ILaunchTargetType type; + private final String id; + + public LaunchTargetTypeInfo(String id, ILaunchTargetType type) { + this.type = type; + this.id = id; + } + + public String getId() { + return id; + } + + public ILaunchTargetType getType() { + return type; + } + } + + public static class LaunchDescriptorTypeInfo { + private final String id; + private final int priority; + private IConfigurationElement element; + private ILaunchDescriptorType type; + + public LaunchDescriptorTypeInfo(String id, int priority, IConfigurationElement element) { + this.id = id; + this.priority = priority; + this.element = element; + } + + // Used for testing + public LaunchDescriptorTypeInfo(String id, int priority, ILaunchDescriptorType type) { + this.id = id; + this.priority = priority; + this.type = type; + } + + public String getId() { + return id; + } + + public int getPriority() { + return priority; + } + + public ILaunchDescriptorType getType() throws CoreException { + if (type == null) { + type = (ILaunchDescriptorType) element.createExecutableExtension("class"); + element = null; + } + return type; + } + } + + public static class LaunchConfigProviderInfo { + private final String launchConfigTypeId; + private IConfigurationElement element; + private ILaunchConfigurationProvider provider; + + public LaunchConfigProviderInfo(String launchConfigTypeId, IConfigurationElement element) { + this.launchConfigTypeId = launchConfigTypeId; + this.element = element; + } + + // For testing + public LaunchConfigProviderInfo(String launchConfigTypeId, ILaunchConfigurationProvider provider) { + this.launchConfigTypeId = launchConfigTypeId; + this.provider = provider; + } + + public String getLaunchConfigTypeId() { + return launchConfigTypeId; + } + + public ILaunchConfigurationProvider getProvider() throws CoreException { + if (provider == null) { + provider = (ILaunchConfigurationProvider) element.createExecutableExtension("class"); + element = null; + } + return provider; + } + } + + public static class LaunchConfigTypeInfo { + private final String descriptorTypeId; + private final String targetTypeId; + private final String launchConfigTypeId; + + public LaunchConfigTypeInfo(String descriptorTypeId, String targetTypeId, String launchConfigTypeId) { + this.descriptorTypeId = descriptorTypeId; + this.targetTypeId = targetTypeId; + this.launchConfigTypeId = launchConfigTypeId; + } + + public String getDescriptorTypeId() { + return descriptorTypeId; + } + + public String getTargetTypeId() { + return targetTypeId; + } + + public String getLaunchConfigTypeId() { + return launchConfigTypeId; + } + } + + private final List listeners = new LinkedList<>(); + + // The launch object providers + private final List objectProviders = new ArrayList<>(); + + // The target types by id - doesn't need to be an executablExtension since it runs right away + private final Map targetTypes = new HashMap<>(); + + // The extended info for the target types as specified in the extension + private final Map targetTypeInfo = new HashMap<>(); + + // The descriptor types + private final Map descriptorTypes = new HashMap<>(); + + // the extended info for loaded descriptor types + private final Map descriptorTypeInfo = new HashMap<>(); + + // Descriptor types ordered from highest priority to lowest + private final List orderedDescriptorTypes = new LinkedList<>(); + + // The mapping from descriptor type to target type to config type info + private final Map> configTypes = new HashMap<>(); + + // Map descriptor type to target type so we can build when no targets have been added + private final Map defaultTargetTypes = new HashMap<>(); + + // The launch config providers + private final Map configProviders = new HashMap<>(); + + // Map from launch config type id to target type id for default config descriptor + private final Map> defaultConfigTargetTypes = new HashMap<>(); + + // Map from launch config type Id to target type id for default config descriptor for null target + private final Map defaultConfigDefaultTargetTypes = new HashMap<>(); + + // Descriptors in MRU order, key is desc type id and desc name. + private final Map, ILaunchDescriptor> descriptors = new LinkedHashMap<>(); + + // Map of launch objects to launch descriptors + private final Map objectDescriptorMap = new HashMap<>(); + + // Targets, key is target type id and target name. + private final Map, ILaunchTarget> targets = new HashMap<>(); + + // The created launch configurations + private final Map> configs = new HashMap<>(); + private ILaunchDescriptor activeLaunchDesc; private ILaunchMode activeLaunchMode; private ILaunchTarget activeLaunchTarget; - private static final String PREF_ACTIVE_CONFIG_DESC = "activeConfigDesc"; + + // The default launch descriptor type used to wrap unclaimed launch configs + private DefaultLaunchDescriptorType defaultDescriptorType = new DefaultLaunchDescriptorType(); + + // private static final String PREF_ACTIVE_CONFIG_DESC = "activeConfigDesc"; private static final String PREF_ACTIVE_LAUNCH_MODE = "activeLaunchMode"; private static final String PREF_ACTIVE_LAUNCH_TARGET = "activeLaunchTarget"; private static final String PREF_CONFIG_DESC_ORDER = "configDescList"; public LaunchBarManager() throws CoreException { - // Load up the active from the preferences before loading the descriptors + // Fetch the desc order before the init messes it up IEclipsePreferences store = getPreferenceStore(); - String activeConfigDescId = store.get(PREF_ACTIVE_CONFIG_DESC, null); - String configDescIds = store.get(PREF_CONFIG_DESC_ORDER, Collections.EMPTY_LIST.toString()); + String configDescIds = store.get(PREF_CONFIG_DESC_ORDER, ""); + + // Load up the types loadExtensions(); + + // Add in the default descriptor type + LaunchDescriptorTypeInfo defaultInfo = new LaunchDescriptorTypeInfo(DefaultLaunchDescriptorType.ID, + 0, defaultDescriptorType); + addDescriptorType(defaultInfo); + // Hook up the existing launch configurations and listen ILaunchManager launchManager = getLaunchManager(); for (ILaunchConfiguration configuration : launchManager.getLaunchConfigurations()) { launchConfigurationAdded(configuration); } launchManager.addLaunchConfigurationListener(this); - reorderDescriptors(configDescIds); - // Now that all the descriptors are loaded, set the one - ILaunchDescriptor configDesc = getDescriptorById(activeConfigDescId); - if (configDesc == null) { - configDesc = getLastUsedDescriptor(); + + // Reorder the descriptors based on the preference + if (!configDescIds.isEmpty()) { + String[] split = configDescIds.split(","); + ILaunchDescriptor last = null; + for (String id : split) { + Pair key = toId(id); + ILaunchDescriptor desc = descriptors.get(key); + if (desc != null) { + descriptors.remove(key); + descriptors.put(key, desc); + last = desc; + } + } + // Set the active desc, with MRU, it should be the last one + if (last != null) { + setActiveLaunchDescriptor(last); + } } - setActiveLaunchDescriptor(configDesc); } - private ILaunchDescriptor getDescriptorById(String activeConfigDescId) { - return descriptors.get(activeConfigDescId); + // To allow override by tests + protected IExtensionPoint getExtensionPoint() throws CoreException { + return Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchBarContributions"); } - protected void loadExtensions() { + // To allow override by tests + protected ILaunchManager getLaunchManager() { + return DebugPlugin.getDefault().getLaunchManager(); + } + + protected void loadExtensions() throws CoreException { IExtensionPoint point = getExtensionPoint(); IExtension[] extensions = point.getExtensions(); - // first pass - targets and descriptors + + // Load up the types for (IExtension extension : extensions) { for (IConfigurationElement element : extension.getConfigurationElements()) { try { @@ -102,10 +289,6 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage if (elementName.equals("descriptorType")) { String id = element.getAttribute("id"); String priorityStr = element.getAttribute("priority"); - ILaunchDescriptorType type = (ILaunchDescriptorType) element.createExecutableExtension("class"); - if (!id.equals(type.getId())) - throw new IllegalArgumentException("Descriptor Type id " + id - + " is mismatched with id defined in class " + type.getId()); int priority = 1; if (priorityStr != null) { try { @@ -115,49 +298,39 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage Activator.log(e); } } - addDescriptorType(type, priority); + LaunchDescriptorTypeInfo typeInfo = new LaunchDescriptorTypeInfo(id, priority, element); + addDescriptorType(typeInfo); } else if (elementName.equals("targetType")) { String id = element.getAttribute("id"); ILaunchTargetType targetType = (ILaunchTargetType) element.createExecutableExtension("class"); - if (!id.equals(targetType.getId())) - throw new IllegalArgumentException("Target Type id " + id - + " is mismatched with id defined in class " + targetType.getId()); - addTargetType(targetType); + LaunchTargetTypeInfo info = new LaunchTargetTypeInfo(id, targetType); + addTargetType(info); + } else if (elementName.equals("configProvider")) { + String configTypeId = element.getAttribute("launchConfigurationType"); + LaunchConfigProviderInfo info = new LaunchConfigProviderInfo(configTypeId, element); + addConfigProvider(info); + } else if (elementName.equals("configType")) { + String descriptorTypeId = element.getAttribute("descriptorType"); + String targetTypeId = element.getAttribute("targetType"); + String configTypeId = element.getAttribute("launchConfigurationType"); + String isDefault = element.getAttribute("isDefault"); + LaunchConfigTypeInfo info = new LaunchConfigTypeInfo(descriptorTypeId, targetTypeId, configTypeId); + addConfigType(info, Boolean.valueOf(isDefault)); + // also assume that the target type works for the config type + addDefaultConfigTargetType(configTypeId, targetTypeId, Boolean.valueOf(isDefault)); + } else if (elementName.equals("defaultConfigTarget")) { + String configTypeId = element.getAttribute("launchConfigurationType"); + String targetTypeId = element.getAttribute("targetType"); + String isDefault = element.getAttribute("isDefault"); + addDefaultConfigTargetType(configTypeId, targetTypeId, Boolean.valueOf(isDefault)); } - } catch (Exception e) { - Activator.log(e); // exceptions during extension loading, log and move on + } catch (CoreException e) { + Activator.log(e.getStatus()); } } } - // second pass config providers that has references to targets and descriptors - for (IExtension extension : extensions) { - for (IConfigurationElement element : extension.getConfigurationElements()) { - try { - String elementName = element.getName(); - if (elementName.equals("configProvider")) { - String descriptorType = element.getAttribute("descriptorType"); - String targetType = element.getAttribute("targetType"); - String isDefault = element.getAttribute("isDefault"); - // TODO don't instantiate this until we need it - ILaunchConfigurationProvider configProvider = (ILaunchConfigurationProvider) element - .createExecutableExtension("class"); - addConfigProvider(descriptorType, targetType, Boolean.valueOf(isDefault), configProvider); - } else if (elementName.equals("defaultConfigProvider")) { - String descriptorType = element.getAttribute("descriptorType"); - String targetType = element.getAttribute("targetType"); - String launchType = element.getAttribute("launchConfigurationType"); - String isDefault = element.getAttribute("isDefault"); - ILaunchDescriptorType type = new ConfigBasedLaunchDescriptorType(descriptorType, launchType); - addDescriptorType(type, 2);// TODO: fix priority - ILaunchConfigurationProvider configProvider = new ConfigBasedLaunchConfigurationProvider(launchType); - addConfigProvider(type.getId(), targetType, Boolean.valueOf(isDefault), configProvider); - } - } catch (Exception e) { - Activator.log(e); // exceptions during extension loading, log and move on - } - } - } - // third pass - object providers + + // Now that all the types are loaded, the object providers which now populate the descriptors for (IExtension extension : extensions) { for (IConfigurationElement element : extension.getConfigurationElements()) { try { @@ -173,58 +346,72 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage } } - private void reorderDescriptors(String configDescIds) { - configDescIds = configDescIds.replaceAll("[\\]\\[]", ""); - String[] split = configDescIds.split(","); - for (int i = 0; i < split.length; i++) { - String string = split[i]; - String id = string.trim(); - ILaunchDescriptor desc = getDescriptorById(id); - if (desc != null) { - descriptors.remove(id); - descriptors.put(id, desc); + public void addDescriptorType(LaunchDescriptorTypeInfo typeInfo) throws CoreException { + descriptorTypes.put(typeInfo.getId(), typeInfo); + // TODO figure out a better place to set the id so we don't load the type object until needed + descriptorTypeInfo.put(typeInfo.getType(), typeInfo); + + Iterator iterator = orderedDescriptorTypes.iterator(); + boolean inserted = false; + for (int i = 0; i < orderedDescriptorTypes.size(); ++i) { + if (iterator.next().getPriority() < typeInfo.getPriority()) { + orderedDescriptorTypes.add(i, typeInfo); + inserted = true; + break; } } + + if (!inserted) { + orderedDescriptorTypes.add(typeInfo); + } + + Activator.trace("registered descriptor type " + typeInfo.getId()); } - protected static void sortMapByValue(LinkedHashMap map) { - List> entries = - new ArrayList>(map.entrySet()); - Collections.sort(entries, new Comparator>() { - public int compare(Map.Entry a, Map.Entry b) { - return b.getValue().compareTo(a.getValue()); // reverse order 3 2 1 + public void addTargetType(final LaunchTargetTypeInfo info) { + targetTypes.put(info.getId(), info.getType()); + targetTypeInfo.put(info.getType(), info); + SafeRunner.run(new ISafeRunnable() { + @Override + public void run() throws Exception { + info.getType().init(LaunchBarManager.this); + } + @Override + public void handleException(Throwable exception) { + Activator.trace("target runner init exception " + info.getId()); } }); - LinkedHashMap sortedMap = new LinkedHashMap(); - for (Map.Entry entry : entries) { - sortedMap.put(entry.getKey(), entry.getValue()); - } - map.clear(); - map.putAll(sortedMap); + Activator.trace("registered target " + info.getId()); } - public void addDescriptorType(ILaunchDescriptorType type, int priority) { - descriptorTypes.put(type, priority); - sortMapByValue(descriptorTypes); - try { - type.init(this); - } catch (Exception e) { - Activator.log(e); + public void addConfigType(LaunchConfigTypeInfo info, boolean isDefault) { + Map targetMap = configTypes.get(info.getDescriptorTypeId()); + if (targetMap == null) { + targetMap = new HashMap<>(); + configTypes.put(info.getDescriptorTypeId(), targetMap); + } + targetMap.put(info.getTargetTypeId(), info); + + if (isDefault) { + defaultTargetTypes.put(info.getDescriptorTypeId(), info.getTargetTypeId()); } - Activator.trace("registered descriptor type " + type); } - /** - * Programmatically add target type - */ - public void addTargetType(ILaunchTargetType targetType) { - targetTypes.put(targetType.getId(), targetType); - try { - targetType.init(this); - } catch (Exception e) { - Activator.log(e); + public void addConfigProvider(LaunchConfigProviderInfo info) { + configProviders.put(info.getLaunchConfigTypeId(), info); + } + + public void addDefaultConfigTargetType(String configTypeId, String targetTypeId, boolean isDefault) { + Set targetTypes = defaultConfigTargetTypes.get(configTypeId); + if (targetTypes == null) { + targetTypes = new HashSet<>(); + defaultConfigTargetTypes.put(configTypeId, targetTypes); + } + targetTypes.add(targetTypeId); + + if (isDefault) { + defaultConfigDefaultTargetTypes.put(configTypeId, targetTypeId); } - Activator.trace("registered target " + targetType); } public void addObjectProvider(ILaunchObjectProvider objectProvider) { @@ -236,129 +423,142 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage } } - protected ILaunchManager getLaunchManager() { - return DebugPlugin.getDefault().getLaunchManager(); + private void addDescriptor(Object element, ILaunchDescriptor descriptor) throws CoreException { + descriptors.put(getDescriptorId(descriptor), descriptor); + objectDescriptorMap.put(element, descriptor); + setActiveLaunchDescriptor(descriptor); } - protected IExtensionPoint getExtensionPoint() { - return Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchBarContributions"); - } - - /** - * Programmatically add launch configuration provider - */ - public void addConfigProvider(String descriptorType, String targetType, boolean isDefaultB, - ILaunchConfigurationProvider configProvider) { - if (targetTypes.get(targetType) == null) - throw new IllegalStateException("Target type " + targetType + " is not registered"); - if (!descriptorTypes.containsKey(getDescriptorType(descriptorType))) - throw new IllegalStateException("Descriptor type " + descriptorType + " is not registered"); - Map targetMap = configProviders.get(descriptorType); - if (targetMap == null) { - targetMap = new HashMap<>(); - configProviders.put(descriptorType, targetMap); - } - targetMap.put(targetType, configProvider); - if (isDefaultB || defaultTargetTypes.get(descriptorType) == null) { - defaultTargetTypes.put(descriptorType, targetType); - } - try { - configProvider.init(this); - } catch (Exception e) { - Activator.log(e); - } - Activator.trace("registered provider " + descriptorType + "->" + targetType); - } - - public ILaunchDescriptorType getDescriptorType(String descriptorTypeId) { - for (ILaunchDescriptorType descriptorType : descriptorTypes.keySet()) { - if (descriptorType.getId().equals(descriptorTypeId)) - return descriptorType; - } - return null; - } - - protected ILaunchDescriptor remapLaunchObject(Object element) { - // remove old mapping. We have to do it anyway, no matter even nobody owns it (and especially because of that) - ILaunchDescriptor old = objectDescriptorMap.get(element); - if (old != null) { // old mapping is removed - objectDescriptorMap.remove(element); - if (!objectDescriptorMap.values().contains(old)) // if no one else is mapped to it - descriptors.remove(getId(old)); - } - ILaunchDescriptor desc = null; - // re-do the mapping, change in object can change descriptor (for example project has new nature) - for (ILaunchDescriptorType descriptorType : descriptorTypes.keySet()) { - try { - if (descriptorType.ownsLaunchObject(element)) { - desc = descriptorType.getDescriptor(element); - Activator.trace("launch object remap found " + element + " -> " + descriptorType + " -> " + desc); - objectDescriptorMap.put(element, desc); // set it even if desc is null to keep object is map - if (desc != null) // null if we own the object but do not create descriptor - descriptors.put(getId(desc), desc); - break; + private void removeDescriptor(Object element, ILaunchDescriptor descriptor) throws CoreException { + objectDescriptorMap.remove(element); // remove launch object unconditionally + if (descriptor != null) { + descriptors.remove(getDescriptorId(descriptor)); + if (descriptor.equals(activeLaunchDesc)) { + setActiveLaunchDescriptor(getLastUsedDescriptor()); + } + // Also delete any configs created for this descriptor + Map configMap = configs.get(descriptor); + if (configMap != null) { + configs.remove(descriptor); + for (ILaunchConfiguration config : configMap.values()) { + config.delete(); } - } catch (Exception e) { - Activator.log(e); } } - Activator.trace("launch object remap " + element + "-> " + objectDescriptorMap.get(element)); - if (old != null && old.equals(activeLaunchDesc) && !old.equals(desc)) { - // change of object caused changed of descriptor, which was active, reset since old is invalid now - // setting it to null, will actually rollback to last used one which is still valid - setActiveLaunchDescriptor(desc); - } else if (old == null && desc != null) { - // new object causes re-set of active descriptor too - setActiveLaunchDescriptor(desc); - } - return desc; + } + public ILaunchDescriptorType getLaunchDescriptorType(String id) throws CoreException { + return descriptorTypes.get(id).getType(); + } + + public ILaunchDescriptor getLaunchDescriptor(Pair id) { + return descriptors.get(id); + } + + public ILaunchDescriptor getLaunchDescriptor(Object launchObject) { + return objectDescriptorMap.get(launchObject); + } + + public String getDescriptorTypeId(ILaunchDescriptorType type) { + return descriptorTypeInfo.get(type).getId(); + } + + public Pair getDescriptorId(ILaunchDescriptor descriptor) { + return new Pair(getDescriptorTypeId(descriptor.getType()), descriptor.getName()); + } + + public ILaunchTargetType getLaunchTargetType(String id) { + return targetTypes.get(id); + } + + public String getTargetTypeId(ILaunchTargetType type) { + return targetTypeInfo.get(type).getId(); + } + + private Pair getTargetId(ILaunchTarget target) { + return new Pair(getTargetTypeId(target.getType()), target.getName()); + } + + public String toString(Pair key) { + return key.getFirst() + ":" + key.getSecond(); + } + + protected Pair toId(String key) { + int i = key.indexOf(':'); + if (i < 0) { + return null; + } + + return new Pair(key.substring(0, i), key.substring(i + 1)); + } + + private ILaunchConfigurationProvider getConfigProvider(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { + if (descriptor == null) { + return null; + } + + ILaunchDescriptorType descriptorType = descriptor.getType(); + + ILaunchTargetType targetType = null; + if (target != null) { + targetType = target.getType(); + } else { + String targetTypeId = defaultTargetTypes.get(getDescriptorTypeId(descriptorType)); + if (targetTypeId != null) { + targetType = targetTypes.get(targetTypeId); + } + } + + if (targetType == null) { + return null; + } + + Map targetMap = configTypes.get(getDescriptorTypeId(descriptorType)); + if (targetMap != null) { + LaunchConfigTypeInfo typeInfo = targetMap.get(getTargetTypeId(targetType)); + if (typeInfo != null) { + LaunchConfigProviderInfo providerInfo = configProviders.get(typeInfo.getLaunchConfigTypeId()); + if (providerInfo != null) { + return providerInfo.getProvider(); + } + } + } + + return null; } @Override public ILaunchDescriptor launchObjectAdded(Object element) { Activator.trace("launch object added " + element); - if (objectDescriptorMap.containsKey(element)) { - // it was added already, perform change - return launchObjectChanged(element); - } - return remapLaunchObject(element); - } - - @Override - public ILaunchDescriptor getLaunchDescriptor(Object element) { - return objectDescriptorMap.get(element); - } - - @Override - public ILaunchDescriptor launchObjectChanged(Object element) { - Activator.trace("launch object changed " + element); - // only applied to object that were added via launchObjectAdded - if (!objectDescriptorMap.containsKey(element)) - return null; - return remapLaunchObject(element); - } - - private String getId(ILaunchDescriptor desc) { - if (desc == null) - return null; - return desc.getId(); - } - - @Override - public void launchObjectRemoved(Object element) { - Activator.trace("launch object removed " + element); ILaunchDescriptor desc = objectDescriptorMap.get(element); - objectDescriptorMap.remove(element); // remove launch object unconditionally - if (desc != null) { - if (!objectDescriptorMap.values().contains(desc)) { // can multiple elements maps to the equal descriptor? - // if no one else is mapped to it - descriptors.remove(getId(desc)); - if (desc.equals(activeLaunchDesc)) { - setActiveLaunchDescriptor(getLastUsedDescriptor()); + if (desc != null) + return desc; + + // TODO use enablement to find out what descriptor types to ask + // to prevent unnecessary plug-in loading + for (LaunchDescriptorTypeInfo descriptorInfo : orderedDescriptorTypes) { + try { + ILaunchDescriptorType descriptorType = descriptorInfo.getType(); + if (descriptorType.ownsLaunchObject(element)) { + desc = descriptorType.getDescriptor(element); + if (desc != null) { + addDescriptor(element, desc); + return desc; + } + break; } + } catch (CoreException e) { + Activator.log(e.getStatus()); } } + return null; + } + + @Override + public void launchObjectRemoved(Object element) throws CoreException { + Activator.trace("launch object removed " + element); + ILaunchDescriptor desc = objectDescriptorMap.get(element); + removeDescriptor(element, desc); } protected ILaunchDescriptor getLastUsedDescriptor() { @@ -368,19 +568,6 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage return descs[descs.length - 1]; } - @Override - public ILaunchDescriptor[] getOpenLaunchDescriptors() { - ArrayList values = new ArrayList<>(descriptors.values()); - for (Iterator iterator = values.iterator(); iterator.hasNext();) { - ILaunchDescriptor d = iterator.next(); - if (!d.isOpen()) - iterator.remove(); - } - Collections.reverse(values); - return values.toArray(new ILaunchDescriptor[values.size()]); - } - - @Override public ILaunchDescriptor[] getLaunchDescriptors() { // return descriptor in usage order (most used first). UI can sort them later as it wishes ArrayList values = new ArrayList<>(descriptors.values()); @@ -388,35 +575,42 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage return values.toArray(new ILaunchDescriptor[values.size()]); } - - @Override public ILaunchDescriptor getActiveLaunchDescriptor() { return activeLaunchDesc; } - @Override - public void setActiveLaunchDescriptor(ILaunchDescriptor configDesc) { - Activator.trace("set active descriptor " + configDesc); - if (activeLaunchDesc == configDesc) { + public void setActiveLaunchDescriptor(ILaunchDescriptor descriptor) throws CoreException { + Activator.trace("set active descriptor " + descriptor); + if (activeLaunchDesc == descriptor) { // Sync since targets could be changed since last time (and modes theoretically too) syncActiveTarget(); syncActiveMode(); - Activator.trace("resync for " + configDesc); + Activator.trace("resync for " + descriptor); return; } - if (configDesc != null && !descriptors.containsValue(configDesc)) + if (descriptor != null && !descriptors.containsValue(descriptor)) throw new IllegalStateException("Active descriptor must be in the map of descriptors"); - if (configDesc == null) - configDesc = getLastUsedDescriptor(); // do not set to null unless no descriptors - activeLaunchDesc = configDesc; - if (configDesc != null) { // keeps most used descriptor last - descriptors.remove(configDesc.getId()); - descriptors.put(configDesc.getId(), configDesc); + if (descriptor == null) + descriptor = getLastUsedDescriptor(); // do not set to null unless no descriptors + activeLaunchDesc = descriptor; + if (descriptor != null) { // keeps most used descriptor last + Pair id = getDescriptorId(descriptor); + descriptors.remove(id); + descriptors.put(id, descriptor); } // store in persistent storage - setPreference(getPreferenceStore(), PREF_ACTIVE_CONFIG_DESC, getId(activeLaunchDesc)); - Activator.trace("new active config is stored " + configDesc); - setPreference(getPreferenceStore(), PREF_CONFIG_DESC_ORDER, descriptors.keySet().toString()); + Activator.trace("new active config is stored " + descriptor); + + // Store the desc order + StringBuffer buff = new StringBuffer(); + for (Pair key : descriptors.keySet()) { + if (buff.length() > 0) { + buff.append(','); + } + buff.append(toString(key)); + } + setPreference(getPreferenceStore(), PREF_CONFIG_DESC_ORDER, buff.toString()); + // Send notifications updateLaunchDescriptor(activeLaunchDesc); // Set active target @@ -425,26 +619,34 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage syncActiveMode(); } - protected void syncActiveTarget() { + private void syncActiveTarget() throws CoreException { if (activeLaunchDesc == null) { setActiveLaunchTarget(null); return; } - // checking active target - if (activeLaunchTarget != null && supportsTargetType(activeLaunchDesc, activeLaunchTarget.getType())) - return; // not changing target + + // TODO turning off for now since it's buggy. There is thought though that we may want + // to keep the active target when changing descriptors if it's valid for that descriptor. + // If we do that, then the active target should be recorded against the target type. + // The active target is too random at startup for this to work as coded here. +// if (activeLaunchTarget != null && supportsTargetType(activeLaunchDesc, activeLaunchTarget)) { +// return; // not changing target +// } + // last stored target from persistent storage String activeTargetId = getPerDescriptorStore().get(PREF_ACTIVE_LAUNCH_TARGET, null); - ILaunchTarget storedTarget = getLaunchTarget(activeTargetId); - if (storedTarget != null && supportsTargetType(activeLaunchDesc, storedTarget.getType())) { - setActiveLaunchTarget(storedTarget); - return; + if (activeTargetId != null) { + ILaunchTarget storedTarget = getLaunchTarget(toId(activeTargetId)); + if (storedTarget != null && supportsTargetType(activeLaunchDesc, storedTarget)) { + setActiveLaunchTarget(storedTarget); + return; + } } // default target for descriptor setActiveLaunchTarget(getDefaultLaunchTarget(activeLaunchDesc)); - } + } - protected void syncActiveMode() { + private void syncActiveMode() throws CoreException { if (activeLaunchDesc == null) { setActiveLaunchMode(null); return; @@ -455,11 +657,11 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage ILaunchMode[] supportedModes = getLaunchModes(); // this is based on active desc and target which are already set if (supportedModes.length > 0) { // mna, what if no modes are supported? String modeNames[] = new String[] { - storedModeId, - lastActiveModeId, - "debug", - "run", - supportedModes[0].getIdentifier() + storedModeId, + lastActiveModeId, + "debug", + "run", + supportedModes[0].getIdentifier() }; for (int i = 0; i < modeNames.length; i++) { foundMode = getLaunchManager().getLaunchMode(modeNames[i]); @@ -470,7 +672,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage setActiveLaunchMode(foundMode); } - public boolean supportsMode(ILaunchMode mode) { + public boolean supportsMode(ILaunchMode mode) throws CoreException { // check that active descriptor supports the given mode if (mode == null) return false; @@ -499,14 +701,13 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage protected Preferences getPerDescriptorStore() { if (activeLaunchDesc == null) return getPreferenceStore(); - return getPreferenceStore().node(activeLaunchDesc.getId()); + return getPreferenceStore().node(toString(getDescriptorId(activeLaunchDesc))); } protected IEclipsePreferences getPreferenceStore() { return InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID); } - @Override public void updateLaunchDescriptor(ILaunchDescriptor configDesc) { for (Listener listener : listeners) { try { @@ -517,8 +718,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage } } - @Override - public ILaunchMode[] getLaunchModes() { + public ILaunchMode[] getLaunchModes() throws CoreException { ILaunchConfigurationType configType = getLaunchConfigurationType(activeLaunchDesc, activeLaunchTarget); if (configType == null) return new ILaunchMode[0]; @@ -532,13 +732,11 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage return modeList.toArray(new ILaunchMode[modeList.size()]); } - @Override public ILaunchMode getActiveLaunchMode() { return activeLaunchMode; } - @Override - public void setActiveLaunchMode(ILaunchMode mode) { + public void setActiveLaunchMode(ILaunchMode mode) throws CoreException { if (activeLaunchMode == mode) return; if (activeLaunchDesc != null && mode != null && !supportsMode(mode)) @@ -560,64 +758,87 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage } public ILaunchTarget[] getAllLaunchTargets() { - List targetList = new ArrayList<>(); - for (ILaunchTargetType targetType : getAllLaunchTargetTypes()) { - for (ILaunchTarget target : targetType.getTargets()) { - targetList.add(target); - } - } - return targetList.toArray(new ILaunchTarget[targetList.size()]); + return targets.values().toArray(new ILaunchTarget[targets.size()]); } - @Override - public ILaunchTarget[] getLaunchTargets() { + public ILaunchTarget[] getLaunchTargets() throws CoreException { return getLaunchTargets(activeLaunchDesc); } - public ILaunchTarget[] getLaunchTargets(ILaunchDescriptor desc) { - if (desc == null) + public ILaunchTarget[] getLaunchTargets(ILaunchDescriptor descriptor) throws CoreException { + if (descriptor == null) return new ILaunchTarget[0]; - List targetList = new ArrayList<>(); - Map targetMap = configProviders.get(desc.getType().getId()); + + // See if there is are targets registered with this descriptor type + Map targetMap = configTypes.get(getDescriptorTypeId(descriptor.getType())); if (targetMap != null) { - for (String targetTypeId : targetMap.keySet()) { - ILaunchTargetType type = targetTypes.get(targetTypeId); - if (type != null) { - ILaunchTarget[] targets = type.getTargets(); - for (ILaunchTarget target : targets) { - targetList.add(target); - } + List targetList = new ArrayList<>(); + // Not super fast, but we're assuming there aren't many targets. + for (Entry, ILaunchTarget> targetEntry : targets.entrySet()) { + if (targetMap.containsKey(targetEntry.getKey().getFirst())) { + targetList.add(targetEntry.getValue()); } } + return targetList.toArray(new ILaunchTarget[targetList.size()]); } - return targetList.toArray(new ILaunchTarget[targetList.size()]); + + // Nope, see if there are any default config targets + ILaunchConfiguration config = (ILaunchConfiguration) descriptor.getAdapter(ILaunchConfiguration.class); + if (config != null) { + Set targetTypeIds = defaultConfigTargetTypes.get(config.getType().getIdentifier()); + if (targetTypeIds != null) { + List targetList = new ArrayList<>(); + // Not super fast, but we're assuming there aren't many targets. + for (Entry, ILaunchTarget> targetEntry : targets.entrySet()) { + if (targetTypeIds.contains(targetEntry.getKey().getFirst())) { + targetList.add(targetEntry.getValue()); + } + } + return targetList.toArray(new ILaunchTarget[targetList.size()]); + } + } + + // Nope, return the local target + for (Entry, ILaunchTarget> targetEntry : targets.entrySet()) { + if (LocalTargetType.ID.equals(targetEntry.getKey().getFirst())) { + return new ILaunchTarget[] { targetEntry.getValue() }; + } + } + + // Not found, weird + return new ILaunchTarget[0]; } - @Override public ILaunchTarget getActiveLaunchTarget() { return activeLaunchTarget; } - @Override - public void setActiveLaunchTarget(ILaunchTarget target) { - if (activeLaunchTarget == target) + public void setActiveLaunchTarget(ILaunchTarget target) throws CoreException { + if (activeLaunchTarget == target) { return; + } + + if (activeLaunchTarget != null) { + activeLaunchTarget.setActive(false); + } + activeLaunchTarget = target; - updateLaunchTarget(activeLaunchTarget); + launchTargetChanged(activeLaunchTarget); if (target == null) { return; // no point storing null, if stored id is invalid it won't be used anyway } - target.setActive(); + + target.setActive(true); if (activeLaunchDesc == null) return; // per desc store - if (supportsTargetType(activeLaunchDesc, target.getType())) + if (supportsTargetType(activeLaunchDesc, target)) setPreference(getPerDescriptorStore(), - PREF_ACTIVE_LAUNCH_TARGET, target.getId()); + PREF_ACTIVE_LAUNCH_TARGET, toString(getTargetId(target))); } @Override - public void updateLaunchTarget(ILaunchTarget target) { + public void launchTargetChanged(ILaunchTarget target) { for (Listener listener : listeners) { try { listener.activeLaunchTargetChanged(); @@ -629,6 +850,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage @Override public void launchTargetAdded(ILaunchTarget target) throws CoreException { + targets.put(getTargetId(target), target); for (Listener listener : listeners) { try { listener.launchTargetsChanged(); @@ -636,11 +858,11 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage Activator.log(e); } } - if (activeLaunchTarget == null && supportsTargetType(activeLaunchDesc, target.getType())) { + if (activeLaunchDesc != null && activeLaunchTarget == null && supportsTargetType(activeLaunchDesc, target)) { setActiveLaunchTarget(target); } } - + @Override public void launchTargetRemoved(ILaunchTarget target) throws CoreException { for (Listener listener : listeners) { @@ -655,7 +877,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage } } - protected ILaunchTarget getDefaultLaunchTarget(ILaunchDescriptor descriptor) { + private ILaunchTarget getDefaultLaunchTarget(ILaunchDescriptor descriptor) throws CoreException { ILaunchTarget[] targets = getLaunchTargets(descriptor); if (targets.length > 0) { return targets[0]; @@ -663,78 +885,87 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage return null; } - @Override - public ILaunchTarget getLaunchTarget(String targetId) { + public ILaunchTarget getLaunchTarget(Pair targetId) { if (targetId == null) return null; - for (ILaunchTargetType type : targetTypes.values()) { - ILaunchTarget target = type.getTarget(targetId); - if (target != null) - return target; - } - return null; + return targets.get(targetId); } public ILaunchTargetType[] getAllLaunchTargetTypes() { return targetTypes.values().toArray(new ILaunchTargetType[targetTypes.values().size()]); } - @Override - public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) { + public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { if (descriptor == null) return null; - try { - if (descriptor instanceof ILaunchDescriptorConfigBased) { - // if descriptor is launch config based we don't need provider to determine the type - return ((ILaunchDescriptorConfigBased) descriptor).getLaunchConfigurationType(); - } - String descriptorTypeId = descriptor.getType().getId(); - String targetTypeId = target != null ? target.getType().getId() : defaultTargetTypes.get(descriptorTypeId); - ILaunchConfigurationProvider configProvider = getConfigProvider(descriptorTypeId, targetTypeId); - if (configProvider != null) { - return configProvider.getLaunchConfigurationType(descriptor); - } - } catch (Exception e) { - Activator.log(e); // we calling provider code inside try block, better be safe + + String descriptorTypeId = getDescriptorTypeId(descriptor.getType()); + + String targetTypeId = null; + if (target != null) { + targetTypeId = getTargetTypeId(target.getType()); + } else { + targetTypeId = defaultTargetTypes.get(getDescriptorTypeId(descriptor.getType())); } + + if (targetTypeId != null) { + Map targetMap = configTypes.get(descriptorTypeId); + if (targetMap != null) { + LaunchConfigTypeInfo typeInfo = targetMap.get(targetTypeId); + return getLaunchManager().getLaunchConfigurationType(typeInfo.getLaunchConfigTypeId()); + } + } + + ILaunchConfiguration config = (ILaunchConfiguration) descriptor.getAdapter(ILaunchConfiguration.class); + if (config != null) + return config.getType(); + return null; } - public boolean supportsTargetType(ILaunchDescriptor descriptor, ILaunchTargetType targetType) { - return getConfigProvider(descriptor, targetType) != null; + private boolean supportsTargetType(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { + return getConfigProvider(descriptor, target) != null; + } + + public ILaunchConfiguration getActiveLaunchConfiguration() throws CoreException { + return getLaunchConfiguration(activeLaunchDesc, activeLaunchTarget); } - @Override public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { - if (target == null) + if (descriptor == null) { return null; - ILaunchConfigurationProvider configProvider = getConfigProvider(descriptor, target.getType()); + } + + ILaunchConfigurationProvider configProvider = getConfigProvider(descriptor, target); if (configProvider != null) { - return configProvider.getLaunchConfiguration(descriptor); + // First see if it exists yet + Map configMap = configs.get(descriptor); + if (configMap != null) { + ILaunchConfiguration config = configMap.get(configProvider); + if (config != null) { + return config; + } + } else { + // we'll need this in a minute + configMap = new HashMap<>(); + configs.put(descriptor, configMap); + } + + // Not found, create, store and return it + ILaunchConfiguration config = configProvider.createLaunchConfiguration(getLaunchManager(), descriptor); + if (config != null) { + configMap.put(configProvider, config); + return config; + } } - return null; + + return (ILaunchConfiguration) descriptor.getAdapter(ILaunchConfiguration.class); } - public ILaunchConfigurationProvider getConfigProvider(ILaunchDescriptor descriptor, ILaunchTargetType targetType) { - if (descriptor == null || targetType == null) - return null; - return getConfigProvider(descriptor.getType().getId(), targetType.getId()); - } - - public ILaunchConfigurationProvider getConfigProvider(String descriptorTypeId, String targetTypeId) { - Map targetMap = configProviders.get(descriptorTypeId); - if (targetMap != null) { - return targetMap.get(targetTypeId); - } - return null; - } - - @Override public void addListener(Listener listener) { listeners.add(listener); } - @Override public void removeListener(Listener listener) { listeners.remove(listener); } @@ -742,46 +973,62 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage @Override public void launchConfigurationAdded(ILaunchConfiguration configuration) { Activator.trace("launch config added " + configuration); - // TODO filter by launch configuration type to avoid loading plug-ins - for (ILaunchDescriptorType descriptorType : descriptorTypes.keySet()) { - Map targetMap = configProviders.get(descriptorType.getId()); - if (targetMap != null) { - for (ILaunchConfigurationProvider configProvider : targetMap.values()) { - try { - if (configProvider.launchConfigurationAdded(configuration)) { - Activator.trace("launch config claimed by " + configProvider); - return; + try { + LaunchConfigProviderInfo info = configProviders.get(configuration.getType().getIdentifier()); + if (info != null) { + ILaunchConfigurationProvider provider = info.getProvider(); + Object launchObject = provider.launchConfigurationAdded(configuration); + if (launchObject != null) { + ILaunchDescriptor descriptor = objectDescriptorMap.get(launchObject); + if (descriptor != null) { + Map configMap = configs.get(descriptor); + if (configMap == null) { + configMap = new HashMap<>(); + configs.put(descriptor, configMap); } - } catch (Exception e) { - Activator.log(e); // don't let one bad provider affect the rest + configMap.put(provider, configuration); } + Activator.trace("launch config claimed by " + provider); + return; } } + } catch (CoreException e) { + Activator.log(e.getStatus()); } - // No one claimed it, send it through the descriptorTypes + Activator.trace("launch config not claimed"); - launchObjectAdded(configuration); + try { + ILaunchDescriptor desc = defaultDescriptorType.getDescriptor(configuration); + addDescriptor(configuration, desc); + } catch (CoreException e) { + Activator.log(e.getStatus()); + } } @Override public void launchConfigurationRemoved(ILaunchConfiguration configuration) { Activator.trace("launch config removed " + configuration); - // TODO filter by launch configuration type - for (ILaunchDescriptorType descriptorType : descriptorTypes.keySet()) { - Map targetMap = configProviders.get(descriptorType.getId()); - for (ILaunchConfigurationProvider configProvider : targetMap.values()) { - try { - if (configProvider.launchConfigurationRemoved(configuration)) { - Activator.trace("launch config claimed by " + configProvider); - return; - } - } catch (Exception e) { - Activator.log(e); // don't let one bad provider affect the rest + + try { + LaunchConfigProviderInfo info = configProviders.get(configuration.getType().getIdentifier()); + if (info != null) { + ILaunchConfigurationProvider provider = info.getProvider(); + if (provider.launchConfigurationRemoved(configuration)) { + Activator.trace("launch config removed by " + provider); + return; } } + } catch (CoreException e) { + Activator.log(e.getStatus()); } + Activator.trace("launch config not claimed"); - launchObjectRemoved(configuration); + ILaunchDescriptor desc = objectDescriptorMap.get(configuration); + try { + removeDescriptor(configuration, desc); + } catch (CoreException e) { + Activator.log(e.getStatus()); + } } @Override @@ -800,4 +1047,10 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage } } } + + @Override + public void launchObjectChanged(Object launchObject) throws CoreException { + // TODO deal with object renames here, somehow + // TODO handle descriptor type changes + } } diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LocalTarget.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LocalTarget.java index ab572df9fd7..264c544e40c 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LocalTarget.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LocalTarget.java @@ -12,24 +12,22 @@ package org.eclipse.cdt.launchbar.core.internal; import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.core.ILaunchTargetType; +import org.eclipse.core.runtime.PlatformObject; -public class LocalTarget implements ILaunchTarget { +/** + * The launch target representing the machine we're running on. + */ +public class LocalTarget extends PlatformObject implements ILaunchTarget { private final LocalTargetType type; - + public LocalTarget(LocalTargetType type) { this.type = type; } - - @Override - public String getId() { - // Use the same ID as the type since we're really a singleton - return type.getId(); - } @Override public String getName() { - return "Local Machine"; // TODO externalize + return Messages.LocalTarget_name; } @Override @@ -38,8 +36,8 @@ public class LocalTarget implements ILaunchTarget { } @Override - public void setActive() { - // nothing to do + public void setActive(boolean active) { + // nothing to do, we have no active state } - + } diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LocalTargetType.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LocalTargetType.java index 68bbcb0cc4a..5364d8468ab 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LocalTargetType.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/LocalTargetType.java @@ -1,34 +1,25 @@ package org.eclipse.cdt.launchbar.core.internal; import org.eclipse.cdt.launchbar.core.ILaunchBarManager; -import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.core.ILaunchTargetType; +import org.eclipse.core.runtime.CoreException; +/** + * The target type that creates the local target. + */ public class LocalTargetType implements ILaunchTargetType { - public static final String ID = "org.eclipse.cdt.launchbar.core.target.local"; - private LocalTarget localTarget; + public static final String ID = Activator.PLUGIN_ID + ".targetType.local"; @Override - public void init(ILaunchBarManager manager) { - localTarget = new LocalTarget(this); - } - - @Override - public String getId() { - return ID; + public void init(ILaunchBarManager manager) throws CoreException { + // create the local target + manager.launchTargetAdded(new LocalTarget(this)); } @Override - public ILaunchTarget[] getTargets() { - return new ILaunchTarget[] { localTarget }; + public void dispose() { + // nothing to do } - @Override - public ILaunchTarget getTarget(String id) { - if (ID.equals(id)) - return localTarget; - return null; - } - } diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorProjectBased.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/Messages.java similarity index 53% rename from launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorProjectBased.java rename to launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/Messages.java index 55db4eaedf8..48dbd38c040 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/ILaunchDescriptorProjectBased.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/Messages.java @@ -6,18 +6,20 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Alena Laskavaia - Initial API and implementation + * Doug Schaefer *******************************************************************************/ -package org.eclipse.cdt.launchbar.core; +package org.eclipse.cdt.launchbar.core.internal; -import org.eclipse.core.resources.IProject; +import org.eclipse.osgi.util.NLS; -/** - * Project Based launch descriptor knows about project it is associated with - */ -public interface ILaunchDescriptorProjectBased extends ILaunchDescriptor { - /** - * Get associate project - */ - public abstract IProject getProject(); -} \ No newline at end of file +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.cdt.launchbar.core.internal.messages"; //$NON-NLS-1$ + public static String LocalTarget_name; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/Pair.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/Pair.java new file mode 100644 index 00000000000..169252b0eab --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/Pair.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2014 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Doug Schaefer + *******************************************************************************/ +package org.eclipse.cdt.launchbar.core.internal; + +/** + * Yet another implementation for Pair. You'd figure Java would have this out of the box. + * Used in the launch bar mainly for modeling descriptor and target id's which includ both + * type id and the object name. + * + * @param first element + * @param second element + */ +public class Pair { + + private final S first; + private final T second; + + public Pair(S first, T second) { + this.first = first; + this.second = second; + } + + public S getFirst() { + return first; + } + + public T getSecond() { + return second; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((first == null) ? 0 : first.hashCode()); + result = prime * result + ((second == null) ? 0 : second.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + @SuppressWarnings("unchecked") Pair other = (Pair) obj; + if (first == null) { + if (other.first != null) + return false; + } else if (!first.equals(other.first)) + return false; + if (second == null) { + if (other.second != null) + return false; + } else if (!second.equals(other.second)) + return false; + return true; + } + +} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/ProjectLaunchObjectProvider.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/ProjectLaunchObjectProvider.java index 300da7028ea..0d6833b0b33 100644 --- a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/ProjectLaunchObjectProvider.java +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/ProjectLaunchObjectProvider.java @@ -24,18 +24,18 @@ import org.eclipse.core.resources.IResourceDeltaVisitor; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +/** + * Injects IProject objects from platform resources into the launch bar model for potential + * project descriptors. + */ public class ProjectLaunchObjectProvider implements ILaunchObjectProvider, IResourceChangeListener { private ILaunchBarManager manager; @Override - public void init(ILaunchBarManager manager) { + public void init(ILaunchBarManager manager) throws CoreException { this.manager = manager; - try { - for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { - manager.launchObjectAdded(project); - } - } catch (CoreException e) { - Activator.log(e.getStatus()); + for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) { + manager.launchObjectAdded(project); } ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE); } diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/messages.properties b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/messages.properties new file mode 100644 index 00000000000..2f8d25fcb68 --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/messages.properties @@ -0,0 +1,12 @@ +################################################################################ +# Copyright (c) 2014 QNX Software Systems and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Doug Schaefer +################################################################################ + +LocalTarget_name=Local Machine diff --git a/launch/org.eclipse.cdt.launchbar.ui/META-INF/MANIFEST.MF b/launch/org.eclipse.cdt.launchbar.ui/META-INF/MANIFEST.MF index b2758f62fbb..e768849fd75 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/META-INF/MANIFEST.MF +++ b/launch/org.eclipse.cdt.launchbar.ui/META-INF/MANIFEST.MF @@ -16,7 +16,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.debug.ui, org.eclipse.ui.workbench, org.eclipse.ui.ide, - org.eclipse.swt + org.eclipse.swt, + org.eclipse.ui.navigator Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-ActivationPolicy: lazy Bundle-Localization: plugin diff --git a/launch/org.eclipse.cdt.launchbar.ui/plugin.properties b/launch/org.eclipse.cdt.launchbar.ui/plugin.properties index 1dedff12797..1a942c2caa3 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/plugin.properties +++ b/launch/org.eclipse.cdt.launchbar.ui/plugin.properties @@ -1,2 +1,3 @@ launchToolBar.label = LaunchBar targetsView.name = Launch Targets +targetsContent.name = Launch Targets diff --git a/launch/org.eclipse.cdt.launchbar.ui/plugin.xml b/launch/org.eclipse.cdt.launchbar.ui/plugin.xml index 5e058f8eba3..e341a8735a9 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/plugin.xml +++ b/launch/org.eclipse.cdt.launchbar.ui/plugin.xml @@ -11,16 +11,6 @@ class="org.eclipse.cdt.launchbar.ui.internal.LaunchBarInjector"> - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/IHoverProvider.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/IHoverProvider.java index 648154e36bc..77e531b368c 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/IHoverProvider.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/IHoverProvider.java @@ -10,6 +10,12 @@ *******************************************************************************/ package org.eclipse.cdt.launchbar.ui; +/** + * An extension to allow different object types to provide fancy hovers. + * + * TODO this does lead to inconsistency when different types provide different hover UI + * which can confuse users. We should provide good UI out of the box. + */ public interface IHoverProvider { /** diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/Activator.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/Activator.java index dabd2844d62..c5df42cde72 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/Activator.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/Activator.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.launchbar.ui.internal; +import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager; import org.eclipse.core.commands.Command; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.IParameter; @@ -54,7 +55,10 @@ public class Activator extends AbstractUIPlugin { // The shared instance private static Activator plugin; - + + // The cache of the Launch Bar UI Manager Object + private LaunchBarUIManager launchBarUIManager; + /** * The constructor */ @@ -64,7 +68,7 @@ public class Activator extends AbstractUIPlugin { public void start(BundleContext context) throws Exception { super.start(context); plugin = this; - + ImageRegistry imageRegistry = getImageRegistry(); imageRegistry.put(IMG_BUTTON_BUILD, imageDescriptorFromPlugin(PLUGIN_ID, "icons/build.png")); imageRegistry.put(IMG_BUTTON_LAUNCH, imageDescriptorFromPlugin(PLUGIN_ID, "icons/launch.png")); @@ -85,6 +89,14 @@ public class Activator extends AbstractUIPlugin { return plugin; } + public LaunchBarUIManager getLaunchBarUIManager() { + if (launchBarUIManager == null) { + LaunchBarManager manager = org.eclipse.cdt.launchbar.core.internal.Activator.getDefault().getLaunchBarManager(); + launchBarUIManager = new LaunchBarUIManager(manager); + } + return launchBarUIManager; + } + public Image getImage(String id) { return getImageRegistry().get(id); } diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/DefaultDescriptorLabelProvider.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/DefaultDescriptorLabelProvider.java index bf5346c3c16..b7c0ce1efe4 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/DefaultDescriptorLabelProvider.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/DefaultDescriptorLabelProvider.java @@ -3,10 +3,11 @@ package org.eclipse.cdt.launchbar.ui.internal; import java.util.HashMap; import java.util.Map; -import org.eclipse.cdt.launchbar.core.ILaunchBarManager; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; -import org.eclipse.cdt.launchbar.core.ILaunchTarget; +import org.eclipse.cdt.launchbar.core.internal.Activator; +import org.eclipse.cdt.launchbar.core.internal.DefaultLaunchDescriptor; import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.jface.resource.ImageDescriptor; @@ -28,12 +29,10 @@ public class DefaultDescriptorLabelProvider extends LabelProvider { @Override public Image getImage(Object element) { if (element instanceof ILaunchDescriptor) { - try { - ILaunchDescriptor desc = (ILaunchDescriptor) element; - ILaunchBarManager manager = desc.getType().getManager(); - ILaunchTarget target = manager.getActiveLaunchTarget(); - ILaunchConfigurationType type = manager.getLaunchConfigurationType(desc, target); - if (type != null) { + ILaunchConfiguration config = (ILaunchConfiguration) ((ILaunchDescriptor) element).getAdapter(ILaunchConfiguration.class); + if (config != null) { + try { + ILaunchConfigurationType type = config.getType(); ImageDescriptor imageDescriptor = DebugUITools.getDefaultImageDescriptor(type); if (imageDescriptor != null) { Image image = images.get(imageDescriptor); @@ -43,9 +42,9 @@ public class DefaultDescriptorLabelProvider extends LabelProvider { } return image; } + } catch (CoreException e) { + Activator.log(e.getStatus()); } - } catch (CoreException e) { - Activator.log(e); } } return super.getImage(element); diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/LaunchBarUIManager.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/LaunchBarUIManager.java index f0c03183c82..fbf2cd92ec4 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/LaunchBarUIManager.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/LaunchBarUIManager.java @@ -15,9 +15,10 @@ import java.net.URL; import java.util.HashMap; import java.util.Map; -import org.eclipse.cdt.launchbar.core.ILaunchBarManager; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchTarget; +import org.eclipse.cdt.launchbar.core.internal.ExecutableExtension; +import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager; import org.eclipse.cdt.launchbar.ui.IHoverProvider; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; @@ -30,14 +31,14 @@ import org.eclipse.swt.graphics.Image; public class LaunchBarUIManager { - ILaunchBarManager manager; - Map descriptorLabelProviders = new HashMap<>(); + LaunchBarManager manager; + Map> descriptorLabelProviders = new HashMap<>(); Map targetContributions = new HashMap<>(); - private final LaunchBarTargetContribution DEFAULT_CONTRIBUTION = new LaunchBarTargetContribution(null, null, null, null, null, + private final LaunchBarTargetContribution DEFAULT_CONTRIBUTION = new LaunchBarTargetContribution(null, null, null, null, null, null); - public LaunchBarUIManager(ILaunchBarManager manager) { + public LaunchBarUIManager(LaunchBarManager manager) { this.manager = manager; IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchBarUIContributions"); @@ -46,58 +47,51 @@ public class LaunchBarUIManager { for (IConfigurationElement element : extension.getConfigurationElements()) { String elementName = element.getName(); if (elementName.equals("descriptorUI")) { - try { - String descriptorTypeId = element.getAttribute("descriptorTypeId"); - - ILabelProvider labelProvider = (ILabelProvider) element.createExecutableExtension("labelProvider"); - descriptorLabelProviders.put(descriptorTypeId, labelProvider); - } catch (CoreException e) { - Activator.log(e.getStatus()); - } + String descriptorTypeId = element.getAttribute("descriptorTypeId"); + ExecutableExtension labelProvider = new ExecutableExtension<>(element, "labelProvider"); + descriptorLabelProviders.put(descriptorTypeId, labelProvider); } else if (elementName.equals("targetUI")) { - try { - String targetTypeId = element.getAttribute("targetTypeId"); - String targetName = element.getAttribute("name"); + String targetTypeId = element.getAttribute("targetTypeId"); + String targetName = element.getAttribute("name"); + String iconStr = element.getAttribute("icon"); + ExecutableExtension labelProvider = new ExecutableExtension(element, "labelProvider"); - String iconStr = element.getAttribute("icon"); - - ILabelProvider labelProvider = (ILabelProvider) element.createExecutableExtension("labelProvider"); - - IHoverProvider hoverProvider = null; - if (element.getAttribute("hoverProvider") != null) { - hoverProvider = (IHoverProvider) element.createExecutableExtension("hoverProvider"); - } - String editCommandId = element.getAttribute("editCommandId"); - String addNewCommandId = element.getAttribute("addNewTargetCommandId"); - - targetContributions.put(targetTypeId, new LaunchBarTargetContribution(targetTypeId, targetName, iconStr, - labelProvider, hoverProvider, editCommandId, addNewCommandId)); - } catch (CoreException e) { - Activator.log(e.getStatus()); + ExecutableExtension hoverProvider = null; + if (element.getAttribute("hoverProvider") != null) { + hoverProvider = new ExecutableExtension(element, "hoverProvider"); } + + String editCommandId = element.getAttribute("editCommandId"); + String addNewCommandId = element.getAttribute("addNewTargetCommandId"); + + targetContributions.put(targetTypeId, new LaunchBarTargetContribution(targetName, iconStr, + labelProvider, hoverProvider, editCommandId, addNewCommandId)); } } } } - public ILaunchBarManager getManager() { + public LaunchBarManager getManager() { return manager; } - public ILabelProvider getLabelProvider(ILaunchDescriptor descriptor) { - return descriptorLabelProviders.get(descriptor.getType().getId()); + public ILabelProvider getLabelProvider(ILaunchDescriptor descriptor) throws CoreException { + ExecutableExtension provider = descriptorLabelProviders.get(manager.getDescriptorTypeId(descriptor.getType())); + return provider != null ? provider.get() : null; } public String getTargetTypeName(ILaunchTarget target) { return getContribution(target).name; } - public ILabelProvider getLabelProvider(ILaunchTarget target) { - return getContribution(target).labelProvider; + public ILabelProvider getLabelProvider(ILaunchTarget target) throws CoreException { + ExecutableExtension provider = getContribution(target).labelProvider; + return provider != null ? provider.get() : null; } - public IHoverProvider getHoverProvider(ILaunchTarget target) { - return getContribution(target).hoverProvider; + public IHoverProvider getHoverProvider(ILaunchTarget target) throws CoreException { + ExecutableExtension hoverProvider = getContribution(target).hoverProvider; + return hoverProvider != null ? hoverProvider.get() : null; } public String getEditCommand(ILaunchTarget target) { @@ -129,7 +123,7 @@ public class LaunchBarUIManager { } private LaunchBarTargetContribution getContribution(ILaunchTarget target) { - LaunchBarTargetContribution c = targetContributions.get(target.getType().getId()); + LaunchBarTargetContribution c = targetContributions.get(manager.getTargetTypeId(target.getType())); if (c == null) { return DEFAULT_CONTRIBUTION; } @@ -137,19 +131,18 @@ public class LaunchBarUIManager { } private class LaunchBarTargetContribution { - - String id; String name; String iconStr; Image icon; - ILabelProvider labelProvider; - IHoverProvider hoverProvider; + ExecutableExtension labelProvider; + ExecutableExtension hoverProvider; String editCommandId; String addNewCommandId; - LaunchBarTargetContribution(String id, String name, String iconStr, ILabelProvider labelProvider, - IHoverProvider hoverProvider, String editCommand, String addNewCommand) { - this.id = id; + LaunchBarTargetContribution(String name, String iconStr, + ExecutableExtension labelProvider, + ExecutableExtension hoverProvider, + String editCommand, String addNewCommand) { this.name = name; this.iconStr = iconStr; this.icon = null; diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/LaunchBarUIManagerAdapterFactory.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/LaunchBarUIManagerAdapterFactory.java deleted file mode 100644 index 338ec3a55c4..00000000000 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/LaunchBarUIManagerAdapterFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Doug Schaefer - *******************************************************************************/ -package org.eclipse.cdt.launchbar.ui.internal; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.cdt.launchbar.core.ILaunchBarManager; -import org.eclipse.core.runtime.IAdapterFactory; - -public class LaunchBarUIManagerAdapterFactory implements IAdapterFactory { - - private static Map uiProvider = new HashMap<>(); - - @Override - public Object getAdapter(Object adaptableObject, Class adapterType) { - if (adaptableObject instanceof ILaunchBarManager && adapterType.equals(LaunchBarUIManager.class)) { - ILaunchBarManager manager = (ILaunchBarManager) adaptableObject; - LaunchBarUIManager uiManager = uiProvider.get(manager); - if (uiManager == null) { - uiManager = new LaunchBarUIManager(manager); - uiProvider.put(manager, uiManager); - } - return uiManager; - } - return null; - } - - @Override - public Class[] getAdapterList() { - return new Class[] { LaunchBarUIManager.class }; - } - -} diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/BuildActiveCommandHandler.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/BuildActiveCommandHandler.java index 301c7827d7b..dd1b056012c 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/BuildActiveCommandHandler.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/BuildActiveCommandHandler.java @@ -15,9 +15,9 @@ import java.util.Collection; import java.util.HashSet; import java.util.Set; -import org.eclipse.cdt.launchbar.core.ILaunchBarManager; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchTarget; +import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager; import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -51,12 +51,6 @@ import org.eclipse.ui.progress.UIJob; */ public class BuildActiveCommandHandler extends AbstractHandler { - private final ILaunchBarManager launchBarManager; - - public BuildActiveCommandHandler() { - launchBarManager = Activator.getService(ILaunchBarManager.class); - } - @Override public Object execute(ExecutionEvent event) throws ExecutionException { new UIJob(Display.getDefault(), "Building Active Configuration") { @@ -67,10 +61,16 @@ public class BuildActiveCommandHandler extends AbstractHandler { public IStatus runInUIThread(IProgressMonitor monitor) { try { + LaunchBarManager launchBarManager = Activator.getDefault().getLaunchBarUIManager().getManager(); ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor(); ILaunchTarget target = launchBarManager.getActiveLaunchTarget(); ILaunchConfiguration config = launchBarManager.getLaunchConfiguration(desc, target); + Collection projects = getProjects(config); + if (BuildAction.isSaveAllSet()) { + saveEditors(projects); + } + if (config == null) { // Default, build the workspace ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); @@ -78,12 +78,6 @@ public class BuildActiveCommandHandler extends AbstractHandler { } ILaunchMode launchMode = launchBarManager.getActiveLaunchMode(); - - Collection projects = getProjects(config); - if (BuildAction.isSaveAllSet()) { - saveEditors(projects); - } - String mode = launchMode.getIdentifier(); Set modes = new HashSet<>(); modes.add(mode); @@ -113,7 +107,7 @@ public class BuildActiveCommandHandler extends AbstractHandler { } catch (CoreException e) { return e.getStatus(); } - + return Status.OK_STATUS; }; }.schedule(); @@ -124,22 +118,24 @@ public class BuildActiveCommandHandler extends AbstractHandler { protected Collection getProjects(ILaunchConfiguration config) { Set projects = new HashSet<>(); - IResource[] mappedResources; - try { - mappedResources = config.getMappedResources(); - } catch (CoreException e) { - return projects; - } - if (mappedResources != null) { - for (IResource resource : mappedResources) { - IProject project = resource.getProject(); - if (projects.contains(project)) - continue; - projects.add(project); - try { - projects.addAll(Arrays.asList(project.getReferencedProjects())); - } catch (CoreException e) { - // skip + if (config != null) { + IResource[] mappedResources; + try { + mappedResources = config.getMappedResources(); + } catch (CoreException e) { + return projects; + } + if (mappedResources != null) { + for (IResource resource : mappedResources) { + IProject project = resource.getProject(); + if (projects.contains(project)) + continue; + projects.add(project); + try { + projects.addAll(Arrays.asList(project.getReferencedProjects())); + } catch (CoreException e) { + // skip + } } } } diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/ConfigureActiveLaunchHandler.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/ConfigureActiveLaunchHandler.java index 1c5d4f70f40..013365d37f9 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/ConfigureActiveLaunchHandler.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/ConfigureActiveLaunchHandler.java @@ -10,9 +10,9 @@ *******************************************************************************/ package org.eclipse.cdt.launchbar.ui.internal.commands; -import org.eclipse.cdt.launchbar.core.ILaunchBarManager; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchTarget; +import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager; import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -30,15 +30,10 @@ import org.eclipse.ui.handlers.HandlerUtil; public class ConfigureActiveLaunchHandler extends AbstractHandler { - private final ILaunchBarManager launchBarManager; - - public ConfigureActiveLaunchHandler() { - launchBarManager = Activator.getService(ILaunchBarManager.class); - } - @Override public Object execute(ExecutionEvent event) throws ExecutionException { try { + LaunchBarManager launchBarManager = Activator.getDefault().getLaunchBarUIManager().getManager(); ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor(); ILaunchTarget target = launchBarManager.getActiveLaunchTarget(); ILaunchConfiguration launchConfiguration = launchBarManager.getLaunchConfiguration(desc, target); diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/LaunchActiveCommandHandler.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/LaunchActiveCommandHandler.java index aa3e54544fa..0fd69e4966d 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/LaunchActiveCommandHandler.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/commands/LaunchActiveCommandHandler.java @@ -10,9 +10,9 @@ *******************************************************************************/ package org.eclipse.cdt.launchbar.ui.internal.commands; -import org.eclipse.cdt.launchbar.core.ILaunchBarManager; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchTarget; +import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager; import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -29,17 +29,12 @@ import org.eclipse.ui.progress.UIJob; public class LaunchActiveCommandHandler extends AbstractHandler { - private final ILaunchBarManager launchBarManager; - - public LaunchActiveCommandHandler() { - launchBarManager = Activator.getService(ILaunchBarManager.class); - } - @Override public Object execute(ExecutionEvent event) throws ExecutionException { new UIJob(Display.getDefault(), "Launching Active Configuration") { public IStatus runInUIThread(IProgressMonitor monitor) { try { + LaunchBarManager launchBarManager = Activator.getDefault().getLaunchBarUIManager().getManager(); ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor(); ILaunchTarget target = launchBarManager.getActiveLaunchTarget(); ILaunchConfiguration config = launchBarManager.getLaunchConfiguration(desc, target); diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/ConfigSelector.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/ConfigSelector.java index 7f475413ea1..ef5ee63d945 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/ConfigSelector.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/ConfigSelector.java @@ -13,9 +13,9 @@ package org.eclipse.cdt.launchbar.ui.internal.controls; import java.util.Arrays; import java.util.Comparator; -import org.eclipse.cdt.launchbar.core.ILaunchBarManager; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchTarget; +import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager; import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.cdt.launchbar.ui.internal.DefaultDescriptorLabelProvider; import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager; @@ -61,7 +61,7 @@ import org.eclipse.ui.PlatformUI; @SuppressWarnings("restriction") public class ConfigSelector extends CSelector { - private LaunchBarUIManager uiManager; + private LaunchBarUIManager uiManager = Activator.getDefault().getLaunchBarUIManager(); private DefaultDescriptorLabelProvider defaultProvider; private static final String[] noConfigs = new String[] { "No Launch Configurations" }; @@ -82,7 +82,7 @@ public class ConfigSelector extends CSelector { } @Override public Object[] getElements(Object inputElement) { - ILaunchDescriptor[] descs = getManager().getOpenLaunchDescriptors(); + ILaunchDescriptor[] descs = uiManager.getManager().getLaunchDescriptors(); if (descs.length > 0) { if (descs.length > SEPARATOR_INDEX + 1) { ILaunchDescriptor[] descsCopy = new ILaunchDescriptor[SEPARATOR_INDEX + descs.length]; @@ -107,12 +107,16 @@ public class ConfigSelector extends CSelector { @Override public Image getImage(Object element) { if (element instanceof ILaunchDescriptor) { - ILaunchDescriptor configDesc = (ILaunchDescriptor)element; - ILabelProvider labelProvider = uiManager.getLabelProvider(configDesc); - if (labelProvider != null) { - Image img = labelProvider.getImage(element); - if (img != null) - return img; + try { + ILaunchDescriptor configDesc = (ILaunchDescriptor)element; + ILabelProvider labelProvider = uiManager.getLabelProvider(configDesc); + if (labelProvider != null) { + Image img = labelProvider.getImage(element); + if (img != null) + return img; + } + } catch (CoreException e) { + Activator.log(e.getStatus()); } } return defaultProvider.getImage(element); @@ -122,12 +126,16 @@ public class ConfigSelector extends CSelector { if (element instanceof String) { return (String)element; } else if (element instanceof ILaunchDescriptor) { - ILaunchDescriptor configDesc = (ILaunchDescriptor)element; - ILabelProvider labelProvider = uiManager.getLabelProvider(configDesc); - if (labelProvider != null) { - String text = labelProvider.getText(element); - if (text != null) - return text; + try { + ILaunchDescriptor configDesc = (ILaunchDescriptor)element; + ILabelProvider labelProvider = uiManager.getLabelProvider(configDesc); + if (labelProvider != null) { + String text = labelProvider.getText(element); + if (text != null) + return text; + } + } catch (CoreException e) { + Activator.log(e.getStatus()); } } return defaultProvider.getText(element); @@ -144,9 +152,9 @@ public class ConfigSelector extends CSelector { if (selected instanceof ILaunchDescriptor) { ILaunchDescriptor configDesc = (ILaunchDescriptor) selected; try { - getManager().setActiveLaunchDescriptor(configDesc); + uiManager.getManager().setActiveLaunchDescriptor(configDesc); } catch (CoreException e) { - Activator.log(e); + Activator.log(e.getStatus()); } } } @@ -160,14 +168,15 @@ public class ConfigSelector extends CSelector { public void handleEdit(Object element) { try { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + LaunchBarManager manager = uiManager.getManager(); ILaunchDescriptor desc = (ILaunchDescriptor) element; - ILaunchMode mode = getManager().getActiveLaunchMode(); - ILaunchTarget target = getManager().getActiveLaunchTarget(); + ILaunchMode mode = manager.getActiveLaunchMode(); + ILaunchTarget target = manager.getActiveLaunchTarget(); if (target == null) { MessageDialog.openError(shell, "No Active Target", "You must create a target to edit this launch configuration."); return; } - ILaunchConfigurationType configType = getManager().getLaunchConfigurationType(desc, target); + ILaunchConfigurationType configType = manager.getLaunchConfigurationType(desc, target); if (configType == null) { MessageDialog.openError(shell, "No launch configuration type", "Cannot edit this configuration"); return; @@ -175,7 +184,7 @@ public class ConfigSelector extends CSelector { ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(configType, mode.getIdentifier()); LaunchGroupExtension groupExt = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(group.getIdentifier()); if (groupExt != null) { - ILaunchConfiguration config = getManager().getLaunchConfiguration(desc, target); + ILaunchConfiguration config = manager.getLaunchConfiguration(desc, target); if (config == null) { MessageDialog.openError(shell, "No launch configuration", "Cannot edit this configuration"); return; @@ -236,7 +245,7 @@ public class ConfigSelector extends CSelector { try { wizard.getWorkingCopy().doSave(); ILaunchMode lm = wizard.getLaunchMode(); - getManager().setActiveLaunchMode(lm); + uiManager.getManager().setActiveLaunchMode(lm); return Status.OK_STATUS; } catch (CoreException e) { return e.getStatus(); @@ -271,16 +280,6 @@ public class ConfigSelector extends CSelector { return super.computeSize(250, hHint, changed); } - private ILaunchBarManager getManager() { - return (ILaunchBarManager) getInput(); - } - - @Override - public void setInput(Object input) { - super.setInput(input); - uiManager = (LaunchBarUIManager) ((ILaunchBarManager) input).getAdapter(LaunchBarUIManager.class); - } - @Override public void setSelection(Object element) { if (element == null) diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/LaunchBarControl.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/LaunchBarControl.java index 1ef343a64ce..f9a00eb4a6e 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/LaunchBarControl.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/LaunchBarControl.java @@ -12,14 +12,13 @@ package org.eclipse.cdt.launchbar.ui.internal.controls; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; -import javax.inject.Inject; -import org.eclipse.cdt.launchbar.core.ILaunchBarManager; import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; import org.eclipse.cdt.launchbar.core.ILaunchTarget; +import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager; +import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager.Listener; import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.cdt.launchbar.ui.internal.Messages; -import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunchMode; import org.eclipse.swt.SWT; import org.eclipse.swt.events.DisposeEvent; @@ -32,13 +31,12 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; -public class LaunchBarControl implements ILaunchBarManager.Listener { +public class LaunchBarControl implements Listener { public static final String ID = "org.eclipse.cdt.launchbar"; //$NON-NLS-1$ public static final String CLASS_URI = "bundleclass://" + Activator.PLUGIN_ID + "/" + LaunchBarControl.class.getName(); //$NON-NLS-1$ //$NON-NLS-2$ - @Inject - private ILaunchBarManager manager; + private LaunchBarManager manager = Activator.getDefault().getLaunchBarUIManager().getManager(); private ConfigSelector configSelector; private ModeSelector modeSelector; @@ -81,18 +79,14 @@ public class LaunchBarControl implements ILaunchBarManager.Listener { targetSelector.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); targetSelector.setInput(manager); - try { - ILaunchDescriptor configDesc = manager.getActiveLaunchDescriptor(); - configSelector.setSelection(configDesc == null ? null : configDesc); + ILaunchDescriptor configDesc = manager.getActiveLaunchDescriptor(); + configSelector.setSelection(configDesc == null ? null : configDesc); - ILaunchMode mode = manager.getActiveLaunchMode(); - modeSelector.setSelection(mode == null ? null : mode); + ILaunchMode mode = manager.getActiveLaunchMode(); + modeSelector.setSelection(mode == null ? null : mode); - ILaunchTarget target = manager.getActiveLaunchTarget(); - targetSelector.setSelection(target == null ? null : target); - } catch (CoreException e) { - Activator.log(e.getStatus()); - } + ILaunchTarget target = manager.getActiveLaunchTarget(); + targetSelector.setSelection(target == null ? null : target); } @PreDestroy @@ -118,54 +112,42 @@ public class LaunchBarControl implements ILaunchBarManager.Listener { @Override public void activeConfigurationDescriptorChanged() { if (configSelector != null && !configSelector.isDisposed()) { - try { - final ILaunchDescriptor configDesc = manager.getActiveLaunchDescriptor(); - configSelector.getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - if (!configSelector.isDisposed()) - configSelector.setSelection(configDesc == null ? null : configDesc); - } - }); - } catch (CoreException e) { - Activator.log(e.getStatus()); - } + final ILaunchDescriptor configDesc = manager.getActiveLaunchDescriptor(); + configSelector.getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + if (!configSelector.isDisposed()) + configSelector.setSelection(configDesc == null ? null : configDesc); + } + }); } } @Override public void activeLaunchModeChanged() { if (modeSelector != null && !modeSelector.isDisposed()) { - try { - final ILaunchMode mode = manager.getActiveLaunchMode(); - modeSelector.getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - if (!modeSelector.isDisposed()) - modeSelector.setSelection(mode == null ? null : mode); - } - }); - } catch (CoreException e) { - Activator.log(e.getStatus()); - } + final ILaunchMode mode = manager.getActiveLaunchMode(); + modeSelector.getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + if (!modeSelector.isDisposed()) + modeSelector.setSelection(mode == null ? null : mode); + } + }); } } @Override public void activeLaunchTargetChanged() { if (targetSelector != null && !targetSelector.isDisposed()) { - try { - final ILaunchTarget target = manager.getActiveLaunchTarget(); - targetSelector.getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - if (!targetSelector.isDisposed()) - targetSelector.setSelection(target == null ? null : target); - } - }); - } catch (CoreException e) { - Activator.log(e.getStatus()); - } + final ILaunchTarget target = manager.getActiveLaunchTarget(); + targetSelector.getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + if (!targetSelector.isDisposed()) + targetSelector.setSelection(target == null ? null : target); + } + }); } } diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/ModeSelector.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/ModeSelector.java index b5a38af0ea6..e653167f8aa 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/ModeSelector.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/ModeSelector.java @@ -14,7 +14,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.Map; -import org.eclipse.cdt.launchbar.core.ILaunchBarManager; +import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager; import org.eclipse.cdt.launchbar.ui.internal.Activator; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunchConfigurationType; @@ -33,7 +33,9 @@ import org.eclipse.swt.widgets.Composite; public class ModeSelector extends CSelector { private static final String[] noModes = new String[] { "---" }; - + + private final LaunchBarManager manager = Activator.getDefault().getLaunchBarUIManager().getManager(); + public ModeSelector(Composite parent, int style) { super(parent, style); @@ -49,11 +51,11 @@ public class ModeSelector extends CSelector { @Override public Object[] getElements(Object inputElement) { try { - ILaunchMode[] modes = getManager().getLaunchModes(); + ILaunchMode[] modes = manager.getLaunchModes(); if (modes.length > 0) return modes; } catch (CoreException e) { - Activator.log(e); + Activator.log(e.getStatus()); } return noModes; } @@ -72,15 +74,19 @@ public class ModeSelector extends CSelector { public Image getImage(Object element) { if (element instanceof ILaunchMode) { ILaunchMode mode = (ILaunchMode) element; - ILaunchGroup group = getLaunchGroup(mode.getIdentifier()); - if (group != null) { - ImageDescriptor imageDesc = group.getImageDescriptor(); - Image image = images.get(imageDesc); - if (image == null) { - image = imageDesc.createImage(); - images.put(imageDesc, image); + try { + ILaunchGroup group = getLaunchGroup(mode.getIdentifier()); + if (group != null) { + ImageDescriptor imageDesc = group.getImageDescriptor(); + Image image = images.get(imageDesc); + if (image == null) { + image = imageDesc.createImage(); + images.put(imageDesc, image); + } + return image; } - return image; + } catch (CoreException e) { + Activator.log(e.getStatus()); } } return super.getImage(element); @@ -89,9 +95,13 @@ public class ModeSelector extends CSelector { public String getText(Object element) { if (element instanceof ILaunchMode) { ILaunchMode mode = (ILaunchMode) element; - ILaunchGroup group = getLaunchGroup(mode.getIdentifier()); - if (group != null) { - return group.getLabel().replace("&", ""); + try { + ILaunchGroup group = getLaunchGroup(mode.getIdentifier()); + if (group != null) { + return group.getLabel().replace("&", ""); + } + } catch (CoreException e) { + Activator.log(e.getStatus()); } } return super.getText(element); @@ -128,16 +138,11 @@ public class ModeSelector extends CSelector { } - protected ILaunchGroup getLaunchGroup(String mode) { - try { - ILaunchConfigurationType type = getManager().getLaunchConfigurationType(getManager().getActiveLaunchDescriptor(), getManager().getActiveLaunchTarget()); - if (type == null) - return null; - return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(type, mode); - } catch (CoreException e) { - Activator.log(e.getStatus()); - } - return null; + protected ILaunchGroup getLaunchGroup(String mode) throws CoreException { + ILaunchConfigurationType type = manager.getLaunchConfigurationType(manager.getActiveLaunchDescriptor(), manager.getActiveLaunchTarget()); + if (type == null) + return null; + return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(type, mode); } @Override @@ -146,27 +151,23 @@ public class ModeSelector extends CSelector { if (selected instanceof ILaunchMode) { ILaunchMode mode = (ILaunchMode) selected; try { - getManager().setActiveLaunchMode(mode); + manager.setActiveLaunchMode(mode); } catch (CoreException e) { - Activator.log(e); + Activator.log(e.getStatus()); } } } - + @Override public Point computeSize(int wHint, int hHint, boolean changed) { return super.computeSize(150, hHint, changed); } - private ILaunchBarManager getManager() { - return (ILaunchBarManager) getInput(); - } - @Override public void setSelection(Object element) { if (element == null) element = noModes[0]; super.setSelection(element); } - + } diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/TargetSelector.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/TargetSelector.java index 247285bb183..b1e7cf04652 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/TargetSelector.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/controls/TargetSelector.java @@ -13,7 +13,6 @@ package org.eclipse.cdt.launchbar.ui.internal.controls; import java.util.Comparator; import java.util.Map; -import org.eclipse.cdt.launchbar.core.ILaunchBarManager; import org.eclipse.cdt.launchbar.core.ILaunchTarget; import org.eclipse.cdt.launchbar.ui.IHoverProvider; import org.eclipse.cdt.launchbar.ui.ILaunchBarUIConstants; @@ -45,16 +44,13 @@ import org.eclipse.ui.dialogs.ListDialog; public class TargetSelector extends CSelector { - private final LaunchBarUIManager uiManager; + private final LaunchBarUIManager uiManager = Activator.getDefault().getLaunchBarUIManager(); private static final String[] noTargets = new String[] { "---" }; public TargetSelector(Composite parent, int style) { super(parent, style); - ILaunchBarManager manager = Activator.getService(ILaunchBarManager.class); - uiManager = (LaunchBarUIManager) manager.getAdapter(LaunchBarUIManager.class); - setContentProvider(new IStructuredContentProvider() { @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { @@ -67,7 +63,7 @@ public class TargetSelector extends CSelector { @Override public Object[] getElements(Object inputElement) { try { - ILaunchTarget[] targets = getManager().getLaunchTargets(); + ILaunchTarget[] targets = uiManager.getManager().getLaunchTargets(); if (targets.length > 0) return targets; } catch (CoreException e) { @@ -81,10 +77,14 @@ public class TargetSelector extends CSelector { @Override public Image getImage(Object element) { if (element instanceof ILaunchTarget) { - ILaunchTarget target = (ILaunchTarget) element; - ILabelProvider labelProvider = uiManager.getLabelProvider(target); - if (labelProvider != null) { - return labelProvider.getImage(element); + try { + ILaunchTarget target = (ILaunchTarget) element; + ILabelProvider labelProvider = uiManager.getLabelProvider(target); + if (labelProvider != null) { + return labelProvider.getImage(element); + } + } catch (CoreException e) { + Activator.log(e.getStatus()); } } return super.getImage(element); @@ -93,12 +93,16 @@ public class TargetSelector extends CSelector { @Override public String getText(Object element) { if (element instanceof ILaunchTarget) { - ILaunchTarget target = (ILaunchTarget) element; - ILabelProvider labelProvider = uiManager.getLabelProvider(target); - if (labelProvider != null) { - return labelProvider.getText(element); - } - return target.getName(); + ILaunchTarget target = (ILaunchTarget) element; + try { + ILabelProvider labelProvider = uiManager.getLabelProvider(target); + if (labelProvider != null) { + return labelProvider.getText(element); + } + } catch (CoreException e) { + Activator.log(e.getStatus()); + } + return target.getName(); } return super.getText(element); } @@ -116,10 +120,14 @@ public class TargetSelector extends CSelector { @Override public boolean displayHover(Object element) { if (element instanceof ILaunchTarget) { - ILaunchTarget target = (ILaunchTarget) element; - IHoverProvider hoverProvider = uiManager.getHoverProvider(target); - if (hoverProvider != null) { - return hoverProvider.displayHover(element); + try { + ILaunchTarget target = (ILaunchTarget) element; + IHoverProvider hoverProvider = uiManager.getHoverProvider(target); + if (hoverProvider != null) { + return hoverProvider.displayHover(element); + } + } catch (CoreException e) { + Activator.log(e.getStatus()); } } return false; @@ -128,10 +136,14 @@ public class TargetSelector extends CSelector { @Override public void dismissHover(Object element, boolean immediate) { if (element instanceof ILaunchTarget) { - ILaunchTarget target = (ILaunchTarget) element; - IHoverProvider hoverProvider = uiManager.getHoverProvider(target); - if (hoverProvider != null) { - hoverProvider.dismissHover(element, immediate); + try { + ILaunchTarget target = (ILaunchTarget) element; + IHoverProvider hoverProvider = uiManager.getHoverProvider(target); + if (hoverProvider != null) { + hoverProvider.dismissHover(element, immediate); + } + } catch (CoreException e) { + Activator.log(e.getStatus()); } } } @@ -261,10 +273,6 @@ public class TargetSelector extends CSelector { return super.computeSize(200, hHint, changed); } - private ILaunchBarManager getManager() { - return (ILaunchBarManager) getInput(); - } - @Override public void setSelection(Object element) { if (element == null) diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/LaunchTargetsActionProvider.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/LaunchTargetsActionProvider.java new file mode 100644 index 00000000000..0f95a0803f0 --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/LaunchTargetsActionProvider.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2014 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Doug Schaefer + *******************************************************************************/ +package org.eclipse.cdt.launchbar.ui.internal.targetsView; + +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.window.SameShellProvider; +import org.eclipse.ui.dialogs.PropertyDialogAction; +import org.eclipse.ui.navigator.CommonActionProvider; + +public class LaunchTargetsActionProvider extends CommonActionProvider { + + @Override + public void fillContextMenu(IMenuManager menu) { + menu.add(new PropertyDialogAction(new SameShellProvider(getActionSite().getViewSite().getShell()), + getActionSite().getStructuredViewer())); + } + +} diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/LaunchTargetsContentProvider.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/LaunchTargetsContentProvider.java new file mode 100644 index 00000000000..272b5a41b2b --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/LaunchTargetsContentProvider.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2014 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Doug Schaefer + *******************************************************************************/ +package org.eclipse.cdt.launchbar.ui.internal.targetsView; + +import java.util.Arrays; +import java.util.Comparator; + +import org.eclipse.cdt.launchbar.core.ILaunchTarget; +import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +public class LaunchTargetsContentProvider implements ITreeContentProvider { + + private LaunchBarManager manager; + + @Override + public Object[] getElements(Object inputElement) { + if (inputElement instanceof LaunchBarManager) { + ILaunchTarget[] targets = ((LaunchBarManager) inputElement).getAllLaunchTargets(); + Arrays.sort(targets, new Comparator() { + @Override + public int compare(ILaunchTarget o1, ILaunchTarget o2) { + return o1.getName().compareTo(o2.getName()); + } + }); + return targets; + } + return null; + } + + @Override + public Object[] getChildren(Object parentElement) { + return new Object[0]; + } + + @Override + public Object getParent(Object element) { + if (element instanceof ILaunchTarget) { + return manager; + } + return null; + } + + @Override + public boolean hasChildren(Object element) { + if (element instanceof LaunchBarManager) + return true; + else if (element instanceof ILaunchTarget) + return false; + return false; + } + + @Override + public void dispose() { + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + if (newInput instanceof LaunchBarManager) { + manager = (LaunchBarManager) newInput; + } + } + +} diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/LaunchTargetsLabelProvider.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/LaunchTargetsLabelProvider.java new file mode 100644 index 00000000000..d84d5061b46 --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/LaunchTargetsLabelProvider.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2014 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Doug Schaefer + *******************************************************************************/ +package org.eclipse.cdt.launchbar.ui.internal.targetsView; + +import org.eclipse.cdt.launchbar.core.ILaunchTarget; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; + +public class LaunchTargetsLabelProvider extends LabelProvider { + + @Override + public Image getImage(Object element) { + return super.getImage(element); + } + + @Override + public String getText(Object element) { + if (element instanceof ILaunchTarget) { + return ((ILaunchTarget) element).getName(); + } + return super.getText(element); + } + +} diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/LaunchTargetsNavigator.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/LaunchTargetsNavigator.java new file mode 100644 index 00000000000..0670cffdb3a --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/LaunchTargetsNavigator.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2014 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Doug Schaefer + *******************************************************************************/ +package org.eclipse.cdt.launchbar.ui.internal.targetsView; + +import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; +import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager; +import org.eclipse.cdt.launchbar.ui.internal.Activator; +import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager; +import org.eclipse.ui.navigator.CommonNavigator; + +public class LaunchTargetsNavigator extends CommonNavigator { + + private final LaunchBarUIManager uiManager = Activator.getDefault().getLaunchBarUIManager(); + + public LaunchTargetsNavigator() { + uiManager.getManager().addListener(new LaunchBarManager.Listener() { + @Override + public void launchTargetsChanged() { + getSite().getShell().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + getCommonViewer().refresh(); + } + }); + } + @Override + public void launchDescriptorRemoved(ILaunchDescriptor descriptor) { + } + @Override + public void activeLaunchTargetChanged() { + } + @Override + public void activeLaunchModeChanged() { + } + @Override + public void activeConfigurationDescriptorChanged() { + } + }); + + } + + @Override + protected Object getInitialInput() { + return uiManager.getManager(); + } + +} diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/LaunchTargetsViewPart.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/LaunchTargetsViewPart.java deleted file mode 100644 index b2700a83fea..00000000000 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/LaunchTargetsViewPart.java +++ /dev/null @@ -1,157 +0,0 @@ -package org.eclipse.cdt.launchbar.ui.internal.targetsView; - -import java.util.Arrays; -import java.util.Comparator; - -import org.eclipse.cdt.launchbar.core.ILaunchBarManager; -import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; -import org.eclipse.cdt.launchbar.core.ILaunchTarget; -import org.eclipse.cdt.launchbar.core.ILaunchTargetType; -import org.eclipse.cdt.launchbar.core.internal.LaunchBarManager; -import org.eclipse.cdt.launchbar.ui.internal.Activator; -import org.eclipse.cdt.launchbar.ui.internal.LaunchBarUIManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerSorter; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.dialogs.PropertyDialogAction; -import org.eclipse.ui.part.ViewPart; - -public class LaunchTargetsViewPart extends ViewPart { - - private TreeViewer treeViewer; - private final LaunchBarUIManager uiManager; - - public LaunchTargetsViewPart() { - ILaunchBarManager manager = Activator.getService(ILaunchBarManager.class); - uiManager = (LaunchBarUIManager) manager.getAdapter(LaunchBarUIManager.class); - } - - @Override - public void createPartControl(Composite parent) { - treeViewer = new TreeViewer(parent, SWT.NONE); - treeViewer.setContentProvider(new ITreeContentProvider() { - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - @Override - public void dispose() { - } - - @Override - public boolean hasChildren(Object element) { - if (element instanceof LaunchBarManager) - return true; - else if (element instanceof ILaunchTargetType) - return true; - else if (element instanceof ILaunchTarget) - return false; - return false; - } - - @Override - public Object getParent(Object element) { - if (element instanceof ILaunchTarget) - return ((ILaunchTarget) element).getType(); - return null; - } - - @Override - public Object[] getElements(Object inputElement) { - // TODO optionally categorize by launch type, maybe - // return ((LaunchBarManager) inputElement).getLaunchTargetTypes(); - return ((LaunchBarManager) inputElement).getAllLaunchTargets(); - } - - @Override - public Object[] getChildren(Object parentElement) { - if (parentElement instanceof ILaunchTargetType) - return ((ILaunchTargetType) parentElement).getTargets(); - return new Object[0]; - } - }); - - treeViewer.setSorter(new ViewerSorter() { - @Override - public void sort(Viewer viewer, Object[] elements) { - if (elements instanceof ILaunchTarget[]) { - Arrays.sort((ILaunchTarget[]) elements, new Comparator() { - @Override - public int compare(ILaunchTarget o1, ILaunchTarget o2) { - return o1.getName().compareTo(o2.getName()); - } - }); - } - } - }); - - treeViewer.setLabelProvider(new LabelProvider() { - @Override - public String getText(Object element) { - if (element instanceof ILaunchTargetType) { - return element.getClass().getSimpleName(); - } else if (element instanceof ILaunchTarget) { - ILaunchTarget target = (ILaunchTarget) element; - ILabelProvider targetLabelProvider = uiManager.getLabelProvider(target); - if (targetLabelProvider != null) { - return targetLabelProvider.getText(element); - } else { - return target.getName(); - } - } else { - return super.getText(element); - } - } - }); - - final ILaunchBarManager launchBarManager = Activator.getService(ILaunchBarManager.class); - treeViewer.setInput(launchBarManager); - launchBarManager.addListener(new ILaunchBarManager.Listener() { - @Override - public void launchTargetsChanged() { - treeViewer.getControl().getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - treeViewer.setInput(launchBarManager); - } - }); - } - @Override - public void launchDescriptorRemoved(ILaunchDescriptor descriptor) { - } - @Override - public void activeLaunchTargetChanged() { - } - @Override - public void activeLaunchModeChanged() { - } - @Override - public void activeConfigurationDescriptorChanged() { - } - }); - - MenuManager menuManager = new MenuManager(); - menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); - menuManager.add(new Separator()); - menuManager.add(new PropertyDialogAction(getSite(), treeViewer)); - Menu menu = menuManager.createContextMenu(treeViewer.getControl()); - treeViewer.getControl().setMenu(menu); - getSite().registerContextMenu(menuManager, treeViewer); - getSite().setSelectionProvider(treeViewer); - } - - @Override - public void setFocus() { - treeViewer.getControl().setFocus(); - } - -} diff --git a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/TargetPropertyPage.java b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/TargetPropertyPage.java index 520755a3fd7..801842898e6 100644 --- a/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/TargetPropertyPage.java +++ b/launch/org.eclipse.cdt.launchbar.ui/src/org/eclipse/cdt/launchbar/ui/internal/targetsView/TargetPropertyPage.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2014 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Doug Schaefer + *******************************************************************************/ package org.eclipse.cdt.launchbar.ui.internal.targetsView; import org.eclipse.cdt.launchbar.core.ILaunchTarget; @@ -29,20 +39,6 @@ public class TargetPropertyPage extends PropertyPage { nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); nameText.setText(target.getName()); - Label targetLabel = new Label(comp, SWT.NONE); - targetLabel.setText("Target Id:"); - - Label targetId = new Label(comp, SWT.NONE); - targetId.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - targetId.setText(target.getId()); - - Label typeLabel = new Label(comp, SWT.NONE); - typeLabel.setText("Target Type:"); - - Label typeId = new Label(comp, SWT.NONE); - typeId.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - typeId.setText(target.getType().getId()); - return comp; }