modifiable root model: stateless content entry editor

This commit is contained in:
Alexey Pegov
2009-10-19 20:01:54 +04:00
parent 9501176d2f
commit caf9a2d4ab
6 changed files with 155 additions and 100 deletions
@@ -25,6 +25,7 @@ import com.intellij.openapi.progress.util.SmoothProgressAdapter;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
@@ -43,8 +44,13 @@ public class JavaContentEntriesEditor extends CommonContentEntriesEditor {
super(moduleName, state);
}
protected ContentEntryEditor createContentEntryEditor(ContentEntry contentEntry) {
return new JavaContentEntryEditor(contentEntry, getModel());
protected ContentEntryEditor createContentEntryEditor(final String contentEntryUrl) {
return new JavaContentEntryEditor(contentEntryUrl) {
@Override
protected ModifiableRootModel getModel() {
return JavaContentEntriesEditor.this.getModel();
}
};
}
protected ContentEntryTreeEditor createContentEntryTreeEditor(Project project) {
@@ -17,22 +17,27 @@ package com.intellij.openapi.roots.ui.configuration;
import com.intellij.openapi.roots.CompilerModuleExtension;
import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ExcludeFolder;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.Nullable;
public class JavaContentEntryEditor extends ContentEntryEditor {
public abstract class JavaContentEntryEditor extends ContentEntryEditor {
private final CompilerModuleExtension myCompilerExtension;
public JavaContentEntryEditor(ContentEntry contentEntry, ModifiableRootModel rootModel) {
super(contentEntry, rootModel);
myCompilerExtension = rootModel.getModuleExtension(CompilerModuleExtension.class);
public JavaContentEntryEditor(final String contentEntryUrl) {
super(contentEntryUrl);
myCompilerExtension = getModel().getModuleExtension(CompilerModuleExtension.class);
}
protected ContentRootPanel createContentRootPane() {
return new JavaContentRootPanel(myContentEntry, this);
return new JavaContentRootPanel(this) {
@Nullable
@Override
protected ContentEntry getContentEntry() {
return JavaContentEntryEditor.this.getContentEntry();
}
};
}
@Nullable
@@ -45,7 +50,7 @@ public class JavaContentEntryEditor extends ContentEntryEditor {
myCompilerExtension.setExcludeOutput(true);
}
if (isExplodedDirectory) {
myRootModel.setExcludeExplodedDirectory(true);
getModel().setExcludeExplodedDirectory(true);
}
return null;
}
@@ -58,7 +63,7 @@ public class JavaContentEntryEditor extends ContentEntryEditor {
myCompilerExtension.setExcludeOutput(false);
}
if (isExplodedDirectory(file)) {
myRootModel.setExcludeExplodedDirectory(false);
getModel().setExcludeExplodedDirectory(false);
}
super.doRemoveExcludeFolder(excludeFolder, file);
}
@@ -79,7 +84,7 @@ public class JavaContentEntryEditor extends ContentEntryEditor {
}
if (myCompilerExtension.isCompilerOutputPathInherited()) {
final String compilerOutput = ProjectStructureConfigurable.getInstance(myRootModel.getModule().getProject()).getProjectConfig().getCompilerOutputUrl();
final String compilerOutput = ProjectStructureConfigurable.getInstance(getModel().getModule().getProject()).getProjectConfig().getCompilerOutputUrl();
if (file != null && Comparing.equal(compilerOutput, file.getUrl())) {
return true;
}
@@ -89,7 +94,7 @@ public class JavaContentEntryEditor extends ContentEntryEditor {
}
private boolean isExplodedDirectory(VirtualFile file) {
final VirtualFile explodedDir = myRootModel.getExplodedDirectory();
final VirtualFile explodedDir = getModel().getExplodedDirectory();
if (explodedDir != null) {
if (explodedDir.equals(file)) {
return true;
@@ -16,10 +16,9 @@
package com.intellij.openapi.roots.ui.configuration;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.ContentFolder;
import com.intellij.openapi.roots.SourceFolder;
import com.intellij.openapi.roots.ExcludeFolder;
import com.intellij.openapi.roots.SourceFolder;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.vfs.VirtualFile;
@@ -29,14 +28,15 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public class JavaContentRootPanel extends ContentRootPanel {
public abstract class JavaContentRootPanel extends ContentRootPanel {
private static final Color SOURCES_COLOR = new Color(0x0A50A1);
private static final Icon ADD_PREFIX_ICON = IconLoader.getIcon("/modules/setPackagePrefix.png");
private static final Icon ADD_PREFIX_ROLLOVER_ICON = IconLoader.getIcon("/modules/setPackagePrefixRollover.png");
public JavaContentRootPanel(ContentEntry contentEntry, ActionCallback callback) {
super(contentEntry, callback);
public JavaContentRootPanel(ActionCallback callback) {
super(callback);
}
@Nullable
@@ -52,7 +52,7 @@ public class JavaContentRootPanel extends ContentRootPanel {
ProjectBundle.message("module.paths.package.prefix.tooltip"), new Runnable() {
public void run() {
final String message = ProjectBundle.message("module.paths.package.prefix.prompt",
toRelativeDisplayPath(folder.getUrl(), myContentEntry.getUrl() + ":"));
toRelativeDisplayPath(folder.getUrl(), getContentEntry().getUrl() + ":"));
final String prefix = Messages.showInputDialog(JavaContentRootPanel.this, message,
ProjectBundle.message("module.paths.package.prefix.title"), Messages.getQuestionIcon(), folder.getPackagePrefix(), null);
if (prefix != null) {
@@ -68,10 +68,10 @@ public class JavaContentRootPanel extends ContentRootPanel {
}
protected void addFolderGroupComponents() {
final java.util.List<ContentFolder> sources = new ArrayList<ContentFolder>();
final java.util.List<ContentFolder> testSources = new ArrayList<ContentFolder>();
final java.util.List<ContentFolder> excluded = new ArrayList<ContentFolder>();
final SourceFolder[] sourceFolders = myContentEntry.getSourceFolders();
final List<ContentFolder> sources = new ArrayList<ContentFolder>();
final List<ContentFolder> testSources = new ArrayList<ContentFolder>();
final List<ContentFolder> excluded = new ArrayList<ContentFolder>();
final SourceFolder[] sourceFolders = getContentEntry().getSourceFolders();
for (SourceFolder folder : sourceFolders) {
if (folder.isSynthetic()) {
continue;
@@ -88,7 +88,7 @@ public class JavaContentRootPanel extends ContentRootPanel {
}
}
final ExcludeFolder[] excludeFolders = myContentEntry.getExcludeFolders();
final ExcludeFolder[] excludeFolders = getContentEntry().getExcludeFolders();
for (final ExcludeFolder excludeFolder : excludeFolders) {
if (!excludeFolder.isSynthetic()) {
excluded.add(excludeFolder);