PDA

View Full Version : Best practice to create custom widgets



zaccret
15 May 2008, 3:56 AM
Hi,

I would like to create a custom widget (using the gxt Item widget). What is the best way to do that :
- just extend Item
- extend Composite using Item
- other ?

gslender
15 May 2008, 12:58 PM
Look at BoxComponent

zaccret
15 May 2008, 10:23 PM
I've just looked now at BoxComponent and Component. From Component javadoc, I saw
All visual widgets that require rendering into a layout should subclass Component (or {@link BoxComponent} if managed box model handling is required). Can we consider this is ok for custom components and not only for gxt internal use ? For example, in GWT, every internal widget is subclassing Widget but they recommand to subclass Composite for custom widgets.

darrellmeyer
15 May 2008, 11:29 PM
If you want to create a GXT widget then you will want to subclass Component or BoxComponent. BoxComponent should be used if the component can be sized. If you are creating a "container" then you can extends one of the container classes.

Keep in mind, you can mix and match GXT and GWT widgets. If you want to create a GXT component I would recommend taking a look at any of the existing widgets starting with Component.

zaccret
28 May 2008, 9:39 AM
When you want a Container with a layout, you should subclass LayoutContainer.
Actually, something is confusing me, there is (not private) layout stuff in the Container class. So at the beginning, I thought I had to subclass Container instead of LayoutContainer.

gslender
28 May 2008, 12:45 PM
I agree, there should be some kind of docs advising against use or a runtime exception on classes that try to extend Container as this may cause many problems. At first glance (and if you've used other UIs) you would think Container is the right place to start... but alas its not.

darrellmeyer
29 May 2008, 3:32 PM
Extending Container is perfectly acceptable and is done by many GXT components such as Table and Tree. The layout code is in Container but is marked protected. This allows Container subclasses to use layouts without making them public as in the case of TabPanel, which uses a CardLayout which should not be changed by the user. LayoutContainer should be extended if you want to expose layouts and the add / insert / remove methods on your subclass.


I agree, there should be some kind of docs advising against use or a runtime exception on classes that try to extend Container as this may cause many problems. At first glance (and if you've used other UIs) you would think Container is the right place to start... but alas its not.As mentioned about, it is acceptable to extend both Container and LayoutContainer. There are already comments in Container stating what subclasses are required to do.

nbourdeau
13 Jun 2008, 5:30 AM
I want to create a custom widget in Ext (not GWT).
What I understand is i have to extend the Component class. But after ?
Is here somewhere I can find some doc or howto for creating custom widgets in Ext ?

googelybear
21 Feb 2009, 9:11 PM
I would be interested in some general rules or guidelines on how to create custom widgets. As I'm having some serious layouting and performance issues with my custom components.

I've already found the very minimal doc at http://extjs.com/learn/Ext_GWT_FAQ#How_to_create_custom_components.3F

Unfortunately there are lots of different opinions about this on the forum and some "official" rules would be really helpful - or is there already something out there and I missed it?

googelybear
23 Feb 2009, 3:12 PM
Today I found out that setting setAutoHeight(true) on my panels actually resolves a lot of my sizing issues. The panels have no explicit height set and contain several other widgets. With auto-height they get automatically resized whenever I add more widgets. What do you think, is auto-height a good idea for this purpose?

googelybear
25 Feb 2009, 7:42 AM
As it turned auto height:auto works fine on Firefox but not on IE...somehow the height is not correctly calculated and some parts of the page are cut off :-( Any suggestions?