in j2me/src/main/java/com/intellij/j2meplugin/module/settings/ui/MobileModuleResourcesSettings.java [112:189]
public void apply() throws ConfigurationException {
if (myResourcesEnable.isSelected()) {
if (myResources.getText() == null || myResources.getText().length() == 0) {
throw new ConfigurationException(J2MEBundle.message("resource.directory.not.set"));
}
myProperties.setResourcePath(myResources.getText());
if (!new File(myResources.getText()).exists()) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
final String path = FileUtil.toSystemIndependentName(myResources.getText());
VirtualFile file = LocalFileSystem.getInstance().findFileByPath(path);
if (file == null) {
final File ioFile = new File(myResources.getText());
CommandProcessor.getInstance().executeCommand(myModule.getProject(), new Runnable() {
@Override
public void run() {
FileUtil.createParentDirs(ioFile);
final LocalFileSystem lfs = LocalFileSystem.getInstance();
final File ioFileParentFile = ioFile.getParentFile();
final VirtualFile dir = ioFileParentFile != null ? lfs.refreshAndFindFileByIoFile(ioFileParentFile) : null;
if (dir != null) {
try {
dir.createChildDirectory(this, ioFile.getName());
}
catch (IOException e) {
LOG.error(e);
}
}
}
}, J2MEBundle.message("resource.directory.create.command"), null);
}
}
});
}
ApplicationManager.getApplication().runWriteAction(() -> {
final String resourcesPath = myResources.getText();
if (resourcesPath == null || resourcesPath.length() == 0) return;
final String path = FileUtil.toSystemIndependentName(resourcesPath);
ContentEntry contentEntry = null;
for (ContentEntry entry : myRootModel.getContentEntries()) {
final VirtualFile contentRoot = entry.getFile();
if (contentRoot != null && path.startsWith(contentRoot.getPath())) {
contentEntry = entry;
break;
}
}
if (contentEntry == null) {
final VirtualFile ioFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(path).getParentFile());
if (ioFile == null) return;
contentEntry = myRootModel.addContentEntry(ioFile);
}
final VirtualFile res = LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
if (res != null) {
contentEntry.addSourceFolder(res, false);
}
});
}
else {
if (myProperties.getResourcePath() != null) {
ApplicationManager.getApplication().runWriteAction(() -> {
for (int i = 0; i < myRootModel.getContentEntries().length; i++) {
ContentEntry contentEntry = myRootModel.getContentEntries()[i];
for (SourceFolder folder : contentEntry.getSourceFolders()) {
final VirtualFile sourceRoot = folder.getFile();
if (sourceRoot != null &&
sourceRoot.getPath().compareTo(FileUtil.toSystemIndependentName(myProperties.getResourcePath())) == 0) {
contentEntry.removeSourceFolder(folder);
}
}
}
});
}
myProperties.setResourcePath(null);
}
myModified = false;
}