Example usage for com.intellij.openapi.fileChooser FileChooserDescriptor setTitle

List of usage examples for com.intellij.openapi.fileChooser FileChooserDescriptor setTitle

Introduction

In this page you can find the example usage for com.intellij.openapi.fileChooser FileChooserDescriptor setTitle.

Prototype

public void setTitle(@Nls(capitalization = Nls.Capitalization.Title) String title) 

Source Link

Usage

From source file:net.andydvorak.intellij.lessc.ui.configurable.TextFieldWithBrowseButtonImpl.java

License:Apache License

private FileChooserDescriptor getFileChooserDescriptor() {
    FileChooserDescriptor d = new FileChooserDescriptor(false, true, false, false, false, false);
    if (myTitle != null) {
        d.setTitle(myTitle);
    }//  w  w w  .  j  av  a2 s .  co  m
    d.setShowFileSystemRoots(true);
    return d;
}

From source file:net.happybrackets.intellij_plugin.IntelliJPluginGUIManager.java

License:Apache License

/**
 * Make Configuration/Known devices pane.
 * @param fileType 0 == configuration, 1 == known devices.
 *///from  w  w w .ja  v a2s .c o m
private Pane makeConfigurationPane(final int fileType) {
    final TextArea configField = new TextArea();
    final String label = fileType == 0 ? "Configuration" : "Known Devices";
    final String setting = fileType == 0 ? "controllerConfigPath" : "knownDevicesPath";

    //configField.setPrefSize(400, 250);
    configField.setMinHeight(minTextAreaHeight);
    // Load initial config into text field.
    if (fileType == 0) {
        configField.setText(HappyBracketsToolWindow.getCurrentConfigString());
    } else {
        StringBuilder map = new StringBuilder();
        deviceConnection.getKnownDevices().forEach((hostname, id) -> map.append(hostname + " " + id + "\n"));
        configField.setText(map.toString());
    }
    configField.textProperty().addListener((observable, oldValue, newValue) -> {
        configApplyButton[fileType].setDisable(false);
    });

    Button loadButton = new Button("Load");
    loadButton.setTooltip(new Tooltip("Load a new " + label.toLowerCase() + " file."));
    loadButton.setOnMouseClicked(event -> {
        //select a file
        final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor()
                .withShowHiddenFiles(true);
        descriptor.setTitle("Select " + label.toLowerCase() + " file");

        String currentFile = HappyBracketsToolWindow.getSettings().getString(setting);
        VirtualFile vfile = currentFile == null ? null
                : LocalFileSystem.getInstance().findFileByPath(currentFile.replace(File.separatorChar, '/'));

        //needs to run in Swing event dispatch thread, and then back again to JFX thread!!
        SwingUtilities.invokeLater(() -> {
            VirtualFile[] virtualFile = FileChooser.chooseFiles(descriptor, null, vfile);
            if (virtualFile != null && virtualFile.length > 0 && virtualFile[0] != null) {
                Platform.runLater(() -> {
                    loadConfigFile(virtualFile[0].getCanonicalPath(), label, configField, setting, loadButton,
                            event);
                });
            }
        });
    });

    Button saveButton = new Button("Save");
    saveButton.setTooltip(new Tooltip("Save these " + label.toLowerCase() + " settings to a file."));
    saveButton.setOnMouseClicked(event -> {
        //select a file
        FileSaverDescriptor fsd = new FileSaverDescriptor("Select " + label.toLowerCase() + " file to save to.",
                "Select " + label.toLowerCase() + " file to save to.");
        fsd.withShowHiddenFiles(true);
        final FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(fsd, project);

        String currentFilePath = HappyBracketsToolWindow.getSettings().getString(setting);
        File currentFile = currentFilePath != null
                ? new File(HappyBracketsToolWindow.getSettings().getString(setting))
                : null;
        VirtualFile baseDir = null;
        String currentName = null;
        if (currentFile != null && currentFile.exists()) {
            baseDir = LocalFileSystem.getInstance().findFileByPath(
                    currentFile.getParentFile().getAbsolutePath().replace(File.separatorChar, '/'));
            currentName = currentFile.getName();
        } else {
            baseDir = LocalFileSystem.getInstance().findFileByPath(HappyBracketsToolWindow.getPluginLocation());
            currentName = fileType == 0 ? "controller-config.json" : "known_devices";
        }
        final VirtualFile baseDirFinal = baseDir;
        final String currentNameFinal = currentName;

        //needs to run in Swing event dispatch thread, and then back again to JFX thread!!
        SwingUtilities.invokeLater(() -> {
            final VirtualFileWrapper wrapper = dialog.save(baseDirFinal, currentNameFinal);

            if (wrapper != null) {
                Platform.runLater(() -> {
                    File configFile = wrapper.getFile();

                    // Check for overwrite of default config files (this doesn't apply to deployed plugin so disabling for now.)
                    //if ((new File(HappyBracketsToolWindow.getDefaultControllerConfigPath())).getAbsolutePath().equals(configFile.getAbsolutePath()) ||
                    //      (new File(HappyBracketsToolWindow.getDefaultKnownDevicesPath())).getAbsolutePath().equals(configFile.getAbsolutePath())) {
                    //   showPopup("Error saving " + label.toLowerCase() + ": cannot overwrite default configuration files.", saveButton, 5, event);
                    //}

                    try (PrintWriter out = new PrintWriter(configFile.getAbsolutePath())) {
                        out.print(configField.getText());

                        HappyBracketsToolWindow.getSettings().set(setting, configFile.getAbsolutePath());
                    } catch (Exception ex) {
                        showPopup("Error saving " + label.toLowerCase() + ": " + ex.getMessage(), saveButton, 5,
                                event);
                    }
                });
            }
        });
    });

    Button resetButton = new Button("Reset");
    resetButton.setTooltip(new Tooltip("Reset these " + label.toLowerCase() + " settings to their defaults."));
    resetButton.setOnMouseClicked(event -> {
        HappyBracketsToolWindow.getSettings().clear(setting);

        if (fileType == 0) {
            loadConfigFile(HappyBracketsToolWindow.getDefaultControllerConfigPath(), label, configField,
                    setting, resetButton, event);
            applyConfig(configField.getText());
        } else {
            loadConfigFile(HappyBracketsToolWindow.getDefaultKnownDevicesPath(), label, configField, setting,
                    resetButton, event);
            applyKnownDevices(configField.getText());
        }
    });

    configApplyButton[fileType] = new Button("Apply");
    configApplyButton[fileType].setTooltip(new Tooltip("Apply these " + label.toLowerCase() + " settings."));
    configApplyButton[fileType].setDisable(true);
    configApplyButton[fileType].setOnMouseClicked(event -> {
        configApplyButton[fileType].setDisable(true);

        if (fileType == 0) {
            applyConfig(configField.getText());
        } else {
            applyKnownDevices(configField.getText());
        }
    });

    FlowPane buttons = new FlowPane(defaultElementSpacing, defaultElementSpacing);
    buttons.setAlignment(Pos.TOP_LEFT);
    buttons.getChildren().addAll(loadButton, saveButton, resetButton, configApplyButton[fileType]);

    // If this is the main configuration pane, include buttons to set preferred IP version.
    FlowPane ipvButtons = null;
    if (fileType == 0) {
        // Set IP version buttons.
        ipvButtons = new FlowPane(defaultElementSpacing, defaultElementSpacing);
        ipvButtons.setAlignment(Pos.TOP_LEFT);

        for (int ipv = 4; ipv <= 6; ipv += 2) {
            final int ipvFinal = ipv;

            Button setIPv = new Button("Set IntelliJ to prefer IPv" + ipv);
            String currentSetting = System.getProperty("java.net.preferIPv" + ipv + "Addresses");

            if (currentSetting != null && currentSetting.toLowerCase().equals("true")) {
                setIPv.setDisable(true);
            }

            setIPv.setTooltip(new Tooltip("Set the JVM used by IntelliJ to prefer IPv" + ipv
                    + " addresses by default.\nThis can help resolve IPv4/Ipv6 incompatibility issues in some cases."));
            setIPv.setOnMouseClicked(event -> {
                // for the 32 and 64 bit versions of the options files.
                for (String postfix : new String[] { "", "64" }) {
                    String postfix2 = "";
                    String filename = "/idea" + postfix + postfix2 + ".vmoptions";
                    // If this (Linux (and Mac?)) version of the file doesn't exist, try the Windows version.
                    if (!Paths.get(PathManager.getBinPath() + filename).toFile().exists()) {
                        postfix2 = ".exe";
                        filename = "/idea" + postfix + postfix2 + ".vmoptions";

                        if (!Paths.get(PathManager.getBinPath() + filename).toFile().exists()) {
                            showPopup("An error occurred: could not find default configuration file.", setIPv,
                                    5, event);
                            return;
                        }
                    }

                    // Create custom options files if they don't already exist.
                    File custOptsFile = new File(PathManager.getCustomOptionsDirectory() + "/idea" + postfix
                            + postfix2 + ".vmoptions");
                    if (!custOptsFile.exists()) {
                        // Create copy of default.
                        try {
                            Files.copy(Paths.get(PathManager.getBinPath() + filename), custOptsFile.toPath());
                        } catch (IOException e) {
                            logger.error("Error creating custom options file.", e);
                            showPopup("Error creating custom options file: " + e.getMessage(), setIPv, 5,
                                    event);
                            return;
                        }
                    }

                    if (custOptsFile.exists()) {
                        StringBuilder newOpts = new StringBuilder();
                        try (Stream<String> stream = Files.lines(custOptsFile.toPath())) {
                            stream.forEach((line) -> {
                                // Remove any existing preferences.
                                if (!line.contains("java.net.preferIPv")) {
                                    newOpts.append(line + "\n");
                                }
                            });
                            // Add new preference to end.
                            newOpts.append("-Djava.net.preferIPv" + ipvFinal + "Addresses=true");
                        } catch (IOException e) {
                            logger.error("Error creating custom options file.", e);
                            showPopup("Error creating custom options file: " + e.getMessage(), setIPv, 5,
                                    event);
                            return;
                        }

                        // Write new options to file.
                        try (PrintWriter out = new PrintWriter(custOptsFile.getAbsolutePath())) {
                            out.println(newOpts);
                        } catch (FileNotFoundException e) {
                            // This totally shouldn't happen.
                        }
                    }
                }

                showPopup("You must restart IntelliJ for the changes to take effect.", setIPv, 5, event);
            });

            ipvButtons.getChildren().add(setIPv);
        }
    }

    VBox configPane = new VBox(defaultElementSpacing);
    configPane.setAlignment(Pos.TOP_LEFT);
    configPane.getChildren().addAll(makeTitle(label), configField, buttons);
    if (ipvButtons != null) {
        configPane.getChildren().add(ipvButtons);
    }

    return configPane;
}

