Example #1
0
  public Vector<String> getPossibleCompletions(String path) {
    Vector<String> result = new Vector<String>();
    int index = Math.max(path.lastIndexOf('\\'), path.lastIndexOf('/'));
    if (index != -1) {
      String currentDirectoryName = path.substring(0, index + 1);

      AbstractFile currentDirectory = FileFactory.getFile(currentDirectoryName);
      if (currentDirectory != null && currentDirectory.exists()) {
        long currentDirectoryDate = currentDirectory.getDate();
        if (cachedDirectoryName == null
            || !cachedDirectoryName.equals(currentDirectoryName)
            || currentDirectoryDate != cachedDirectoryDate) {
          AbstractFile[] currentDirectoryFiles;
          try {
            currentDirectoryFiles = getFiles(currentDirectory);
          } catch (IOException e) {
            LOGGER.debug("Caught exception", e);
            return new Vector<String>();
          }

          int nbCurrentDirectoryFiles = currentDirectoryFiles.length;
          cachedDirectoryFileNames = new String[nbCurrentDirectoryFiles];

          for (int i = 0; i < nbCurrentDirectoryFiles; i++) {
            AbstractFile abstractFileI = currentDirectoryFiles[i];
            cachedDirectoryFileNames[i] =
                abstractFileI.getName()
                    + (abstractFileI.isDirectory() ? abstractFileI.getSeparator() : "");
          }

          Arrays.sort(cachedDirectoryFileNames, String.CASE_INSENSITIVE_ORDER);

          cachedDirectoryName =
              currentDirectory.getAbsolutePath()
                  + (currentDirectory.isDirectory() ? "" : currentDirectory.getSeparator());
          cachedDirectoryDate = currentDirectoryDate;
        }

        final String prefix =
            index == path.length() - 1 ? null : path.substring(index + 1).toLowerCase();
        result = PrefixFilter.createPrefixFilter(prefix).filter(cachedDirectoryFileNames);
      }
    }
    return result;
  }
 @Override
 public String getSeparator() {
   return file.getSeparator();
 }