applicationController
.errorMessage("Error : no root directory was found in the database. Attempt to create one resulted in the error : "
+ e.getMessage());
}
}
IDirectory newDirectoryImpl = searchDirectory(oldDirectoryModel.getId(), loadRootDirectory);
List<IConfig<?>> modifiedConfigsList = unsavedConfigList();
if (newDirectoryImpl != null) {
newDirectoryImpl.setDirectory(null);
IDirectory newDirectoryModel = AutoCopier.copyDirectoryToModel(newDirectoryImpl);
/*DirectoryModelWrapperFactory.getInstance().wrap(
newDirectoryImpl);*/
if (oldDirectoryModel.equals(rootDirectory)) {
rootDirectory = newDirectoryModel;
}
else {
removeContent(rootDirectory, newDirectoryModel);
IDirectory parentDirectory = searchDirectory(oldDirectoryModel.getDirectory()
.getId(), rootDirectory);
if (parentDirectory == null) {
parentDirectory = rootDirectory;
}
newDirectoryModel.setDirectory(parentDirectory);
parentDirectory.getSubDirectoriesList().add(newDirectoryModel);
}
}
else {
if (oldDirectoryModel.equals(rootDirectory)) {
IDirectory newDirectoryModel = AutoCopier.copyDirectoryToModel(loadRootDirectory);
// DirectoryModelWrapperFactory.getInstance().wrap(
// loadRootDirectory);
rootDirectory = newDirectoryModel;
}
else {
oldDirectoryModel.getDirectory().getSubDirectoriesList().remove(oldDirectoryModel);
}
}
// We restore the modified configs.
IConfig<?> foundConfig;
for (IConfig<?> modifiedConfig : modifiedConfigsList) {
if (modifiedConfig.getId() != null) {
foundConfig = searchConfig(modifiedConfig.getId(), rootDirectory);
if (foundConfig != null) {
if (!foundConfig.isModified()) {
if (!view.askRefreshConfigModified(modifiedConfig.getName())) {
IDirectory parentDirectory = foundConfig.getDirectory();
parentDirectory.getConfigList().remove(foundConfig);
parentDirectory.getConfigList().add(modifiedConfig);
modifiedConfig.setDirectory(parentDirectory);
}
else {
if (modifiedConfig.equals(currentConfig)) {
IConfig<?> newConfigLoaded;
try {
newConfigLoaded = ConfigApi.getConfigById(foundConfig.getId());
}
catch (ScanNotFoundException e) {
e.printStackTrace();
newConfigLoaded = foundConfig;
}
IConfig<?> newConfigModel = wrap(newConfigLoaded);
IDirectory parentDirectory = foundConfig.getDirectory();
newConfigModel.setDirectory(parentDirectory);
parentDirectory.getConfigList().remove(foundConfig);
parentDirectory.getConfigList().add(newConfigModel);
currentConfig = newConfigModel;
applicationController.setConfig(newConfigModel);
}
}
}
}
else {
// The modified config has been deleted.
if (!view.askRefreshConfigDeleted(modifiedConfig.getName())) {
IDirectory foundDirectory = searchDirectory(modifiedConfig.getDirectory()
.getId(), rootDirectory);
if (foundDirectory == null) {
foundDirectory = rootDirectory;
}
foundDirectory.getConfigList().add(modifiedConfig);
modifiedConfig.setDirectory(foundDirectory);
}
else {
if (modifiedConfig.equals(currentDirectory)) {
currentConfig = null;
applicationController.setConfig(null);
}
}
}
}
else {
modifiedConfig.getDirectory().getConfigList().remove(modifiedConfig);
IDirectory foundDirectory = searchDirectory(modifiedConfig.getDirectory().getId(),
rootDirectory);
if (foundDirectory == null) {
foundDirectory = rootDirectory;
}
foundDirectory.getConfigList().add(modifiedConfig);
modifiedConfig.setDirectory(foundDirectory);
}
}
if (currentDirectory != null) {
currentDirectory = searchDirectory(currentDirectory.getId(), rootDirectory);