From source file:net.happybrackets.intellij_plugin.IntelliJPluginGUIManager.java

License:Apache License

private Pane makeCompositionFolderPane() {
    compositionPathText = new Text();
    TextFlow compositionPathTextPane = new TextFlow(compositionPathText);
    compositionPathTextPane.setTextAlignment(TextAlignment.RIGHT);

    Button changeCompositionPath = new Button("Change");
    changeCompositionPath.setTooltip(new Tooltip("Select a new folder containing composition files."));
    changeCompositionPath.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override/*from w  w w. ja v a  2 s  .c  om*/
        public void handle(MouseEvent event) {
            //select a folder
            final FileChooserDescriptor descriptor = FileChooserDescriptorFactory
                    .createSingleFolderDescriptor();
            descriptor.setTitle("Select Composition Folder");
            //needs to run in Swing event dispatch thread, and then back again to JFX thread!!
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    VirtualFile[] virtualFile = FileChooser.chooseFiles(descriptor, null, null);
                    if (virtualFile != null && virtualFile.length > 0 && virtualFile[0] != null) {
                        Platform.runLater(new Runnable() {
                            @Override
                            public void run() {
                                updateCompositionPath(virtualFile[0].getCanonicalPath());
                            }
                        });
                    }
                }
            });
        }
    });
    Button refreshButton = new Button("Refresh");
    refreshButton.setTooltip(new Tooltip("Reload the available composition files."));
    refreshButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            refreshCompositionList();
        }
    });

    FlowPane compositionFolderPane = new FlowPane(10, 10);
    compositionFolderPane.setAlignment(Pos.TOP_LEFT);
    compositionFolderPane.getChildren().addAll(compositionPathText, changeCompositionPath, refreshButton);

    return compositionFolderPane;
}

