Search in sources :

Example 16 with OrderRootType

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

the class IdeaJdkConfigurable method createComponent.

public JComponent createComponent() {
    mySandboxHome.setHistorySize(5);
    JPanel wholePanel = new JPanel(new GridBagLayout());
    wholePanel.add(mySandboxHomeLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0));
    wholePanel.add(GuiUtils.constructFieldWithBrowseButton(mySandboxHome, new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
            descriptor.setTitle(DevKitBundle.message("sandbox.home"));
            descriptor.setDescription(DevKitBundle.message("sandbox.purpose"));
            VirtualFile file = FileChooser.chooseFile(descriptor, mySandboxHome, null, null);
            if (file != null) {
                mySandboxHome.setText(FileUtil.toSystemDependentName(file.getPath()));
            }
            myModified = true;
        }
    }), new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, JBUI.insets(0, 30, 0, 0), 0, 0));
    wholePanel.add(myInternalJreLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0));
    wholePanel.add(myInternalJres, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1, 1, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, JBUI.insets(0, 30, 0, 0), 0, 0));
    myInternalJres.setRenderer(new ListCellRendererWrapper() {

        @Override
        public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
            if (value instanceof Sdk) {
                setText(((Sdk) value).getName());
            }
        }
    });
    myInternalJres.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            if (myFreeze)
                return;
            final Sdk javaJdk = (Sdk) e.getItem();
            for (OrderRootType type : OrderRootType.getAllTypes()) {
                if (!((SdkType) javaJdk.getSdkType()).isRootTypeApplicable(type)) {
                    continue;
                }
                final VirtualFile[] internalRoots = javaJdk.getSdkModificator().getRoots(type);
                final VirtualFile[] configuredRoots = mySdkModificator.getRoots(type);
                for (VirtualFile file : internalRoots) {
                    if (e.getStateChange() == ItemEvent.DESELECTED) {
                        mySdkModificator.removeRoot(file, type);
                    } else {
                        if (ArrayUtil.find(configuredRoots, file) == -1) {
                            mySdkModificator.addRoot(file, type);
                        }
                    }
                }
            }
        }
    });
    mySandboxHome.addDocumentListener(new DocumentAdapter() {

        protected void textChanged(DocumentEvent e) {
            myModified = true;
        }
    });
    mySandboxHome.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            myModified = true;
        }
    });
    mySandboxHome.setText("");
    myModified = true;
    return wholePanel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) ActionListener(java.awt.event.ActionListener) OrderRootType(com.intellij.openapi.roots.OrderRootType) ItemListener(java.awt.event.ItemListener)

Example 17 with OrderRootType

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

the class LibraryDataService method registerPaths.

