Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 84c8eee5d96a7117b2afb2963bc9e384b95229e9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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) {
	}

}

Back to the top