Search in sources :

Example 11 with FileChooserDescriptor

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

the class PyUniversalTestForm method create.

/**
   * @param configuration configuration to configure form on creation
   * @param customOptions additional option names this form shall support. Make sure your configuration has appropriate properties.
   */
@NotNull
public static PyUniversalTestForm create(@NotNull final PyUniversalTestConfiguration configuration, @NotNull final CustomOption... customOptions) {
    // TODO: DOC
    final PyUniversalTestForm form = new PyUniversalTestForm();
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileOrFolderDescriptor(PythonFileType.INSTANCE);
    form.myTargetText.addBrowseFolderListener("Choose File or Folder", null, configuration.getProject(), descriptor);
    for (final TestTargetType testTargetType : TestTargetType.values()) {
        final JBRadioButton button = new JBRadioButton(StringUtil.capitalize(testTargetType.name().toLowerCase(Locale.getDefault())));
        button.setActionCommand(testTargetType.name());
        button.addActionListener(o -> form.configureElementsVisibility());
        form.myButtonGroup.add(button);
        form.myTargets.add(button);
    }
    form.myButtonGroup.getElements().nextElement().setSelected(true);
    form.myOptionsForm = PyCommonOptionsFormFactory.getInstance().createForm(configuration.getCommonOptionsFormData());
    final GridConstraints constraints = new GridConstraints();
    constraints.setFill(GridConstraints.FILL_BOTH);
    form.myOptionsPanel.add(form.myOptionsForm.getMainPanel(), constraints);
    form.myLabel.setText(configuration.getTestFrameworkName());
    form.addCustomOptions(ObjectArrays.concat(customOptions, new CustomOption(PyUniversalTestsKt.getAdditionalArgumentsPropertyName(), TestTargetType.values())));
    configuration.copyTo(ReflectionUtilsKt.getProperties(form, null, true));
    return form;
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) JBRadioButton(com.intellij.ui.components.JBRadioButton) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with FileChooserDescriptor

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

the class CreateVirtualEnvDialog method layoutPanel.

protected void layoutPanel(final List<Sdk> allSdks) {
    final GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.insets = new Insets(2, 2, 2, 2);
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 0.0;
    myMainPanel.add(new JBLabel(PyBundle.message("sdk.create.venv.dialog.label.name")), c);
    c.gridx = 1;
    c.gridy = 0;
    c.gridwidth = 2;
    c.weightx = 1.0;
    myMainPanel.add(myName, c);
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = 1;
    c.weightx = 0.0;
    myMainPanel.add(new JBLabel(PyBundle.message("sdk.create.venv.dialog.label.location")), c);
    c.gridx = 1;
    c.gridy = 1;
    c.gridwidth = 2;
    c.weightx = 1.0;
    myMainPanel.add(myDestination, c);
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = 1;
    c.weightx = 0.0;
    myMainPanel.add(new JBLabel(PyBundle.message("sdk.create.venv.dialog.label.base.interpreter")), c);
    c.gridx = 1;
    c.gridy = 2;
    mySdkCombo = new ComboBox();
    c.insets = new Insets(2, 2, 2, 2);
    c.weightx = 1.0;
    myMainPanel.add(mySdkCombo, c);
    c.gridx = 2;
    c.gridy = 2;
    c.insets = new Insets(0, 0, 2, 2);
    c.weightx = 0.0;
    FixedSizeButton button = new FixedSizeButton();
    button.setPreferredSize(myDestination.getButton().getPreferredSize());
    myMainPanel.add(button, c);
    c.gridx = 0;
    c.gridy = 3;
    c.gridwidth = 3;
    c.insets = new Insets(2, 2, 2, 2);
    mySitePackagesCheckBox = new JBCheckBox(PyBundle.message("sdk.create.venv.dialog.label.inherit.global.site.packages"));
    myMainPanel.add(mySitePackagesCheckBox, c);
    c.gridx = 0;
    c.gridy = 4;
    myMainPanel.add(myMakeAvailableToAllProjectsCheckbox, c);
    button.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            final PythonSdkType sdkType = PythonSdkType.getInstance();
            final FileChooserDescriptor descriptor = sdkType.getHomeChooserDescriptor();
            String suggestedPath = sdkType.suggestHomePath();
            VirtualFile suggestedDir = suggestedPath == null ? null : LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(suggestedPath));
            final NullableConsumer<Sdk> consumer = sdk -> {
                if (sdk == null)
                    return;
                if (!allSdks.contains(sdk)) {
                    allSdks.add(sdk);
                }
                updateSdkList(allSdks, sdk);
            };
            FileChooser.chooseFiles(descriptor, myProject, suggestedDir, new FileChooser.FileChooserConsumer() {

                @Override
                public void consume(List<VirtualFile> selectedFiles) {
                    String path = selectedFiles.get(0).getPath();
                    if (sdkType.isValidSdkHome(path)) {
                        path = FileUtil.toSystemDependentName(path);
                        Sdk newSdk = null;
                        for (Sdk sdk : allSdks) {
                            if (path.equals(sdk.getHomePath())) {
                                newSdk = sdk;
                            }
                        }
                        if (newSdk == null) {
                            newSdk = new PyDetectedSdk(path);
                        }
                        consumer.consume(newSdk);
                    }
                }

                @Override
                public void cancelled() {
                }
            });
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ComboBox(com.intellij.openapi.ui.ComboBox) ActionEvent(java.awt.event.ActionEvent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) JBCheckBox(com.intellij.ui.components.JBCheckBox) ActionListener(java.awt.event.ActionListener) JBLabel(com.intellij.ui.components.JBLabel) ArrayList(java.util.ArrayList) List(java.util.List) Sdk(com.intellij.openapi.projectRoots.Sdk) NullableConsumer(com.intellij.util.NullableConsumer) FixedSizeButton(com.intellij.openapi.ui.FixedSizeButton)

