« [News] VUG meeting wednesday | Main | [Quiz] Binary fun »
June 02, 2008
[Article] Accordion tab panels
by David Workman and Troy Elliott
Data Mosaic
Introduction
Accordion tabs can be the answer when you start running out of room to put secondary information. Compared to traditional tab panels, the "tabs" take up the y-axis of space instead of the x-axis making them great for long side columns.
While not as straight forward to code as traditional custom tab panels, the code in this sample solution will work in most situations with little to no modification.
Accordion tab panels are a cool addition to your UI bag of tricks that your users will like. Enjoy!
How it works
An accordion tab panel has three distinct objects: the tab panel, tab bars (the "tabs"), and arrow graphics. These are arranged with uniform width in a vertical space.
Each tab bar is linked to a specific tab panel tab. When clicked, that tab is selected in the tab panel. The tab panel is expanded to a default or specified height (see meta data) and moved to just below the selected tab bar. Subsequent tab bars are moved below the bottom of the tab panel. This little bit is where most of the coding complexity is involved.
You can click on a selected tab bar to "collapse" that tab. This will result in all tab bars in a "closed" or "unselected" state. No tab panel will show in this case.
Besides the positioning of the tab panel just below the selected tab bar, the "selected" state is further differentiated from the "unselected" state in three ways: the background color of the tab bar, the label color (foreground color) of the tab bar, and the direction the arrow graphic is pointing.
What you need: Objects
1) A tab panel named "tab_sidebar_a". You can have multiple accordion tabs on a form by using the naming convention "tab_sidebar_b", "tab_sidebar_c", etc.
2) A tab bar for each tab in the tab panel. Name "bar_a_1", "bar_a_2", etc. Specify a text property for each tab bar to give a label for the tab.
3) Arrow graphics for each tab bar. Name "bar_a_1_arrow", "bar_a_2_arrow", etc. Assign "arrow_right.png" to the imageMedia property.
What you need: Methods
1) An initialize method: "TAB_accordion_init". This should run on the onShow event of the form. You would think that the form onLoad event would be the appropriate place but this event triggers before the form objects are loaded. Which makes it a bit difficult to setup initial form object states
Even though the code is fired on the onShow event, it has logic to only fire once per form in memory.
2) The tab controller method: "TAB_change_accordion". Assign this to the onAction event of each tab bar.
Both methods are abstracted to work with an unlimited number of accordion tab panels throughout your solution using the naming conventions specified above.
Optional: Using meta data
There is default bar colors and a tab panel height specification in the methods. For each accordion tab panel in your solution, you can configure these properties by creating a meta data record. Our code will check to see if a meta data record exists before using the default properties.
Steps:
1) Create a meta data record. Specify the form name and the accordion tab panel name. Every accordion tab panel on a form will need it's own meta data record.
2) Specify the selected and unselected colors of the tab bars. Note that the foreground color is for the label of the tab bar.
3) You can specify the height of the tab panel for each individual tab bar (in pixels). The default will fill the vertical space of the accordion tab panel area.
| Posted by David Workman on June 2, 2008 at 12:37 PM in Articles | Permalink
Comments
Newbie here trying to import this sample into 4.0.
I'm getting an error on solution import
Importing accordion.servoy...
[info] Import contains XML version 12 and repository version 31.
[error] Server 'data' does not exist. Import failed.
[error] com.servoy.j2db.persistence.RepositoryException: Operation cancelled
What do I need to do to make this work?
Posted by: Keith Schuster | Jul 1, 2008 6:22:52 PM
Create a database connection called "data" first before importing.
Also keep in mind that the sample solution was created in 3.5. In general we're getting good results with our 3.5 apps in 4.0 but this accordion stuff we haven't tested yet in 4.0.
Posted by: David Workman | Jul 1, 2008 6:27:07 PM