From source file:org.clarent.ivyidea.config.ui.orderedfilelist.OrderedFileList.java

License:Apache License

private void wireAddButton() {
    btnAdd.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            final FileChooserDescriptor fcDescriptor = FileChooserDescriptorFactory
                    .createMultipleFilesNoJarsDescriptor();
            fcDescriptor.setTitle("Select properties file(s)");
            final VirtualFile[] files = FileChooser.chooseFiles(project, fcDescriptor);
            for (VirtualFile file : files) {
                addFilenameToList(file.getPresentableUrl());
            }/*  w  w  w  .j a  v a2 s.c o m*/
        }
    });

}

From source file:org.codehaus.groovy.intellij.configuration.GroovySettingsEditor.java

License:Apache License

private LabeledComponent createScriptPathComponent() {
    FileChooserDescriptor scriptChooserDescriptor = FileChooserDescriptorFactory
            .createSingleFileNoJarsDescriptor();

    String title = "Select Groovy Script";
    scriptChooserDescriptor.setTitle(title);
    scriptPathTextField.addBrowseFolderListener(title, null, project, scriptChooserDescriptor);

    LabeledComponent<TextFieldWithBrowseButton> scriptPathComponent = new LabeledComponent<TextFieldWithBrowseButton>();
    scriptPathComponent.setComponent(scriptPathTextField);
    scriptPathComponent.setText("Groovy &Script:");
    return scriptPathComponent;
}

