Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » DOM object
DOM object [message #713910] Tue, 09 August 2011 11:15 Go to next message
Mathew Missing name is currently offline Mathew Missing name
Messages: 6
Registered: August 2011
Junior Member
I'm fighting with this all the morning and can't see any entry point.
In my plugin I'm extending XMLMultiPageEditorPart and providing some visual preview to them. I would like also to show this xml document in another view (from another point of view also). These two "items" (editor and view) should work on the same model (I assume it would be IDOMModel/IDOMDocument). But...

How to get DOM model from mentioned editor? I've got access to StructuredTextEditor, but can't see how to get to xml tree.

Greetings
Mathew
Re: DOM object [message #714343 is a reply to message #713910] Wed, 10 August 2011 11:29 Go to previous messageGo to next message
Mathew Missing name is currently offline Mathew Missing name
Messages: 6
Registered: August 2011
Junior Member
to anyone interested:
	private IDocument getXmlDocument() {
		StructuredTextEditor textEditor = (StructuredTextEditor) getAdapter(StructuredTextEditor.class);
		IDocumentProvider provider = textEditor.getDocumentProvider();
		IDocument document = provider.getDocument(textEditor.getEditorInput());
		return document;
	}

	private IDOMModel getXmlModel() {
		IDocument document = getXmlDocument();
		IStructuredModel model = null;
		model = StructuredModelManager.getModelManager()
				.getExistingModelForEdit(document);
		IDOMModel dom = (IDOMModel) model;
		return dom;
	}
Re: DOM object [message #714587 is a reply to message #714343] Thu, 11 August 2011 00:25 Go to previous message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2277
Registered: July 2009
Senior Member
On 8/10/2011 7:29 AM, Mathew wrote:
> to anyone interested:
> private IDocument getXmlDocument() {
> StructuredTextEditor textEditor = (StructuredTextEditor)
> getAdapter(StructuredTextEditor.class);
> IDocumentProvider provider = textEditor.getDocumentProvider();
> IDocument document = provider.getDocument(textEditor.getEditorInput());
> return document;
> }
>
> private IDOMModel getXmlModel() {
> IDocument document = getXmlDocument();
> IStructuredModel model = null;
> model = StructuredModelManager.getModelManager()
> .getExistingModelForEdit(document);
> IDOMModel dom = (IDOMModel) model;
> return dom;
> }

Don't forget to call #releaseFromEdit() on the model when you're done.

You might also consider decoupling the view from the editor--the
selection sent across the workbench's selection service should contain
DOM Nodes, from which you can access the DOM Document and model if needed.

http://www.eclipse.org/articles/Article-WorkbenchSelections/article.html
http://wiki.eclipse.org/New_Help_for_Old_Friends_IV#Selection_in_the_XML.2FHTML.2FJSP_Editors

--
Nitin Dahyabhai
Eclipse WTP Source Editing and JSDT
IBM Rational


---
Nitin Dahyabhai
Eclipse WTP, IBM
Previous Topic:associate a project with server
Next Topic:Axis web service wsdl file being altered after deploying to application server
Goto Forum:
  


Current Time: Tue Sep 23 22:30:00 GMT 2014

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

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