Example 13 with FileChooserDescriptor

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

the class SSHCredentialsDialog method actionPerformed.

public void actionPerformed(ActionEvent e) {
    if (e.getSource() == myPasswordButton || e.getSource() == myKeyButton || e.getSource() == mySshAgentButton) {
        updateFields();
        checkKeyFile();
        updateOKButton();
    } else {
        final String[] path = { myKeyFileText.getText() };
        VirtualFile file;
        if (path[0] != null && path[0].trim().length() > 0) {
            path[0] = "file://" + path[0].replace(File.separatorChar, '/');
            file = VirtualFileManager.getInstance().findFileByUrl(path[0]);
        } else {
            path[0] = "file://" + SystemProperties.getUserHome() + "/.ssh/identity";
            path[0] = path[0].replace(File.separatorChar, '/');
            file = VirtualFileManager.getInstance().findFileByUrl(path[0]);
            if (file == null || !file.exists()) {
                path[0] = "file://" + SystemProperties.getUserHome() + "/.ssh";
                file = VirtualFileManager.getInstance().findFileByUrl(path[0]);
            }
        }
        FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor().withTitle(SvnBundle.message("dialog.title.openssh.v2.private.key")).withDescription(SvnBundle.message("dialog.description.openssh.v2.private.key")).withShowFileSystemRoots(true).withHideIgnored(false).withShowHiddenFiles(true);
        FileChooser.chooseFiles(descriptor, myProject, file, files -> {
            if (files.size() == 1) {
                path[0] = FileUtil.toSystemDependentName(files.get(0).getPath());
                myKeyFileText.setText(path[0]);
            }
            checkKeyFile();
            updateOKButton();
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor)

Example 14 with FileChooserDescriptor

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

the class ImportOptionsDialog method actionPerformed.

public void actionPerformed(ActionEvent e) {
    // choose directory here/
    FileChooserDescriptor fcd = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    fcd.setShowFileSystemRoots(true);
    fcd.setTitle("Checkout Directory");
    fcd.setDescription("Select directory to checkout from subversion");
    fcd.setHideIgnored(false);
    VirtualFile file = FileChooser.chooseFile(fcd, getContentPane(), myProject, null);
    if (file == null) {
        return;
    }
    myPathField.setText(file.getPath().replace('/', File.separatorChar));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor)

Example 15 with FileChooserDescriptor

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

the class CaptureConfigurable method createComponent.

@Nullable
@Override
public JComponent createComponent() {
    myTableModel = new MyTableModel();
    JBTable table = new JBTable(myTableModel);
    table.setColumnSelectionAllowed(false);
    TableColumnModel columnModel = table.getColumnModel();
    TableUtil.setupCheckboxColumn(columnModel.getColumn(MyTableModel.ENABLED_COLUMN));
    ToolbarDecorator decorator = ToolbarDecorator.createDecorator(table);
    decorator.setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            myTableModel.addRow();
        }
    });
    decorator.setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            TableUtil.removeSelectedItems(table);
        }
    });
    decorator.setMoveUpAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            TableUtil.moveSelectedItemsUp(table);
        }
    });
    decorator.setMoveDownAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            TableUtil.moveSelectedItemsDown(table);
        }
    });
    decorator.addExtraAction(new DumbAwareActionButton("Duplicate", "Duplicate", PlatformIcons.COPY_ICON) {

        @Override
        public boolean isEnabled() {
            return table.getSelectedRowCount() == 1;
        }

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            selectedCapturePoints(table).forEach(c -> {
                try {
                    int idx = myTableModel.add(c.clone());
                    table.getSelectionModel().setSelectionInterval(idx, idx);
                } catch (CloneNotSupportedException ex) {
                    LOG.error(ex);
                }
            });
        }
    });
    decorator.addExtraAction(new DumbAwareActionButton("Enable Selected", "Enable Selected", PlatformIcons.SELECT_ALL_ICON) {

        @Override
        public boolean isEnabled() {
            return table.getSelectedRowCount() > 0;
        }

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            selectedCapturePoints(table).forEach(c -> c.myEnabled = true);
            table.repaint();
        }
    });
    decorator.addExtraAction(new DumbAwareActionButton("Disable Selected", "Disable Selected", PlatformIcons.UNSELECT_ALL_ICON) {

        @Override
        public boolean isEnabled() {
            return table.getSelectedRowCount() > 0;
        }

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            selectedCapturePoints(table).forEach(c -> c.myEnabled = false);
            table.repaint();
        }
    });
    new DumbAwareAction("Toggle") {

        @Override
        public void update(@NotNull AnActionEvent e) {
            e.getPresentation().setEnabled(table.getSelectedRowCount() == 1);
        }

        @Override
        public void actionPerformed(@NotNull final AnActionEvent e) {
            selectedCapturePoints(table).forEach(c -> c.myEnabled = !c.myEnabled);
            table.repaint();
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)), table);
    decorator.addExtraAction(new DumbAwareActionButton("Import", "Import", AllIcons.Actions.Install) {

        @Override
        public void actionPerformed(@NotNull final AnActionEvent e) {
            FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, false, true, true) {

                @Override
                public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
                    return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || "xml".equals(file.getExtension()) || file.getFileType() == FileTypes.ARCHIVE);
                }

                @Override
                public boolean isFileSelectable(VirtualFile file) {
                    return file.getFileType() == StdFileTypes.XML;
                }
            };
            descriptor.setDescription("Please select a file to import.");
            descriptor.setTitle("Import Capture Points");
            VirtualFile[] files = FileChooser.chooseFiles(descriptor, e.getProject(), null);
            if (ArrayUtil.isEmpty(files))
                return;
            table.getSelectionModel().clearSelection();
            for (VirtualFile file : files) {
                try {
                    Document document = JDOMUtil.loadDocument(file.getInputStream());
                    List<Element> children = document.getRootElement().getChildren();
                    children.forEach(element -> {
                        int idx = myTableModel.addIfNeeded(XmlSerializer.deserialize(element, CapturePoint.class));
                        table.getSelectionModel().addSelectionInterval(idx, idx);
                    });
                } catch (Exception ex) {
                    final String msg = ex.getLocalizedMessage();
                    Messages.showErrorDialog(e.getProject(), msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed");
                }
            }
        }
    });
    decorator.addExtraAction(new DumbAwareActionButton("Export", "Export", AllIcons.Actions.Export) {

        @Override
        public void actionPerformed(@NotNull final AnActionEvent e) {
            VirtualFileWrapper wrapper = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Export Selected Capture Points to File...", "", "xml"), e.getProject()).save(null, null);
            if (wrapper == null)
                return;
            Element rootElement = new Element("capture-points");
            selectedCapturePoints(table).forEach(c -> {
                try {
                    CapturePoint clone = c.clone();
                    clone.myEnabled = false;
                    rootElement.addContent(XmlSerializer.serialize(clone));
                } catch (CloneNotSupportedException ex) {
                    LOG.error(ex);
                }
            });
            try {
                JDOMUtil.write(rootElement, wrapper.getFile());
            } catch (Exception ex) {
                final String msg = ex.getLocalizedMessage();
                Messages.showErrorDialog(e.getProject(), msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed");
            }
        }

        @Override
        public boolean isEnabled() {
            return table.getSelectedRowCount() > 0;
        }
    });
    BorderLayoutPanel panel = JBUI.Panels.simplePanel();
    panel.addToCenter(decorator.createPanel());
    myCaptureVariables = new JCheckBox(DebuggerBundle.message("label.capture.configurable.capture.variables"));
    panel.addToBottom(myCaptureVariables);
    return panel;
}
Also used : JVMNameUtil(com.intellij.debugger.engine.JVMNameUtil) JavaDebuggerSupport(com.intellij.debugger.ui.JavaDebuggerSupport) AllIcons(com.intellij.icons.AllIcons) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) Document(org.jdom.Document) Nls(org.jetbrains.annotations.Nls) BorderLayoutPanel(com.intellij.util.ui.components.BorderLayoutPanel) JBUI(com.intellij.util.ui.JBUI) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper) FileTypes(com.intellij.openapi.fileTypes.FileTypes) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) FileChooserFactory(com.intellij.openapi.fileChooser.FileChooserFactory) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) KeyEvent(java.awt.event.KeyEvent) com.intellij.ui(com.intellij.ui) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Debugger(org.jetbrains.annotations.Debugger) AnnotatedElementsSearch(com.intellij.psi.search.searches.AnnotatedElementsSearch) StreamEx(one.util.streamex.StreamEx) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Registry(com.intellij.openapi.util.registry.Registry) IntStreamEx(one.util.streamex.IntStreamEx) com.intellij.psi(com.intellij.psi) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) XmlSerializer(com.intellij.util.xmlb.XmlSerializer) ArrayUtil(com.intellij.util.ArrayUtil) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) TableColumnModel(javax.swing.table.TableColumnModel) ArrayList(java.util.ArrayList) JDOMUtil(com.intellij.openapi.util.JDOMUtil) AbstractTableModel(javax.swing.table.AbstractTableModel) Project(com.intellij.openapi.project.Project) DebuggerBundle(com.intellij.debugger.DebuggerBundle) PlatformIcons(com.intellij.util.PlatformIcons) DecompiledLocalVariable(com.intellij.debugger.jdi.DecompiledLocalVariable) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) StringUtil(com.intellij.openapi.util.text.StringUtil) ItemRemovable(com.intellij.util.ui.ItemRemovable) JBTable(com.intellij.ui.table.JBTable) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) Element(org.jdom.Element) FileChooser(com.intellij.openapi.fileChooser.FileChooser) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) javax.swing(javax.swing) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Element(org.jdom.Element) TableColumnModel(javax.swing.table.TableColumnModel) JBTable(com.intellij.ui.table.JBTable) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Document(org.jdom.Document) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) List(java.util.List) ArrayList(java.util.ArrayList) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) BorderLayoutPanel(com.intellij.util.ui.components.BorderLayoutPanel) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ConfigurationException(com.intellij.openapi.options.ConfigurationException) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper) Nullable(org.jetbrains.annotations.Nullable)

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