Search in sources :

Example 1 with ContentEntry

use of com.intellij.openapi.roots.ContentEntry in project intellij-plugins by StepicOrg.

the class ModuleBuilderWithSrc method setupRootModel.

@Override
public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {
    super.setupRootModel(rootModel);
    ContentEntry contentEntry = this.doAddContentEntry(rootModel);
    String moduleLibraryPath;
    if (contentEntry != null) {
        moduleLibraryPath = this.getContentEntryPath() + File.separator + "src";
        //noinspection ResultOfMethodCallIgnored
        (new File(moduleLibraryPath)).mkdirs();
        LocalFileSystem localFS = LocalFileSystem.getInstance();
        String name = FileUtil.toSystemIndependentName(moduleLibraryPath);
        VirtualFile sourceLibraryPath = localFS.refreshAndFindFileByPath(name);
        if (sourceLibraryPath != null) {
            contentEntry.addSourceFolder(sourceLibraryPath, false, "");
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentEntry(com.intellij.openapi.roots.ContentEntry) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 2 with ContentEntry

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

the class CommonContentEntriesEditor method createComponentImpl.

@Override
public JPanel createComponentImpl() {
    final Module module = getModule();
    final Project project = module.getProject();
    myContentEntryEditorListener = new MyContentEntryEditorListener();
    final JPanel mainPanel = new JPanel(new BorderLayout());
    addAdditionalSettingsToPanel(mainPanel);
    final DefaultActionGroup group = new DefaultActionGroup();
    final AddContentEntryAction action = new AddContentEntryAction();
    action.registerCustomShortcutSet(KeyEvent.VK_C, InputEvent.ALT_DOWN_MASK, mainPanel);
    group.add(action);
    myEditorsPanel = new ScrollablePanel(new VerticalStackLayout());
    myEditorsPanel.setBackground(BACKGROUND_COLOR);
    JScrollPane myScrollPane = ScrollPaneFactory.createScrollPane(myEditorsPanel, true);
    final ToolbarPanel toolbarPanel = new ToolbarPanel(myScrollPane, group);
    int border = myWithBorders ? 1 : 0;
    toolbarPanel.setBorder(new CustomLineBorder(1, 0, border, border));
    final JBSplitter splitter = new OnePixelSplitter(false);
    splitter.setProportion(0.6f);
    splitter.setHonorComponentsMinimumSize(true);
    myRootTreeEditor = createContentEntryTreeEditor(project);
    final JComponent component = myRootTreeEditor.createComponent();
    component.setBorder(new CustomLineBorder(1, border, border, 0));
    splitter.setFirstComponent(component);
    splitter.setSecondComponent(toolbarPanel);
    JPanel contentPanel = new JPanel(new GridBagLayout());
    final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, myRootTreeEditor.getEditingActionsGroup(), true);
    contentPanel.add(new JLabel("Mark as:"), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, 0, JBUI.insets(0, 10), 0, 0));
    contentPanel.add(actionToolbar.getComponent(), new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, JBUI.emptyInsets(), 0, 0));
    contentPanel.add(splitter, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, JBUI.emptyInsets(), 0, 0));
    mainPanel.add(contentPanel, BorderLayout.CENTER);
    final JPanel innerPanel = createBottomControl(module);
    if (innerPanel != null) {
        mainPanel.add(innerPanel, BorderLayout.SOUTH);
    }
    final ModifiableRootModel model = getModel();
    if (model != null) {
        final ContentEntry[] contentEntries = model.getContentEntries();
        if (contentEntries.length > 0) {
            for (final ContentEntry contentEntry : contentEntries) {
                addContentEntryPanel(contentEntry.getUrl());
            }
            selectContentEntry(contentEntries[0].getUrl());
        }
    }
    return mainPanel;
}
Also used : OnePixelSplitter(com.intellij.ui.OnePixelSplitter) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Project(com.intellij.openapi.project.Project) VerticalStackLayout(com.intellij.openapi.roots.ui.componentsList.layout.VerticalStackLayout) ScrollablePanel(com.intellij.openapi.roots.ui.componentsList.components.ScrollablePanel) CustomLineBorder(com.intellij.ui.border.CustomLineBorder) ContentEntry(com.intellij.openapi.roots.ContentEntry) JBSplitter(com.intellij.ui.JBSplitter) Module(com.intellij.openapi.module.Module) ToolbarPanel(com.intellij.ui.roots.ToolbarPanel)

Example 3 with ContentEntry

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

the class ContentEntryTreeCellRenderer method customizeCellRenderer.

