Code example for JTextComponent

Methods: getSelectedTextreplaceSelection

0
    myDescriptor = descriptor;
  } 
 
  @Override 
  public void actionPerformed(AnActionEvent e) {
    String selectedText = myTextField.getSelectedText();
    VirtualFile virtualFile;
    if (selectedText != null ) {
      virtualFile = LocalFileSystem.getInstance().findFileByPath(selectedText.replace(File.separatorChar, '/'));
    } 
    else { 
      virtualFile = null;
    } 
    //TODO use from openapi 
    //FeatureUsageTracker.getInstance().triggerFeatureUsed("ui.commandLine.insertPath"); 
    VirtualFile[] files = FileChooser.chooseFiles(myDescriptor, myTextField, getEventProject(e), virtualFile);
    if (files.length != 0) {
      myTextField.replaceSelection(files[0].getPresentableUrl());
    } 
  } 
 
  private void uninstall() { 
    uninstallPopupHandler();