From source file:org.codehaus.groovy.intellij.configuration.GroovySettingsEditor.java

License:Apache License

private LabeledComponent createWorkingDirectoryPathComponent() {
    FileChooserDescriptor workingDirectoryChooserDescriptor = FileChooserDescriptorFactory
            .createSingleFolderDescriptor();

    String title = "Select Working Directory";
    workingDirectoryChooserDescriptor.setTitle(title);
    workingDirectoryPathTextField.addBrowseFolderListener(title, null, project,
            workingDirectoryChooserDescriptor);

    LabeledComponent<TextFieldWithBrowseButton> workingDirectoryPathComponent = new LabeledComponent<TextFieldWithBrowseButton>();
    workingDirectoryPathComponent.setComponent(workingDirectoryPathTextField);
    workingDirectoryPathComponent.setOpaque(true);
    workingDirectoryPathComponent.setText("&Working Directory:");
    return workingDirectoryPathComponent;
}

From source file:org.community.intellij.plugins.communitycase.actions.Init.java

License:Apache License

/**
 * {@inheritDoc}//from w w w .ja  v  a2 s  .c o m
 */
public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getData(PlatformDataKeys.PROJECT);
    if (project == null) {
        return;
    }
    FileChooserDescriptor fcd = new FileChooserDescriptor(false, true, false, false, false, false);
    fcd.setShowFileSystemRoots(true);
    fcd.setTitle(Bundle.getString("init.destination.directory.title"));
    fcd.setDescription(Bundle.getString("init.destination.directory.description"));
    fcd.setHideIgnored(false);
    final VirtualFile baseDir = project.getBaseDir();
    final VirtualFile[] files = FileChooser.chooseFiles(project, fcd, baseDir);
    if (files.length == 0) {
        return;
    }
    final VirtualFile root = files[0];
    if (Util.isUnder(root)) {
        final int v = Messages.showYesNoDialog(project,
                Bundle.message("init.warning.already.under.git",
                        StringUtil.escapeXml(root.getPresentableUrl())),
                Bundle.getString("init.warning.title"), Messages.getWarningIcon());
        if (v != 0) {
            return;
        }
    }
    LineHandler h = new LineHandler(project, root, Command.INIT);
    h.setRemote(true);
    HandlerUtil.doSynchronously(h, Bundle.getString("initializing.title"), h.printableCommandLine());
    if (!h.errors().isEmpty()) {
        UiUtil.showOperationErrors(project, h.errors(), " init");
        return;
    }
    int rc = Messages.showYesNoDialog(project, Bundle.getString("init.add.root.message"),
            Bundle.getString("init.add.root.title"), Messages.getQuestionIcon());
    if (rc != 0) {
        return;
    }
    final String path = root.equals(baseDir) ? "" : root.getPath();
    Vcs.getInstance(project)
            .runInBackground(new Task.Backgroundable(project, Bundle.getString("common.refreshing")) {

                public void run(@NotNull ProgressIndicator indicator) {
                    refreshAndConfigureVcsMappings(project, root, path);
                }
            });
}