static void registerPaths(boolean unresolved, @NotNull Map<OrderRootType, Collection<File>> libraryFiles, @NotNull Library.ModifiableModel model, @NotNull String libraryName) {
    for (Map.Entry<OrderRootType, Collection<File>> entry : libraryFiles.entrySet()) {
        for (File file : entry.getValue()) {
            VirtualFile virtualFile = unresolved ? null : ExternalSystemUtil.refreshAndFindFileByIoFile(file);
            if (virtualFile == null) {
                if (!unresolved && ExternalSystemConstants.VERBOSE_PROCESSING && entry.getKey() == OrderRootType.CLASSES) {
                    LOG.warn(String.format("Can't find %s of the library '%s' at path '%s'", entry.getKey(), libraryName, file.getAbsolutePath()));
                }
                String url = VfsUtil.getUrlForLibraryRoot(file);
                String[] urls = model.getUrls(entry.getKey());
                if (!ArrayUtil.contains(url, urls)) {
                    model.addRoot(url, entry.getKey());
                }
                continue;
            }
            if (virtualFile.isDirectory()) {
                VirtualFile[] files = model.getFiles(entry.getKey());
                if (!ArrayUtil.contains(virtualFile, files)) {
                    model.addRoot(virtualFile, entry.getKey());
                }
            } else {
                VirtualFile root = virtualFile;
                if (virtualFile.getFileType() instanceof ArchiveFileType) {
                    root = JarFileSystem.getInstance().getJarRootForLocalFile(virtualFile);
                    if (root == null) {
                        LOG.warn(String.format("Can't parse contents of the JAR file at path '%s' for the library '%s''", file.getAbsolutePath(), libraryName));
                        continue;
                    }
                }
                VirtualFile[] files = model.getFiles(entry.getKey());
                if (!ArrayUtil.contains(root, files)) {
                    model.addRoot(root, entry.getKey());
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArchiveFileType(com.intellij.ide.highlighter.ArchiveFileType) OrderRootType(com.intellij.openapi.roots.OrderRootType) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 18 with OrderRootType

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

the class ChangeLibraryLevelActionBase method doCopy.

@Nullable
protected Library doCopy(LibraryEx library) {
    final VirtualFile baseDir = getBaseDir();
    final String libPath = baseDir != null ? baseDir.getPath() + "/lib" : "";
    final VirtualFile[] classesRoots = library.getFiles(OrderRootType.CLASSES);
    boolean allowEmptyName = isConvertingToModuleLibrary() && classesRoots.length == 1;
    final String libraryName = allowEmptyName ? "" : StringUtil.notNullize(library.getName(), LibraryTypeServiceImpl.suggestLibraryName(classesRoots));
    final LibraryTableModifiableModelProvider provider = getModifiableTableModelProvider();
    final ChangeLibraryLevelDialog dialog = new ChangeLibraryLevelDialog(getParentComponent(), myProject, myCopy, libraryName, libPath, allowEmptyName, provider);
    if (!dialog.showAndGet()) {
        return null;
    }
    final Set<File> fileToCopy = new LinkedHashSet<>();
    final Map<String, String> copiedFiles = new HashMap<>();
    final String targetDirectoryPath = dialog.getDirectoryForFilesPath();
    if (targetDirectoryPath != null) {
        for (OrderRootType type : OrderRootType.getAllTypes()) {
            for (VirtualFile root : library.getFiles(type)) {
                if (root.isInLocalFileSystem() || root.getFileSystem() instanceof ArchiveFileSystem) {
                    fileToCopy.add(VfsUtil.virtualToIoFile(PathUtil.getLocalFile(root)));
                }
            }
        }
        if (!copyOrMoveFiles(fileToCopy, targetDirectoryPath, copiedFiles)) {
            return null;
        }
    }
    final Library copied = provider.getModifiableModel().createLibrary(StringUtil.nullize(dialog.getLibraryName()), library.getKind());
    final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx) copied.getModifiableModel();
    LibraryEditingUtil.copyLibrary(library, copiedFiles, model);
    WriteAction.run(() -> model.commit());
    return copied;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) ChangeLibraryLevelDialog(com.intellij.openapi.roots.ui.configuration.libraryEditor.ChangeLibraryLevelDialog) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) ArchiveFileSystem(com.intellij.openapi.vfs.newvfs.ArchiveFileSystem) LibraryTableModifiableModelProvider(com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider) OrderRootType(com.intellij.openapi.roots.OrderRootType) Library(com.intellij.openapi.roots.libraries.Library) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with OrderRootType

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

the class LibraryRootsComponent method init.

private void init(AbstractTreeStructure treeStructure) {
    myTree = new Tree(new DefaultTreeModel(new DefaultMutableTreeNode()));
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);
    new LibraryRootsTreeSpeedSearch(myTree);
    myTree.setCellRenderer(new LibraryTreeRenderer());
    myTreeBuilder = new LibraryTableTreeBuilder(myTree, (DefaultTreeModel) myTree.getModel(), treeStructure);
    myTreePanel.setLayout(new BorderLayout());
    ToolbarDecorator toolbarDecorator = ToolbarDecorator.createDecorator(myTree).disableUpDownActions().setRemoveActionName(ProjectBundle.message("library.remove.action")).disableRemoveAction();
    toolbarDecorator.setPanelBorder(new CustomLineBorder(1, 0, 0, 0));
    final List<AttachRootButtonDescriptor> popupItems = new ArrayList<>();
    for (AttachRootButtonDescriptor descriptor : myDescriptor.createAttachButtons()) {
        Icon icon = descriptor.getToolbarIcon();
        if (icon != null) {
            AttachItemAction action = new AttachItemAction(descriptor, descriptor.getButtonText(), icon);
            toolbarDecorator.addExtraAction(AnActionButton.fromAction(action));
        } else {
            popupItems.add(descriptor);
        }
    }
    myAddExcludedRootActionButton = new AddExcludedRootActionButton();
    toolbarDecorator.addExtraAction(myAddExcludedRootActionButton);
    toolbarDecorator.addExtraAction(new AnActionButton("Remove", IconUtil.getRemoveIcon()) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final Object[] selectedElements = getSelectedElements();
            if (selectedElements.length == 0) {
                return;
            }
            ApplicationManager.getApplication().runWriteAction(() -> {
                for (Object selectedElement : selectedElements) {
                    if (selectedElement instanceof ItemElement) {
                        final ItemElement itemElement = (ItemElement) selectedElement;
                        getLibraryEditor().removeRoot(itemElement.getUrl(), itemElement.getRootType());
                    } else if (selectedElement instanceof OrderRootTypeElement) {
                        final OrderRootType rootType = ((OrderRootTypeElement) selectedElement).getOrderRootType();
                        final String[] urls = getLibraryEditor().getUrls(rootType);
                        for (String url : urls) {
                            getLibraryEditor().removeRoot(url, rootType);
                        }
                    } else if (selectedElement instanceof ExcludedRootElement) {
                        getLibraryEditor().removeExcludedRoot(((ExcludedRootElement) selectedElement).getUrl());
                    }
                }
            });
            libraryChanged(true);
        }

        @Override
        public void updateButton(AnActionEvent e) {
            super.updateButton(e);
            Object[] elements = getSelectedElements();
            Presentation presentation = e.getPresentation();
            if (ContainerUtil.and(elements, new FilteringIterator.InstanceOf<>(ExcludedRootElement.class))) {
                presentation.setText("Cancel Exclusion");
            } else {
                presentation.setText(getTemplatePresentation().getText());
            }
        }

        @Override
        public ShortcutSet getShortcut() {
            return CommonShortcuts.getDelete();
        }
    });
    toolbarDecorator.setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            if (popupItems.isEmpty()) {
                new AttachFilesAction(myDescriptor.getAttachFilesActionName()).actionPerformed(null);
                return;
            }
            List<AnAction> actions = new ArrayList<>();
            actions.add(new AttachFilesAction(myDescriptor.getAttachFilesActionName()));
            for (AttachRootButtonDescriptor descriptor : popupItems) {
                actions.add(new AttachItemAction(descriptor, descriptor.getButtonText(), null));
            }
            final DefaultActionGroup group = new DefaultActionGroup(actions);
            JBPopupFactory.getInstance().createActionGroupPopup(null, group, DataManager.getInstance().getDataContext(button.getContextComponent()), JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true).show(button.getPreferredPopupPoint());
        }
    });
    myTreePanel.add(toolbarDecorator.createPanel(), BorderLayout.CENTER);
    Disposer.register(this, myTreeBuilder);
}
Also used : AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Tree(com.intellij.ui.treeStructure.Tree) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) List(java.util.List) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) AnActionButton(com.intellij.ui.AnActionButton) CustomLineBorder(com.intellij.ui.border.CustomLineBorder) PersistentOrderRootType(com.intellij.openapi.roots.PersistentOrderRootType) OrderRootType(com.intellij.openapi.roots.OrderRootType)

