Search in sources :

Example 1 with FileSystemTreeImpl

use of com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl 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 2 with FileSystemTreeImpl

use of com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl in project intellij-community by JetBrains.

the class NewFileAction method createNewFile.

private static void createNewFile(FileSystemTree fileSystemTree, final FileType fileType, final String initialContent) {
    final VirtualFile file = fileSystemTree.getNewFileParent();
    if (file == null || !file.isDirectory())
        return;
    String newFileName;
    while (true) {
        newFileName = Messages.showInputDialog(UIBundle.message("create.new.file.enter.new.file.name.prompt.text"), UIBundle.message("new.file.dialog.title"), Messages.getQuestionIcon());
        if (newFileName == null) {
            return;
        }
        if ("".equals(newFileName.trim())) {
            Messages.showMessageDialog(UIBundle.message("create.new.file.file.name.cannot.be.empty.error.message"), UIBundle.message("error.dialog.title"), Messages.getErrorIcon());
            continue;
        }
        Exception failReason = ((FileSystemTreeImpl) fileSystemTree).createNewFile(file, newFileName, fileType, initialContent);
        if (failReason != null) {
            Messages.showMessageDialog(UIBundle.message("create.new.file.could.not.create.file.error.message", newFileName), UIBundle.message("error.dialog.title"), Messages.getErrorIcon());
            continue;
        }
        return;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileSystemTreeImpl(com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl)

Example 3 with FileSystemTreeImpl

use of com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl in project intellij-community by JetBrains.

the class NewFolderAction method createNewFolder.

private static void createNewFolder(FileSystemTree fileSystemTree) {
    final VirtualFile file = fileSystemTree.getNewFileParent();
    if (file == null || !file.isDirectory())
        return;
    final InputValidatorEx validator = new NewFolderValidator(file);
    final String newFolderName = Messages.showInputDialog(UIBundle.message("create.new.folder.enter.new.folder.name.prompt.text"), UIBundle.message("new.folder.dialog.title"), Messages.getQuestionIcon(), "", validator);
    if (newFolderName == null) {
        return;
    }
    Exception failReason = ((FileSystemTreeImpl) fileSystemTree).createNewFolder(file, newFolderName);
    if (failReason != null) {
        Messages.showMessageDialog(UIBundle.message("create.new.folder.could.not.create.folder.error.message", newFolderName), UIBundle.message("error.dialog.title"), Messages.getErrorIcon());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileSystemTreeImpl(com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl) InputValidatorEx(com.intellij.openapi.ui.InputValidatorEx)

Example 4 with FileSystemTreeImpl

use of com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl in project intellij-community by JetBrains.

the class VcsStructureChooser method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    myTree = new Tree();
    myTree.setBorder(BORDER);
    myTree.setShowsRootHandles(true);
    myTree.setRootVisible(false);
    myTree.setExpandableItemsEnabled(false);
    FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, true, true, false, true) {

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            if (!super.isFileVisible(file, showHiddenFiles))
                return false;
            if (myRoots.contains(file))
                return false;
            ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
            return !changeListManager.isIgnoredFile(file) && !changeListManager.isUnversioned(file);
        }
    };
    descriptor.withRoots(new ArrayList<>(myRoots)).withShowHiddenFiles(true).withHideIgnored(true);
    final MyCheckboxTreeCellRenderer cellRenderer = new MyCheckboxTreeCellRenderer(mySelectionManager, myModulesSet, myProject, myTree, myRoots);
    FileSystemTreeImpl fileSystemTree = new FileSystemTreeImpl(myProject, descriptor, myTree, cellRenderer, null, o -> {
        DefaultMutableTreeNode lastPathComponent = ((DefaultMutableTreeNode) o.getLastPathComponent());
        Object uo = lastPathComponent.getUserObject();
        if (uo instanceof FileNodeDescriptor) {
            VirtualFile file = ((FileNodeDescriptor) uo).getElement().getFile();
            String module = myModulesSet.get(file);
            if (module != null)
                return module;
            return file == null ? "" : file.getName();
        }
        return o.toString();
    });
    fileSystemTree.getTreeBuilder().getUi().setNodeDescriptorComparator((o1, o2) -> {
        if (o1 instanceof FileNodeDescriptor && o2 instanceof FileNodeDescriptor) {
            VirtualFile f1 = ((FileNodeDescriptor) o1).getElement().getFile();
            VirtualFile f2 = ((FileNodeDescriptor) o2).getElement().getFile();
            boolean isDir1 = f1.isDirectory();
            boolean isDir2 = f2.isDirectory();
            if (isDir1 != isDir2)
                return isDir1 ? -1 : 1;
            return f1.getPath().compareToIgnoreCase(f2.getPath());
        }
        return o1.getIndex() - o2.getIndex();
    });
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            int row = myTree.getRowForLocation(e.getX(), e.getY());
            if (row < 0)
                return false;
            Object o = myTree.getPathForRow(row).getLastPathComponent();
            if (getTreeRoot() == o || getFile(o) == null)
                return false;
            Rectangle rowBounds = myTree.getRowBounds(row);
            cellRenderer.setBounds(rowBounds);
            Rectangle checkBounds = cellRenderer.myCheckbox.getBounds();
            checkBounds.setLocation(rowBounds.getLocation());
            if (checkBounds.height == 0)
                checkBounds.height = rowBounds.height;
            if (checkBounds.contains(e.getPoint())) {
                mySelectionManager.toggleSelection((DefaultMutableTreeNode) o);
                myTree.revalidate();
                myTree.repaint();
            }
            return true;
        }
    }.installOn(myTree);
    myTree.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                TreePath[] paths = myTree.getSelectionPaths();
                if (paths == null)
                    return;
                for (TreePath path : paths) {
                    if (path == null)
                        continue;
                    Object o = path.getLastPathComponent();
                    if (getTreeRoot() == o || getFile(o) == null)
                        return;
                    mySelectionManager.toggleSelection((DefaultMutableTreeNode) o);
                }
                myTree.revalidate();
                myTree.repaint();
                e.consume();
            }
        }
    });
    JBPanel panel = new JBPanel(new BorderLayout());
    panel.add(new JBScrollPane(fileSystemTree.getTree()), BorderLayout.CENTER);
    final JLabel selectedLabel = new JLabel("");
    selectedLabel.setBorder(JBUI.Borders.empty(2, 0));
    panel.add(selectedLabel, BorderLayout.SOUTH);
    mySelectionManager.setSelectionChangeListener(new PlusMinus<VirtualFile>() {

        @Override
        public void plus(VirtualFile virtualFile) {
            mySelectedFiles.add(virtualFile);
            recalculateErrorText();
        }

        private void recalculateErrorText() {
            checkEmpty();
            if (mySelectionManager.canAddSelection()) {
                selectedLabel.setText("");
            } else {
                selectedLabel.setText(CAN_NOT_ADD_TEXT);
            }
            selectedLabel.revalidate();
        }

        @Override
        public void minus(VirtualFile virtualFile) {
            mySelectedFiles.remove(virtualFile);
            recalculateErrorText();
        }
    });
    panel.setPreferredSize(JBUI.size(400, 300));
    return panel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyAdapter(java.awt.event.KeyAdapter) KeyEvent(java.awt.event.KeyEvent) Tree(com.intellij.ui.treeStructure.Tree) MouseEvent(java.awt.event.MouseEvent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) FileSystemTreeImpl(com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl) FileNodeDescriptor(com.intellij.openapi.fileChooser.ex.FileNodeDescriptor) JBPanel(com.intellij.ui.components.JBPanel) TreePath(javax.swing.tree.TreePath) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 5 with FileSystemTreeImpl

