// append file extension
if (!StringUtils.hasText(mainPage.getFileExtension())) {
IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(mainPage.getContainerFullPath());
mainPage.setFileExtension("xml");
BeansProject beansProject = getProject(resource);
if (beansProject != null) {
Set<String> suffixes = beansProject.getConfigSuffixes();
if (!suffixes.isEmpty()) {
mainPage.setFileExtension(suffixes.iterator().next());
}
}
}
final IFile file = mainPage.createNewFile();
BeansProject beansProject = getProject(file);
if (beansProject == null) {
WorkspaceModifyOperation oper = new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException,
InterruptedException {
SpringCoreUtils.addProjectNature(file.getProject(), SpringCore.NATURE_ID, monitor);
}
};
try {
getContainer().run(true, true, oper);
}
catch (InvocationTargetException e) {
SpringCore.log(e);
}
catch (InterruptedException e) {
SpringCore.log(e);
}
beansProject = new BeansProject(BeansCorePlugin.getModel(), file.getProject());
}
if (beansProject != null) {
beansProject.addConfig(file, IBeansConfig.Type.MANUAL);
newConfig = beansProject.getConfig(file);
Set<IBeansConfigSet> configSets = linkPage.getBeansConfigSets();
for (IBeansConfigSet bcs : configSets) {
if (beansProject.equals(bcs.getElementParent())) {
((BeansConfigSet) bcs).addConfig(newConfig.getElementName());
}
}
// Now save modified project description
beansProject.saveDescription();
// Finally (after saving the modified project description!!!)
// refresh the label decoration of all config files
BeansModelLabelDecorator.update();
}