@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    super.customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);
    final ContentEntryEditor editor = myTreeEditor.getContentEntryEditor();
    if (editor != null) {
        final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
        if (userObject instanceof NodeDescriptor) {
            final Object element = ((NodeDescriptor) userObject).getElement();
            if (element instanceof FileElement) {
                final VirtualFile file = ((FileElement) element).getFile();
                if (file != null && file.isDirectory()) {
                    final ContentEntry contentEntry = editor.getContentEntry();
                    if (contentEntry != null) {
                        final String prefix = getPresentablePrefix(contentEntry, file);
                        if (!prefix.isEmpty()) {
                            append(" (" + prefix + ")", new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.GRAY));
                        }
                        setIcon(updateIcon(contentEntry, file, getIcon()));
                    }
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ContentEntry(com.intellij.openapi.roots.ContentEntry) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) FileElement(com.intellij.openapi.fileChooser.FileElement)

Example 4 with ContentEntry

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

the class ContentEntryTreeEditor method setContentEntryEditor.

/**
   * @param contentEntryEditor : null means to clear the editor
   */
public void setContentEntryEditor(final ContentEntryEditor contentEntryEditor) {
    if (myContentEntryEditor != null && myContentEntryEditor.equals(contentEntryEditor)) {
        return;
    }
    if (myFileSystemTree != null) {
        Disposer.dispose(myFileSystemTree);
        myFileSystemTree = null;
    }
    if (myContentEntryEditor != null) {
        myContentEntryEditor.removeContentEntryEditorListener(myContentEntryEditorListener);
        myContentEntryEditor = null;
    }
    if (contentEntryEditor == null) {
        ((DefaultTreeModel) myTree.getModel()).setRoot(EMPTY_TREE_ROOT);
        myTreePanel.setVisible(false);
        if (myFileSystemTree != null) {
            Disposer.dispose(myFileSystemTree);
        }
        return;
    }
    myTreePanel.setVisible(true);
    myContentEntryEditor = contentEntryEditor;
    myContentEntryEditor.addContentEntryEditorListener(myContentEntryEditorListener);
    final ContentEntry entry = contentEntryEditor.getContentEntry();
    assert entry != null : contentEntryEditor;
    final VirtualFile file = entry.getFile();
    if (file != null) {
        myDescriptor.setRoots(file);
    } else {
        String path = VfsUtilCore.urlToPath(entry.getUrl());
        myDescriptor.setTitle(FileUtil.toSystemDependentName(path));
    }
    final Runnable init = () -> {
        //noinspection ConstantConditions
        myFileSystemTree.updateTree();
        myFileSystemTree.select(file, null);
    };
    myFileSystemTree = new FileSystemTreeImpl(myProject, myDescriptor, myTree, getContentEntryCellRenderer(), init, null) {

        @Override
        protected AbstractTreeBuilder createTreeBuilder(JTree tree, DefaultTreeModel treeModel, AbstractTreeStructure treeStructure, Comparator<NodeDescriptor> comparator, FileChooserDescriptor descriptor, final Runnable onInitialized) {
            return new MyFileTreeBuilder(tree, treeModel, treeStructure, comparator, descriptor, onInitialized);
        }
    };
    myFileSystemTree.showHiddens(true);
    Disposer.register(myProject, myFileSystemTree);
    final NewFolderAction newFolderAction = new MyNewFolderAction();
    final DefaultActionGroup mousePopupGroup = new DefaultActionGroup();
    mousePopupGroup.add(myEditingActionsGroup);
    mousePopupGroup.addSeparator();
    mousePopupGroup.add(newFolderAction);
    myFileSystemTree.registerMouseListener(mousePopupGroup);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) AbstractTreeBuilder(com.intellij.ide.util.treeView.AbstractTreeBuilder) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) FileSystemTreeImpl(com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl) NewFolderAction(com.intellij.openapi.fileChooser.actions.NewFolderAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) ContentEntry(com.intellij.openapi.roots.ContentEntry) AbstractTreeStructure(com.intellij.ide.util.treeView.AbstractTreeStructure)

Example 5 with ContentEntry

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

the class FindClassTest method testClassUnderExcludedFolder.

public void testClassUnderExcludedFolder() {
    ApplicationManager.getApplication().runWriteAction(() -> {
        PsiTestUtil.addExcludedRoot(myModule, myPackDir);
        PsiClass psiClass = myJavaFacade.findClass("p.A", GlobalSearchScope.allScope(myProject));
        assertNull(psiClass);
        ModifiableRootModel rootModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
        final ContentEntry content = rootModel.getContentEntries()[0];
        content.removeExcludeFolder(content.getExcludeFolders()[0]);
        rootModel.commit();
        psiClass = myJavaFacade.findClass("p.A", GlobalSearchScope.allScope(myProject));
        assertEquals("p.A", psiClass.getQualifiedName());
    });
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry) PsiClass(com.intellij.psi.PsiClass)

Aggregations

ContentEntry (com.intellij.openapi.roots.ContentEntry)60 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)27 VirtualFile (com.intellij.openapi.vfs.VirtualFile)27 Module (com.intellij.openapi.module.Module)17 File (java.io.File)16 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)11 SourceFolder (com.intellij.openapi.roots.SourceFolder)7 NotNull (org.jetbrains.annotations.NotNull)7 FilePaths.findParentContentEntry (com.android.tools.idea.gradle.util.FilePaths.findParentContentEntry)4 IOException (java.io.IOException)4 Nullable (org.jetbrains.annotations.Nullable)4 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)3 Project (com.intellij.openapi.project.Project)3 JavaModuleContentRoot (com.android.tools.idea.gradle.model.java.JavaModuleContentRoot)2 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)2 ModifiableFlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 PsiFile (com.intellij.psi.PsiFile)2 ArrayList (java.util.ArrayList)2 SyncIssue (com.android.builder.model.SyncIssue)1