Example usage for com.intellij.openapi.ui TextFieldWithBrowseButton TextFieldWithBrowseButton

List of usage examples for com.intellij.openapi.ui TextFieldWithBrowseButton TextFieldWithBrowseButton

Introduction

In this page you can find the example usage for com.intellij.openapi.ui TextFieldWithBrowseButton TextFieldWithBrowseButton.

Prototype

public TextFieldWithBrowseButton(ActionListener browseActionListener, Disposable parent) 

Source Link

Usage

From source file:com.android.tools.idea.gradle.structure.DefaultSdksConfigurable.java

License:Apache License

private void createSdkLocationTextField() {
    final FileChooserDescriptor descriptor = createSingleFolderDescriptor("Choose Android SDK Location",
            new Function<File, Void>() {
                @Override//from   w  ww  .j  a va 2s.  c  o  m
                public Void fun(File file) {
                    if (!DefaultSdks.isValidAndroidSdkPath(file)) {
                        throw new IllegalArgumentException(CHOOSE_VALID_SDK_DIRECTORY_ERR);
                    }
                    return null;
                }
            });

    JTextField textField = new JTextField(10);
    mySdkLocationTextField = new TextFieldWithBrowseButton(textField, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            VirtualFile suggestedDir = null;
            File sdkLocation = getSdkLocation();
            if (sdkLocation.isDirectory()) {
                suggestedDir = VfsUtil.findFileByIoFile(sdkLocation, false);
            }
            VirtualFile chosen = FileChooser.chooseFile(descriptor, null, suggestedDir);
            if (chosen != null) {
                File f = VfsUtilCore.virtualToIoFile(chosen);
                mySdkLocationTextField.setText(f.getPath());
            }
        }
    });
    installValidationListener(textField);
}

From source file:com.android.tools.idea.gradle.structure.DefaultSdksConfigurable.java

License:Apache License

private void createJdkLocationTextField() {
    final FileChooserDescriptor descriptor = createSingleFolderDescriptor("Choose JDK Location",
            new Function<File, Void>() {
                @Override/*from w w  w .  j av a  2  s . co m*/
                public Void fun(File file) {
                    if (!JavaSdk.checkForJdk(file)) {
                        throw new IllegalArgumentException(CHOOSE_VALID_JDK_DIRECTORY_ERR);
                    }
                    return null;
                }
            });

    JTextField textField = new JTextField(10);
    myJdkLocationTextField = new TextFieldWithBrowseButton(textField, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            VirtualFile suggestedDir = null;
            File jdkLocation = getJdkLocation();
            if (jdkLocation.isDirectory()) {
                suggestedDir = VfsUtil.findFileByIoFile(jdkLocation, false);
            }
            VirtualFile chosen = FileChooser.chooseFile(descriptor, null, suggestedDir);
            if (chosen != null) {
                File f = VfsUtilCore.virtualToIoFile(chosen);
                myJdkLocationTextField.setText(f.getPath());
            }
        }
    });
    installValidationListener(textField);
}

From source file:com.android.tools.idea.gradle.structure.IdeSdksConfigurable.java

License:Apache License

@NotNull
private TextFieldWithBrowseButton createTextFieldWithBrowseButton(@NotNull String title,
        @NotNull String errorMessage, @NotNull Function<File, ValidationResult> validation) {
    FileChooserDescriptor descriptor = createSingleFolderDescriptor(title, file -> {
        ValidationResult validationResult = validation.fun(file);
        if (!validationResult.success) {
            String msg = validationResult.message;
            if (isEmpty(msg)) {
                msg = errorMessage;/*www  . j  av  a 2 s .  co m*/
            }
            throw new IllegalArgumentException(msg);
        }
        return null;
    });

    JTextField textField = new JTextField(10);
    return new TextFieldWithBrowseButton(textField, e -> {
        VirtualFile suggestedDir = null;
        File ndkLocation = getNdkLocation();
        if (ndkLocation.isDirectory()) {
            suggestedDir = findFileByIoFile(ndkLocation, false);
        }
        VirtualFile chosen = chooseFile(descriptor, null, suggestedDir);
        if (chosen != null) {
            File f = virtualToIoFile(chosen);
            textField.setText(f.getPath());
        }
    });
}

From source file:com.android.tools.idea.gradle.structure.IdeSdksConfigurable.java

License:Apache License

private void createJdkLocationTextField() {
    JTextField textField = new JTextField(10);
    myJdkLocationTextField = new TextFieldWithBrowseButton(textField, e -> chooseJdkLocation());
}

From source file:com.android.tools.idea.structure.DefaultSdksConfigurable.java

License:Apache License

private TextFieldWithBrowseButton createTextFieldWithBrowseButton(String title, final String errorMessagae,
        final Function<File, ValidationResult> validation) {
    final FileChooserDescriptor descriptor = createSingleFolderDescriptor(title, new Function<File, Void>() {
        @Override//from www  .  java  2 s .  c o m
        public Void fun(File file) {
            ValidationResult validationResult = validation.fun(file);
            if (!validationResult.success) {
                String msg = validationResult.message;
                if (isEmpty(msg)) {
                    msg = errorMessagae;
                }
                throw new IllegalArgumentException(msg);
            }
            return null;
        }
    });

    final JTextField textField = new JTextField(10);
    installValidationListener(textField);
    return new TextFieldWithBrowseButton(textField, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            VirtualFile suggestedDir = null;
            File ndkLocation = getNdkLocation();
            if (ndkLocation.isDirectory()) {
                suggestedDir = findFileByIoFile(ndkLocation, false);
            }
            VirtualFile chosen = FileChooser.chooseFile(descriptor, null, suggestedDir);
            if (chosen != null) {
                File f = virtualToIoFile(chosen);
                textField.setText(f.getPath());
            }
        }
    });
}