use of com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl in project android by JetBrains.

the class FileChooserDialogFixture method select.

@NotNull
public FileChooserDialogFixture select(@NotNull final VirtualFile file) {
    final FileSystemTreeImpl fileSystemTree = field("myFileSystemTree").ofType(FileSystemTreeImpl.class).in(getDialogWrapper()).get();
    // Windows: Default temporary folder (../AppData/..) is hidden.
    fileSystemTree.showHiddens(true);
    final AtomicBoolean fileSelected = new AtomicBoolean();
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            fileSystemTree.select(file, () -> {
                fileSelected.set(true);
            });
        }
    });
    Wait.seconds(5).expecting("file " + quote(file.getPath()) + " to be selected").until(fileSelected::get);
    return this;
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FileSystemTreeImpl(com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FileSystemTreeImpl (com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2 AbstractTreeBuilder (com.intellij.ide.util.treeView.AbstractTreeBuilder)1 AbstractTreeStructure (com.intellij.ide.util.treeView.AbstractTreeStructure)1 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 NewFolderAction (com.intellij.openapi.fileChooser.actions.NewFolderAction)1 FileNodeDescriptor (com.intellij.openapi.fileChooser.ex.FileNodeDescriptor)1 ContentEntry (com.intellij.openapi.roots.ContentEntry)1 InputValidatorEx (com.intellij.openapi.ui.InputValidatorEx)1 ChangeListManager (com.intellij.openapi.vcs.changes.ChangeListManager)1 JBPanel (com.intellij.ui.components.JBPanel)1 JBScrollPane (com.intellij.ui.components.JBScrollPane)1 Tree (com.intellij.ui.treeStructure.Tree)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 MouseEvent (java.awt.event.MouseEvent)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1