From dcf1440fe4ef9655ca27420003669ac79139a351 Mon Sep 17 00:00:00 2001 From: Alena Laskavaia Date: Wed, 23 Jul 2014 15:50:29 -0400 Subject: [PATCH] LaunchBar - new extension for simple providers * If provider only wants to associate lc type with target the only thing is needed is to specy this lc type somewhere and framework should take care of the rest Change-Id: I3f60c7a0a5b1334f989e972fe8f773c6e2d7f71a Signed-off-by: Alena Laskavaia Reviewed-on: https://git.eclipse.org/r/30381 Reviewed-by: Doug Schaefer Tested-by: Doug Schaefer --- .../schema/launchBarContributions.exsd | 48 ++++++++++++ .../core/internal/LaunchBarManager.java | 41 ++++++---- .../TypeBasedLaunchConfigurationProvider.java | 77 +++++++++++++++++++ .../TypeBasedLaunchDescriptorType.java | 65 ++++++++++++++++ 4 files changed, 218 insertions(+), 13 deletions(-) create mode 100644 launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/TypeBasedLaunchConfigurationProvider.java create mode 100644 launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/TypeBasedLaunchDescriptorType.java diff --git a/launch/org.eclipse.cdt.launchbar.core/schema/launchBarContributions.exsd b/launch/org.eclipse.cdt.launchbar.core/schema/launchBarContributions.exsd index 78b8e1abdfe..f9c33b79d68 100644 --- a/launch/org.eclipse.cdt.launchbar.core/schema/launchBarContributions.exsd +++ b/launch/org.eclipse.cdt.launchbar.core/schema/launchBarContributions.exsd @@ -143,6 +143,54 @@ + + + + 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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Is this the default target type for this descriptor type. + + + + + + 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 39bf4d9141c..080646ee7e4 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 @@ -104,20 +104,21 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage } else 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"); - - Map targetTypes = configProviders.get(descriptorType); - if (targetTypes == null) { - targetTypes = new HashMap<>(); - configProviders.put(descriptorType, targetTypes); - } - targetTypes.put(targetType, configProvider); - + 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"); - if (isDefault != null && Boolean.valueOf(isDefault)) { - defaultTargetTypes.put(descriptorType, targetType); - } + ILaunchConfigurationProvider configProvider = new TypeBasedLaunchConfigurationProvider(launchType); + addConfigProvider(descriptorType, targetType, Boolean.valueOf(isDefault), configProvider); + + ILaunchDescriptorType type = new TypeBasedLaunchDescriptorType(descriptorType, launchType); + descriptorTypes.add(type); + typePriorities.put(type, 2); // TODO: fix priority } } } @@ -179,6 +180,19 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage } } + protected void addConfigProvider(String descriptorType, String targetType, boolean isDefaultB, + ILaunchConfigurationProvider configProvider) { + Map targetTypes = configProviders.get(descriptorType); + if (targetTypes == null) { + targetTypes = new HashMap<>(); + configProviders.put(descriptorType, targetTypes); + } + targetTypes.put(targetType, configProvider); + if (isDefaultB) { + defaultTargetTypes.put(descriptorType, targetType); + } + } + @Override public ILaunchDescriptor launchObjectAdded(Object element) { ILaunchDescriptor desc = objectDescriptorMap.get(element); @@ -193,8 +207,9 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage String id = getId(desc); ILaunchDescriptor old = descriptors.get(id); if (old != null && !desc.equals(old)) - throw new IllegalStateException( - "Name of descriptor must be unique within same type (or descriptors with same name must be equal)"); + Activator.log(new IllegalStateException( + "Name of descriptor must be unique within same type " + + "(or descriptors with same name must be equal)")); descriptors.put(id, desc); objectDescriptorMap.put(element, desc); setActiveLaunchDescriptor(desc); diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/TypeBasedLaunchConfigurationProvider.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/TypeBasedLaunchConfigurationProvider.java new file mode 100644 index 00000000000..49e708ae74f --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/TypeBasedLaunchConfigurationProvider.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: + * QNX Software Systems (Elena Laskavaia) - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.launchbar.core.internal; + +import org.eclipse.cdt.launchbar.core.DefaultLaunchDescriptor; +import org.eclipse.cdt.launchbar.core.ILaunchBarManager; +import org.eclipse.cdt.launchbar.core.ILaunchConfigurationProvider; +import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; + +public class TypeBasedLaunchConfigurationProvider implements ILaunchConfigurationProvider { + protected ILaunchBarManager manager; + private String typeId; + + public TypeBasedLaunchConfigurationProvider(String launchConfigurationTypeId) { + this.typeId = launchConfigurationTypeId; + } + + @Override + public void init(ILaunchBarManager manager) throws CoreException { + this.manager = manager; + } + + public boolean ownsConfiguration(ILaunchConfiguration element) { + try { + return element.getType().getIdentifier().equals(typeId); + } catch (CoreException e) { + return false; + } + } + + @Override + public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException { + if (ownsConfiguration(configuration)) { + manager.launchObjectAdded(configuration); + return true; + } + return false; + } + + @Override + public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException { + if (ownsConfiguration(configuration)) { + manager.launchObjectRemoved(configuration); + return true; + } + return false; + } + + @Override + public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor) throws CoreException { + if (descriptor instanceof DefaultLaunchDescriptor) { + return ((DefaultLaunchDescriptor) descriptor).getConfig(); + } + return null; + } + + @Override + public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor) throws CoreException { + if (descriptor instanceof DefaultLaunchDescriptor) { + return ((DefaultLaunchDescriptor) descriptor).getConfig().getType(); + } + return null; + } +} diff --git a/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/TypeBasedLaunchDescriptorType.java b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/TypeBasedLaunchDescriptorType.java new file mode 100644 index 00000000000..d8be527eb2f --- /dev/null +++ b/launch/org.eclipse.cdt.launchbar.core/src/org/eclipse/cdt/launchbar/core/internal/TypeBasedLaunchDescriptorType.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2014 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems (Elena Laskavaia) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.launchbar.core.internal; + +import org.eclipse.cdt.launchbar.core.DefaultLaunchDescriptor; +import org.eclipse.cdt.launchbar.core.ILaunchBarManager; +import org.eclipse.cdt.launchbar.core.ILaunchDescriptor; +import org.eclipse.cdt.launchbar.core.ILaunchDescriptorType; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; + +public class TypeBasedLaunchDescriptorType implements ILaunchDescriptorType { + protected ILaunchBarManager manager; + private String typeId; + private String id; + + public TypeBasedLaunchDescriptorType(String descId, String launchConfigurationTypeId) { + if (launchConfigurationTypeId == null) + throw new NullPointerException(); + this.typeId = launchConfigurationTypeId; + this.id = descId != null ? descId : typeId + ".desc"; + } + + @Override + public String getId() { + return id; + } + + public boolean ownsConfiguration(ILaunchConfiguration element) { + try { + return element.getType().getIdentifier().equals(typeId); + } catch (CoreException e) { + return false; + } + } + + @Override + public void init(ILaunchBarManager manager) { + this.manager = manager; + } + + @Override + public ILaunchDescriptor getDescriptor(Object element) { + return new DefaultLaunchDescriptor(this, (ILaunchConfiguration) element); + } + + @Override + public ILaunchBarManager getManager() { + return manager; + } + + @Override + public boolean ownsLaunchObject(Object element) { + return element instanceof ILaunchConfiguration + && ownsConfiguration((ILaunchConfiguration) element); + } +}