Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » EditorPart.init() question
EditorPart.init() question [message #336569] Tue, 23 June 2009 22:37 Go to next message
Vsevolod Sandomirskiy is currently offline Vsevolod SandomirskiyFriend
Messages: 21
Registered: July 2009
Junior Member
My editor extends EditorPart and implements init(IEditorSite site,
IEditorInput input). In some cases init() detects that input is invalid,
and I have to show a message box and close the editor. What is the right
way to close the editor?

I guess I can call
getSite().getPage().closeEditor(this, false)
but I'm not sure init() should call that

Thanks.
Re: EditorPart.init() question [message #336570 is a reply to message #336569] Wed, 24 June 2009 00:01 Go to previous messageGo to next message
Ben Vitale is currently offline Ben VitaleFriend
Messages: 247
Registered: July 2009
Senior Member
There isn't a way in the framework to gracefully close the editor
immediately after detecting an invalid input. The best you can do is
throw a PartInitException which will display a special error part.
Unfortunately it's not very user friendly and will show them the
stacktrace if they expand the details button.

Alternatively, you could implement your own error part that displays in
the editor when it detects an invalid input. You could provide a close
button for them to click which would use the close API you mentioned.
Certainly you could automatically open a dialog box to prompt them to
close it but I'm unsure of the usability implications of this.

HTH
Ben

Vsevolod Sandomirskiy wrote:
> My editor extends EditorPart and implements init(IEditorSite site,
> IEditorInput input). In some cases init() detects that input is invalid,
> and I have to show a message box and close the editor. What is the right
> way to close the editor?
>
> I guess I can call
> getSite().getPage().closeEditor(this, false)
> but I'm not sure init() should call that
>
> Thanks.
Re: EditorPart.init() question [message #336571 is a reply to message #336569] Wed, 24 June 2009 04:21 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

Vsevolod Sandomirskiy wrote:
> My editor extends EditorPart and implements init(IEditorSite site,
> IEditorInput input). In some cases init() detects that input is invalid,
> and I have to show a message box and close the editor. What is the right
> way to close the editor?
>
> I guess I can call
> getSite().getPage().closeEditor(this, false)
> but I'm not sure init() should call that

I've done this on a past project, in editors that extend
org.eclipse.ui.forms.editor.FormEditor
In the init() method when I detected invalid input, I opened a JFace
MessageDialog offering the user the option of opening the file in a
plain text editor. If the user declined, I would just call
this.close(false) (inherited from
org.eclipse.ui.forms.editor.FormEditor). It worked fine for 3.3 and 3.4,
but has not been tested in Eclipse 3.5 yet.

Let me know if you can't find the code for FormEditor.close(boolean) and
I can post it. It is pretty simple, just calling the code you describe
above via Display.asyncExec().

Hope this helps,
Eric
Previous Topic:Getting wrong selection, sometimes
Next Topic:Exception when trying to update
Goto Forum:
  


Current Time: Sat Apr 20 01:42:19 GMT 2024

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

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

Back to the top