I want to sort a tree after building it from a XUL template, but I can't sort the tree until it has finished building, and nsIXULTemplateBuilder doesn't have any public interfaces for determining the status of its asynchronous builds. http://lxr.mozilla.org/seamonkey/source/rdf/base/idl/nsIXULTemplateBuilder.idl MailNews accomplishes this task with nsIMsgViewNavigationService's EnsureDocumentIsLoaded method, and Address Book does the same thing (tagged with a "fix me" that says Address Book should not be reliant on this MailNews-specific interface), so it isn't just an issue for my custom XUL-based application. http://lxr.mozilla.org/seamonkey/source/mailnews/addrbook/resources/content/abCommon.js#363 What I'd like is the equivalent of what nsIRDFXMLSink provides for asynchronously loading datasources (observers for begin/interrupt/resume/end/error events on the build) or perhaps more simply just a boolean "built" property of the builder object that tells me whether the build is complete or not (like the boolean "loaded" property of nsIRDFRemoteDataSource). http://lxr.mozilla.org/seamonkey/source/rdf/base/idl/nsIRDFRemoteDataSource.idl#35
For asynchronously loading content, the builder doesn't know any more than you do. Only the datasource knows. Observe those datasource.
I *am* observing the datasource. I don't do anything until the datasource is completely loaded (per nsIRDFXMLSink), then I add the datasource to the tree (per tree.database.AddDataSource), rebuild the tree (per tree.builder.rebuild), and sort the tree (per nsIXULSortService's Sort method). Doing this throws an exception, but if I wait a few seconds after building the tree to sort it then it works, which leads me to believe the tree can't be rebuilt and sorted simultaneously, and that's why I want to know the status of the build. Chris, your suggestion to watch the datasource makes it sound like if the datasource is loaded the tree is built, but that doesn't make much sense if the builder itself waits for the datasource to complete loading before commencing the rebuilding process. If the issue is that tree building and sorting should be able to take place at the same time and it shouldn't be necessary to wait for the former to complete before commencing the latter then perhaps I need to file a bug on the exception being thrown?
I'm not sure exactly what you're doing, so it's hard for me to comment. I do know that the XUL template builder's "rebuild()" method is synchronous. It will not return until it's done building all the content that it can. I also think that you can set the "sort" for the tree (or whatever) before you start putting content into it. The builder should obey your sort criteria. That might be easier (and faster) than building unsorted, then re-sorting.
tever is not RDF QA anymore