blob: 84c8eee5d96a7117b2afb2963bc9e384b95229e9 [file] [log] [blame]
package org.eclipse.debug.internal.core.groups;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationListener;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
/**
* Manages renames of launch configurations that are members of group launches
*
* @since 3.11
*/
public class GroupMemberChangeListener implements ILaunchConfigurationListener {
private static final String GROUP_TYPE_ID = "org.eclipse.debug.core.groups.GroupLaunchConfigurationType"; //$NON-NLS-1$
@Override
public void launchConfigurationAdded(ILaunchConfiguration configuration) {
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfiguration original = launchManager.getMovedFrom(configuration);
if (original != null) {
ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(GROUP_TYPE_ID);
if (type == null) {
DebugPlugin.logMessage("cannot find group launch configuration type", null); //$NON-NLS-1$
return;
}
try {
for (ILaunchConfiguration c : DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(type)) {
List<GroupLaunchElement> elements = GroupLaunchConfigurationDelegate.createLaunchElements(c);
boolean updated = false;
for (GroupLaunchElement e : elements) {
if (e.name.equals(original.getName())) {
updated = true;
e.name = configuration.getName();
}
}
if (updated) {
ILaunchConfigurationWorkingCopy workingCopy = c.getWorkingCopy();
GroupLaunchConfigurationDelegate.storeLaunchElements(workingCopy, elements);
workingCopy.doSave();
}
}
} catch (CoreException e) {
DebugPlugin.log(e);
}
}
}
@Override
public void launchConfigurationChanged(ILaunchConfiguration configuration) {
}
@Override
public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
}
}