Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Synchronizing open editors on the same file
Synchronizing open editors on the same file [message #334536] Mon, 16 February 2009 18:10 Go to next message
Eclipse UserFriend
Originally posted by: marc.esher.comcast.net

All,
I'm interested in contributing this feature to an open source project
based on Eclipse. I have done a fair amount of plugin programming but never
any Editor programming.
Basically, the editor in this project doesn't currently support
synchronization between two open editors on the same file. For example, if I
have any text file, and I open it in the Default Text Editor, then choose
"New Editor" and modify that file in one editor, the other editor
automatically reflects those changes. I'd like to add that behavior into the
editor in this project.
Can someone point me down the right path?

thanks so much.

marc
Re: Synchronizing open editors on the same file [message #334540 is a reply to message #334536] Mon, 16 February 2009 22:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

On 2/16/2009 1:10 PM, Marc E wrote:
> All,
> I'm interested in contributing this feature to an open source project
> based on Eclipse. I have done a fair amount of plugin programming but
> never any Editor programming.
> Basically, the editor in this project doesn't currently support
> synchronization between two open editors on the same file. For example,
> if I have any text file, and I open it in the Default Text Editor, then
> choose "New Editor" and modify that file in one editor, the other editor
> automatically reflects those changes. I'd like to add that behavior into
> the editor in this project.
> Can someone point me down the right path?

I think this is more of a fundamental design problem than a particular
code problem. The editor in question must be using some kind of backing
model that can be shared between editor instances. If it does not have
some kind og in-memory model that is sharable, I'm not sure if you can
do what you want.
If EMF is involved, this is quite doable. But if not I would first look
at the code of the basic text editor to see how they are doing it. Try
org.eclipse.ui.editors.text.TextEditor

Hope this helps,
Eric
Re: Synchronizing open editors on the same file [message #334542 is a reply to message #334540] Mon, 16 February 2009 23:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marc.esher.comcast.net

Eric,
Thanks for responding. I've been poring through TextEditor and its
partners for quite a while now and am still having trouble tracking down the
thing that's making it tick.

To rule out any weirdness in the project i'm working on, I created a new
fresh plugin project with an editor contribution... straight from the plugin
wizard, no mods except to change the file extension (I made mine a .marc
file editor). and I've verified that even that editor won't do what the
default text editor does. If I open up my .marc file in the
plugin-wizard-generated editor, I don't get the synched behavior. Open the
same file in two instances of TextEditor, and I get what I'm looking for.

I see that FileDocumentProvider has a FileSynchronizer inner class, and I
thought maybe he was involved, but I can only get its methods to trip on
save, not just dirtying the file.

I imagine it's some listener, somewhere. But I don't yet have the Eclipse
KungFu to track the bugger down.

Anyway, thanks for responding, and thanks for listening.

Cheers!

Marc



"Eric Rizzo" <eclipse-news@rizzoweb.com> wrote in message
news:gncqno$u5d$1@build.eclipse.org...
> On 2/16/2009 1:10 PM, Marc E wrote:
>> All,
>> I'm interested in contributing this feature to an open source project
>> based on Eclipse. I have done a fair amount of plugin programming but
>> never any Editor programming.
>> Basically, the editor in this project doesn't currently support
>> synchronization between two open editors on the same file. For example,
>> if I have any text file, and I open it in the Default Text Editor, then
>> choose "New Editor" and modify that file in one editor, the other editor
>> automatically reflects those changes. I'd like to add that behavior into
>> the editor in this project.
>> Can someone point me down the right path?
>
> I think this is more of a fundamental design problem than a particular
> code problem. The editor in question must be using some kind of backing
> model that can be shared between editor instances. If it does not have
> some kind og in-memory model that is sharable, I'm not sure if you can do
> what you want.
> If EMF is involved, this is quite doable. But if not I would first look at
> the code of the basic text editor to see how they are doing it. Try
> org.eclipse.ui.editors.text.TextEditor
>
> Hope this helps,
> Eric
Re: Synchronizing open editors on the same file [message #334544 is a reply to message #334540] Tue, 17 February 2009 00:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marc.esher.comcast.net

I found the difference: TextEditor uses TextFileDocumentProvider instead of
FileDocumentProvider.

Interestingly enough, this is in the javadoc:

* Text file document providers use {@linkplain
org.eclipse.core.filebuffers.ITextFileBuffer text file buffers}
* to access the file content. This allows to share it between various
clients including
* headless ones. Text file document providers should be preferred over file
document
* providers due to this advantage.

Here's one of those cases where a dude like me says, "if it's preferred,
then why doesn't the wizard generate code that uses this one instead!?" I"m
sure there's quite a good reason. For example, I don't see anything
immediately obvious for partitioning, so maybe that's it. Not sure.

Anyway.... looks like I at least found the path to go down. I sure was
hoping for a 3-line "oh, dude, just add this listenener..." kind of answer,
which so often seems to be the case.

Time to get my game face on!

marc


"Eric Rizzo" <eclipse-news@rizzoweb.com> wrote in message
news:gncqno$u5d$1@build.eclipse.org...
> On 2/16/2009 1:10 PM, Marc E wrote:
>> All,
>> I'm interested in contributing this feature to an open source project
>> based on Eclipse. I have done a fair amount of plugin programming but
>> never any Editor programming.
>> Basically, the editor in this project doesn't currently support
>> synchronization between two open editors on the same file. For example,
>> if I have any text file, and I open it in the Default Text Editor, then
>> choose "New Editor" and modify that file in one editor, the other editor
>> automatically reflects those changes. I'd like to add that behavior into
>> the editor in this project.
>> Can someone point me down the right path?
>
> I think this is more of a fundamental design problem than a particular
> code problem. The editor in question must be using some kind of backing
> model that can be shared between editor instances. If it does not have
> some kind og in-memory model that is sharable, I'm not sure if you can do
> what you want.
> If EMF is involved, this is quite doable. But if not I would first look at
> the code of the basic text editor to see how they are doing it. Try
> org.eclipse.ui.editors.text.TextEditor
>
> Hope this helps,
> Eric
Re: Synchronizing open editors on the same file [message #334545 is a reply to message #334544] Tue, 17 February 2009 06:45 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Marc E wrote:
> I found the difference: TextEditor uses TextFileDocumentProvider
> instead of FileDocumentProvider.
>
> Interestingly enough, this is in the javadoc:
>
> * Text file document providers use {@linkplain
> org.eclipse.core.filebuffers.ITextFileBuffer text file buffers}
> * to access the file content. This allows to share it between various
> clients including
> * headless ones. Text file document providers should be preferred over
> file document
> * providers due to this advantage.
>
> Here's one of those cases where a dude like me says, "if it's
> preferred, then why doesn't the wizard generate code that uses this
> one instead!?"
Which wizard? Simply looks like the wizard needs some updating.

Dani
> I"m sure there's quite a good reason. For example, I don't see
> anything immediately obvious for partitioning, so maybe that's it. Not
> sure.
>
> Anyway.... looks like I at least found the path to go down. I sure was
> hoping for a 3-line "oh, dude, just add this listenener..." kind of
> answer, which so often seems to be the case.
>
> Time to get my game face on!
>
> marc
>
>
> "Eric Rizzo" <eclipse-news@rizzoweb.com> wrote in message
> news:gncqno$u5d$1@build.eclipse.org...
>> On 2/16/2009 1:10 PM, Marc E wrote:
>>> All,
>>> I'm interested in contributing this feature to an open source project
>>> based on Eclipse. I have done a fair amount of plugin programming but
>>> never any Editor programming.
>>> Basically, the editor in this project doesn't currently support
>>> synchronization between two open editors on the same file. For example,
>>> if I have any text file, and I open it in the Default Text Editor, then
>>> choose "New Editor" and modify that file in one editor, the other
>>> editor
>>> automatically reflects those changes. I'd like to add that behavior
>>> into
>>> the editor in this project.
>>> Can someone point me down the right path?
>>
>> I think this is more of a fundamental design problem than a
>> particular code problem. The editor in question must be using some
>> kind of backing model that can be shared between editor instances. If
>> it does not have some kind og in-memory model that is sharable, I'm
>> not sure if you can do what you want.
>> If EMF is involved, this is quite doable. But if not I would first
>> look at the code of the basic text editor to see how they are doing
>> it. Try org.eclipse.ui.editors.text.TextEditor
>>
>> Hope this helps,
>> Eric
>
Re: Synchronizing open editors on the same file [message #334546 is a reply to message #334536] Tue, 17 February 2009 08:05 Go to previous messageGo to next message
Damian Philipp is currently offline Damian PhilippFriend
Messages: 30
Registered: July 2009
Member
Hello,

Marc E schrieb:
> Basically, the editor in this project doesn't currently support
> synchronization between two open editors on the same file.

I'm doing something similar. In my case, it's editing files of different
formats in a common Editor. Here is my code to get the IDocument:

input = new FileEditorInput(file);
provider = DocumentProviderRegistry.getDefault().getDocumentProvider(in put);

provider.connect(input);
document = provider.getDocument(input);

Since I'm editing structured data, my Editor has an IPartListener that
checks whether the Editor gains/looses focus and (de)serializes the text
data into the model data.

This enables users to work with the custom editor and a text editor at
the same time. They shouldn't break the well-formedness of the text data
though.

The only feature this solution doesn't give you is detecting when the
file changed on disk. For that, I have no solution. But if anyone else
has any idea about that, I'm all ears.

Regards
Damian Philipp

PS: Never ever forget to call provider.disconnect() exactly once for
every provider.connect(), or you'll get the weirdest behaviour!
Re: Synchronizing open editors on the same file [message #334547 is a reply to message #334545] Tue, 17 February 2009 10:23 Go to previous message
Eclipse UserFriend
Originally posted by: marc.esher.comcast.net

> Which wizard? Simply looks like the wizard needs some updating.
>
> Dani


Dani, this is the "Plugin with an Editor" Wizard that appears during Plug-in
project creation.


I'm wondering: do any of you know of documentation or otherwise that offers
guidance and gotchas on converting a DocumentProvider from extending
FileDocumentProvider to TextFileDocumentProvider? I have two books on
Eclipse programming, and neither of them touch on this much at all.

thanks.

marc





>> I"m sure there's quite a good reason. For example, I don't see anything
>> immediately obvious for partitioning, so maybe that's it. Not sure.
>>
>> Anyway.... looks like I at least found the path to go down. I sure was
>> hoping for a 3-line "oh, dude, just add this listenener..." kind of
>> answer, which so often seems to be the case.
>>
>> Time to get my game face on!
>>
>> marc
>>
>>
>> "Eric Rizzo" <eclipse-news@rizzoweb.com> wrote in message
>> news:gncqno$u5d$1@build.eclipse.org...
>>> On 2/16/2009 1:10 PM, Marc E wrote:
>>>> All,
>>>> I'm interested in contributing this feature to an open source project
>>>> based on Eclipse. I have done a fair amount of plugin programming but
>>>> never any Editor programming.
>>>> Basically, the editor in this project doesn't currently support
>>>> synchronization between two open editors on the same file. For example,
>>>> if I have any text file, and I open it in the Default Text Editor, then
>>>> choose "New Editor" and modify that file in one editor, the other
>>>> editor
>>>> automatically reflects those changes. I'd like to add that behavior
>>>> into
>>>> the editor in this project.
>>>> Can someone point me down the right path?
>>>
>>> I think this is more of a fundamental design problem than a particular
>>> code problem. The editor in question must be using some kind of backing
>>> model that can be shared between editor instances. If it does not have
>>> some kind og in-memory model that is sharable, I'm not sure if you can
>>> do what you want.
>>> If EMF is involved, this is quite doable. But if not I would first look
>>> at the code of the basic text editor to see how they are doing it. Try
>>> org.eclipse.ui.editors.text.TextEditor
>>>
>>> Hope this helps,
>>> Eric
>>
Previous Topic:List Open Files
Next Topic:Filters & colors in Eclipse Console
Goto Forum:
  


Current Time: Fri Dec 27 03:03:08 GMT 2024

Powered by FUDForum. Page generated in 0.04422 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top