Java Code Examples for com.intellij.openapi.vfs.VirtualFileListener

The following examples show how to use com.intellij.openapi.vfs.VirtualFileListener. These examples are extracted from open source projects. 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 Project: p4ic4idea   Source File: MockVirtualFileSystem.java    License: 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 Project: p4ic4idea   Source File: MockVirtualFileSystem.java    License: 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 Project: consulo   Source File: EditorBasedStatusBarPopup.java    License: 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 Project: consulo   Source File: EncodingPanel.java    License: 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
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 Project: intellij-pants-plugin   Source File: FileChangeTracker.java    License: 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 Project: intellij-pants-plugin   Source File: FileChangeTracker.java    License: 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 Project: consulo   Source File: NewVirtualFileSystem.java    License: 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
@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 Project: p4ic4idea   Source File: MockVirtualFileSystem.java    License: 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 Project: p4ic4idea   Source File: MockVirtualFileSystem.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void removeVirtualFileListener(@NotNull VirtualFileListener listener) {
    listeners.remove(listener);
}
 
Example 12
Source Project: intellij-pants-plugin   Source File: FileChangeTracker.java    License: 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 Project: consulo   Source File: NewVirtualFileSystem.java    License: 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 Project: consulo   Source File: VirtualFileTracker.java    License: 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 Project: nosql4idea   Source File: NoSqlDatabaseFileSystem.java    License: Apache License 2.0 2 votes vote down vote up
@Override
public void addVirtualFileListener(@NotNull VirtualFileListener listener) {

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

}