Java Code Examples for com.intellij.openapi.vfs.LocalFileSystem#WatchRequest

The following examples show how to use com.intellij.openapi.vfs.LocalFileSystem#WatchRequest . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileChooserDialogImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void treeExpanded(TreeExpansionEvent event) {
  final Object[] path = event.getPath().getPath();
  if (path.length == 2 && path[1] instanceof DefaultMutableTreeNode) {
    // top node has been expanded => watch disk recursively
    final DefaultMutableTreeNode node = (DefaultMutableTreeNode)path[1];
    Object userObject = node.getUserObject();
    if (userObject instanceof FileNodeDescriptor) {
      final VirtualFile file = ((FileNodeDescriptor)userObject).getElement().getFile();
      if (file != null && file.isDirectory()) {
        final String rootPath = file.getPath();
        if (myRequests.get(rootPath) == null) {
          final LocalFileSystem.WatchRequest watchRequest = LocalFileSystem.getInstance().addRootToWatch(rootPath, true);
          myRequests.put(rootPath, watchRequest);
        }
      }
    }
  }
}
 
Example 2
Source File: FileRefresher.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * Stops watching file, which was added before.
 *
 * @param watcher an object that allows to stop watching a file
 */
protected void unwatch(Object watcher) {
  if (watcher instanceof LocalFileSystem.WatchRequest) {
    LocalFileSystem.getInstance().removeWatchedRoot((LocalFileSystem.WatchRequest)watcher);
  }
}