Example usage for com.intellij.openapi.fileChooser FileChooserDescriptorFactory createSingleLocalFileDescriptor

List of usage examples for com.intellij.openapi.fileChooser FileChooserDescriptorFactory createSingleLocalFileDescriptor

Introduction

In this page you can find the example usage for com.intellij.openapi.fileChooser FileChooserDescriptorFactory createSingleLocalFileDescriptor.

Prototype

public static FileChooserDescriptor createSingleLocalFileDescriptor() 

Source Link

Usage

From source file:com.aijia.plugin.gradle.GradleRunTaskDialog.java

License:Apache License

private void setUpDialog() {
    JComponent commandLineComponent;
    if (myHistory == null) {
        commandLineEditor = new EditorTextField("", myProject, PlainTextFileType.INSTANCE);
        commandLineComponent = commandLineEditor;

        commandLineLabel.setLabelFor(commandLineEditor);
    } else {// w  ww. j  ava 2  s.c  o m
        commandLineComboBox = new ComboBox(ArrayUtilRt.toStringArray(myHistory));
        commandLineComponent = commandLineComboBox;

        commandLineLabel.setLabelFor(commandLineComboBox);

        commandLineComboBox.setLightWeightPopupEnabled(false);

        EditorComboBoxEditor editor = new StringComboboxEditor(myProject, PlainTextFileType.INSTANCE,
                commandLineComboBox);
        //noinspection GtkPreferredJComboBoxRenderer
        commandLineComboBox.setRenderer(new EditorComboBoxRenderer(editor));

        commandLineComboBox.setEditable(true);
        commandLineComboBox.setEditor(editor);
        commandLineComboBox.setFocusable(true);

        commandLineEditor = editor.getEditorComponent();
    }

    commandLinePanel.add(commandLineComponent);

    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(GradleConstants.SYSTEM_ID);
    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",
            GradleConstants.SYSTEM_ID.getReadableName());
    myProjectPathField = new ExternalProjectPathField(myProject, GradleConstants.SYSTEM_ID,
            projectPathChooserDescriptor, title) {
        @Override
        public Dimension getPreferredSize() {
            return commandLinePanel == null ? super.getPreferredSize() : commandLinePanel.getPreferredSize();
        }
    };

    projectPathFieldPanel.add(myProjectPathField);

    new GradleArgumentsCompletionProvider(myProject, myProjectPathField).apply(commandLineEditor);
}

From source file:com.goide.runconfig.GoRunUtil.java

License:Apache License

public static void installFileChooser(@Nonnull Project project, @Nonnull ComponentWithBrowseButton field,
        boolean directory, boolean showFileSystemRoots, @Nullable Condition<VirtualFile> fileFilter) {
    FileChooserDescriptor chooseDirectoryDescriptor = directory
            ? FileChooserDescriptorFactory.createSingleFolderDescriptor()
            : FileChooserDescriptorFactory.createSingleLocalFileDescriptor();
    chooseDirectoryDescriptor.setRoots(project.getBaseDir());
    chooseDirectoryDescriptor.setShowFileSystemRoots(showFileSystemRoots);
    chooseDirectoryDescriptor.withFileFilter(fileFilter);
    if (field instanceof TextFieldWithBrowseButton) {
        ((TextFieldWithBrowseButton) field)
                .addBrowseFolderListener(new TextBrowseFolderListener(chooseDirectoryDescriptor, project));
    } else {//from   w  w  w  .ja v a2 s.com
        //noinspection unchecked
        field.addBrowseFolderListener(project,
                new ComponentWithBrowseButton.BrowseFolderActionListener(null, null, field, project,
                        chooseDirectoryDescriptor, TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT));
    }
}

From source file:com.intellij.ide.actions.ChooseComponentsToExportDialog.java

License:Apache License

@NotNull
public static AsyncResult<String> chooseSettingsFile(String oldPath, Component parent, final String title,
        final String description) {
    FileChooserDescriptor chooserDescriptor = FileChooserDescriptorFactory.createSingleLocalFileDescriptor();
    chooserDescriptor.setDescription(description);
    chooserDescriptor.setHideIgnored(false);
    chooserDescriptor.setTitle(title);/*from   w  ww  .  j  a va 2  s  .c  o  m*/

    VirtualFile initialDir;
    if (oldPath != null) {
        final File oldFile = new File(oldPath);
        initialDir = LocalFileSystem.getInstance().findFileByIoFile(oldFile);
        if (initialDir == null && oldFile.getParentFile() != null) {
            initialDir = LocalFileSystem.getInstance().findFileByIoFile(oldFile.getParentFile());
        }
    } else {
        initialDir = null;
    }
    final AsyncResult<String> result = new AsyncResult<String>();
    FileChooser.chooseFiles(chooserDescriptor, null, parent, initialDir, new FileChooser.FileChooserConsumer() {
        @Override
        public void consume(List<VirtualFile> files) {
            VirtualFile file = files.get(0);
            if (file.isDirectory()) {
                result.setDone(file.getPath() + '/' + new File(DEFAULT_PATH).getName());
            } else {
                result.setDone(file.getPath());
            }
        }

        @Override
        public void cancelled() {
            result.setRejected();
        }
    });
    return result;
}

