com.intellij.openapi.ui.TextBrowseFolderListener Java Examples

The following examples show how to use com.intellij.openapi.ui.TextBrowseFolderListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Settings.java    From backgroundImagePlus with MIT License 6 votes vote down vote up
@Nullable
@Override
public JComponent createComponent() {
    FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    imageFolder.addBrowseFolderListener(new TextBrowseFolderListener(descriptor) {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = new JFileChooser();
            String current = imageFolder.getText();
            if (!current.isEmpty()) {
                fc.setCurrentDirectory(new File(current));
            }
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            fc.showOpenDialog(rootPanel);

            File file = fc.getSelectedFile();
            String path = file == null
                    ? ""
                    : file.getAbsolutePath();
            imageFolder.setText(path);
        }
    });
    autoChangeCheckBox.addActionListener(e -> intervalSpinner.setEnabled(autoChangeCheckBox.isSelected()));
    return rootPanel;
}
 
Example #2
Source File: TwigNamespaceDialog.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private TextBrowseFolderListener createBrowseFolderListener(final JTextField textField, final FileChooserDescriptor fileChooserDescriptor) {
    return new TextBrowseFolderListener(fileChooserDescriptor) {
        @Override
        public void actionPerformed(ActionEvent e) {
            VirtualFile projectDirectory = ProjectUtil.getProjectDir(project);
            VirtualFile selectedFile = FileChooser.chooseFile(
                    fileChooserDescriptor,
                    project,
                    VfsUtil.findRelativeFile(textField.getText(), projectDirectory)
            );

            if (null == selectedFile) {
                return; // Ignore but keep the previous path
            }

            String path = VfsUtil.getRelativePath(selectedFile, projectDirectory, '/');
            if (null == path) {
                path = selectedFile.getPath();
            }

            textField.setText(path);
        }
    };
}
 
Example #3
Source File: SettingsForm.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private TextBrowseFolderListener createBrowseFolderListener(final JTextField textField, final FileChooserDescriptor fileChooserDescriptor) {
    return new TextBrowseFolderListener(fileChooserDescriptor) {
        @Override
        public void actionPerformed(ActionEvent e) {
            VirtualFile projectDirectory = ProjectUtil.getProjectDir(project);
            VirtualFile selectedFile = FileChooser.chooseFile(
                fileChooserDescriptor,
                project,
                VfsUtil.findRelativeFile(textField.getText(), projectDirectory)
            );

            if (null == selectedFile) {
                return; // Ignore but keep the previous path
            }

            String path = VfsUtil.getRelativePath(selectedFile, projectDirectory, '/');
            if (null == path) {
                path = selectedFile.getPath();
            }

            textField.setText(path);
        }
    };
}
 
Example #4
Source File: ProfilerSettingsDialog.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private TextBrowseFolderListener createBrowseFolderListener(final JTextField textField, final FileChooserDescriptor fileChooserDescriptor) {
    return new TextBrowseFolderListener(fileChooserDescriptor) {
        @Override
        public void actionPerformed(ActionEvent e) {
            VirtualFile projectDirectory = ProjectUtil.getProjectDir(project);

            String text = textField.getText();
            VirtualFile toSelect = VfsUtil.findRelativeFile(text, projectDirectory);
            if(toSelect == null) {
                toSelect = projectDirectory;
            }

            VirtualFile selectedFile = FileChooser.chooseFile(
                FileChooserDescriptorFactory.createSingleFileDescriptor("csv"),
                project,
                toSelect
            );

            if (null == selectedFile) {
                return;
            }

            String path = VfsUtil.getRelativePath(selectedFile, projectDirectory, '/');
            if (null == path) {
                path = selectedFile.getPath();
            }

            textField.setText(path);
        }
    };
}
 
Example #5
Source File: CreatePatchConfigurationPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public CreatePatchConfigurationPanel(@Nonnull final Project project) {
  myProject = project;
  initMainPanel();

  myFileNameField.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      final FileSaverDialog dialog =
              FileChooserFactory.getInstance().createSaveFileDialog(
                      new FileSaverDescriptor("Save Patch to", ""), myMainPanel);
      final String path = FileUtil.toSystemIndependentName(getFileName());
      final int idx = path.lastIndexOf("/");
      VirtualFile baseDir = idx == -1 ? project.getBaseDir() :
                            (LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(path.substring(0, idx))));
      baseDir = baseDir == null ? project.getBaseDir() : baseDir;
      final String name = idx == -1 ? path : path.substring(idx + 1);
      final VirtualFileWrapper fileWrapper = dialog.save(baseDir, name);
      if (fileWrapper != null) {
        myFileNameField.setText(fileWrapper.getFile().getPath());
      }
    }
  });

  myFileNameField.setTextFieldPreferredWidth(TEXT_FIELD_WIDTH);
  myBasePathField.setTextFieldPreferredWidth(TEXT_FIELD_WIDTH);
  myBasePathField.addBrowseFolderListener(new TextBrowseFolderListener(FileChooserDescriptorFactory.createSingleFolderDescriptor()));
  myWarningLabel.setForeground(JBColor.RED);
  selectBasePath(ObjectUtils.assertNotNull(myProject.getBaseDir()));
  initEncodingCombo();
}
 
Example #6
Source File: CrudDirSelectInfoStep.java    From crud-intellij-plugin with Apache License 2.0 4 votes vote down vote up
private void createUIComponents() {
    // TODO: place custom component creation code here
    TextFieldWithBrowseButton browseButton = new TextFieldWithBrowseButton();
    browseButton.addBrowseFolderListener(new TextBrowseFolderListener(new FileChooserDescriptor(false, true, false, false, false, false)));
    this.myMapperField = browseButton;
}
 
Example #7
Source File: OptionsDialogWrapper.java    From intellij-thrift with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
protected JComponent createCenterPanel() {
  final JPanel content = new JPanel(new BorderLayout());

  final JPanel topLine = new JPanel(new BorderLayout());
  content.setBorder(IdeBorderFactory.createTitledBorder("Thrift compiler " + myGenerator.getType().name(), false));
  myOutputFolderChooser.addBrowseFolderListener(
    new TextBrowseFolderListener(FileChooserDescriptorFactory.createSingleFolderDescriptor(), myProject) {
      @Nullable
      @Override
      protected VirtualFile getInitialFile() {
        if (myGenerator.getOutputDir() != null) {
          return LocalFileFinder.findFile(myGenerator.getOutputDir());
        }
        else {
          return null;
        }
      }

      @Override
      protected void onFileChosen(@NotNull VirtualFile chosenFile) {
        final String absolutePath = VfsUtil.virtualToIoFile(chosenFile).getAbsolutePath();
        myOutputFolderChooser.setText(absolutePath);
      }
    }
  );

  topLine.add(new JBLabel("Output folder:"), BorderLayout.WEST);
  topLine.add(myOutputFolderChooser, BorderLayout.CENTER);

  content.add(topLine, BorderLayout.NORTH);

  final JPanel options = new JPanel(new BorderLayout());
  content.add(options, BorderLayout.CENTER);

  myPane = AOptionPane.get(myGenerator.getType());
  if (myPane != null) {
    options.setBorder(IdeBorderFactory.createTitledBorder("Additional options"));
    options.add(myPane.getPanel());
    myPane.setValues(myGenerator);
  }
  else {
    options.setBorder(null);
  }

  final String url = myGenerator.getOutputDir();
  final VirtualFile file = url == null ? null : VirtualFileManager.getInstance().findFileByUrl(url);
  myOutputFolderChooser.setText(file == null ? VfsUtil.urlToPath(url) : file.getPath());

  return content;
}