From source file:org.community.intellij.plugins.communitycase.checkout.CloneDialog.java

License:Apache License

/**
 * Init components//from  w  ww .j  av a2 s.c o  m
 */
private void initListeners() {
    FileChooserDescriptor fcd = new FileChooserDescriptor(false, true, false, false, false, false);
    fcd.setShowFileSystemRoots(true);
    fcd.setTitle(Bundle.getString("clone.destination.directory.title"));
    fcd.setDescription(Bundle.getString("clone.destination.directory.description"));
    fcd.setHideIgnored(false);
    myParentDirectory.addActionListener(new ComponentWithBrowseButton.BrowseFolderActionListener<JTextField>(
            fcd.getTitle(), fcd.getDescription(), myParentDirectory, myProject, fcd,
            TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT) {
        @Override
        protected VirtualFile getInitialFile() {
            // suggest project base directory only if nothing is typed in the component.
            String text = getComponentText();
            if (text.length() == 0) {
                VirtualFile file = myProject.getBaseDir();
                if (file != null) {
                    return file;
                }
            }
            return super.getInitialFile();
        }
    });
    final DocumentListener updateOkButtonListener = new DocumentListener() {
        // update Ok button state depending on the current state of the fields
        public void insertUpdate(final DocumentEvent e) {
            updateOkButton();
        }

        public void removeUpdate(final DocumentEvent e) {
            updateOkButton();
        }

        public void changedUpdate(final DocumentEvent e) {
            updateOkButton();
        }
    };
    myParentDirectory.getChildComponent().getDocument().addDocumentListener(updateOkButtonListener);
    myDirectoryName.getDocument().addDocumentListener(updateOkButtonListener);
    myOriginName.getDocument().addDocumentListener(updateOkButtonListener);
    myRepositoryURL.getDocument().addDocumentListener(new DocumentListener() {
        // enable test button only if something is entered in repository URL
        public void insertUpdate(final DocumentEvent e) {
            changed();
        }

        public void removeUpdate(final DocumentEvent e) {
            changed();
        }

        public void changedUpdate(final DocumentEvent e) {
            changed();
        }

        private void changed() {
            final String url = myRepositoryURL.getText();
            myTestButton.setEnabled(url.length() != 0);
            if (myDefaultDirectoryName.equals(myDirectoryName.getText())
                    || myDirectoryName.getText().length() == 0) {
                // modify field if it was unmodified or blank
                myDefaultDirectoryName = defaultDirectoryName(url);
                myDirectoryName.setText(myDefaultDirectoryName);
            }
            updateOkButton();
        }
    });
    myTestButton.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            myTestURL = myRepositoryURL.getText();
            String output = HandlerUtil.doSynchronously(checkRepository(myProject, myTestURL),
                    Bundle.message("clone.testing", myTestURL), "connection test");
            if (output != null) {
                Messages.showInfoMessage(myTestButton, Bundle.message("clone.test.success.message", myTestURL),
                        Bundle.getString("clone.test.success"));
                myTestResult = Boolean.TRUE;
            } else {
                myTestResult = Boolean.FALSE;
            }
            updateOkButton();
        }
    });
    setOKActionEnabled(false);
}

From source file:org.f3.ideaplugin.run.F3RunSettingsPanel.java

License:Open Source License

public F3RunSettingsPanel() {
    workingDirectoryBrowseButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
            descriptor.setTitle("Choose working directory");
            VirtualFile[] avirtualfile = FileChooser.chooseFiles(workingDirectoryBrowseButton, descriptor);
            if (avirtualfile.length != 0)
                workingDirectoryText.setText(avirtualfile[0].getPath());
        }//  ww  w  . ja  v a  2 s. c o  m
    });
}

From source file:org.intellij.erlang.console.ErlangConsoleRunConfigurationForm.java

License:Apache License

@NotNull
private static FileChooserDescriptor addFileChooser(@NotNull final String title,
        @NotNull final TextFieldWithBrowseButton textField, @NotNull final Project project) {
    final FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(false, true, false, false,
            false, false) {//www.  j  a va  2  s.c o m
        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return super.isFileVisible(file, showHiddenFiles) && file.isDirectory();
        }
    };
    fileChooserDescriptor.setTitle(title);
    textField.addBrowseFolderListener(title, null, project, fileChooserDescriptor);
    return fileChooserDescriptor;
}