From source file:com.intellij.ide.macro.FilePromptMacro.java

License:Apache License

@Override
protected String promptUser(DataContext dataContext) {
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleLocalFileDescriptor();
    final VirtualFile[] result = FileChooser.chooseFiles(descriptor, project, null);
    return result.length == 1 ? FileUtil.toSystemDependentName(result[0].getPath()) : null;
}

From source file:com.intellij.ui.InsertPathAction.java

License:Apache License

private InsertPathAction(JTextComponent textField) {
    this(textField, FileChooserDescriptorFactory.createSingleLocalFileDescriptor());
}

From source file:com.microsoft.intellij.docker.wizards.publish.forms.AzureConfigureDockerContainerStep.java

License:Open Source License

private void initUI() {
    dockerContainerNameTextField.setText(dockerImageDescription.dockerContainerName);
    dockerContainerNameTextField.setToolTipText(AzureDockerValidationUtils.getDockerContainerNameTip());
    dockerContainerNameTextField.setInputVerifier(new InputVerifier() {
        @Override//from   ww  w. ja va  2  s  .co m
        public boolean verify(JComponent input) {
            if (AzureDockerValidationUtils.validateDockerContainerName(((JTextField) input).getText())) {
                dockerContainerNameLabel.setVisible(false);
                setDialogButtonsState(doValidate(false) == null);
                return true;
            } else {
                dockerContainerNameLabel.setVisible(true);
                setDialogButtonsState(false);
                return false;
            }
        }
    });
    dockerContainerNameTextField.getDocument()
            .addDocumentListener(resetDialogButtonsState(dockerContainerNameLabel));
    dockerContainerNameLabel.setVisible(false);

    selectContainerButtonGroup = new ButtonGroup();
    selectContainerButtonGroup.add(predefinedDockerfileRadioButton);
    selectContainerButtonGroup.add(customDockerfileRadioButton);

    predefinedDockerfileRadioButton.setSelected(true);
    dockerfileComboBox.setEnabled(true);

    for (KnownDockerImages image : dockerManager.getDefaultDockerImages()) {
        // Add predefined images that can run .WAR as default
        if (!image.isCanRunJarFile()) {
            dockerfileComboBox.addItem(image);
        }
    }

    if (dockerImageDescription.predefinedDockerfile != null) {
        dockerfileComboBox
                .setSelectedItem(KnownDockerImages.valueOf(dockerImageDescription.predefinedDockerfile));
    } else {
        dockerfileComboBox.setSelectedIndex(0);
    }
    dockerfileComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dockerContainerPortSettings
                    .setText(getDefaultPortMapping((KnownDockerImages) dockerfileComboBox.getSelectedItem()));
            setDialogButtonsState(doValidate(false) == null);
        }
    });

    customDockerfileBrowseButton.setEnabled(false);
    customDockerfileBrowseButton
            .addActionListener(UIUtils.createFileChooserListener(customDockerfileBrowseButton,
                    model.getProject(), FileChooserDescriptorFactory.createSingleLocalFileDescriptor()));
    customDockerfileBrowseButton.getTextField()
            .setToolTipText(AzureDockerValidationUtils.getDockerfilePathTip());
    customDockerfileBrowseButton.getTextField().setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            if (customDockerfileRadioButton.isSelected() && !AzureDockerValidationUtils
                    .validateDockerfilePath(customDockerfileBrowseButton.getText())) {
                customDockerfileBrowseLabel.setVisible(true);
                setDialogButtonsState(false);
                return false;
            } else {
                customDockerfileBrowseLabel.setVisible(false);
                setDialogButtonsState(doValidate(false) == null);
                return true;
            }
        }
    });
    customDockerfileBrowseButton.getTextField().getDocument()
            .addDocumentListener(resetDialogButtonsState(customDockerfileBrowseLabel));
    customDockerfileBrowseLabel.setVisible(false);
    customDockerfileBrowseButton.setText("");

    predefinedDockerfileRadioButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dockerfileComboBox.setEnabled(true);
            customDockerfileBrowseLabel.setVisible(false);
            customDockerfileBrowseButton.setEnabled(false);
            setDialogButtonsState(doValidate(false) == null);
        }
    });

    customDockerfileRadioButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dockerfileComboBox.setEnabled(false);
            customDockerfileBrowseButton.setEnabled(true);
            if (AzureDockerValidationUtils.validateDockerfilePath(customDockerfileBrowseButton.getText())) {
                customDockerfileBrowseLabel.setVisible(false);
                setDialogButtonsState(doValidate(false) == null);
            } else {
                customDockerfileBrowseLabel.setVisible(true);
                setDialogButtonsState(false);
            }
        }
    });

    dockerContainerPortSettings
            .setText(getDefaultPortMapping((KnownDockerImages) dockerfileComboBox.getSelectedItem()));
    dockerContainerPortSettings.setToolTipText(AzureDockerValidationUtils.getDockerPortSettingsTip());
    dockerContainerPortSettings.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            if (AzureDockerValidationUtils
                    .validateDockerPortSettings(dockerContainerPortSettings.getText()) != null) {
                dockerContainerPortSettingsLabel.setVisible(false);
                setDialogButtonsState(doValidate(false) == null);
                return true;
            } else {
                dockerContainerPortSettingsLabel.setVisible(true);
                setDialogButtonsState(false);
                return false;
            }
        }
    });
    dockerContainerPortSettings.getDocument()
            .addDocumentListener(resetDialogButtonsState(dockerContainerPortSettingsLabel));
    dockerContainerPortSettingsLabel.setVisible(false);

}

