com.intellij.openapi.vfs.VirtualFileListener Java Examples

The following examples show how to use com.intellij.openapi.vfs.VirtualFileListener. 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: MockVirtualFileSystem.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
protected VirtualFile createChildFile(Object requestor, @NotNull VirtualFile vDir, @NotNull String fileName)
        throws IOException {
    if (vDir instanceof MockVirtualFile) {
        MockVirtualFile mvd = (MockVirtualFile) vDir;
        if (registeredFiles.containsKey(mvd.getPath())) {
            if (mvd.getChild(fileName) != null) {
                throw new FileAlreadyExistsException(mvd.getPath() + "/" + fileName);
            }
            MockVirtualFile child = new MockVirtualFile(this, fileName, mvd, "", getDefaultCharset());
            mvd.markChild(child);
            VirtualFileEvent event = new VirtualFileEvent(requestor, child, fileName, vDir);
            for (VirtualFileListener listener : listeners) {
                listener.fileCreated(event);
            }
            return child;
        }
    } else if (vDir instanceof IOVirtualFile) {
        return new IOVirtualFile(new File(((IOVirtualFile) vDir).getIOFile(), fileName), false);
    }
    throw new NoSuchFileException(vDir.getCanonicalPath());
}
 
Example #2
Source File: MockVirtualFileSystem.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
protected VirtualFile createChildDirectory(Object requestor, @NotNull VirtualFile vDir, @NotNull String dirName)
        throws IOException {
    if (vDir instanceof MockVirtualFile) {
        MockVirtualFile mvd = (MockVirtualFile) vDir;
        if (registeredFiles.containsKey(mvd.getPath())) {
            if (mvd.getChild(dirName) != null) {
                throw new FileAlreadyExistsException(mvd.getPath() + "/" + dirName);
            }
            MockVirtualFile child = new MockVirtualFile(this, dirName, mvd);
            mvd.markChild(child);
            registeredFiles.put(child.getPath(), child);
            VirtualFileEvent event = new VirtualFileEvent(requestor, child, dirName, vDir);
            for (VirtualFileListener listener : listeners) {
                listener.fileCreated(event);
            }
            return child;
        }
    }
    throw new NoSuchFileException(vDir.getCanonicalPath());
}
 
Example #3
Source File: EditorBasedStatusBarPopup.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void install(@Nonnull StatusBar statusBar) {
  super.install(statusBar);
  registerCustomListeners();
  EditorFactory.getInstance().getEventMulticaster().addDocumentListener(new DocumentListener() {
    @Override
    public void documentChanged(@Nonnull DocumentEvent e) {
      Document document = e.getDocument();
      updateForDocument(document);
    }
  }, this);
  if (myWriteableFileRequired) {
    ApplicationManager.getApplication().getMessageBus().connect(this).subscribe(VirtualFileManager.VFS_CHANGES, new BulkVirtualFileListenerAdapter(new VirtualFileListener() {
      @Override
      public void propertyChanged(@Nonnull VirtualFilePropertyEvent event) {
        if (VirtualFile.PROP_WRITABLE.equals(event.getPropertyName())) {
          updateForFile(event.getFile());
        }
      }
    }));
  }
}
 
Example #4
Source File: EncodingPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void registerCustomListeners() {
  // should update to reflect encoding-from-content
  EncodingManager.getInstance().addPropertyChangeListener(evt -> {
    if (evt.getPropertyName().equals(EncodingManagerImpl.PROP_CACHED_ENCODING_CHANGED)) {
      Document document = evt.getSource() instanceof Document ? (Document)evt.getSource() : null;
      updateForDocument(document);
    }
  }, this);
  ApplicationManager.getApplication().getMessageBus().connect(this).subscribe(VirtualFileManager.VFS_CHANGES, new BulkVirtualFileListenerAdapter(new VirtualFileListener() {
    @Override
    public void propertyChanged(@Nonnull VirtualFilePropertyEvent event) {
      if (VirtualFile.PROP_ENCODING.equals(event.getPropertyName())) {
        updateForFile(event.getFile());
      }
    }
  }));
}
 
