|
Re: DOM from editor [message #150794 is a reply to message #150788] |
Mon, 05 December 2005 18:25 |
Eclipse User |
|
|
|
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 |
Brian Jakubik 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 |
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03676 seconds