Example 20 with OrderRootType

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

the class LibraryDownloadSettings method download.

@Nullable
public NewLibraryEditor download(JComponent parent, @Nullable String rootPath) {
    final List<DownloadableFileDescription> toDownload = new ArrayList<>(mySelectedDownloads);
    Map<DownloadableFileDescription, OrderRootType> rootTypes = new HashMap<>();
    for (DownloadableLibraryFileDescription description : mySelectedDownloads) {
        final DownloadableFileDescription sources = description.getSourcesDescription();
        if (myDownloadSources && sources != null) {
            toDownload.add(sources);
            rootTypes.put(sources, OrderRootType.SOURCES);
        }
        final DownloadableFileDescription docs = description.getDocumentationDescription();
        if (myDownloadJavaDocs && docs != null) {
            toDownload.add(docs);
            rootTypes.put(docs, JavadocOrderRootType.getInstance());
        }
    }
    String path = rootPath != null && !FileUtil.isAbsolute(myLibrariesPath) ? new File(rootPath, myLibrariesPath).getPath() : myLibrariesPath;
    List<Pair<VirtualFile, DownloadableFileDescription>> downloaded = DownloadableFileService.getInstance().createDownloader(toDownload, myLibraryName + " Library").downloadWithProgress(path, null, parent);
    if (downloaded == null) {
        return null;
    }
    final NewLibraryEditor libraryEditor;
    if (myLibraryType != null) {
        libraryEditor = new NewLibraryEditor(myLibraryType, new LibraryVersionProperties(myVersion.getVersionString()));
    } else {
        libraryEditor = new NewLibraryEditor();
    }
    libraryEditor.setName(myLibraryName);
    for (Pair<VirtualFile, DownloadableFileDescription> pair : downloaded) {
        final OrderRootType rootType = rootTypes.containsKey(pair.getSecond()) ? rootTypes.get(pair.getSecond()) : OrderRootType.CLASSES;
        libraryEditor.addRoot(pair.getFirst(), rootType);
    }
    return libraryEditor;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DownloadableLibraryFileDescription(com.intellij.framework.library.DownloadableLibraryFileDescription) LibraryVersionProperties(com.intellij.framework.library.LibraryVersionProperties) DownloadableFileDescription(com.intellij.util.download.DownloadableFileDescription) OrderRootType(com.intellij.openapi.roots.OrderRootType) JavadocOrderRootType(com.intellij.openapi.roots.JavadocOrderRootType) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NewLibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor) Pair(com.intellij.openapi.util.Pair) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

OrderRootType (com.intellij.openapi.roots.OrderRootType)31 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 File (java.io.File)7 Element (org.jdom.Element)7 PersistentOrderRootType (com.intellij.openapi.roots.PersistentOrderRootType)6 JavadocOrderRootType (com.intellij.openapi.roots.JavadocOrderRootType)5 Library (com.intellij.openapi.roots.libraries.Library)4 VirtualFilePointerContainer (com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer)4 NotNull (org.jetbrains.annotations.NotNull)4 AnnotationOrderRootType (com.intellij.openapi.roots.AnnotationOrderRootType)3 ArrayList (java.util.ArrayList)3 Nullable (org.jetbrains.annotations.Nullable)3 Disposable (com.intellij.openapi.Disposable)2 LibraryPathType (com.intellij.openapi.externalSystem.model.project.LibraryPathType)2 RootProvider (com.intellij.openapi.roots.RootProvider)2 OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)2 Pair (com.intellij.openapi.util.Pair)2 VirtualFileManager (com.intellij.openapi.vfs.VirtualFileManager)2 HashMap (com.intellij.util.containers.HashMap)2 HashMap (java.util.HashMap)2