List candidateConfigs = Collections.EMPTY_LIST;
try {
ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(configType);
candidateConfigs = new ArrayList(configs.length);
for (int i = 0; i < configs.length; i++) {
ILaunchConfiguration config = configs[i];
if (config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "").equals(
type.getFullyQualifiedName())) { //$NON-NLS-1$
if (config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "").equals(
type.getJavaProject().getElementName())) { //$NON-NLS-1$
candidateConfigs.add(config);
}
}
}
} catch (CoreException e) {
ProsePlugin.log(e);
}
// If there are no existing configs associated with the IType, create one.
// If there is exactly one config associated with the IType, return it.
// Otherwise, if there is more than one config associated with the IType, prompt the
// user to choose one.
int candidateCount = candidateConfigs.size();
if (candidateCount < 1) {
return createConfiguration(type);
} else if (candidateCount == 1) {
return (ILaunchConfiguration) candidateConfigs.get(0);
} else {
// Prompt the user to choose a config. A null result means the user
// cancelled the dialog, in which case this method returns null,
// since cancelling the dialog should also cancel launching anything.
ILaunchConfiguration config = chooseConfiguration(candidateConfigs, mode);
if (config != null) { return config; }
}
return null;
}