From source file:com.microsoft.intellij.ui.AddApplicationDialog.java

License:Open Source License

@Override
protected void init() {
    setTitle(message("appDlgTxt"));
    fileTxt.addActionListener(UIUtils.createFileChooserListener(fileTxt, myProject,
            FileChooserDescriptorFactory.createSingleLocalFileDescriptor()));
    fileRadioBtn.addItemListener(createFileBtnListener());
    //        if (PlatformUtils.isIdeaUltimate()) {
    //            projRadioBtn.addItemListener(createProjectBtnListener());
    //        } else {
    projRadioBtn.setEnabled(false);/*  w  w  w .j a  v  a 2s.  com*/
    //        }
    super.init();
}

From source file:com.microsoft.intellij.ui.azureroles.ImportExportDialog.java

License:Open Source License

public ActionListener createBtnFileSysListener() {
    return new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String oldPath = txtFromPath.getText();
            VirtualFile[] files = FileChooser.chooseFiles(
                    FileChooserDescriptorFactory.createSingleLocalFileDescriptor(), txtFromPath, project,
                    txtFromPath.getText().isEmpty() ? null
                            : LocalFileSystem.getInstance().findFileByPath(txtFromPath.getText()));
            if (files.length > 0) {
                txtFromPath.setText(FileUtil.toSystemDependentName(files[0].getPath()));
                try {
                    String selFile = txtFromPath.getText();
                    String projectPath = project.getBasePath();
                    if (isWorkspaceProj(waProjManager.getProjectName()) && selFile.contains(projectPath)) {
                        String replaceString = selFile;
                        String subString = selFile.substring(selFile.indexOf(projectPath),
                                projectPath.length());
                        selFile = replaceString.replace(subString, BASE_PATH);
                    }/*from  w w w  .  ja  va2s. c o m*/
                    txtFromPath.setText(selFile);
                    /*
                     * If new from path is selected then
                    * remove previous As name text.
                    */
                    if (!oldPath.equals(selFile)) {
                        txtName.setText("");
                    }
                    updateImportMethodCombo(selFile);
                    updateDeployMethodCombo();
                } catch (WindowsAzureInvalidProjectOperationException ex) {
                    log(ex.getMessage(), ex);
                }
            }
        }
    };
}

From source file:com.microsoft.intellij.ui.WARemoteAccessPanel.java

License:Open Source License

