Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » use of addDocumentListener(..)
use of addDocumentListener(..) [message #309170] Tue, 17 October 2006 16:31 Go to next message
Eclipse UserFriend
Originally posted by: m_gla.yahoo.com

Hi All,
Is it possible to use:
getDocumentProvider().getDocument(getEditorInput()).addDocum entListener(this)
to listen to documents besides those with .java extension, like .xml,
txt, .doc etc.
It seems not to be working for me.
I will appreciate any help.

Mgla
Re: use of addDocumentListener(..) [message #309171 is a reply to message #309170] Tue, 17 October 2006 17:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vik_ram.hotmail.com

Hi,
If you want to share the document provider, you have to declare an extn.
to org.eclipse.ui.documentProviders in the plugin manifest file.
This gets registered with the DocumentProviderRegistry and you can
access it from your code. OR

You can create it directly in your code.
By creating it in your code directly, the provider is not added to the
provider registry, so you wont be able to share changes on input with
other active editors.



Mgla wrote:

> Hi All,
> Is it possible to use:
> getDocumentProvider().getDocument(getEditorInput()).addDocum entListener(this)
>
> to listen to documents besides those with .java extension, like .xml,
> txt, .doc etc.
> It seems not to be working for me.
> I will appreciate any help.
>
> Mgla
>
Re: use of addDocumentListener(..) [message #309175 is a reply to message #309171] Tue, 17 October 2006 19:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: m_gla.yahoo.com

Hi vikram,
Can i get more insight..
I must acknowledge here that i am still very much a novice in
understanding how eclipse works, but what i intend to do is add a document
listener to every type of document (.xml,.doc.txt etc) that can be opened
in an eclipse document window. I want to access the document provider of
any existing editor in eclipse, get the document and then add a document
listener. Below are my codes.

Thanks,
Mgla

public void docListner(){
IWorkbenchPage page =
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
getActivePage();
IEditorPart part = page.getActiveEditor();
if (!(part instanceof AbstractTextEditor))
return;
ITextEditor editor = (ITextEditor) part;
IDocumentProvider dp = editor.getDocumentProvider();
IDocument doc = dp.getDocument(editor.getEditorInput());
doc.addDocumentListener(this);
}
Re: use of addDocumentListener(..) [message #309189 is a reply to message #309170] Wed, 18 October 2006 03:23 Go to previous messageGo to next message
Eclipse UserFriend
Mgla wrote:

> Hi All,
> Is it possible to use:
> getDocumentProvider().getDocument(getEditorInput()).addDocum entListener(this)
>
> to listen to documents besides those with .java extension, like .xml,
> txt, .doc etc.

No.

Dani

> It seems not to be working for me.
> I will appreciate any help.
>
> Mgla
>
Re: use of addDocumentListener(..) [message #309192 is a reply to message #309189] Wed, 18 October 2006 03:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: m_gla.yahoo.com

Is there any way i can get around this then.
Mgla
Re: use of addDocumentListener(..) [message #309193 is a reply to message #309192] Wed, 18 October 2006 03:47 Go to previous messageGo to next message
Eclipse UserFriend
Mgla wrote:

> Is there any way i can get around this then.

No idea since you didn't tell what you want to achieve in the end.

Dani

> Mgla
>
Re: use of addDocumentListener(..) [message #309194 is a reply to message #309193] Wed, 18 October 2006 03:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: m_gla.yahoo.com

What i want to do is simply to monitor the number of keyboard presses to
on an active editor part, using
"getSourceViewer().getTextWidget().addKeyListener(this)" is not yielding
the expected result so i taught rather listening to document change events
will do.
Re: use of addDocumentListener(..) [message #309195 is a reply to message #309194] Wed, 18 October 2006 05:25 Go to previous message
Eclipse UserFriend
Mgla wrote:

> What i want to do is simply to monitor the number of keyboard presses
> to on an active editor part, using
> "getSourceViewer().getTextWidget().addKeyListener(this)" is not
> yielding the expected result so i taught rather listening to document
> change events will do.

Ok. Then the code you initially posted might help - at least for textual
editors. But you must do something like that:
- listen for editor activation
- if editor is activated
- remove the old listener
- add listener using your initial code
- if editor is closed remove listener

A simpler approach would be to use file buffers: most (i.e. no guarantee
that you really catch all) textual editors indirectly use file buffers.
Take a look at:
- FileBuffers.getTextFileBufferManager()
- IFileBufferManager.addFileBufferListener()
- ITextFileBuffer.getDocument()

HTH
Dani
Previous Topic:Restoring view from external file
Next Topic:JET vs Velocity?
Goto Forum:
  


Current Time: Sat May 10 16:20:10 EDT 2025

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

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

Back to the top