Skip to main content



      Home
Home » Language IDEs » ServerTools (WTP) » How to programatically get the content from a JavaScript editor
How to programatically get the content from a JavaScript editor [message #160080] Fri, 10 February 2006 05:27 Go to next message
Eclipse UserFriend
Originally posted by: zhling.gmail.com

Hi,

I want to get the content of a JavaScript editor (including dirty part).

Below code works well for ".java" and ".jsp" editor, but doesn't work for
".js" editor:

-------------------------------------------
IEditorPart part =
workbench.getActiveWorkbenchWindow().getActivePage().getActi veEditor();
ITextEditor texteditor = (ITextEditor)part;
IDocument doc =
texteditor.getDocumentProvider().getDocument(workbench.getAc tiveWorkbenchWindow().getActivePage().getActiveEditor().getE ditorInput());

System.out.println("Content in editor: " + doc.get());
-----------------------------------------------

The problem is "part" can not be casted to "ITextEditor", it's an instance
of "JSMultiPageEditorPart" class. Any ideas?

Thanks

- Zhang Ling
Re: How to programatically get the content from a JavaScript editor [message #160099 is a reply to message #160080] Fri, 10 February 2006 06:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kroka.atlas.cz

Hi, try this:

IEditorPart activeWin= this.window.getActivePage().getActiveEditor();
IDocument doc = ((ITextEditor)
activeWin).getDocumentProvider().getDocument(activeWin.getEd itorInput());
String text = doc.get();

krokan
Re: How to programatically get the content from a JavaScript editor [message #160295 is a reply to message #160080] Fri, 10 February 2006 16:31 Go to previous message
Eclipse UserFriend
Zhang Ling wrote:
> I want to get the content of a JavaScript editor (including dirty part).
>
> Below code works well for ".java" and ".jsp" editor, but doesn't work for
> ".js" editor:
>
> -------------------------------------------
> IEditorPart part =
> workbench.getActiveWorkbenchWindow().getActivePage().getActi veEditor();
> ITextEditor texteditor = (ITextEditor)part;
> IDocument doc =
> texteditor.getDocumentProvider().getDocument(workbench.getAc tiveWorkbenchWindow().getActivePage().getActiveEditor().getE ditorInput());
>
> System.out.println("Content in editor: " + doc.get());
> -----------------------------------------------
>
> The problem is "part" can not be casted to "ITextEditor", it's an instance
> of "JSMultiPageEditorPart" class. Any ideas?

Most of the WTP editors respond to a request for an adapter for
ITextEditor.class--except for the JavaScript editor. Next week's
1.5M5 build will have the fix.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=127340


This should work, then:

IEditorPart part =
workbench.getActiveWorkbenchWindow().getActivePage().getActi veEditor();
ITextEditor texteditor = null;
if(part instanceof ITextEditor) {
texteditor = (ITextEditor) part;
}
else {
texteditor = (ITextEditor) part.getAdapter(ITextEditor.class);
}
// hopefully you'd have a null check here
IDocument doc =
texteditor.getDocumentProvider().getDocument(workbench.getAc tiveWorkbenchWindow().getActivePage().getActiveEditor().getE ditorInput());
System.out.println("Content in editor: " + doc.get());


--
- Nitin
Previous Topic:extends CSSContentOutlineConfiguration
Next Topic:Publishing a webapp is not complete
Goto Forum:
  


Current Time: Thu Jul 03 17:32:02 EDT 2025

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

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

Back to the top