Nice! I now do it like this:
private class InitializeModuleListener extends
AccordionSelectionListener.Adapter {
private List<Component> initializedComponents = new
ArrayList<Component>();
public void selectedIndexChanged(Accordion accordion, int
previousSelectedIndex) {
Component selected = accordion.getSelectedPanel();
if (!initializedComponents.contains(selected) && selected
instanceof Initializable) {
((Initializable) selected).initialize();
initializedComponents.add(selected);
}
}
}
This way, each Module (the panel added to the Accordion) just implement
my Initializable interface if it wants to do lazy loading, and I don't
need to keep initialized state in each component. Much cleaner :)
I don't need to either veto or show progress indicator for now, each
panel loads fairly quickly, but loading all at once could take a couple
of seconds. By the way, my BRAP Remoting (http://brap.tornado.no) is a
perfect fit for Pivot applications :) hehe..
-- Edvin
Den 12.06.2011 12:38, skrev Chris Bartlett:
Could you use an AccordionSelectionListener which would intercept any
panel selection change requests via the previewSelectedIndexChange() method?
http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/AccordionSelectionListener.html#previewSelectedIndexChange(org.apache.pivot.wtk.Accordion,
int)
It could keep track of the panels that have been initialized, and Veto
the selection change until the panel is ready to be displayed. (Disable
the panel / show a busy cursor / show an ActivityIndicator / etc)
http://pivot.apache.org/tutorials/activity-indicators.html
If you don't want to actually Veto the change, you could just use the
event as a notification to start initializing the panel.
If you want to show an ActivityIndicator while the panel loads, you
could use a StackPane as per the iTunes search demo
http://pivot.apache.org/demos/itunes-search.html
http://svn.apache.org/repos/asf/pivot/trunk/demos/src/org/apache/pivot/demos/itunes/
Chris
On 12 June 2011 15:59, Edvin Syse <[email protected]
<mailto:[email protected]>> wrote:
My Pivot App uses JDK ServiceLoader to load "modules" for an
Accordion. Some of the modules will pull data from a remote server
and do some initialization when created so I want to do it when each
panel is shown for the first time.
I want to check if my approach is viable: Most Panels are
ScrollPanes, and they are ofcourse unexpensive to create. I then
override the layout() method and to something like:
protected void layout() {
if (!initialized) {
setColumnHeader(createColumnHeader());
setView(createView());
initialized = true;
}
super.layout();
}
This seems to work, but is it an OK approach?
-- Edvin