Search in sources :

Example 26 with FileChooserDescriptor

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

the class ExternalSystemTaskSettingsControl method fillUi.

@Override
public void fillUi(@NotNull final PaintAwarePanel canvas, int indentLevel) {
    myProjectPathLabel = new JBLabel(ExternalSystemBundle.message("run.configuration.settings.label.project", myExternalSystemId.getReadableName()));
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(myExternalSystemId);
    FileChooserDescriptor projectPathChooserDescriptor = null;
    if (manager instanceof ExternalSystemUiAware) {
        projectPathChooserDescriptor = ((ExternalSystemUiAware) manager).getExternalProjectConfigDescriptor();
    }
    if (projectPathChooserDescriptor == null) {
        projectPathChooserDescriptor = FileChooserDescriptorFactory.createSingleLocalFileDescriptor();
    }
    String title = ExternalSystemBundle.message("settings.label.select.project", myExternalSystemId.getReadableName());
    myProjectPathField = new ExternalProjectPathField(myProject, myExternalSystemId, projectPathChooserDescriptor, title) {

        @Override
        public Dimension getPreferredSize() {
            return myVmOptionsEditor == null ? super.getPreferredSize() : myVmOptionsEditor.getTextField().getPreferredSize();
        }
    };
    canvas.add(myProjectPathLabel, ExternalSystemUiUtil.getLabelConstraints(0));
    canvas.add(myProjectPathField, ExternalSystemUiUtil.getFillLineConstraints(0));
    myTasksLabel = new JBLabel(ExternalSystemBundle.message("run.configuration.settings.label.tasks"));
    myTasksTextField = new EditorTextField("", myProject, PlainTextFileType.INSTANCE);
    canvas.add(myTasksLabel, ExternalSystemUiUtil.getLabelConstraints(0));
    GridBag c = ExternalSystemUiUtil.getFillLineConstraints(0);
    c.insets.right = myProjectPathField.getButton().getPreferredSize().width + 8;
    canvas.add(myTasksTextField, c);
    new TaskCompletionProvider(myProject, myExternalSystemId, myProjectPathField).apply(myTasksTextField);
    myVmOptionsLabel = new JBLabel(ExternalSystemBundle.message("run.configuration.settings.label.vmoptions"));
    myVmOptionsEditor = new RawCommandLineEditor();
    myVmOptionsEditor.setDialogCaption(ExternalSystemBundle.message("run.configuration.settings.label.vmoptions"));
    canvas.add(myVmOptionsLabel, ExternalSystemUiUtil.getLabelConstraints(0));
    canvas.add(myVmOptionsEditor, ExternalSystemUiUtil.getFillLineConstraints(0));
    myArgumentsLabel = new JBLabel(ExternalSystemBundle.message("run.configuration.settings.label.arguments"));
    myArgumentsEditor = new RawCommandLineEditor();
    myArgumentsEditor.setDialogCaption(ExternalSystemBundle.message("run.configuration.settings.label.arguments"));
    canvas.add(myArgumentsLabel, ExternalSystemUiUtil.getLabelConstraints(0));
    canvas.add(myArgumentsEditor, ExternalSystemUiUtil.getFillLineConstraints(0));
}
Also used : ExternalProjectPathField(com.intellij.openapi.externalSystem.service.ui.ExternalProjectPathField) JBLabel(com.intellij.ui.components.JBLabel) EditorTextField(com.intellij.ui.EditorTextField) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) RawCommandLineEditor(com.intellij.ui.RawCommandLineEditor) GridBag(com.intellij.util.ui.GridBag) ExternalSystemUiAware(com.intellij.openapi.externalSystem.ExternalSystemUiAware)

Example 27 with FileChooserDescriptor

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

the class AntExplorer method addBuildFile.

private void addBuildFile() {
    final FileChooserDescriptor descriptor = createXmlDescriptor();
    descriptor.setTitle(AntBundle.message("select.ant.build.file.dialog.title"));
    descriptor.setDescription(AntBundle.message("select.ant.build.file.dialog.description"));
    final VirtualFile[] files = FileChooser.chooseFiles(descriptor, myProject, null);
    addBuildFile(files);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor)

Example 28 with FileChooserDescriptor

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

the class EclipseImportBuilder method createEclipseLibrary.

private static void createEclipseLibrary(final Project project, final Collection<String> libraries, final String libraryName) {
    if (libraries.contains(libraryName)) {
        final FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(false, true, false, false, false, false) {

            @Override
            public Icon getIcon(final VirtualFile file) {
                return looksLikeEclipse(file) ? dressIcon(file, EclipseIcons.Eclipse) : super.getIcon(file);
            }

            private boolean looksLikeEclipse(final VirtualFile file) {
                return file.findChild(".eclipseproduct") != null;
            }
        };
        fileChooserDescriptor.setTitle(EclipseBundle.message("eclipse.create.library.title"));
        fileChooserDescriptor.setDescription(EclipseBundle.message("eclipse.create.library.description", libraryName));
        final VirtualFile file = FileChooser.chooseFile(fileChooserDescriptor, project, null);
        if (file != null) {
            final VirtualFile pluginsDir = file.findChild("plugins");
            if (pluginsDir != null) {
                ApplicationManager.getApplication().runWriteAction(() -> {
                    final LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(LibraryTablesRegistrar.APPLICATION_LEVEL, project);
                    assert table != null;
                    final LibraryTable.ModifiableModel tableModel = table.getModifiableModel();
                    final Library library = tableModel.createLibrary(libraryName);
                    final Library.ModifiableModel libraryModel = library.getModifiableModel();
                    libraryModel.addJarDirectory(pluginsDir, true);
                    libraryModel.commit();
                    tableModel.commit();
                });
                libraries.remove(libraryName);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Library(com.intellij.openapi.roots.libraries.Library)

Example 29 with FileChooserDescriptor

use of com.intellij.openapi.fileChooser.FileChooserDescriptor 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 30 with FileChooserDescriptor

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

the class CvsConfigurationPanel method addBrowseHandler.

public static void addBrowseHandler(Project project, final TextFieldWithBrowseButton field, final String title) {
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor();
    field.addBrowseFolderListener(title, null, project, descriptor, new TextComponentAccessor<JTextField>() {

        @Override
        public String getText(JTextField textField) {
            String text = textField.getText();
            if (!text.isEmpty()) {
                text = CvsApplicationLevelConfiguration.convertToIOFilePath(text);
            }
            return text;
        }

        @Override
        public void setText(JTextField textField, @NotNull String text) {
            textField.setText(text);
        }
    });
}
Also used : FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor)

Aggregations

FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)166 VirtualFile (com.intellij.openapi.vfs.VirtualFile)110 NotNull (org.jetbrains.annotations.NotNull)35 File (java.io.File)24 Project (com.intellij.openapi.project.Project)22 TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)21 Nullable (org.jetbrains.annotations.Nullable)19 ActionEvent (java.awt.event.ActionEvent)17 ActionListener (java.awt.event.ActionListener)16 DocumentEvent (javax.swing.event.DocumentEvent)14 DocumentAdapter (com.intellij.ui.DocumentAdapter)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 FileChooser (com.intellij.openapi.fileChooser.FileChooser)9 List (java.util.List)9 FileChooserDialog (com.intellij.openapi.fileChooser.FileChooserDialog)7 JBLabel (com.intellij.ui.components.JBLabel)7 javax.swing (javax.swing)7 MacroComboBoxWithBrowseButton (com.intellij.execution.ui.MacroComboBoxWithBrowseButton)5 Module (com.intellij.openapi.module.Module)5