Bug 37982 - [EditorMgmt] Different behavior for EditorPart.init required
Summary: [EditorMgmt] Different behavior for EditorPart.init required
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-05-22 13:14 EDT by Jon Skeet CLA
Modified: 2019-09-06 16:16 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jon Skeet CLA 2003-05-22 13:14:45 EDT
I've just been writing a very simple editor, and it took me ages to work out
that I needed to call setSite(site) in order to avoid the NullPointerException I
was getting, and I had to ask in the newsgroup in order to work out to call
setInput(input). Presumably most editors will want to do this, so either it
should be documented clearly within the init() documentation that it's a good
thing to do, or perhaps the default behaviour should be changed so that it's not
required. I confess to still being an almost complete newbie to SWT/JFace, but
this kind of thing (which gives NPEs which really don't give much hint to the
newbie as to what they've done wrong) makes the learning curve very steep indeed.
Comment 1 Simon Arsenault CLA 2003-05-22 13:54:21 EDT
I've seen this problem arise may times with developers creating editors (and 
not just first timers - its easy to forget to make these two calls). The 
EditorPart.init method doc does state these two methods need to be call, but 
obviously that is not enough.

We should change the API here to fix this problem. Maybe we could make the init 
method final. In the EditorPart.init method, we could call the abstract method 
validateEditorInput which could throw a PartInitException if the subclass 
cannot accept the input. We could then set the site and editor input. Then 
maybe call something like an abstract "finishInit" method to allow the subclass 
to complete there initialization process. We could then make setSite and 
setInput non-accessible outside the framework.

Nick, can you assign to me if you agree with this and want the changes to go 
ahead. This would be a broken API change. But I see this as beneficial to 
developers.
Comment 2 Jon Skeet CLA 2003-05-22 14:46:12 EDT
Does the documentation really say it? Here's what I got from the online 2.1 docs:

<quote>
Initializes this editor with the given editor site and input.

This method is automatically called shortly after part construction; it marks
the start of the part's lifecycle. The IWorkbenchPart.dispose method will be
called automically at the end of the lifecycle. Clients must not call this method.

Implementors of this method must examine the editor input object type to
determine if it is understood. If not, the implementor must throw a
PartInitException.
</quote>

I took that to mean "Do whatever your particular editor needs to use the given
input and site."

Stating explicitly (if the API doesn't get changed or maybe until it does)
"during this method you should call setSite and setInput" would be good :)
Comment 3 Debbie Wilson CLA 2003-05-28 15:32:20 EDT
Awaiting comment from Nick.
Comment 4 Nick Edgar CLA 2003-05-29 14:24:25 EDT
Can we do it in a non-breaking way?
E.g.: change init to be non-abstract, and call a new method to check the input, 
which can be overridden?


public void init(IEditorSite site, IEditorInput input) throws PartInitException 
{
    checkInput(input);
    setSite(site);
    setInput(input);
}

protected void checkInput(IEditorInput input) throws PartInitException {
  // do nothing by default
}
Comment 5 Simon Arsenault CLA 2003-06-04 11:23:14 EDT
Jon - The doc on EditorPart.init (the class here, not the interface 
IEditorPart) does state that setSite and setInput must be call. Its an 
implementation detail for that class.

Nick - Yep, that is possible and we could update the doc about this. However, 
if we end up breaking other APIs on editor part for other reasons, I would like 
to then fix this problem properly by breaking the init api method.
Comment 6 Susan McCourt CLA 2009-07-09 19:02:53 EDT
As per http://wiki.eclipse.org/Platform_UI/Bug_Triage_Change_2009
Comment 7 Boris Bokowski CLA 2009-11-17 13:06:46 EST
Remy is now responsible for watching the [EditorMgmt] component area.
Comment 8 Eclipse Webmaster CLA 2019-09-06 16:16:20 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.