protected void init(String uname, String pwd, String cnfPwd) {
    remoteChkBtn.addItemListener(createRemoteChkBtnListener());
    newButton.addActionListener(createNewButtonListener());
    fileSystemButton.addActionListener(UIUtils.createFileChooserListener(txtPath, myModule.getProject(),
            FileChooserDescriptorFactory.createSingleLocalFileDescriptor()));
    try {/* w w w  .  j a  v a 2 s .  c o m*/
        remoteChkBtn.setSelected(waProjManager.getRemoteAccessAllRoles());
    } catch (WindowsAzureInvalidProjectOperationException e2) {
        PluginUtil.displayErrorDialogAndLog(message("remAccErrTitle"), message("remAccErAllRoles"), e2);
    }
    try {
        txtUserName.setText(waProjManager.getRemoteAccessUsername());
    } catch (WindowsAzureInvalidProjectOperationException e1) {
        txtUserName.setText("");
        remoteChkBtn.setSelected(false);
        /*
         * When user data is not consistent we are making
         * isInconsistent as true and later on we are checking the status
         * of this variable and throwing the error message to user.
         */
        isInconsistent = true;
        log(message("remAccErUserName"), e1);
    }

    createPasswordComponent();

    createConfPwdComponent();

    createExpiryDateComponent();

    try {
        txtPath.setText(waProjManager.getRemoteAccessCertificatePath());
    } catch (WindowsAzureInvalidProjectOperationException e1) {
        txtPath.setText("");
        remoteChkBtn.setSelected(false);
        /*
         * When user data is not consistent we are making
         * isInconsistent as true and later on we are checking the status
         * of this variable and throwing the error message to user.
         */
        isInconsistent = true;
        log(message("remAccErCertPath"), e1);
    }
    /*
             * Check if we are coming from Publish wizard link,
             */
    if (isFrmEncLink) {
        if (uname.isEmpty()) {
            // disable remote access
            remoteChkBtn.setSelected(false);
            makeAllTextBlank();
        } else {
            /*
             * enable remote access and
            * show values given on publish wizard
            */
            remoteChkBtn.setSelected(true);
            txtUserName.setText(uname);
            txtPassword.setText(pwd);
            txtConfirmPwd.setText(cnfPwd);
            try {
                if (!waProjManager.getRemoteAccessEncryptedPassword().equals(pwd)) {
                    isPwdChanged = true;
                }
            } catch (WindowsAzureInvalidProjectOperationException e) {
                log(message("remAccErPwd"), e);
            }
            isFrmEncLink = true;
        }
    } else {
        if (remoteChkBtn.isSelected()) {
            getDefaultValues();
        } else {
            makeAllTextBlank();
        }
    }
    setComponentStatus(remoteChkBtn.isSelected());
    /*
     * Here we are checking the isInconsistent value
     * and showing the error message to user on UI.
     */
    if (isInconsistent) {
        PluginUtil.displayErrorDialog(message("remAccErTxtTitle"), message("remAccDataInc"));
    }
    /*
     * Non windows OS then disable components,
     * but keep values as it is
     */
    if (!AzurePlugin.IS_WINDOWS) {
        setComponentStatus(false);
        if (!remoteChkBtn.isSelected()) {
            remoteChkBtn.setEnabled(false);
        }
    }
}

From source file:com.microsoftopentechnologies.intellij.ui.azureroles.ImportExportDialog.java

License:Apache License

public ActionListener createBtnFileSysListener() {
    return new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String oldPath = txtFromPath.getText();
            VirtualFile[] files = FileChooser.chooseFiles(
                    FileChooserDescriptorFactory.createSingleLocalFileDescriptor(), txtFromPath, project,
                    txtFromPath.getText().isEmpty() ? null
                            : LocalFileSystem.getInstance().findFileByPath(txtFromPath.getText()));
            if (files.length > 0) {
                txtFromPath.setText(FileUtil.toSystemDependentName(files[0].getPath()));
                try {
                    String selFile = txtFromPath.getText();
                    String projectPath = project.getBasePath();
                    if (isWorkspaceProj(waProjManager.getProjectName()) && selFile.contains(projectPath)) {
                        String replaceString = selFile;
                        String subString = selFile.substring(selFile.indexOf(projectPath),
                                projectPath.length());
                        selFile = replaceString.replace(subString, BASE_PATH);
                    }/*from w  w w  . j a v a2s  .c o  m*/
                    txtFromPath.setText(selFile);
                    /*
                    * If new from path is selected then
                    * remove previous As name text.
                    */
                    if (!oldPath.equals(selFile)) {
                        txtName.setText("");
                    }
                    updateImportMethodCombo(selFile);
                    updateDeployMethodCombo();
                } catch (WindowsAzureInvalidProjectOperationException ex) {
                    log(ex.getMessage(), ex);
                }
            }
        }
    };
}