Ejemplo n.º 1
0
  // {{{ loadDirectory() method
  public void loadDirectory(
      final Object node, String path, final boolean addToHistory, final Runnable delayedAWTTask) {
    path = MiscUtilities.constructPath(browser.getDirectory(), path);
    VFS vfs = VFSManager.getVFSForPath(path);

    Object session = vfs.createVFSSession(path, this);
    if (session == null) {
      if (delayedAWTTask != null) ThreadUtilities.runInDispatchThread(delayedAWTTask);
      return;
    }

    if (node == null) {
      parentDirectories.setListData(new Object[] {new LoadingPlaceholder()});
    }

    final Object[] loadInfo = new Object[2];
    Runnable awtRunnable =
        new Runnable() {
          public void run() {
            browser.directoryLoaded(node, loadInfo, addToHistory);
            if (delayedAWTTask != null) delayedAWTTask.run();
          }
        };
    ThreadUtilities.runInBackground(
        new ListDirectoryBrowserTask(browser, session, vfs, path, loadInfo, awtRunnable));
  } // }}}
Ejemplo n.º 2
0
  /**
   * Rebuild the parent view after a directory has been loaded.
   *
   * @param node
   * @param path
   * @param directory
   */
  public void directoryLoaded(Object node, String path, java.util.List<VFSFile> directory) {
    // {{{ If reloading root, update parent directory list
    if (node == null) {
      DefaultListModel parentList = new DefaultListModel();

      String parent = path;

      for (; ; ) {
        VFS _vfs = VFSManager.getVFSForPath(parent);
        VFSFile file = null;
        if (_vfs instanceof FileVFS) {
          Object session = _vfs.createVFSSession(path, browser);
          try {
            file = _vfs._getFile(session, parent, browser);
            if (file != null) {
              file.setName(_vfs.getFileName(parent));
            }
          } catch (IOException e) {
            Log.log(Log.ERROR, this, e, e);
          }
        }
        if (file == null) {
          // create a DirectoryEntry manually
          // instead of using _vfs._getFile()
          // since so many VFS's have broken
          // implementations of this method
          file =
              new VFSFile(_vfs.getFileName(parent), parent, parent, VFSFile.DIRECTORY, 0L, false);
        }

        /*parentList.insertElementAt(new VFSFile(
        _vfs.getFileName(parent),
        parent,parent,
        VFSFile.DIRECTORY,
        0L,false),0);*/
        parentList.insertElementAt(file, 0);
        String newParent = _vfs.getParentOfPath(parent);

        if (newParent == null || MiscUtilities.pathsEqual(parent, newParent)) break;
        else parent = newParent;
      }

      parentDirectories.setModel(parentList);
      int index = parentList.getSize() - 1;
      parentDirectories.setSelectedIndex(index);
      parentDirectories.ensureIndexIsVisible(index);
    } // }}}

    table.setDirectory(VFSManager.getVFSForPath(path), node, directory, tmpExpanded);
  } // }}}
Ejemplo n.º 3
0
 /**
  * Copy a file to another using VFS.
  *
  * @param progress the progress observer. It could be null if you don't want to monitor progress.
  *     If not null you should probably launch this command in a WorkThread
  * @param sourcePath the source path
  * @param targetPath the target path
  * @param comp comp The component that will parent error dialog boxes
  * @param canStop if true the copy can be stopped
  * @return true if the copy was successful
  * @throws IOException IOException If an I/O error occurs
  * @since jEdit 4.3pre3
  */
 public static boolean copy(
     ProgressObserver progress,
     String sourcePath,
     String targetPath,
     Component comp,
     boolean canStop)
     throws IOException {
   VFS sourceVFS = VFSManager.getVFSForPath(sourcePath);
   Object sourceSession = sourceVFS.createVFSSession(sourcePath, comp);
   if (sourceSession == null) {
     Log.log(
         Log.WARNING,
         VFS.class,
         "Unable to get a valid session from " + sourceVFS + " for path " + sourcePath);
     return false;
   }
   VFS targetVFS = VFSManager.getVFSForPath(targetPath);
   Object targetSession = targetVFS.createVFSSession(targetPath, comp);
   if (targetSession == null) {
     Log.log(
         Log.WARNING,
         VFS.class,
         "Unable to get a valid session from " + targetVFS + " for path " + targetPath);
     return false;
   }
   return copy(
       progress,
       sourceVFS,
       sourceSession,
       sourcePath,
       targetVFS,
       targetSession,
       targetPath,
       comp,
       canStop);
 } // }}}