Using FormEditor with a single page
January 4th, 2008 | Published in Rich Client Platform, Tips | 6 Comments
I tried to think of a snazzier title for this post, but I’m in a literal mood I guess. So have you ever faced this problem? You want to use the FormEditor class (or it’s new subclass SharedHeaderFormEditor), but you only have a single page.
Sure, you can use FormEditor with a single page, but you’ll wind up with a single tab at the bottom of the editor. It looks a bit goofy:

Well the solution is surprisingly simple. In your subclass of FormEditor, just override the createPages method like this:
protected void createPages() {
super.createPages();
if (getPageCount() == 1 &&
getContainer() instanceof CTabFolder) {
((CTabFolder) getContainer()).setTabHeight(0);
}
}
This code hides the tabs when there is only one page, and you wind up with this:

Note that you need to call the super method before resizing the tab height, or this won’t work.



Patrick on the RCP Panel at EclipseCon
January 4th, 2008 at 9:55 pm (#)
I don’t think making the method public is a good idea.
January 4th, 2008 at 11:44 pm (#)
Thanks, Remy. That was a typo and it’s now fixed.
January 5th, 2008 at 2:48 am (#)
I enjoyed this installment of “stupid editor tricks” :)
I think this should be the default behavior of FormEditor, so that clients don’t have to worry about overriding it.
January 10th, 2008 at 11:59 am (#)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=74811
July 26th, 2010 at 6:08 am (#)
Oh ~ thank you ,big master
hut how to save what you are editing?
July 27th, 2010 at 9:47 am (#)
Hi idiotgenius,
Glad you found this tip helpful. As for saving, form editors rely on AbstractFormParts which generally map to form sections. Form parts are registered with the ManagedForm controller and then notified when a save has been requested (commit method is called). You can take whatever action you like in the commit method.
The PDE editors can serve as a good example here. Check out the org.eclipse.pde.ui source bundle and examine the source code.
Hope this helps,
— Patrick