1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-02 14:45:25 +02:00

Bug 484993 - Hook up label provider to remote launch target

Since we're using label providers to provide the name and image
for ILaunchTargets, we don't need the dual id, name in the launch
target. Switching to id instead of name tho.

Change-Id: I96071cfd40873494d4cf73f0e845d62bc46ea1cb
This commit is contained in:
Doug Schaefer 2015-12-30 21:59:29 -05:00
parent b588b08034
commit 7a1e27eb12
16 changed files with 203 additions and 51 deletions

View file

@ -14,12 +14,10 @@ public class LaunchTarget extends PlatformObject implements ILaunchTarget {
private final String typeId;
private final String id;
private final String name;
public LaunchTarget(String typeId, String id, String name) {
public LaunchTarget(String typeId, String id) {
this.typeId = typeId;
this.id = id;
this.name = name;
}
@Override
@ -27,11 +25,6 @@ public class LaunchTarget extends PlatformObject implements ILaunchTarget {
return id;
}
@Override
public String getName() {
return name;
}
@Override
public String getTypeId() {
return typeId;

View file

@ -39,8 +39,7 @@ public class LaunchTargetManager implements ILaunchTargetManager {
private List<ILaunchTargetListener> listeners = new LinkedList<>();
private static final String DELIMETER1 = ","; //$NON-NLS-1$
private static final String DELIMETER2 = "!"; //$NON-NLS-1$
private static final String DELIMETER3 = ":"; //$NON-NLS-1$
private static final String DELIMETER2 = ":"; //$NON-NLS-1$
private Preferences getTargetsPref() {
return InstanceScope.INSTANCE.getNode(Activator.getDefault().getBundle().getSymbolicName())
@ -75,12 +74,7 @@ public class LaunchTargetManager implements ILaunchTargetManager {
}
for (String name : prefs.get(typeId, "").split(DELIMETER1)) { //$NON-NLS-1$
if (name.contains(DELIMETER2)) {
String[] list = name.split(DELIMETER2);
type.put(list[0], new LaunchTarget(typeId, list[0], list[1]));
} else {
type.put(name, new LaunchTarget(typeId, name, name));
}
type.put(name, new LaunchTarget(typeId, name));
}
}
} catch (BackingStoreException e) {
@ -162,7 +156,7 @@ public class LaunchTargetManager implements ILaunchTargetManager {
}
@Override
public ILaunchTarget addLaunchTarget(String typeId, String id, String name) {
public ILaunchTarget addLaunchTarget(String typeId, String id) {
initTargets();
Map<String, ILaunchTarget> type = targets.get(typeId);
if (type == null) {
@ -170,11 +164,11 @@ public class LaunchTargetManager implements ILaunchTargetManager {
targets.put(typeId, type);
}
ILaunchTarget target = new LaunchTarget(typeId, id, name);
ILaunchTarget target = new LaunchTarget(typeId, id);
type.put(id, target);
getTargetsPref().put(typeId, type.values().stream().map(t -> t.getId() + DELIMETER2 + t.getName())
.collect(Collectors.joining(DELIMETER1)));
getTargetsPref().put(typeId,
type.values().stream().map(t -> t.getId()).collect(Collectors.joining(DELIMETER1)));
for (ILaunchTargetListener listener : listeners) {
listener.launchTargetAdded(target);
@ -188,13 +182,13 @@ public class LaunchTargetManager implements ILaunchTargetManager {
initTargets();
Map<String, ILaunchTarget> type = targets.get(target.getTypeId());
if (type != null) {
type.remove(target.getName());
type.remove(target.getId());
if (type.isEmpty()) {
targets.remove(target.getTypeId());
getTargetsPref().remove(target.getTypeId());
} else {
getTargetsPref().put(target.getTypeId(), type.values().stream()
.map(t -> t.getId() + DELIMETER2 + t.getName()).collect(Collectors.joining(DELIMETER1)));
getTargetsPref().put(target.getTypeId(),
type.values().stream().map(t -> t.getId()).collect(Collectors.joining(DELIMETER1)));
}
for (ILaunchTargetListener listener : listeners) {
@ -215,7 +209,7 @@ public class LaunchTargetManager implements ILaunchTargetManager {
Preferences prefs = getTargetsPref().node("configs"); //$NON-NLS-1$
String targetId = prefs.get(configuration.getName(), null);
if (targetId != null) {
String[] parts = targetId.split(DELIMETER3);
String[] parts = targetId.split(DELIMETER2);
return getLaunchTarget(parts[0], parts[1]);
}
return null;
@ -224,7 +218,7 @@ public class LaunchTargetManager implements ILaunchTargetManager {
@Override
public void setDefaultLaunchTarget(ILaunchConfiguration configuration, ILaunchTarget target) {
Preferences prefs = getTargetsPref().node("configs"); //$NON-NLS-1$
String targetId = String.join(DELIMETER3, target.getTypeId(), target.getId());
String targetId = String.join(DELIMETER2, target.getTypeId(), target.getId());
prefs.put(configuration.getName(), targetId);
try {
prefs.flush();

View file

@ -19,8 +19,7 @@ public class LocalLaunchTargetProvider implements ILaunchTargetProvider {
public void init(ILaunchTargetManager targetManager) {
if (targetManager.getLaunchTarget(ILaunchTargetManager.localLaunchTargetTypeId,
Messages.LocalTarget_name) == null) {
targetManager.addLaunchTarget(ILaunchTargetManager.localLaunchTargetTypeId, Messages.LocalTarget_name,
Messages.LocalTarget_name);
targetManager.addLaunchTarget(ILaunchTargetManager.localLaunchTargetTypeId, Messages.LocalTarget_name);
}
}

View file

@ -18,7 +18,7 @@ import org.eclipse.launchbar.core.internal.target.LaunchTarget;
* @noimplement not to be implemented by clients
*/
public interface ILaunchTarget extends IAdaptable {
public static final ILaunchTarget NULL_TARGET = new LaunchTarget("null", "null", "---");
public static final ILaunchTarget NULL_TARGET = new LaunchTarget("null", "---"); //$NON-NLS-1$ //$NON-NLS-2$
/**
* The id for the target. It is unique for each type.
@ -29,10 +29,14 @@ public interface ILaunchTarget extends IAdaptable {
/**
* The user consumable name of the target.
*
*
* @deprecated this will be the same as the id
* @return name of the target
*/
String getName();
@Deprecated
default String getName() {
return getId();
}
/**
* The type of the target.

View file

@ -67,25 +67,9 @@ public interface ILaunchTargetManager {
* type id of the launch target
* @param id
* id for the target.
* @param name
* name of the launch target
* @return the created launch target
*/
ILaunchTarget addLaunchTarget(String typeId, String id, String name);
/**
* Add a launch target with the given typeId and name. The name is also the
* id for the target.
*
* @param typeId
* type id of the launch target
* @param name
* name of the launch target
* @return the created launch target
*/
default ILaunchTarget addLaunchTarget(String typeId, String name) {
return addLaunchTarget(typeId, name, name);
}
ILaunchTarget addLaunchTarget(String typeId, String id);
/**
* Removes a launch target.

View file

@ -10,3 +10,4 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.remote.core;bundle-version="2.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.launchbar.remote.core.internal;x-friends:="org.eclipse.launchbar.remote.ui"

View file

@ -23,7 +23,7 @@ public class RemoteConnectionListener implements IRemoteConnectionChangeListener
switch (event.getType()) {
case RemoteConnectionChangeEvent.CONNECTION_ADDED:
targetManager.addLaunchTarget(RemoteLaunchTargetProvider.TYPE_ID,
RemoteLaunchTargetProvider.getTargetId(connection), connection.getName());
RemoteLaunchTargetProvider.getTargetId(connection));
break;
case RemoteConnectionChangeEvent.CONNECTION_REMOVED:
ILaunchTarget target = targetManager.getLaunchTarget(RemoteLaunchTargetProvider.TYPE_ID,

View file

@ -17,8 +17,8 @@ import org.eclipse.remote.core.IRemoteServicesManager;
public class RemoteLaunchTargetProvider implements ILaunchTargetProvider {
static final String TYPE_ID = "org.eclipse.launchbar.remote.core.launchTargetType"; //$NON-NLS-1$
static final String DELIMITER = "|"; //$NON-NLS-1$
public static final String TYPE_ID = "org.eclipse.launchbar.remote.core.launchTargetType"; //$NON-NLS-1$
public static final String DELIMITER = "|"; //$NON-NLS-1$
private static final TargetStatus CLOSED = new TargetStatus(Code.ERROR, Messages.RemoteLaunchTargetProvider_Closed);
@ -39,7 +39,7 @@ public class RemoteLaunchTargetProvider implements ILaunchTargetProvider {
for (IRemoteConnection connection : manager.getAllRemoteConnections()) {
String id = getTargetId(connection);
if (targetManager.getLaunchTarget(TYPE_ID, id) == null) {
targetManager.addLaunchTarget(TYPE_ID, id, connection.getName());
targetManager.addLaunchTarget(TYPE_ID, id);
}
}
}

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.launchbar.remote.ui</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

View file

@ -0,0 +1,16 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Remote Launch Target UI
Bundle-SymbolicName: org.eclipse.launchbar.remote.ui;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.eclipse.launchbar.remote.ui.internal.Activator
Bundle-Vendor: Eclipse CDT
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.remote.core;bundle-version="2.0.0",
org.eclipse.remote.ui;bundle-version="2.0.0",
org.eclipse.launchbar.core;bundle-version="2.0.0",
org.eclipse.launchbar.ui;bundle-version="2.0.0",
org.eclipse.launchbar.remote.core;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy

View file

@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.launchbar.ui.launchTargetTypeUI">
<launchTargetTypeUI
id="org.eclipse.launchbar.remote.core.launchTargetType"
labelProvider="org.eclipse.launchbar.remote.ui.internal.RemoteLaunchTargetLabelProvider">
</launchTargetTypeUI>
</extension>
</plugin>

View file

@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.launchbar.remote.ui.internal;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.launchbar.remote.ui"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
public static Activator getDefault() {
return plugin;
}
public static <T> T getService(Class<T> service) {
BundleContext context = plugin.getBundle().getBundleContext();
ServiceReference<T> ref = context.getServiceReference(service);
return ref != null ? context.getService(ref) : null;
}
}

View file

@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.launchbar.remote.ui.internal;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.remote.core.internal.RemoteLaunchTargetProvider;
import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.ui.IRemoteUIConnectionService;
import org.eclipse.swt.graphics.Image;
public class RemoteLaunchTargetLabelProvider extends LabelProvider {
@Override
public String getText(Object element) {
IRemoteConnection connection = getConnection(element);
if (connection != null) {
IRemoteUIConnectionService uiService = connection.getConnectionType()
.getService(IRemoteUIConnectionService.class);
if (uiService != null) {
return uiService.getLabelProvider().getText(connection);
}
}
return super.getText(element);
}
@Override
public Image getImage(Object element) {
IRemoteConnection connection = getConnection(element);
if (connection != null) {
IRemoteUIConnectionService uiService = connection.getConnectionType()
.getService(IRemoteUIConnectionService.class);
if (uiService != null) {
return uiService.getLabelProvider().getImage(connection);
}
}
return super.getImage(element);
}
private IRemoteConnection getConnection(Object element) {
if (element instanceof ILaunchTarget) {
ILaunchTarget target = (ILaunchTarget) element;
if (target.getTypeId().equals(RemoteLaunchTargetProvider.TYPE_ID)) {
IRemoteConnection connection = target.getAdapter(IRemoteConnection.class);
return connection;
}
}
return null;
}
}