Is there a simple method to get whole navigation graph (tree) of all
registered sections/subsections? I have to make a navigation map and
I'd like it to be ganerated dynamically
If there's a method to list all regitered sections for a
SectionController, I could build the sitemap tree.
I see here a gugga.util.Weaver - maybe I could put some join points on
'registerChildSection' and do the trick.
I think I will finally make all my SectionsControllers inherit from
some CommonSectionController (well, they do already:) ) and override
'registerChildSection' method to add sections to sitemap.
Thanks for Your help.
I need something flexible, some of my sections are 'real' sections,
but some of them are based on overriding 'openSection' method. For
example "Products.Category.5" - 5 of course is not a section but it's
i category ID. Even "Category" isn't a section. Navigation to
"Products" does, nothing.
Some sections are loaded dynamically - there's one Section MovieClip,
regitered as multiply sections, based on DB data (user can add
sections via CMS)
My idea was to keep (let's call it) local sitemap in every
SectionsController, My SectionsControllers extends my
CommonSectionController class. There are 2 steps:
1. Registering sections is joined with adding node to sitemap.
private function
registerSitemapChildSection(sectionInstanceName:String,id:String,menuItemId:String,sitemapName:String,navigationCommand:ICommand)
{
this.registerChildSection(sectionInstanceName,id,menuItemId);
this.sitemap.push(
{
name : sitemapName,
command : navigationCommand,
section : this.getComponent(sectionInstanceName)
}
);
}
As You can see, sitemap here is vector of nodes containing human
readable sitemap nodes, navigation command (used in navigable sitemap)
and reference to section - used in step two.
2. Second step is fired after initialization of all sections
controllers. It's a recursive joining those local sitemaps into a
tree.
public function getSiteMap():Array{
for(var i :Number=0;i<this.sitemap.length;i++) {
if (this.sitemap[i].section instanceof CommonSectionsController) {
this.sitemap[i].subsections =
this.sitemap[i].section.getSiteMap();
}
}
return this.sitemap;
}
It's pretty similar to your code :) The idea of composite structure is
kept, and solution is really easy.
For example :
this.registerSitemapChildSection("RecommendedSitesSection","RecommendedSites","RecommendedSites","Polecane
strony",new NavigationCommand("NotOnlyBusiness.RecommendedSites"));
On the other hand sitemap is separated from sections tree, so I can
put "something" that is not a section into a sitemap (it's client's
requirement)
this.sitemap.push(
{
name : "Some external link",
command : new OpenUrlCommand("http://google.pl","_blank"),
section : null
}
);
The solution works good, is simple for me and You and a bit advanced
programmers, but I feel it can be made simpler - of course with some
limitations.
I think the idea of totally external sitemap is good, but :
- adding sections to sitemap should be joined with regitering sections
(in initUI)
- sitemap have to be created recursive, walkinkg through graph using
the "deep first" method (I'm not sure how to call this in English)
Using external sitemap (for example Sitemap.addNode(parentNode,
childNode) ) makes it difficult to be sure that nodes are registered
in specific order.