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

Add method to ILaunchTarget to get all the attributes.

This is used by CDT, for example, to be able to map targets to
toolchains.

Change-Id: I98d7463d512299c43c405fd474bb8e128a81663f
This commit is contained in:
Doug Schaefer 2016-11-11 12:36:48 -05:00
parent f5264933cf
commit 80c6a9694e
5 changed files with 44 additions and 4 deletions

View file

@ -14,6 +14,7 @@ import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.launchbar.core.internal.messages"; //$NON-NLS-1$
public static String ILaunchTarget_notSupported;
public static String LaunchBarManager_0;
public static String LaunchBarManager_1;
public static String LaunchBarManager_2;

View file

@ -1,5 +1,3 @@
LaunchBarManager_1=Active descriptor must be in the map of descriptors
LaunchBarManager_2=Mode is not supported by descriptor
################################################################################
# Copyright (c) 2014 QNX Software Systems and others.
# All rights reserved. This program and the accompanying materials
@ -10,7 +8,9 @@ LaunchBarManager_2=Mode is not supported by descriptor
# Contributors:
# Doug Schaefer
################################################################################
ILaunchTarget_notSupported=getWorkingCopy is not supported for NULL_TARGET
LaunchBarManager_0=Launch Bar Initialization
LaunchBarManager_1=Active descriptor must be in the map of descriptors
LaunchBarManager_2=Mode is not supported by descriptor
LocalTarget_name=Local
OK=OK

View file

@ -7,9 +7,14 @@
*******************************************************************************/
package org.eclipse.launchbar.core.internal.target;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.launchbar.core.internal.Activator;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.core.target.ILaunchTargetWorkingCopy;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
public class LaunchTarget extends PlatformObject implements ILaunchTarget {
@ -59,6 +64,22 @@ public class LaunchTarget extends PlatformObject implements ILaunchTarget {
}
}
@Override
public Map<String, String> getAttributes() {
Map<String, String> attrs = new HashMap<>();
try {
for (String key : attributes.keys()) {
String value = attributes.get(key, null);
if (value != null) {
attrs.put(key, value);
}
}
} catch (BackingStoreException e) {
Activator.log(e);
}
return attrs;
}
@Override
public int hashCode() {
final int prime = 31;

View file

@ -61,6 +61,13 @@ public class LaunchTargetWorkingCopy extends PlatformObject implements ILaunchTa
}
}
@Override
public Map<String, String> getAttributes() {
Map<String, String> attrs = original.getAttributes();
attrs.putAll(changes);
return attrs;
}
@Override
public void setAttribute(String key, String value) {
changes.put(key, value);

View file

@ -7,7 +7,10 @@
*******************************************************************************/
package org.eclipse.launchbar.core.target;
import java.util.Map;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.launchbar.core.internal.Messages;
import org.eclipse.launchbar.core.internal.target.LaunchTarget;
/**
@ -29,7 +32,7 @@ public interface ILaunchTarget extends IAdaptable {
public static final ILaunchTarget NULL_TARGET = new LaunchTarget("null", "---") { //$NON-NLS-1$ //$NON-NLS-2$
@Override
public ILaunchTargetWorkingCopy getWorkingCopy() {
throw new UnsupportedOperationException("getWorkingCopy is not supported for NULL_TARGET");
throw new UnsupportedOperationException(Messages.ILaunchTarget_notSupported);
};
};
@ -69,6 +72,14 @@ public interface ILaunchTarget extends IAdaptable {
*/
String getAttribute(String key, String defValue);
/**
* Returns a read-only map of the attributes.
*
* @return the attributes for this target
* @since 2.1
*/
Map<String, String> getAttributes();
/**
* Create a working copy of this launch target to allow setting of attributes. It also allows
* changing the id, which results in a new launch target when saved.