Example #5
Source File: ParametersPanel.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
private void setupFileSpecificEditor(Project project, VirtualFile cypherFile) {
    if (project == null || cypherFile == null) {
        return;
    }
    try {
        String params = FileUtil.getParams(cypherFile);
        LightVirtualFile lightVirtualFile = new LightVirtualFile("", JsonFileType.INSTANCE, params);
        Document document = FileDocumentManager.getInstance().getDocument(lightVirtualFile);
        fileSpecificParamEditor = createEditor(project, document);
        VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileListener() {
            @Override
            public void contentsChanged(@NotNull VirtualFileEvent event) {
                if (event.getFile().equals(cypherFile) && document != null) {
                    FileUtil.setParams(cypherFile, document.getText());
                }
            }
        });
        JLabel jLabel = new JLabel("<html>Parameters for data source <b>" +
                getTabTitle(cypherFile) + "</b>:</html>");
        jLabel.setIcon(ICON_HELP);
        jLabel.setToolTipText("Enter parameters in JSON format. Will be applied to <b>" + getTabTitle(cypherFile) +
                "</b> data source when executed");
        fileSpecificParamEditor.setHeaderComponent(jLabel);
        if (document != null) {
            setInitialContent(document);
        }
        graphConsoleView.getFileSpecificParametersTab().add(fileSpecificParamEditor.getComponent(), BorderLayout.CENTER);
    } catch (Throwable e) {
        Throwables.throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
 
Example #6
Source File: FileChangeTracker.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private static void markDirty(@NotNull VirtualFile file, final PantsOptions pantsOptions, @NotNull VirtualFileListener listener) {
  Project project = listenToProjectMap.get(listener);

  ChangeType changeType = detectChangeType(project, pantsOptions, file);
  LOG.debug(String.format("Changed: %s. In project: %s", file.getPath(), changeType));
  if (changeType == ChangeType.UNRELATED) {
    return;
  }

  markDirty(project);

  if (changeType == ChangeType.BUILD) {
    ProjectRefreshListener.notify(project);
  }
}
 
Example #7
Source File: FileChangeTracker.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
public static void unregisterProject(@NotNull Project project) {
  projectStates.remove(project);

  // Remove the listener for the project.
  listenToProjectMap.entrySet().stream()
    .filter(s -> s.getValue() == project)
    .findFirst()
    .ifPresent(x -> {
      VirtualFileListener listener = x.getKey();
      listenToProjectMap.remove(listener);
      LocalFileSystem.getInstance().removeVirtualFileListener(listener);
    });
}
 
Example #8
Source File: NewVirtualFileSystem.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void removeVirtualFileListener(@Nonnull final VirtualFileListener listener) {
  VirtualFileListener wrapper = myListenerWrappers.remove(listener);
  if (wrapper != null) {
    VirtualFileManager.getInstance().removeVirtualFileListener(wrapper);
  }
}
 
Example #9
Source File: BackgroundTaskByVfsChangeManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Inject
public BackgroundTaskByVfsChangeManagerImpl(@Nonnull Project project) {
  myProject = project;

  VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileListener() {
    @Override
    public void contentsChanged(@Nonnull VirtualFileEvent event) {
      runTasks(event.getFile());
    }
  }, this);
}
 
Example #10
Source File: MockVirtualFileSystem.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
@Override
public void addVirtualFileListener(@NotNull VirtualFileListener listener) {
    if (!listeners.contains(listener)) {
        listeners.add(listener);
    }
}
 
Example #11
Source File: MockVirtualFileSystem.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
@Override
public void removeVirtualFileListener(@NotNull VirtualFileListener listener) {
    listeners.remove(listener);
}
 
Example #12
Source File: FileChangeTracker.java    From intellij-pants-plugin with Apache License 2.0 4 votes vote down vote up
public static void registerProject(@NotNull Project project, final PantsOptions pantsOptions) {
  VirtualFileListener listener = getNewListener(pantsOptions);
  LocalFileSystem.getInstance().addVirtualFileListener(listener);
  listenToProjectMap.put(listener, project);
}
 
Example #13
Source File: NewVirtualFileSystem.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void addVirtualFileListener(@Nonnull final VirtualFileListener listener) {
  VirtualFileListener wrapper = new VirtualFileFilteringListener(listener, this);
  VirtualFileManager.getInstance().addVirtualFileListener(wrapper);
  myListenerWrappers.put(listener, wrapper);
}
 
Example #14
Source File: VirtualFileTracker.java    From consulo with Apache License 2.0 4 votes vote down vote up
void addTracker(
@Nonnull String fileUrl,
@Nonnull VirtualFileListener listener,
boolean fromRefreshOnly,
@Nonnull Disposable parentDisposable);
 
Example #15
Source File: NoSqlDatabaseFileSystem.java    From nosql4idea with Apache License 2.0 2 votes vote down vote up
@Override
public void addVirtualFileListener(@NotNull VirtualFileListener listener) {

}
 
Example #16
Source File: NoSqlDatabaseFileSystem.java    From nosql4idea with Apache License 2.0 2 votes vote down vote up
@Override
public void removeVirtualFileListener(@NotNull VirtualFileListener listener) {

}