Forcing Content Update in Custom and Default FileEditors

I have implemented a custom File Editor and it does its job. The default editor is also shown as a tab along with mu custom editor.

How can I force the content to change in other editor if user update the content in one of these 2 editor?

Content in both of the editors needs to be sync always.

0
8 comments

Default text editor makes changes to a Document instance. That instance generates change events, which can be processed by another editor to update its view. Default text editor also will update its view, if its document is changed externally. Document instance can be obtained for a given VirtualFile using FileDocumentManager.

0
Avatar
Permanently deleted user

I am using the below approach to update the file in my custom editor.

VfsUtil.saveText(myFile, gson.toJson(response));

Based on your response I assume this is a wrong approach to update the file directly via VFS Utils.

 

How do I update the file using Document instance? Any help would be useful.

0

You can try

FileDocumentManger.getInstance().getDocument(myFile).setText(gson.toJson(response))

1
Avatar
Permanently deleted user

This works great. But when I edit the file in default editor, it's not updated in my custom editor.

 

Any tip on loading the updated file content?

0

Try getting the content from the document, not from the file.

0
Avatar
Permanently deleted user

I am doing the same in my custom editor panel.

I am having a custom JSON editor which shows the json file content in a JTable view.  From the gson object I update the JTable view.

gson.fromJson(document.getText())
0

Maybe you just need to reload your panel, when document contents changes?

You can listen to changes in document - see Document.addDocumentListener

 

0
Avatar
Permanently deleted user

Works now. Thanks.

0

Please sign in to leave a comment.