Need some support about Web Page Editor [message #476003] |
Sat, 30 August 2008 02:47  |
Eclipse User |
|
|
|
Hello,
My Name's Khai Huynh, I'm Vietnamese student. I have just install Eclipse
WTP, I want to use "Web Page Editor" to design my html file, then I
implement a plug-in which get content of "Web Page Editor" (get content of
file html which I'm designing).
But I have problem about get content of "Web Page Editor". The follow code
which is OK when I use some other text-editor, but it don't work when I use
"Web Page Editor":
//---------------------------------------------------------- ----------
IDocumentProvider documentProvider;
ITextEditor textEditor = (ITextEditor)
window.getPages()[0].getActiveEditor();
documentProvider = textEditor.getDocumentProvider();
IDocument document;
document =
documentProvider.getDocument(window.getPages()[0].getActiveE ditor().getEditorInput());
// then document variable will contain the content of current editor, but
it
doesn't work with Web Page Editor
//---------------------------------------------------------- ----------
Can you help me to get content of Web Page Editor?
Can you give the sample code to get content of Web Page Editor?
Looking for your respond,
Thank you very much,
Best regards,
Khai Huynh
|
|
|
|
|
Re: Need some support about Web Page Editor [message #476006 is a reply to message #476005] |
Wed, 03 September 2008 06:39  |
Eclipse User |
|
|
|
Dear Cam,
I am sorry, I just found my solution. It is create one ITextEditor from
IEditorPart:
ITextEditor textEditor = (ITextEditor)
editorPart.getAdapter(ITextEditor.class);
And then, I work with textEditor, this is my old work.
This solution base on your respond. So, thank you very much.
Best regards,
Khai Huynh
|
|
|
Re: Need some support about Web Page Editor [message #618337 is a reply to message #476003] |
Tue, 02 September 2008 14:10  |
Eclipse User |
|
|
|
> IDocumentProvider documentProvider;
> ITextEditor textEditor = (ITextEditor)
> window.getPages()[0].getActiveEditor();
> documentProvider = textEditor.getDocumentProvider();
> IDocument document;
> document =
> documentProvider.getDocument(window.getPages()[0].getActiveE ditor
> ().getEditorInput());
Try instead:
IEditorPart editorPart = window.getPages()[0].getActiveEditor();
IDocument document = (IDocument) editorPart.getAdapter(IDocument.class);
if (document != null)
...
--Cam
|
|
|
Re: Need some support about Web Page Editor [message #618339 is a reply to message #476004] |
Wed, 03 September 2008 06:11  |
Eclipse User |
|
|
|
Dear Cam,
Thank you very much for your respond!
But I have one problem about the current position of cursor. How do I get
the current position of cursor?
In my previous code which work with text-editor, I use: (textEditor is
ITextEditor)
/*************************************************/
ITextSelection textSelection = (ITextSelection)
textEditor.getSelectionProvider().getSelection();
System.out.println(textSelection.getOffset());
// It println the current position of cursor
/*************************************************/
But it don't work with WPE,
Follow the new way which you help me to get content of html file, I change
my code:
/*************************************************/
IEditorPart editorPart = window.getPages()[0].getActiveEditor();
ITextSelection textSel = (ITextSelection)
editorPart.getAdapter(ITextSelection.class);
System.out.println(textSel.getOffset());
/*************************************************/
But It don't work, I catch NullPointerException, I think my way is wrong
way.
Would you help me to get the current position of cursor?
Thank you very much!
Best Regards!
Khai Huynh
|
|
|
Re: Need some support about Web Page Editor [message #618341 is a reply to message #476005] |
Wed, 03 September 2008 06:39  |
Eclipse User |
|
|
|
Dear Cam,
I am sorry, I just found my solution. It is create one ITextEditor from
IEditorPart:
ITextEditor textEditor = (ITextEditor)
editorPart.getAdapter(ITextEditor.class);
And then, I work with textEditor, this is my old work.
This solution base on your respond. So, thank you very much.
Best regards,
Khai Huynh
|
|
|
Powered by
FUDForum. Page generated in 0.04803 seconds