Beispiel #1
0
  private void selectFileTreeItemForSelectedFile(final File file) {
    if (updatingSelectedFiles) return;

    updatingSelectedFiles = true;
    try {
      final FileTreeItem<?> fileTreeItem = rootFileTreeItem.findFirst(file);
      if (fileTreeItem == null) {
        IllegalStateException x =
            new IllegalStateException("File does not have corresponding FileTreeItem: " + file);
        logger.warn("selectFileTreeItemForSelectedFile: " + x, x);
      } else {
        TreeItem<?> ti = fileTreeItem.getParent();
        while (ti != null) {
          ti.setExpanded(true);
          ti = ti.getParent();
        }

        // TODO maybe, instead of scrolling here (after each single item is selected), immediately,
        // we should wait (=> Timer) and scroll to the *first* selection, later?!
        treeTableView.getSelectionModel().select(fileTreeItem);
        int row = treeTableView.getRow(fileTreeItem);
        if (row >= 0) treeTableView.scrollTo(row);
      }
    } finally {
      updatingSelectedFiles = false;
    }
  }
Beispiel #2
0
  private void unselectTreeItemForUnselectedFile(final File file) {
    if (updatingSelectedFiles) return;

    updatingSelectedFiles = true;
    try {
      final FileTreeItem<?> fileTreeItem = rootFileTreeItem.findFirst(file);
      if (fileTreeItem != null) {
        final Set<TreeItem<FileTreeItem<?>>> selectedItems =
            new LinkedHashSet<TreeItem<FileTreeItem<?>>>(
                treeTableView.getSelectionModel().getSelectedItems());
        if (selectedItems.remove(fileTreeItem)) {
          treeTableView.getSelectionModel().clearSelection();
          for (TreeItem<FileTreeItem<?>> treeItem : selectedItems)
            treeTableView.getSelectionModel().select(treeItem);
        }
      }
    } finally {
      updatingSelectedFiles = false;
    }
  }