Initial impl of Navigation instance class
This commit is contained in:
parent
e2d596152d
commit
f09ab62d52
2 changed files with 58 additions and 9 deletions
|
|
@ -15,6 +15,7 @@ public class WebAdminServer {
|
||||||
|
|
||||||
private PluginManager pluginManager;
|
private PluginManager pluginManager;
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
LogUtil.setGlobalLevel(Level.FINEST);
|
LogUtil.setGlobalLevel(Level.FINEST);
|
||||||
LogUtil.setGlobalFormatter(new CompactLogFormatter());
|
LogUtil.setGlobalFormatter(new CompactLogFormatter());
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ package wa.server.page.struct;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class representing a navigation hierarchy.
|
* A class representing a navigation hierarchy/tree for a web application.
|
||||||
*
|
*
|
||||||
* Created by Ziver on 2015-04-02.
|
* Created by Ziver on 2015-04-02.
|
||||||
*/
|
*/
|
||||||
|
|
@ -96,14 +96,18 @@ public class WANavigation implements Iterable{
|
||||||
public String getUrl(){
|
public String getUrl(){
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
public Object getResource(){
|
private void setParentNav(WANavigation nav){
|
||||||
return resource;
|
this.parentNav = nav;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Assign a resource object specific to this navigation object.
|
||||||
|
* This can be used if target page needs some additional information.
|
||||||
|
*/
|
||||||
public void setResource(Object obj){
|
public void setResource(Object obj){
|
||||||
resource = obj;
|
resource = obj;
|
||||||
}
|
}
|
||||||
private void setParentNav(WANavigation nav){
|
public Object getResource(){
|
||||||
this.parentNav = nav;
|
return resource;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Sets the weight of this navigation object. The weight is
|
* Sets the weight of this navigation object. The weight is
|
||||||
|
|
@ -126,11 +130,18 @@ public class WANavigation implements Iterable{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static List<WANavigation> getRootNav(){
|
/**
|
||||||
return rootNav.getSubNavs();
|
* Will create a clone of the navigation tree with some request instance specific information
|
||||||
|
*/
|
||||||
|
public NavInstance createNavInstance(Map<String, String> request){
|
||||||
|
return createNavInstance(getBreadcrumb(request));
|
||||||
}
|
}
|
||||||
public static WANavigation createRootNav(String name){
|
private NavInstance createNavInstance(List<WANavigation> activeList){
|
||||||
return rootNav.createSubNav(name);
|
NavInstance instance = new NavInstance(this);
|
||||||
|
instance.setActive(activeList.contains(this));
|
||||||
|
for (WANavigation nav : subNav)
|
||||||
|
instance.addSubNav(nav.createNavInstance(activeList));
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -149,4 +160,41 @@ public class WANavigation implements Iterable{
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<WANavigation> getRootNav(){
|
||||||
|
return rootNav.getSubNavs();
|
||||||
|
}
|
||||||
|
public static WANavigation createRootNav(String name){
|
||||||
|
return rootNav.createSubNav(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static class NavInstance{
|
||||||
|
private WANavigation nav;
|
||||||
|
private boolean active;
|
||||||
|
private ArrayList<NavInstance> subNavs;
|
||||||
|
|
||||||
|
protected NavInstance(WANavigation nav){
|
||||||
|
this.nav = nav;
|
||||||
|
this.subNavs = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setActive(boolean active){
|
||||||
|
this.active = active;
|
||||||
|
}
|
||||||
|
protected void addSubNav(NavInstance subNav){
|
||||||
|
subNavs.add(subNav);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActive(){
|
||||||
|
return active;
|
||||||
|
}
|
||||||
|
public List<NavInstance> getSubNavs() { return subNavs; }
|
||||||
|
|
||||||
|
// Mirror getters from WANavigation
|
||||||
|
public String getName(){ return nav.getName(); }
|
||||||
|
public String getUrl(){ return nav.getUrl(); }
|
||||||
|
public Object getResource(){ return nav.getResource(); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue