コード例 #1
1
  private void updatePathFromTree(final List<VirtualFile> selection, boolean now) {
    if (!isToShowTextField() || myTreeIsUpdating) return;

    String text = "";
    if (selection.size() > 0) {
      text = VfsUtil.getReadableUrl(selection.get(0));
    } else {
      final List<VirtualFile> roots = myChooserDescriptor.getRoots();
      if (!myFileSystemTree.getTree().isRootVisible() && roots.size() == 1) {
        text = VfsUtil.getReadableUrl(roots.get(0));
      }
    }

    myPathTextField.setText(
        text,
        now,
        () -> {
          myPathTextField.getField().selectAll();
          setErrorText(null);
        });
  }
コード例 #2
0
  @Nullable
  protected final JComponent createTitlePane() {
    final String description = myChooserDescriptor.getDescription();
    if (StringUtil.isEmptyOrSpaces(description)) return null;

    final JLabel label = new JLabel(description);
    label.setBorder(
        BorderFactory.createCompoundBorder(
            new SideBorder(UIUtil.getPanelBackground().darker(), SideBorder.BOTTOM),
            JBUI.Borders.empty(0, 5, 10, 5)));
    return label;
  }
コード例 #3
0
  protected JTree createTree() {
    Tree internalTree = createInternalTree();
    myFileSystemTree =
        new FileSystemTreeImpl(myProject, myChooserDescriptor, internalTree, null, null, null);
    internalTree.setRootVisible(myChooserDescriptor.isTreeRootVisible());
    internalTree.setShowsRootHandles(true);
    Disposer.register(myDisposable, myFileSystemTree);

    myFileSystemTree.addOkAction(this::doOKAction);
    JTree tree = myFileSystemTree.getTree();
    tree.setCellRenderer(new NodeRenderer());
    tree.getSelectionModel().addTreeSelectionListener(new FileTreeSelectionListener());
    tree.addTreeExpansionListener(new FileTreeExpansionListener());
    setOKActionEnabled(false);

    myFileSystemTree.addListener(
        new FileSystemTree.Listener() {
          public void selectionChanged(final List<VirtualFile> selection) {
            updatePathFromTree(selection, false);
          }
        },
        myDisposable);

    new FileDrop(
        tree,
        new FileDrop.Target() {
          public FileChooserDescriptor getDescriptor() {
            return myChooserDescriptor;
          }

          public boolean isHiddenShown() {
            return myFileSystemTree.areHiddensShown();
          }

          public void dropFiles(final List<VirtualFile> files) {
            if (!myChooserDescriptor.isChooseMultiple() && files.size() > 0) {
              selectInTree(new VirtualFile[] {files.get(0)}, true, true);
            } else {
              selectInTree(VfsUtilCore.toVirtualFileArray(files), true, true);
            }
          }
        });

    return tree;
  }
コード例 #4
0
  protected void doOKAction() {
    if (!isOKActionEnabled()) {
      return;
    }

    if (isTextFieldActive()) {
      final String text = myPathTextField.getTextFieldText();
      final LookupFile file = myPathTextField.getFile();
      if (text == null || file == null || !file.exists()) {
        setErrorText("Specified path cannot be found");
        return;
      }
    }

    final List<VirtualFile> selectedFiles = Arrays.asList(getSelectedFilesInt());
    final VirtualFile[] files =
        VfsUtilCore.toVirtualFileArray(
            FileChooserUtil.getChosenFiles(myChooserDescriptor, selectedFiles));
    if (files.length == 0) {
      myChosenFiles = VirtualFile.EMPTY_ARRAY;
      close(CANCEL_EXIT_CODE);
      return;
    }

    try {
      myChooserDescriptor.validateSelectedFiles(files);
    } catch (Exception e) {
      Messages.showErrorDialog(getContentPane(), e.getMessage(), getTitle());
      return;
    }

    myChosenFiles = files;
    storeSelection(files[files.length - 1]);

    super.doOKAction();
  }
コード例 #5
0
  public FileChooserDescriptor build() {
    FileChooserDescriptor descriptor =
        new FileChooserDescriptor(
            myChooseFiles,
            myChooseFolders,
            myChooseJars,
            myChooseJarsAsFiles,
            myChooseJarContents,
            myChooseMultiple);

    if (myTitle != null) {
      descriptor.setTitle(myTitle);
    }

    if (myDescription != null) {
      descriptor.setDescription(myDescription);
    }

    if (myShowFileSystemRoots != null) {
      descriptor.setShowFileSystemRoots(myShowFileSystemRoots);
    }

    if (myHideIgnored != null) {
      descriptor.setHideIgnored(myHideIgnored);
    }

    if (myTreeRootVisible != null) {
      descriptor.setIsTreeRootVisible(myTreeRootVisible);
    }

    if (myRoots != null) {
      descriptor.setRoots(myRoots);
    }

    return descriptor;
  }
コード例 #6
0
 private static String getChooserTitle(final FileChooserDescriptor descriptor) {
   final String title = descriptor.getTitle();
   return title != null ? title : UIBundle.message("file.chooser.default.title");
 }