private void validate() { Validator validator = new Validator(); TextFieldWithHistory exeComponent = stylintExeField.getChildComponent(); if (!ValidationUtils.validatePath(project, exeComponent.getText(), false)) { validator.add(exeComponent.getTextEditor(), StylintBundle.message("stylint.settings.validate.exe"), StylintBundle.message("stylint.settings.validate.fix")); } TextFieldWithHistory configComponent = stylintConfigFile.getChildComponent(); if (!ValidationUtils.validatePath(project, configComponent.getText(), true)) { validator.add(configComponent.getTextEditor(), StylintBundle.message("stylint.settings.validate.config"), StylintBundle.message("stylint.settings.validate.fix")); } if (validator.hasErrors()) { versionLabel.setText("n.a."); } else { updateVersion(); } packagesNotificationPanel.processErrors(validator); }
private void createLogFileChooser() { myLogFile = new TextFieldWithHistory(); JPanel panel = GuiUtils.constructFieldWithBrowseButton(myLogFile, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(); FileChooser.chooseFiles(descriptor, myProject, null, new Consumer<List<VirtualFile>>() { @Override public void consume(List<VirtualFile> files) { myLogFile.setText(FileUtil.toSystemDependentName(files.get(files.size() - 1).getPath())); } }); } }); myLogFileChooserPanel.setLayout(new BorderLayout()); myLogFileChooserPanel.add(panel, BorderLayout.CENTER); }
@NotNull public static TextFieldWithHistoryWithBrowseButton createTextFieldWithHistoryWithBrowseButton(@Nullable Project project, @NotNull String browseDialogTitle, @NotNull FileChooserDescriptor fileChooserDescriptor, @Nullable NotNullProducer<List<String>> historyProvider) { TextFieldWithHistoryWithBrowseButton textFieldWithHistoryWithBrowseButton = new TextFieldWithHistoryWithBrowseButton(); TextFieldWithHistory textFieldWithHistory = textFieldWithHistoryWithBrowseButton.getChildComponent(); textFieldWithHistory.setHistorySize(-1); textFieldWithHistory.setMinimumAndPreferredWidth(0); if (historyProvider != null) { addHistoryOnExpansion(textFieldWithHistory, historyProvider); } installFileCompletionAndBrowseDialog( project, textFieldWithHistoryWithBrowseButton, browseDialogTitle, fileChooserDescriptor ); return textFieldWithHistoryWithBrowseButton; }
private void createUIComponents() { mavenHomeField = new TextFieldWithHistory(); mavenHomeField.setHistorySize(-1); final ArrayList<String> foundMavenHomes = new ArrayList<String>(); foundMavenHomes.add(MavenServerManager.BUNDLED_MAVEN_2); foundMavenHomes.add(MavenServerManager.BUNDLED_MAVEN_3); final File mavenHomeDirectory = MavenUtil.resolveMavenHomeDirectory(null); if (mavenHomeDirectory != null) { foundMavenHomes.add(FileUtil.toSystemIndependentName(mavenHomeDirectory.getPath())); } mavenHomeField.setHistory(foundMavenHomes); mavenHomeComponent = LabeledComponent.create( new ComponentWithBrowseButton<TextFieldWithHistory>(mavenHomeField, null), "Maven &home directory"); final JBLabel versionLabel = new JBLabel(); versionLabel.setOpaque(true); versionLabel.setVerticalAlignment(SwingConstants.TOP); versionLabel.setVerticalTextPosition(SwingConstants.TOP); mavenVersionLabelComponent = LabeledComponent.create(versionLabel, ""); }
public UseExistingBazelWorkspaceOption(BlazeNewProjectBuilder builder) { this.directoryField = new TextFieldWithHistory(); this.directoryField.setName("workspace-directory-field"); this.directoryField.setHistory(builder.getWorkspaceHistory(BuildSystem.Bazel)); this.directoryField.setHistorySize(BlazeNewProjectBuilder.HISTORY_SIZE); this.directoryField.setText(builder.getLastImportedWorkspace(BuildSystem.Bazel)); JButton button = new JButton("..."); button.addActionListener(action -> this.chooseDirectory()); int buttonSize = this.directoryField.getPreferredSize().height; button.setPreferredSize(new Dimension(buttonSize, buttonSize)); JComponent box = UiUtil.createHorizontalBox( HORIZONTAL_LAYOUT_GAP, getIconComponent(), new JLabel("Workspace:"), this.directoryField, button); UiUtil.setPreferredWidth(box, PREFERRED_COMPONENT_WIDTH); this.component = box; }
private void createLogFileChooser() { myLogFile = new TextFieldWithHistory(); JPanel panel = GuiUtils.constructFieldWithBrowseButton(myLogFile, new ActionListener() { public void actionPerformed(ActionEvent e) { FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(); FileChooser.chooseFiles(descriptor, myProject, null, new Consumer<List<VirtualFile>>() { @Override public void consume(List<VirtualFile> files) { myLogFile.setText(FileUtil.toSystemDependentName(files.get(files.size() - 1).getPath())); } }); } }); myLogFileChooserPanel.setLayout(new BorderLayout()); myLogFileChooserPanel.add(panel, BorderLayout.CENTER); }
private void configESLintBinField() { TextFieldWithHistory textFieldWithHistory = stylintExeField.getChildComponent(); textFieldWithHistory.setHistorySize(-1); textFieldWithHistory.setMinimumAndPreferredWidth(0); SwingHelper.addHistoryOnExpansion(textFieldWithHistory, () -> FileUtils.toAbsolutePath(StylintFinder.findAllStylintExe())); SwingHelper.installFileCompletionAndBrowseDialog(project, stylintExeField, "Select Stylint Exe", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor()); }
private void configStylintConfigField() { TextFieldWithHistory textFieldWithHistory = stylintConfigFile.getChildComponent(); textFieldWithHistory.setHistorySize(-1); textFieldWithHistory.setMinimumAndPreferredWidth(0); SwingHelper.addHistoryOnExpansion(textFieldWithHistory, () -> StylintFinder.searchForLintConfigFiles(new File(project.getBaseDir().getPath()))); SwingHelper.installFileCompletionAndBrowseDialog(project, stylintConfigFile, "Select Stylint Config", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor()); }
private void configConfigFileField() { TextFieldWithHistory textFieldWithHistory = configWithDefaults(sassLintConfigFile); SwingHelper.addHistoryOnExpansion(textFieldWithHistory, new NotNullProducer<List<String>>() { @NotNull public List<String> produce() { return SassLintFinder.searchForConfigFiles(getProjectPath()); } }); SwingHelper.installFileCompletionAndBrowseDialog(project, sassLintConfigFile, "Select Sass Lint Config", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor()); }
private void configNodeField() { TextFieldWithHistory textFieldWithHistory = configWithDefaults(nodeInterpreterField); SwingHelper.addHistoryOnExpansion(textFieldWithHistory, new NotNullProducer<List<String>>() { @NotNull public List<String> produce() { List<File> newFiles = NodeDetectionUtil.listAllPossibleNodeInterpreters(); return FileUtils.toAbsolutePath(newFiles); } }); SwingHelper.installFileCompletionAndBrowseDialog(project, nodeInterpreterField, "Select Node Interpreter", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor()); }
public static void setHistory(@NotNull TextFieldWithHistory textFieldWithHistory, @NotNull List<String> history, boolean mergeWithPrevHistory) { Set<String> newHistorySet = ContainerUtil.newHashSet(history); List<String> prevHistory = textFieldWithHistory.getHistory(); List<String> mergedHistory = ContainerUtil.newArrayListWithCapacity(history.size()); if (mergeWithPrevHistory) { for (String item : prevHistory) { if (!newHistorySet.contains(item)) { mergedHistory.add(item); } } } mergedHistory.addAll(history); String oldText = StringUtil.notNullize(textFieldWithHistory.getText()); String oldSelectedItem = ObjectUtils.tryCast(textFieldWithHistory.getSelectedItem(), String.class); if (!mergedHistory.contains(oldSelectedItem)) { oldSelectedItem = null; } textFieldWithHistory.setHistory(mergedHistory); setLongestAsPrototype(textFieldWithHistory, mergedHistory); if (oldSelectedItem != null) { textFieldWithHistory.setSelectedItem(oldSelectedItem); } if (!oldText.equals(oldSelectedItem)) { textFieldWithHistory.setText(oldText); } }
private void configNodeField() { TextFieldWithHistory textFieldWithHistory = configWithDefaults(nodeInterpreterField); SwingHelper.addHistoryOnExpansion(textFieldWithHistory, new NotNullProducer<List<String>>() { @NotNull public List<String> produce() { List<File> newFiles = NodeDetectionUtil.listAllPossibleNodeInterpreters(); return FileUtils.toAbsolutePath(newFiles); } }); SwingHelper.installFileCompletionAndBrowseDialog(project, nodeInterpreterField, "Select Node interpreter", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor()); }
private void configConfigFileField() { TextFieldWithHistory textFieldWithHistory = configWithDefaults(eslintrcFile); SwingHelper.addHistoryOnExpansion(textFieldWithHistory, new NotNullProducer<List<String>>() { @NotNull public List<String> produce() { return CoffeeLintFinder.searchForConfigFiles(getProjectPath()); } }); SwingHelper.installFileCompletionAndBrowseDialog(project, eslintrcFile, "Select CoffeeLint config", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor()); }
private void configJscsRcField() { TextFieldWithHistory textFieldWithHistory = configWithDefaults(jscsrcFile); SwingHelper.addHistoryOnExpansion(textFieldWithHistory, new NotNullProducer<List<String>>() { @NotNull public List<String> produce() { return JscsFinder.searchForJscsRCFiles(getProjectPath()); } }); SwingHelper.installFileCompletionAndBrowseDialog(project, jscsrcFile, "Select JSCS config", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor()); }
private void configESLintRulesField() { TextFieldWithHistory textFieldWithHistory = rulesPathField.getChildComponent(); SwingHelper.addHistoryOnExpansion(textFieldWithHistory, new NotNullProducer<List<String>>() { @NotNull public List<String> produce() { return ESLintFinder.tryFindRulesAsString(getProjectPath()); } }); SwingHelper.installFileCompletionAndBrowseDialog(project, rulesPathField, "Select Built in rules", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor()); }
private void configESLintRcField() { TextFieldWithHistory textFieldWithHistory = configWithDefaults(eslintrcFile); SwingHelper.addHistoryOnExpansion(textFieldWithHistory, new NotNullProducer<List<String>>() { @NotNull public List<String> produce() { return ESLintFinder.searchForESLintRCFiles(getProjectPath()); } }); SwingHelper.installFileCompletionAndBrowseDialog(project, eslintrcFile, "Select ESLint config", FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor()); }
/** * Creates a label and text field input and adds them to the configuration * window. * * @param settings Panel to add components to. * @param labelText Which text to show to the left of the field. * @return The TextFieldWithBrowseButton created. */ public static TextFieldWithHistory createTextfield(JPanel settings, String labelText, Object constraints) { // Create UI elements. TextFieldWithHistory tf = new TextFieldWithHistory(); // Add elements to Panel. JPanel subPanel = new JPanel(new GridBagLayout()); subPanel.add(new JLabel(labelText + ':')); subPanel.add(tf, ExternalSystemUiUtil.getFillLineConstraints(0)); settings.add(subPanel, constraints); return tf; }
public AlternativeJREPanel() { myCbEnabled = new JBCheckBox(ExecutionBundle.message("run.configuration.use.alternate.jre.checkbox")); myFieldWithHistory = new TextFieldWithHistory(); final ArrayList<String> foundJDKs = new ArrayList<String>(); for (JreProvider provider : JreProvider.EP_NAME.getExtensions()) { String path = provider.getJrePath(); if (!StringUtil.isEmpty(path)) { foundJDKs.add(path); } } final Sdk[] allJDKs = ProjectJdkTable.getInstance().getAllJdks(); for (Sdk jdk : allJDKs) { foundJDKs.add(jdk.getHomePath()); } myFieldWithHistory.setHistory(foundJDKs); myPathField = new ComponentWithBrowseButton<TextFieldWithHistory>(myFieldWithHistory, null); myPathField.addBrowseFolderListener(ExecutionBundle.message("run.configuration.select.alternate.jre.label"), ExecutionBundle.message("run.configuration.select.jre.dir.label"), null, BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR, TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT); setLayout(new MigLayout("ins 0, gap 10, fill, flowx")); add(myCbEnabled, "shrinkx"); add(myPathField, "growx, pushx"); InsertPathAction.addTo(myFieldWithHistory.getTextEditor()); myCbEnabled.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { enabledChanged(); } }); enabledChanged(); setAnchor(myCbEnabled); updateUI(); }
public AlternativeJREPanel() { myCbEnabled = new JBCheckBox(ExecutionBundle.message("run.configuration.use.alternate.jre.checkbox")); myFieldWithHistory = new TextFieldWithHistory(); final ArrayList<String> foundJDKs = new ArrayList<String>(); final Sdk[] allJDKs = SdkTable.getInstance().getAllSdks(); for (Sdk jdk : allJDKs) { foundJDKs.add(jdk.getHomePath()); } myFieldWithHistory.setHistory(foundJDKs); myPathField = new ComponentWithBrowseButton<TextFieldWithHistory>(myFieldWithHistory, null); myPathField.addBrowseFolderListener(ExecutionBundle.message("run.configuration.select.alternate.jre.label"), ExecutionBundle.message("run.configuration.select.jre.dir.label"), null, BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR, TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT); setLayout(new MigLayout("ins 0, gap 10, fill, flowx")); add(myCbEnabled, "shrinkx"); add(myPathField, "growx, pushx"); InsertPathAction.addTo(myFieldWithHistory.getTextEditor()); myCbEnabled.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { enabledChanged(); } }); enabledChanged(); setAnchor(myCbEnabled); updateUI(); }
private void createLogFileChooser() { myLogFile = new TextFieldWithHistory(); JPanel panel = GuiUtils.constructFieldWithBrowseButton(myLogFile, e -> { FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(); FileChooser.chooseFiles(descriptor, myProject, null, files -> myLogFile.setText(FileUtil.toSystemDependentName(files.get(files.size() - 1).getPath()))); }); myLogFileChooserPanel.setLayout(new BorderLayout()); myLogFileChooserPanel.add(panel, BorderLayout.CENTER); }
private static TextFieldWithHistory configWithDefaults(TextFieldWithHistoryWithBrowseButton field) { TextFieldWithHistory textFieldWithHistory = field.getChildComponent(); textFieldWithHistory.setHistorySize(-1); textFieldWithHistory.setMinimumAndPreferredWidth(0); return textFieldWithHistory; }
public AlternativeJREPanel() { myCbEnabled = new JBCheckBox(ExecutionBundle.message("run.configuration.use.alternate.jre.checkbox")); myFieldWithHistory = new TextFieldWithHistory(); myFieldWithHistory.setHistorySize(-1); final ArrayList<String> foundJDKs = new ArrayList<String>(); final Sdk[] allJDKs = ProjectJdkTable.getInstance().getAllJdks(); for (Sdk sdk : allJDKs) { foundJDKs.add(sdk.getName()); } for (JreProvider provider : JreProvider.EP_NAME.getExtensions()) { String path = provider.getJrePath(); if (!StringUtil.isEmpty(path)) { foundJDKs.add(path); } } for (Sdk jdk : allJDKs) { String homePath = jdk.getHomePath(); if (!SystemInfo.isMac) { final File jre = new File(jdk.getHomePath(), "jre"); if (jre.isDirectory()) { homePath = jre.getPath(); } } if (!foundJDKs.contains(homePath)) { foundJDKs.add(homePath); } } myFieldWithHistory.setHistory(foundJDKs); myPathField = new ComponentWithBrowseButton<TextFieldWithHistory>(myFieldWithHistory, null); myPathField.addBrowseFolderListener(ExecutionBundle.message("run.configuration.select.alternate.jre.label"), ExecutionBundle.message("run.configuration.select.jre.dir.label"), null, BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR, TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT); setLayout(new MigLayout("ins 0, gap 10, fill, flowx")); add(myCbEnabled, "shrinkx"); add(myPathField, "growx, pushx"); InsertPathAction.addTo(myFieldWithHistory.getTextEditor()); myCbEnabled.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { enabledChanged(); } }); enabledChanged(); setAnchor(myCbEnabled); updateUI(); }
@Override public String getText(TextFieldWithHistory textField) { return textField.getText(); }
@Override public void setText(TextFieldWithHistory textField, @NotNull String text) { textField.setText(text); }
private TextFieldWithHistory getNameField() { return getForm().myNameField; }
public static TextFieldWithHistory createTextfield(JPanel settings, String labelText) { return createTextfield(settings, labelText, ExternalSystemUiUtil.getFillLineConstraints(0)); }
public String getText(TextFieldWithHistory textField) { return textField.getText(); }
public void setText(TextFieldWithHistory textField, String text) { textField.setText(text); }