How to Detect File Changes

Hi everyone,

     I'm trying to develop a tool window. It has a JTable that shows some data in xml files that kept in a specific directory. I want to update my JTable when new xml file is added or modified(There is an add option in my plugin). How can I listen these files? I found some solutions but I can't figure how to implement. If you gonna reply, please explain detailed.

I'm looking for BulkFileListener now. But how to connect my file to MessageBus?

2 comments
Comment actions Permalink

I did something with BulkFileListener:

    @Override
    public void initComponent() {
        messageBus.subscribe(VirtualFileManager.VFS_CHANGES,this);
    }

    @Override
    public void disposeComponent() {
        messageBus.disconnect();
    }

//Override projectComponent methods

    final MessageBusConnection messageBus = ProjectManager.getInstance().getDefaultProject().getMessageBus().connect();

    @Override
    public void before(@NotNull List<? extends VFileEvent> vFileEvents) {

    }

    @Override
    public void after(@NotNull List<? extends VFileEvent> vFileEvents) {
        Messages.showMessageDialog("there are","some changes",Messages.getWarningIcon());
    }

Now, it gives a warning for everything.(Sometime twice)
It also gives warning everytime I press ctrl + S

How can I specify it for my file?

0
Comment actions Permalink

Now, I'm trying VirtualFileListener. But I can't find to tied something to trigger VirtualFileListener(Like connection in BulkFileListener). Please help...

0

Please sign in to leave a comment.