From source file:com.android.tools.idea.structure.DefaultSdksConfigurable.java

License:Apache License

private void createJdkLocationTextField() {
    JTextField textField = new JTextField(10);
    myJdkLocationTextField = new TextFieldWithBrowseButton(textField, new ActionListener() {
        @Override//w w  w .jav  a2s .  c  o m
        public void actionPerformed(ActionEvent e) {
            chooseJdkLocation();
        }
    });
    installValidationListener(textField);
}

From source file:com.intellij.execution.scratch.JavaScratchConfigurable.java

License:Apache License

public JavaScratchConfigurable(final Project project) {
    myMainClass = new LabeledComponent<JTextField>();
    myMainClass.setLabelLocation(BorderLayout.WEST);
    myMainClass.setText("Main &class:");
    myMainClass.setComponent(new JTextField());

    myScratchPathField = new LabeledComponent<TextFieldWithBrowseButton>();
    myScratchPathField.setLabelLocation(BorderLayout.WEST);
    myScratchPathField.setText("&Path to scratch file:");
    myScratchPathField.setComponent(new TextFieldWithBrowseButton(new ActionListener() {
        @Override//  www. ja v a2  s .co m
        public void actionPerformed(ActionEvent e) {
            VirtualFile toSelect = getVFileFromEditor();
            if (toSelect == null) {
                final String scratchesRoot = ScratchFileService.getInstance()
                        .getRootPath(ScratchRootType.getInstance());
                toSelect = LocalFileSystem.getInstance().findFileByPath(scratchesRoot);
            }
            final VirtualFile file = FileChooser.chooseFile(
                    FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(),
                    myScratchPathField.getComponent(), project, toSelect);
            if (file != null) {
                setVFileToEditor(file);
            }
        }
    }, this));

    myModule = new LabeledComponent<ModulesComboBox>();
    myModule.setLabelLocation(BorderLayout.WEST);
    myModule.setComponent(new ModulesComboBox());
    myModule.setText("Use classpath of &module:");
    myModuleSelector = new ConfigurationModuleSelector(project, myModule.getComponent());

    myCommonProgramParameters = new CommonJavaParametersPanel();
    myCommonProgramParameters.setModuleContext(myModuleSelector.getModule());
    myModule.getComponent().addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            myCommonProgramParameters.setModuleContext(myModuleSelector.getModule());
        }
    });
    myJrePathEditor = new JrePathEditor(DefaultJreSelector.projectSdk(project));

    myWholePanel = new JPanel(new GridBagLayout());
    myWholePanel.add(myMainClass,
            new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, NORTHWEST, HORIZONTAL, JBUI.insetsTop(6), 0, 0));
    myWholePanel.add(myScratchPathField, new GridBagConstraints(RELATIVE, 1, 1, 1, 1.0, 0.0, NORTHWEST,
            HORIZONTAL, JBUI.insetsTop(6), 0, 0));
    myWholePanel.add(myCommonProgramParameters,
            new GridBagConstraints(RELATIVE, 2, 1, 1, 1.0, 1.0, NORTHWEST, BOTH, JBUI.insets(12, 0), 0, 0));
    myWholePanel.add(myModule, new GridBagConstraints(RELATIVE, 3, 1, 1, 1.0, 0.0, NORTHWEST, HORIZONTAL,
            JBUI.emptyInsets(), 0, 0));
    myWholePanel.add(myJrePathEditor, new GridBagConstraints(RELATIVE, 4, 1, 1, 1.0, 0.0, NORTHWEST, HORIZONTAL,
            JBUI.insetsTop(6), 0, 0));

    myAnchor = UIUtil.mergeComponentsWithAnchor(myMainClass, myScratchPathField, myCommonProgramParameters,
            myJrePathEditor, myModule);
}

From source file:com.intellij.ide.util.newProjectWizard.modes.ImportImlMode.java

License:Apache License

public JComponent getAdditionalSettings(final WizardContext wizardContext) {
    JTextField tfModuleFilePath = new JTextField();
    final String productName = ApplicationNamesInfo.getInstance().getProductName();
    final String message = IdeBundle.message("prompt.select.module.file.to.import", productName);
    final BrowseFilesListener listener = new BrowseFilesListener(tfModuleFilePath, message, null,
            new ModuleFileChooserDescriptor()) {
        @Override// w w  w .  j a  v a  2s.c  om
        protected VirtualFile getFileToSelect() {
            final VirtualFile fileToSelect = super.getFileToSelect();
            if (fileToSelect != null) {
                return fileToSelect;
            }
            final Project project = wizardContext.getProject();
            return project != null ? project.getBaseDir() : null;
        }
    };
    myModulePathFieldPanel = new TextFieldWithBrowseButton(tfModuleFilePath, listener);
    onChosen(false);
    return myModulePathFieldPanel;
}