Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JavaServer Faces » Need some support about Web Page Editor
Need some support about Web Page Editor [message #476003] Sat, 30 August 2008 06:47 Go to next message
Khai Huynh is currently offline Khai HuynhFriend
Messages: 6
Registered: July 2009
Junior Member
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 #476004 is a reply to message #476003] Tue, 02 September 2008 18:10 Go to previous messageGo to next message
Cameron Bateman is currently offline Cameron BatemanFriend
Messages: 481
Registered: July 2009
Senior Member
> 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 #476005 is a reply to message #476004] Wed, 03 September 2008 10:11 Go to previous messageGo to next message
Khai Huynh is currently offline Khai HuynhFriend
Messages: 6
Registered: July 2009
Junior Member
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 #476006 is a reply to message #476005] Wed, 03 September 2008 10:39 Go to previous message
Khai Huynh is currently offline Khai HuynhFriend
Messages: 6
Registered: July 2009
Junior Member
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 18:10 Go to previous message
Cameron Bateman is currently offline Cameron BatemanFriend
Messages: 481
Registered: July 2009
Senior Member
> 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 10:11 Go to previous message
Khai Huynh is currently offline Khai HuynhFriend
Messages: 6
Registered: July 2009
Junior Member
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 10:39 Go to previous message
Khai Huynh is currently offline Khai HuynhFriend
Messages: 6
Registered: July 2009
Junior Member
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
Previous Topic:Need some support about Web Page Editor
Next Topic:JSF taglib directive mistakenly inserted
Goto Forum:
  


Current Time: Thu Apr 25 04:59:13 GMT 2024

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

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

Back to the top