mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 21:05:37 +02:00
LaunchBar - added interface to notify launch bar on object changes
* added launchObjectUpdated API * added tests for it * changed abstract provider to use it instead of hack that it used before * fixed login in launchObjectAdded to correctly update object map Change-Id: I697594c34097e5439ca1550d0d68758baf7208e2 Signed-off-by: Alena Laskavaia <elaskavaia.cdt@gmail.com> Reviewed-on: https://git.eclipse.org/r/30830 Tested-by: Hudson CI
This commit is contained in:
parent
86a08c918e
commit
0b62fee46c
4 changed files with 64 additions and 28 deletions
|
@ -334,6 +334,15 @@ public class LaunchBarManagerTest extends TestCase {
|
||||||
assertEquals(2, manager.getLaunchDescriptors().length);
|
assertEquals(2, manager.getLaunchDescriptors().length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLaunchObjectChanged() throws CoreException {
|
||||||
|
basicSetup();
|
||||||
|
assertNull(manager.launchObjectChanged(lc));
|
||||||
|
manager.launchObjectAdded(lc);
|
||||||
|
assertEquals(1, manager.getLaunchDescriptors().length);
|
||||||
|
assertNotNull(manager.launchObjectChanged(lc));
|
||||||
|
}
|
||||||
|
|
||||||
public IProject mockProject(String projectName) {
|
public IProject mockProject(String projectName) {
|
||||||
IProject project = mock(Project.class);
|
IProject project = mock(Project.class);
|
||||||
when(project.getAdapter(IResource.class)).thenReturn(project);
|
when(project.getAdapter(IResource.class)).thenReturn(project);
|
||||||
|
|
|
@ -50,6 +50,8 @@ public interface ILaunchBarManager extends IAdaptable {
|
||||||
|
|
||||||
void launchObjectRemoved(Object element) throws CoreException;
|
void launchObjectRemoved(Object element) throws CoreException;
|
||||||
|
|
||||||
|
ILaunchDescriptor launchObjectChanged(Object element) throws CoreException;
|
||||||
|
|
||||||
interface Listener {
|
interface Listener {
|
||||||
|
|
||||||
void activeConfigurationDescriptorChanged();
|
void activeConfigurationDescriptorChanged();
|
||||||
|
|
|
@ -27,7 +27,7 @@ public abstract class ProjectBasedLaunchConfigurationProvider extends ConfigBase
|
||||||
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
|
public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException {
|
||||||
boolean res = super.launchConfigurationAdded(configuration);
|
boolean res = super.launchConfigurationAdded(configuration);
|
||||||
IProject project = getProject(configuration);
|
IProject project = getProject(configuration);
|
||||||
getManager().launchObjectRemoved(project);
|
getManager().launchObjectChanged(project);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ public abstract class ProjectBasedLaunchConfigurationProvider extends ConfigBase
|
||||||
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
|
public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException {
|
||||||
boolean res = super.launchConfigurationRemoved(configuration);
|
boolean res = super.launchConfigurationRemoved(configuration);
|
||||||
IProject project = getProject(configuration);
|
IProject project = getProject(configuration);
|
||||||
getManager().launchObjectAdded(project);
|
getManager().launchObjectChanged(project);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -232,33 +232,54 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected ILaunchDescriptor remapLaunchObject(Object element) {
|
||||||
public ILaunchDescriptor launchObjectAdded(Object element) {
|
// remove old mapping. We have to do it anyway, no matter even nobody own it (and especially because of that)
|
||||||
|
ILaunchDescriptor old = objectDescriptorMap.get(element);
|
||||||
|
if (old != null) { // old mapping is removed
|
||||||
|
objectDescriptorMap.remove(element);
|
||||||
|
descriptors.remove(getId(old));
|
||||||
|
}
|
||||||
ILaunchDescriptor desc = null;
|
ILaunchDescriptor desc = null;
|
||||||
// don't use objectDescriptorMap as cache - provider may decide to remap objects
|
// re-do the mapping, change in object can change descriptor (for example project has new nature)
|
||||||
for (ILaunchDescriptorType descriptorType : descriptorTypes.keySet()) {
|
for (ILaunchDescriptorType descriptorType : descriptorTypes.keySet()) {
|
||||||
try {
|
try {
|
||||||
if (descriptorType.ownsLaunchObject(element)) {
|
if (descriptorType.ownsLaunchObject(element)) {
|
||||||
desc = descriptorType.getDescriptor(element);
|
desc = descriptorType.getDescriptor(element);
|
||||||
ILaunchDescriptor old = objectDescriptorMap.get(element);
|
objectDescriptorMap.put(element, desc); // set it even if desc is null to keep object is map
|
||||||
if (old != null) { // old mapping is removed
|
if (desc != null) // null if we own the object but do not create descriptor
|
||||||
objectDescriptorMap.remove(element);
|
|
||||||
descriptors.remove(getId(old));
|
|
||||||
}
|
|
||||||
if (desc != null) { // null if we own the object but do not create descriptor to ignore it
|
|
||||||
descriptors.put(getId(desc), desc);
|
descriptors.put(getId(desc), desc);
|
||||||
objectDescriptorMap.put(element, desc);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (desc != null)
|
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);
|
setActiveLaunchDescriptor(desc);
|
||||||
|
} else if (old == null && desc != null) {
|
||||||
|
// new object causes re-set of active descriptor too
|
||||||
|
setActiveLaunchDescriptor(desc);
|
||||||
|
}
|
||||||
return desc;
|
return desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ILaunchDescriptor launchObjectAdded(Object element) {
|
||||||
|
if (objectDescriptorMap.containsKey(element)) {
|
||||||
|
// it was added already, perform change
|
||||||
|
return launchObjectChanged(element);
|
||||||
|
}
|
||||||
|
return remapLaunchObject(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ILaunchDescriptor launchObjectChanged(Object element) {
|
||||||
|
// only applied to object that were added via launchObjectAdded
|
||||||
|
if (!objectDescriptorMap.containsKey(element))
|
||||||
|
return null;
|
||||||
|
return remapLaunchObject(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getId(ILaunchDescriptor desc) {
|
private String getId(ILaunchDescriptor desc) {
|
||||||
|
@ -270,8 +291,8 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
||||||
@Override
|
@Override
|
||||||
public void launchObjectRemoved(Object element) {
|
public void launchObjectRemoved(Object element) {
|
||||||
ILaunchDescriptor desc = objectDescriptorMap.get(element);
|
ILaunchDescriptor desc = objectDescriptorMap.get(element);
|
||||||
|
objectDescriptorMap.remove(element);
|
||||||
if (desc != null) {
|
if (desc != null) {
|
||||||
objectDescriptorMap.remove(element);
|
|
||||||
descriptors.remove(getId(desc)); // can multiple elements maps to the same descriptor?
|
descriptors.remove(getId(desc)); // can multiple elements maps to the same descriptor?
|
||||||
if (desc.equals(activeLaunchDesc)) {
|
if (desc.equals(activeLaunchDesc)) {
|
||||||
// Roll back to the last one and make sure we don't come back
|
// Roll back to the last one and make sure we don't come back
|
||||||
|
@ -366,27 +387,32 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
||||||
ILaunchMode[] supportedModes = getLaunchModes(); // this is based on active desc and target which are already set
|
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?
|
if (supportedModes.length > 0) { // mna, what if no modes are supported?
|
||||||
String modeNames[] = new String[] {
|
String modeNames[] = new String[] {
|
||||||
storedModeId, lastActiveModeId,
|
storedModeId,
|
||||||
"debug", "run",
|
lastActiveModeId,
|
||||||
|
"debug",
|
||||||
|
"run",
|
||||||
supportedModes[0].getIdentifier()
|
supportedModes[0].getIdentifier()
|
||||||
};
|
};
|
||||||
for (int i = 0; i < modeNames.length && foundMode == null; i++) {
|
for (int i = 0; i < modeNames.length; i++) {
|
||||||
foundMode = getLaunchModeByName(modeNames[i], supportedModes);
|
foundMode = getLaunchManager().getLaunchMode(modeNames[i]);
|
||||||
|
if (supportsMode(foundMode))
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setActiveLaunchMode(foundMode);
|
setActiveLaunchMode(foundMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ILaunchMode getLaunchModeByName(String mode, ILaunchMode[] supportedModes) {
|
public boolean supportsMode(ILaunchMode mode) {
|
||||||
|
// check that active descriptor supports the given mode
|
||||||
if (mode == null)
|
if (mode == null)
|
||||||
return null;
|
return false;
|
||||||
|
ILaunchMode[] supportedModes = getLaunchModes();
|
||||||
for (int j = 0; j < supportedModes.length; j++) {
|
for (int j = 0; j < supportedModes.length; j++) {
|
||||||
ILaunchMode lm = supportedModes[j];
|
ILaunchMode lm = supportedModes[j];
|
||||||
if (lm.getIdentifier().equals(mode)) {
|
if (lm.equals(mode))
|
||||||
return lm;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setPreference(Preferences store, String prefId, String value) {
|
protected void setPreference(Preferences store, String prefId, String value) {
|
||||||
|
@ -447,8 +473,7 @@ public class LaunchBarManager extends PlatformObject implements ILaunchBarManage
|
||||||
public void setActiveLaunchMode(ILaunchMode mode) {
|
public void setActiveLaunchMode(ILaunchMode mode) {
|
||||||
if (activeLaunchMode == mode)
|
if (activeLaunchMode == mode)
|
||||||
return;
|
return;
|
||||||
ILaunchConfigurationType configType = getLaunchConfigurationType(activeLaunchDesc, activeLaunchTarget);
|
if (activeLaunchDesc != null && mode != null && !supportsMode(mode))
|
||||||
if (!(activeLaunchDesc == null || mode == null || (configType != null && configType.supportsMode(mode.getIdentifier()))))
|
|
||||||
throw new IllegalStateException("Mode is not supported by descriptor");
|
throw new IllegalStateException("Mode is not supported by descriptor");
|
||||||
// change mode
|
// change mode
|
||||||
activeLaunchMode = mode;
|
activeLaunchMode = mode;
|
||||||
|
|
Loading…
Add table
Reference in a new issue