Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » DOM from editor
DOM from editor [message #150788] Mon, 05 December 2005 17:21 Go to next message
Brian Jakubik is currently offline Brian JakubikFriend
Messages: 140
Registered: July 2009
Senior Member
How do I get a DOM node or DOM Model or anything that can get me into the
DOM from an ITextEditor, IWorkbenchPart, ISelection, IDocumentProvider,
IDocument, or IRegion or by drilling into these. Its been killing me this
morning.

Thanks
Brian Jakubik
Re: DOM from editor [message #150794 is a reply to message #150788] Mon, 05 December 2005 18:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: enorman.webmethods.com

I've been getting at the DOM via the StructuredModelManager:

IStructuredModel editModel = null;
try {
//retrieve a reference to the file being edited
IFile file = [TODO: get IFile here];

//get the model manager
IModelManager modelManager = StructuredModelManager.getModelManager();

//open the model for edit if making changes, if you only need read-only
access to the model, you could use getModelForRead(IFile) instead.
// Alternatively, use modelManager.getModelForEdit(IStructuredDocument)
if you have a reference to the IStructuredDocument instead of the IFile.
editModel = modelManager.getModelForEdit(file);

//cast the structured model to a DOM Model
IDOMModel domModel = (IDOMModel)model;

//get the DOM document from the DOM model
Document doc = domModel.getDocument();

//TODO: perform the edits to the DOM here

} finally {
//release the model from editing
if (editModel != null) {
editModel.releaseFromEdit();
//or editModel.releaseFromRead() if opened for read
}
}


Regards,
-Eric Norman

"Brian Jakubik" <brian.jakubik@intervoice.com> wrote in message
news:dn1stu$4br$1@news.eclipse.org...
> How do I get a DOM node or DOM Model or anything that can get me into the
> DOM from an ITextEditor, IWorkbenchPart, ISelection, IDocumentProvider,
> IDocument, or IRegion or by drilling into these. Its been killing me this
> morning.
>
> Thanks
> Brian Jakubik
>
>
Re: DOM from editor [message #150929 is a reply to message #150794] Tue, 06 December 2005 17:07 Go to previous messageGo to next message
Brian Jakubik is currently offline Brian JakubikFriend
Messages: 140
Registered: July 2009
Senior Member
Thanks Eric, thats somewhat what I needed. The problem is I have an
ITextSelection with the line text, I need a node from the selection, so I
can walk up it to find the parent tag. My problem with getting the whole
DOM is I dont know where the line text is in the DOM to start walking up....
Hope that makes sense.

Anyone have anyother ideas?
Thanks


"Eric Norman" <enorman@webmethods.com> wrote in message
news:dn20d1$ag1$1@news.eclipse.org...
> I've been getting at the DOM via the StructuredModelManager:
>
> IStructuredModel editModel = null;
> try {
> //retrieve a reference to the file being edited
> IFile file = [TODO: get IFile here];
>
> //get the model manager
> IModelManager modelManager = StructuredModelManager.getModelManager();
>
> //open the model for edit if making changes, if you only need read-only
> access to the model, you could use getModelForRead(IFile) instead.
> // Alternatively, use
> modelManager.getModelForEdit(IStructuredDocument)
> if you have a reference to the IStructuredDocument instead of the IFile.
> editModel = modelManager.getModelForEdit(file);
>
> //cast the structured model to a DOM Model
> IDOMModel domModel = (IDOMModel)model;
>
> //get the DOM document from the DOM model
> Document doc = domModel.getDocument();
>
> //TODO: perform the edits to the DOM here
>
> } finally {
> //release the model from editing
> if (editModel != null) {
> editModel.releaseFromEdit();
> //or editModel.releaseFromRead() if opened for read
> }
> }
>
>
> Regards,
> -Eric Norman
>
> "Brian Jakubik" <brian.jakubik@intervoice.com> wrote in message
> news:dn1stu$4br$1@news.eclipse.org...
>> How do I get a DOM node or DOM Model or anything that can get me into the
>> DOM from an ITextEditor, IWorkbenchPart, ISelection, IDocumentProvider,
>> IDocument, or IRegion or by drilling into these. Its been killing me
>> this
>> morning.
>>
>> Thanks
>> Brian Jakubik
>>
>>
>
>
Re: DOM from editor [message #150942 is a reply to message #150929] Tue, 06 December 2005 17:43 Go to previous message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

Brian Jakubik wrote:
> Thanks Eric, thats somewhat what I needed. The problem is I have an
> ITextSelection with the line text, I need a node from the selection, so I
> can walk up it to find the parent tag. My problem with getting the whole
> DOM is I dont know where the line text is in the DOM to start walking up....
> Hope that makes sense.
>
> Anyone have anyother ideas?

As of 1.0M8, you'll find that the StructuredTextEditor's selection
is both ITextSelection and an IStructuredSelection of DOM Nodes (for
DOM models, anyway).

--
- Nitin


_
Nitin Dahyabhai
Eclipse Web Tools Platform
Previous Topic:Annouce 1.0RC1 on the front page
Next Topic:web.xml error
Goto Forum:
  


Current Time: Thu Apr 25 21:07:25 GMT 2024

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

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

Back to the top