mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
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 <elaskavaia.cdt@gmail.com> Reviewed-on: https://git.eclipse.org/r/30381 Reviewed-by: Doug Schaefer <dschaefer@qnx.com> Tested-by: Doug Schaefer <dschaefer@qnx.com>
This commit is contained in:
parent
cd81c09a4f
commit
dcf1440fe4
4 changed files with 218 additions and 13 deletions
|
@ -143,6 +143,54 @@
|
||||||
</complexType>
|
</complexType>
|
||||||
</element>
|
</element>
|
||||||
|
|
||||||
|
<element name="defaultConfigProvider">
|
||||||
|
<annotation>
|
||||||
|
<documentation>
|
||||||
|
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
|
||||||
|
</documentation>
|
||||||
|
</annotation>
|
||||||
|
<complexType>
|
||||||
|
<attribute name="launchConfigurationType" type="string" use="required">
|
||||||
|
<annotation>
|
||||||
|
<documentation>
|
||||||
|
|
||||||
|
</documentation>
|
||||||
|
<appinfo>
|
||||||
|
<meta.attribute kind="identifier" basedOn="org.eclipse.debug.core.launchConfigurationTypes/launchConfigurationType/@id"/>
|
||||||
|
</appinfo>
|
||||||
|
</annotation>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="descriptorType" type="string">
|
||||||
|
<annotation>
|
||||||
|
<documentation>
|
||||||
|
|
||||||
|
</documentation>
|
||||||
|
<appinfo>
|
||||||
|
<meta.attribute kind="identifier" basedOn="org.eclipse.cdt.launchbar.core.launchBarContributions/descriptorType/@id"/>
|
||||||
|
</appinfo>
|
||||||
|
</annotation>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="targetType" type="string" use="required">
|
||||||
|
<annotation>
|
||||||
|
<documentation>
|
||||||
|
|
||||||
|
</documentation>
|
||||||
|
<appinfo>
|
||||||
|
<meta.attribute kind="identifier" basedOn="org.eclipse.cdt.launchbar.core.launchBarContributions/targetType/@id"/>
|
||||||
|
</appinfo>
|
||||||
|
</annotation>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="isDefault" type="boolean">
|
||||||
|
<annotation>
|
||||||
|
<documentation>
|
||||||
|
Is this the default target type for this descriptor type.
|
||||||
|
</documentation>
|
||||||
|
</annotation>
|
||||||
|
</attribute>
|
||||||
|
</complexType>
|
||||||
|
</element>
|
||||||
|
|
||||||
<element name="objectProvider">
|
<element name="objectProvider">
|
||||||
<complexType>
|
<complexType>
|
||||||
<attribute name="id" type="string" use="required">
|
<attribute name="id" type="string" use="required">
|
||||||
|
|
|
@ -104,20 +104,21 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
||||||
} else if (elementName.equals("configProvider")) {
|
} else if (elementName.equals("configProvider")) {
|
||||||
String descriptorType = element.getAttribute("descriptorType");
|
String descriptorType = element.getAttribute("descriptorType");
|
||||||
String targetType = element.getAttribute("targetType");
|
String targetType = element.getAttribute("targetType");
|
||||||
|
String isDefault = element.getAttribute("isDefault");
|
||||||
// TODO don't instantiate this until we need it
|
// TODO don't instantiate this until we need it
|
||||||
ILaunchConfigurationProvider configProvider = (ILaunchConfigurationProvider) element.createExecutableExtension("class");
|
ILaunchConfigurationProvider configProvider = (ILaunchConfigurationProvider) element.createExecutableExtension("class");
|
||||||
|
addConfigProvider(descriptorType, targetType, Boolean.valueOf(isDefault), configProvider);
|
||||||
Map<String, ILaunchConfigurationProvider> targetTypes = configProviders.get(descriptorType);
|
} else if (elementName.equals("defaultConfigProvider")) {
|
||||||
if (targetTypes == null) {
|
String descriptorType = element.getAttribute("descriptorType");
|
||||||
targetTypes = new HashMap<>();
|
String targetType = element.getAttribute("targetType");
|
||||||
configProviders.put(descriptorType, targetTypes);
|
String launchType = element.getAttribute("launchConfigurationType");
|
||||||
}
|
|
||||||
targetTypes.put(targetType, configProvider);
|
|
||||||
|
|
||||||
String isDefault = element.getAttribute("isDefault");
|
String isDefault = element.getAttribute("isDefault");
|
||||||
if (isDefault != null && Boolean.valueOf(isDefault)) {
|
ILaunchConfigurationProvider configProvider = new TypeBasedLaunchConfigurationProvider(launchType);
|
||||||
defaultTargetTypes.put(descriptorType, targetType);
|
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<String, ILaunchConfigurationProvider> 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
|
@Override
|
||||||
public ILaunchDescriptor launchObjectAdded(Object element) {
|
public ILaunchDescriptor launchObjectAdded(Object element) {
|
||||||
ILaunchDescriptor desc = objectDescriptorMap.get(element);
|
ILaunchDescriptor desc = objectDescriptorMap.get(element);
|
||||||
|
@ -193,8 +207,9 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
||||||
String id = getId(desc);
|
String id = getId(desc);
|
||||||
ILaunchDescriptor old = descriptors.get(id);
|
ILaunchDescriptor old = descriptors.get(id);
|
||||||
if (old != null && !desc.equals(old))
|
if (old != null && !desc.equals(old))
|
||||||
throw new IllegalStateException(
|
Activator.log(new IllegalStateException(
|
||||||
"Name of descriptor must be unique within same type (or descriptors with same name must be equal)");
|
"Name of descriptor must be unique within same type "
|
||||||
|
+ "(or descriptors with same name must be equal)"));
|
||||||
descriptors.put(id, desc);
|
descriptors.put(id, desc);
|
||||||
objectDescriptorMap.put(element, desc);
|
objectDescriptorMap.put(element, desc);
|
||||||
setActiveLaunchDescriptor(desc);
|
setActiveLaunchDescriptor(desc);
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue