Search in sources :

Example 1 with SourceFolder

use of com.intellij.openapi.roots.SourceFolder in project intellij-community by JetBrains.

the class ContentEntryTreeCellRenderer method updateIcon.

protected Icon updateIcon(final ContentEntry entry, final VirtualFile file, Icon originalIcon) {
    if (ContentEntryEditor.isExcludedOrUnderExcludedDirectory(myTreeEditor.getProject(), entry, file)) {
        return AllIcons.Modules.ExcludeRoot;
    }
    final SourceFolder[] sourceFolders = entry.getSourceFolders();
    for (SourceFolder sourceFolder : sourceFolders) {
        if (file.equals(sourceFolder.getFile())) {
            return SourceRootPresentation.getSourceRootIcon(sourceFolder);
        }
    }
    Icon icon = originalIcon;
    VirtualFile currentRoot = null;
    for (SourceFolder sourceFolder : sourceFolders) {
        final VirtualFile sourcePath = sourceFolder.getFile();
        if (sourcePath != null && VfsUtilCore.isAncestor(sourcePath, file, true)) {
            if (currentRoot != null && VfsUtilCore.isAncestor(sourcePath, currentRoot, false)) {
                continue;
            }
            Icon folderIcon = getSourceFolderIcon(sourceFolder.getRootType());
            if (folderIcon != null) {
                icon = folderIcon;
            }
            currentRoot = sourcePath;
        }
    }
    return icon;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFolder(com.intellij.openapi.roots.SourceFolder)

Example 2 with SourceFolder

use of com.intellij.openapi.roots.SourceFolder in project intellij-community by JetBrains.

the class ContentRootPanel method createFolderComponent.

private <P extends JpsElement> JComponent createFolderComponent(final ContentFolder folder, Color foreground, ModuleSourceRootEditHandler<P> editor) {
    final VirtualFile folderFile = folder.getFile();
    final VirtualFile contentEntryFile = getContentEntry().getFile();
    final String properties = folder instanceof SourceFolder ? StringUtil.notNullize(editor.getPropertiesString((P) ((SourceFolder) folder).getJpsElement().getProperties())) : "";
    if (folderFile != null && contentEntryFile != null) {
        String path = folderFile.equals(contentEntryFile) ? "." : VfsUtilCore.getRelativePath(folderFile, contentEntryFile, File.separatorChar);
        HoverHyperlinkLabel hyperlinkLabel = new HoverHyperlinkLabel(path + properties, foreground);
        hyperlinkLabel.setMinimumSize(new Dimension(0, 0));
        hyperlinkLabel.addHyperlinkListener(new HyperlinkListener() {

            @Override
            public void hyperlinkUpdate(HyperlinkEvent e) {
                myCallback.navigateFolder(getContentEntry(), folder);
            }
        });
        registerTextComponent(hyperlinkLabel, foreground);
        return new UnderlinedPathLabel(hyperlinkLabel);
    } else {
        String path = toRelativeDisplayPath(folder.getUrl(), getContentEntry().getUrl());
        final JLabel pathLabel = new JLabel(path + properties);
        pathLabel.setOpaque(false);
        pathLabel.setForeground(JBColor.RED);
        return new UnderlinedPathLabel(pathLabel);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFolder(com.intellij.openapi.roots.SourceFolder) HoverHyperlinkLabel(com.intellij.ui.HoverHyperlinkLabel) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener)

Example 3 with SourceFolder

use of com.intellij.openapi.roots.SourceFolder in project intellij-community by JetBrains.

the class ContentRootPanel method addFolderGroupComponents.

protected void addFolderGroupComponents() {
    final SourceFolder[] sourceFolders = getContentEntry().getSourceFolders();
    MultiMap<JpsModuleSourceRootType<?>, SourceFolder> folderByType = new MultiMap<>();
    for (SourceFolder folder : sourceFolders) {
        if (!folder.isSynthetic()) {
            folderByType.putValue(folder.getRootType(), folder);
        }
    }
    Insets insets = JBUI.insetsBottom(10);
    GridBagConstraints constraints = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, insets, 0, 0);
    for (ModuleSourceRootEditHandler<?> editor : myModuleSourceRootEditHandlers) {
        Collection<SourceFolder> folders = folderByType.get(editor.getRootType());
        if (folders.isEmpty())
            continue;
        ContentFolder[] foldersArray = folders.toArray(new ContentFolder[folders.size()]);
        final JComponent sourcesComponent = createFolderGroupComponent(editor.getRootsGroupTitle(), foldersArray, editor.getRootsGroupColor(), editor);
        add(sourcesComponent, constraints);
    }
    ExcludeFolder[] excluded = getContentEntry().getExcludeFolders();
    if (excluded.length > 0) {
        final JComponent excludedComponent = createFolderGroupComponent(ProjectBundle.message("module.paths.excluded.group"), excluded, EXCLUDED_COLOR, null);
        this.add(excludedComponent, constraints);
    }
}
Also used : SourceFolder(com.intellij.openapi.roots.SourceFolder) MultiMap(com.intellij.util.containers.MultiMap) JpsModuleSourceRootType(org.jetbrains.jps.model.module.JpsModuleSourceRootType) ContentFolder(com.intellij.openapi.roots.ContentFolder) ExcludeFolder(com.intellij.openapi.roots.ExcludeFolder)

Example 4 with SourceFolder

use of com.intellij.openapi.roots.SourceFolder in project intellij-community by JetBrains.

the class ContentEntryImpl method clearSourceFolders.

@Override
public void clearSourceFolders() {
    assert !isDisposed();
    getRootModel().assertWritable();
    for (SourceFolder folder : mySourceFolders) {
        Disposer.dispose((Disposable) folder);
    }
    mySourceFolders.clear();
}
Also used : SourceFolder(com.intellij.openapi.roots.SourceFolder)

Example 5 with SourceFolder

use of com.intellij.openapi.roots.SourceFolder in project intellij-community by JetBrains.

the class ContentEntryImpl method getSourceFolderFiles.

@Override
@NotNull
public VirtualFile[] getSourceFolderFiles() {
    assert !isDisposed();
    final SourceFolder[] sourceFolders = getSourceFolders();
    ArrayList<VirtualFile> result = new ArrayList<>(sourceFolders.length);
    for (SourceFolder sourceFolder : sourceFolders) {
        final VirtualFile file = sourceFolder.getFile();
        if (file != null) {
            result.add(file);
        }
    }
    return VfsUtilCore.toVirtualFileArray(result);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFolder(com.intellij.openapi.roots.SourceFolder) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SourceFolder (com.intellij.openapi.roots.SourceFolder)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 ContentEntry (com.intellij.openapi.roots.ContentEntry)7 Module (com.intellij.openapi.module.Module)6 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)5 NotNull (org.jetbrains.annotations.NotNull)5 ExcludeFolder (com.intellij.openapi.roots.ExcludeFolder)3 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)3 JavaSourceRootProperties (org.jetbrains.jps.model.java.JavaSourceRootProperties)3 JpsModuleSourceRootType (org.jetbrains.jps.model.module.JpsModuleSourceRootType)3 Project (com.intellij.openapi.project.Project)2 ContentFolder (com.intellij.openapi.roots.ContentFolder)2 File (java.io.File)2 Assert.assertNotNull (junit.framework.Assert.assertNotNull)2 GuiTask (org.fest.swing.edt.GuiTask)2 Nullable (org.jetbrains.annotations.Nullable)2 JpsElement (org.jetbrains.jps.model.JpsElement)2 JpsModuleSourceRoot (org.jetbrains.jps.model.module.JpsModuleSourceRoot)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 GradleUtil.getGradleBuildFile (com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile)1