Home » Eclipse Projects » Eclipse Platform » Text Editor problem.
Text Editor problem. [message #323887] |
Fri, 11 January 2008 03:49  |
Eclipse User |
|
|
|
Hi,
I'm now working on a text editor of my own. The only difference between
my editor and the standard text editor is that the input of my editor is
a string which is built myself( actually, I parse an xml, and make a
string according to the content of the xml).
So, I extended the org.eclipse.ui.editors.text.TextEditor, and the
AbstractDocumentProvider.
In the DocumentProvider class, I only override the createDocument method.
@Override
protected IDocument createDocument(Object element) throws CoreException {
if (element instanceof IEditorInput) {
IDocument document= createEmptyDocument();
if (setDocumentContent(document, (IEditorInput) element, null)) { // in
the setDocumentContent method, I only call the document.set() to set //
the content of the document.
return document;
}
}
return null;
}
as of the other method of this class, do nothing special.
And in the editor's class, only called the setDocumentprovider() in the
constructor.
It can now display the string I give to it, but cann't edit (just like
"readonly"), and there is now ruler in the left side even if I chose to
display the line number.
What else should I do to edit the content and to display the ruler in
the side?
Any suggestion is welcome and may be great help to me.
Thanks.
--
*/Dollyn/*
|
|
|
Re: Text Editor problem. [message #323902 is a reply to message #323887] |
Fri, 11 January 2008 13:21   |
Eclipse User |
|
|
|
Try providing something like these overrides in your DocumentProvider:
/*
* @see
org.eclipse.ui.texteditor.IDocumentProviderExtension#isModif iable(java.lang.Object)
*/
public boolean isModifiable(Object element) {
if (element instanceof IPathEditorInput) {
IPathEditorInput pei= (IPathEditorInput) element;
File file= pei.getPath().toFile();
return file.canWrite() || !file.exists(); // Allow to edit new files
}
return false;
}
/*
* @see
org.eclipse.ui.texteditor.IDocumentProviderExtension#isReadO nly(java.lang.Object)
*/
public boolean isReadOnly(Object element) {
return !isModifiable(element);
}
Dollyn wrote:
> Hi,
> I'm now working on a text editor of my own. The only difference between
> my editor and the standard text editor is that the input of my editor is
> a string which is built myself( actually, I parse an xml, and make a
> string according to the content of the xml).
>
> So, I extended the org.eclipse.ui.editors.text.TextEditor, and the
> AbstractDocumentProvider.
>
> In the DocumentProvider class, I only override the createDocument method.
>
> @Override
> protected IDocument createDocument(Object element) throws CoreException {
>
> if (element instanceof IEditorInput) {
> IDocument document= createEmptyDocument();
> if (setDocumentContent(document, (IEditorInput) element, null)) { // in
> the setDocumentContent method, I only call the document.set() to set //
> the content of the document.
> return document;
> }
> }
>
> return null;
> }
>
> as of the other method of this class, do nothing special.
>
> And in the editor's class, only called the setDocumentprovider() in the
> constructor.
>
> It can now display the string I give to it, but cann't edit (just like
> "readonly"), and there is now ruler in the left side even if I chose to
> display the line number.
>
> What else should I do to edit the content and to display the ruler in
> the side?
>
> Any suggestion is welcome and may be great help to me.
>
> Thanks.
>
|
|
|
Re: Text Editor problem. [message #323932 is a reply to message #323902] |
Sun, 13 January 2008 22:03   |
Eclipse User |
|
|
|
Thanks for your help! The content is now editable.
But the line number is still unvisable, even if I select the "show line
number" in the prefereces page.
Is this some thing matter with the document provider? Or, it is just
needed to modify the Editor class?
But I just extended the TextEdotor directly, and the TextEditor can show
the ruler.
By the way, my editor is under a rcp program, I donn't know whether this
is relational.
Francis Upton wrote:
> Try providing something like these overrides in your DocumentProvider:
>
> /*
> * @see
> org.eclipse.ui.texteditor.IDocumentProviderExtension#isModif iable(java.lang.Object)
> */
> public boolean isModifiable(Object element) {
> if (element instanceof IPathEditorInput) {
> IPathEditorInput pei= (IPathEditorInput) element;
> File file= pei.getPath().toFile();
> return file.canWrite() || !file.exists(); // Allow to edit new files
> }
> return false;
> }
>
> /*
> * @see
> org.eclipse.ui.texteditor.IDocumentProviderExtension#isReadO nly(java.lang.Object)
> */
> public boolean isReadOnly(Object element) {
> return !isModifiable(element);
> }
>
>
>
> Dollyn wrote:
>
>> Hi,
>> I'm now working on a text editor of my own. The only difference between
>> my editor and the standard text editor is that the input of my editor is
>> a string which is built myself( actually, I parse an xml, and make a
>> string according to the content of the xml).
>>
>> So, I extended the org.eclipse.ui.editors.text.TextEditor, and the
>> AbstractDocumentProvider.
>>
>> In the DocumentProvider class, I only override the createDocument method.
>>
>> @Override
>> protected IDocument createDocument(Object element) throws CoreException {
>>
>> if (element instanceof IEditorInput) {
>> IDocument document= createEmptyDocument();
>> if (setDocumentContent(document, (IEditorInput) element, null)) { // in
>> the setDocumentContent method, I only call the document.set() to set //
>> the content of the document.
>> return document;
>> }
>> }
>>
>> return null;
>> }
>>
>> as of the other method of this class, do nothing special.
>>
>> And in the editor's class, only called the setDocumentprovider() in the
>> constructor.
>>
>> It can now display the string I give to it, but cann't edit (just like
>> "readonly"), and there is now ruler in the left side even if I chose to
>> display the line number.
>>
>> What else should I do to edit the content and to display the ruler in
>> the side?
>>
>> Any suggestion is welcome and may be great help to me.
>>
>> Thanks.
>>
>>
--
*/Dollyn/*
|
|
|
Re: Text Editor problem. [message #323933 is a reply to message #323932] |
Sun, 13 January 2008 22:29   |
Eclipse User |
|
|
|
Make sure you subclass from AbstractDecoratedTextEditor, that has the
line number stuff, and it should just work with the preferences.
This will work fine with an RCP app.
Dollyn wrote:
> Thanks for your help! The content is now editable.
>
> But the line number is still unvisable, even if I select the "show line
> number" in the prefereces page.
> Is this some thing matter with the document provider? Or, it is just
> needed to modify the Editor class?
> But I just extended the TextEdotor directly, and the TextEditor can show
> the ruler.
>
> By the way, my editor is under a rcp program, I donn't know whether this
> is relational.
>
> Francis Upton wrote:
>> Try providing something like these overrides in your DocumentProvider:
>>
>> /*
>> * @see
>> org.eclipse.ui.texteditor.IDocumentProviderExtension#isModif iable(java.lang.Object)
>> */
>> public boolean isModifiable(Object element) {
>> if (element instanceof IPathEditorInput) {
>> IPathEditorInput pei= (IPathEditorInput) element;
>> File file= pei.getPath().toFile();
>> return file.canWrite() || !file.exists(); // Allow to edit new files
>> }
>> return false;
>> }
>>
>> /*
>> * @see
>> org.eclipse.ui.texteditor.IDocumentProviderExtension#isReadO nly(java.lang.Object)
>> */
>> public boolean isReadOnly(Object element) {
>> return !isModifiable(element);
>> }
>>
>>
>>
>> Dollyn wrote:
>>
>>> Hi,
>>> I'm now working on a text editor of my own. The only difference between
>>> my editor and the standard text editor is that the input of my editor is
>>> a string which is built myself( actually, I parse an xml, and make a
>>> string according to the content of the xml).
>>>
>>> So, I extended the org.eclipse.ui.editors.text.TextEditor, and the
>>> AbstractDocumentProvider.
>>>
>>> In the DocumentProvider class, I only override the createDocument method.
>>>
>>> @Override
>>> protected IDocument createDocument(Object element) throws CoreException {
>>>
>>> if (element instanceof IEditorInput) {
>>> IDocument document= createEmptyDocument();
>>> if (setDocumentContent(document, (IEditorInput) element, null)) { // in
>>> the setDocumentContent method, I only call the document.set() to set //
>>> the content of the document.
>>> return document;
>>> }
>>> }
>>>
>>> return null;
>>> }
>>>
>>> as of the other method of this class, do nothing special.
>>>
>>> And in the editor's class, only called the setDocumentprovider() in the
>>> constructor.
>>>
>>> It can now display the string I give to it, but cann't edit (just like
>>> "readonly"), and there is now ruler in the left side even if I chose to
>>> display the line number.
>>>
>>> What else should I do to edit the content and to display the ruler in
>>> the side?
>>>
>>> Any suggestion is welcome and may be great help to me.
>>>
>>> Thanks.
>>>
>>>
>
|
|
|
Re: Text Editor problem. [message #323934 is a reply to message #323933] |
Mon, 14 January 2008 00:46   |
Eclipse User |
|
|
|
Yes, I subclass the AbstractDecoratedTextEditor ,and do nothing except
the constructor:
super();
setDocumentProvider();
But the linenumber can not be seen. I checked the TextEditor class, and
find nothing special in it, so I donn't know what else should I do.
Francis Upton wrote:
> Make sure you subclass from AbstractDecoratedTextEditor, that has the
> line number stuff, and it should just work with the preferences.
>
> This will work fine with an RCP app.
>
> Dollyn wrote:
>
>> Thanks for your help! The content is now editable.
>>
>> But the line number is still unvisable, even if I select the "show line
>> number" in the prefereces page.
>> Is this some thing matter with the document provider? Or, it is just
>> needed to modify the Editor class?
>> But I just extended the TextEdotor directly, and the TextEditor can show
>> the ruler.
>>
>> By the way, my editor is under a rcp program, I donn't know whether this
>> is relational.
>>
>> Francis Upton wrote:
>>
>>> Try providing something like these overrides in your DocumentProvider:
>>>
>>> /*
>>> * @see
>>> org.eclipse.ui.texteditor.IDocumentProviderExtension#isModif iable(java.lang.Object)
>>> */
>>> public boolean isModifiable(Object element) {
>>> if (element instanceof IPathEditorInput) {
>>> IPathEditorInput pei= (IPathEditorInput) element;
>>> File file= pei.getPath().toFile();
>>> return file.canWrite() || !file.exists(); // Allow to edit new files
>>> }
>>> return false;
>>> }
>>>
>>> /*
>>> * @see
>>> org.eclipse.ui.texteditor.IDocumentProviderExtension#isReadO nly(java.lang.Object)
>>> */
>>> public boolean isReadOnly(Object element) {
>>> return !isModifiable(element);
>>> }
>>>
>>>
>>>
>>> Dollyn wrote:
>>>
>>>
>>>> Hi,
>>>> I'm now working on a text editor of my own. The only difference between
>>>> my editor and the standard text editor is that the input of my editor is
>>>> a string which is built myself( actually, I parse an xml, and make a
>>>> string according to the content of the xml).
>>>>
>>>> So, I extended the org.eclipse.ui.editors.text.TextEditor, and the
>>>> AbstractDocumentProvider.
>>>>
>>>> In the DocumentProvider class, I only override the createDocument method.
>>>>
>>>> @Override
>>>> protected IDocument createDocument(Object element) throws CoreException {
>>>>
>>>> if (element instanceof IEditorInput) {
>>>> IDocument document= createEmptyDocument();
>>>> if (setDocumentContent(document, (IEditorInput) element, null)) { // in
>>>> the setDocumentContent method, I only call the document.set() to set //
>>>> the content of the document.
>>>> return document;
>>>> }
>>>> }
>>>>
>>>> return null;
>>>> }
>>>>
>>>> as of the other method of this class, do nothing special.
>>>>
>>>> And in the editor's class, only called the setDocumentprovider() in the
>>>> constructor.
>>>>
>>>> It can now display the string I give to it, but cann't edit (just like
>>>> "readonly"), and there is now ruler in the left side even if I chose to
>>>> display the line number.
>>>>
>>>> What else should I do to edit the content and to display the ruler in
>>>> the side?
>>>>
>>>> Any suggestion is welcome and may be great help to me.
>>>>
>>>> Thanks.
>>>>
>>>>
>>>>
--
*/Dollyn/*
|
|
|
Re: Text Editor problem. [message #323935 is a reply to message #323933] |
Mon, 14 January 2008 01:14   |
Eclipse User |
|
|
|
It is the case that there is something wrong with my document provider.
I returned a null in the createAnnotationModel method. And now, I give
it an instance, the line number can be seen now.
It seems that the text editor framwork is somewhat complex to me. :)
Francis Upton wrote:
> Make sure you subclass from AbstractDecoratedTextEditor, that has the
> line number stuff, and it should just work with the preferences.
>
> This will work fine with an RCP app.
>
> Dollyn wrote:
>
>> Thanks for your help! The content is now editable.
>>
>> But the line number is still unvisable, even if I select the "show line
>> number" in the prefereces page.
>> Is this some thing matter with the document provider? Or, it is just
>> needed to modify the Editor class?
>> But I just extended the TextEdotor directly, and the TextEditor can show
>> the ruler.
>>
>> By the way, my editor is under a rcp program, I donn't know whether this
>> is relational.
>>
>> Francis Upton wrote:
>>
>>> Try providing something like these overrides in your DocumentProvider:
>>>
>>> /*
>>> * @see
>>> org.eclipse.ui.texteditor.IDocumentProviderExtension#isModif iable(java.lang.Object)
>>> */
>>> public boolean isModifiable(Object element) {
>>> if (element instanceof IPathEditorInput) {
>>> IPathEditorInput pei= (IPathEditorInput) element;
>>> File file= pei.getPath().toFile();
>>> return file.canWrite() || !file.exists(); // Allow to edit new files
>>> }
>>> return false;
>>> }
>>>
>>> /*
>>> * @see
>>> org.eclipse.ui.texteditor.IDocumentProviderExtension#isReadO nly(java.lang.Object)
>>> */
>>> public boolean isReadOnly(Object element) {
>>> return !isModifiable(element);
>>> }
>>>
>>>
>>>
>>> Dollyn wrote:
>>>
>>>
>>>> Hi,
>>>> I'm now working on a text editor of my own. The only difference between
>>>> my editor and the standard text editor is that the input of my editor is
>>>> a string which is built myself( actually, I parse an xml, and make a
>>>> string according to the content of the xml).
>>>>
>>>> So, I extended the org.eclipse.ui.editors.text.TextEditor, and the
>>>> AbstractDocumentProvider.
>>>>
>>>> In the DocumentProvider class, I only override the createDocument method.
>>>>
>>>> @Override
>>>> protected IDocument createDocument(Object element) throws CoreException {
>>>>
>>>> if (element instanceof IEditorInput) {
>>>> IDocument document= createEmptyDocument();
>>>> if (setDocumentContent(document, (IEditorInput) element, null)) { // in
>>>> the setDocumentContent method, I only call the document.set() to set //
>>>> the content of the document.
>>>> return document;
>>>> }
>>>> }
>>>>
>>>> return null;
>>>> }
>>>>
>>>> as of the other method of this class, do nothing special.
>>>>
>>>> And in the editor's class, only called the setDocumentprovider() in the
>>>> constructor.
>>>>
>>>> It can now display the string I give to it, but cann't edit (just like
>>>> "readonly"), and there is now ruler in the left side even if I chose to
>>>> display the line number.
>>>>
>>>> What else should I do to edit the content and to display the ruler in
>>>> the side?
>>>>
>>>> Any suggestion is welcome and may be great help to me.
>>>>
>>>> Thanks.
>>>>
>>>>
>>>>
--
*/Dollyn/*
|
|
|
Re: Text Editor problem. [message #323936 is a reply to message #323935] |
Mon, 14 January 2008 02:34  |
Eclipse User |
|
|
|
I think it's complex to everyone. Thanks for your discovery and glad
you got it working.
Dollyn wrote:
> It is the case that there is something wrong with my document provider.
> I returned a null in the createAnnotationModel method. And now, I give
> it an instance, the line number can be seen now.
>
> It seems that the text editor framwork is somewhat complex to me. :)
>
> Francis Upton wrote:
>> Make sure you subclass from AbstractDecoratedTextEditor, that has the
>> line number stuff, and it should just work with the preferences.
>>
>> This will work fine with an RCP app.
>>
>> Dollyn wrote:
>>
>>> Thanks for your help! The content is now editable.
>>>
>>> But the line number is still unvisable, even if I select the "show line
>>> number" in the prefereces page.
>>> Is this some thing matter with the document provider? Or, it is just
>>> needed to modify the Editor class?
>>> But I just extended the TextEdotor directly, and the TextEditor can show
>>> the ruler.
>>>
>>> By the way, my editor is under a rcp program, I donn't know whether this
>>> is relational.
>>>
>>> Francis Upton wrote:
>>>
>>>> Try providing something like these overrides in your DocumentProvider:
>>>>
>>>> /*
>>>> * @see
>>>> org.eclipse.ui.texteditor.IDocumentProviderExtension#isModif iable(java.lang.Object)
>>>> */
>>>> public boolean isModifiable(Object element) {
>>>> if (element instanceof IPathEditorInput) {
>>>> IPathEditorInput pei= (IPathEditorInput) element;
>>>> File file= pei.getPath().toFile();
>>>> return file.canWrite() || !file.exists(); // Allow to edit new files
>>>> }
>>>> return false;
>>>> }
>>>>
>>>> /*
>>>> * @see
>>>> org.eclipse.ui.texteditor.IDocumentProviderExtension#isReadO nly(java.lang.Object)
>>>> */
>>>> public boolean isReadOnly(Object element) {
>>>> return !isModifiable(element);
>>>> }
>>>>
>>>>
>>>>
>>>> Dollyn wrote:
>>>>
>>>>
>>>>> Hi,
>>>>> I'm now working on a text editor of my own. The only difference between
>>>>> my editor and the standard text editor is that the input of my editor is
>>>>> a string which is built myself( actually, I parse an xml, and make a
>>>>> string according to the content of the xml).
>>>>>
>>>>> So, I extended the org.eclipse.ui.editors.text.TextEditor, and the
>>>>> AbstractDocumentProvider.
>>>>>
>>>>> In the DocumentProvider class, I only override the createDocument method.
>>>>>
>>>>> @Override
>>>>> protected IDocument createDocument(Object element) throws CoreException {
>>>>>
>>>>> if (element instanceof IEditorInput) {
>>>>> IDocument document= createEmptyDocument();
>>>>> if (setDocumentContent(document, (IEditorInput) element, null)) { // in
>>>>> the setDocumentContent method, I only call the document.set() to set //
>>>>> the content of the document.
>>>>> return document;
>>>>> }
>>>>> }
>>>>>
>>>>> return null;
>>>>> }
>>>>>
>>>>> as of the other method of this class, do nothing special.
>>>>>
>>>>> And in the editor's class, only called the setDocumentprovider() in the
>>>>> constructor.
>>>>>
>>>>> It can now display the string I give to it, but cann't edit (just like
>>>>> "readonly"), and there is now ruler in the left side even if I chose to
>>>>> display the line number.
>>>>>
>>>>> What else should I do to edit the content and to display the ruler in
>>>>> the side?
>>>>>
>>>>> Any suggestion is welcome and may be great help to me.
>>>>>
>>>>> Thanks.
>>>>>
>>>>>
>>>>>
>
|
|
|
Goto Forum:
Current Time: Thu Jul 10 02:55:30 EDT 2025
Powered by FUDForum. Page generated in 0.42327 seconds
|