Implemented navigation
This commit is contained in:
parent
846ed78252
commit
b3e0757b29
11 changed files with 203 additions and 90 deletions
|
|
@ -22,42 +22,62 @@
|
|||
|
||||
package wa.server.page.struct;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-04-02.
|
||||
*/
|
||||
public class WANavigation {
|
||||
private static WANavigation rootNav;
|
||||
private static int nextId;
|
||||
private static List<WANavigation> root_nav = new ArrayList<WANavigation>();
|
||||
private static HashMap<Integer, WANavigation> nav_map = new HashMap<Integer, WANavigation>();
|
||||
|
||||
private int id;
|
||||
private String url;
|
||||
private String name;
|
||||
private ArrayList<WANavigation> subNavs;
|
||||
private ArrayList<WANavigation> sub_navs;
|
||||
|
||||
private WANavigation parent_nav;
|
||||
private Object resource;
|
||||
|
||||
|
||||
public WANavigation(String name) {
|
||||
this.id = nextId++;
|
||||
this.nav_map.put(this.id, this);
|
||||
this.url = "?i="+this.id;
|
||||
this.name = name;
|
||||
this.subNavs = new ArrayList<>();
|
||||
this.sub_navs = new ArrayList<>();
|
||||
}
|
||||
public WANavigation(String name, WANavigation[] sub_nav) {
|
||||
public WANavigation(String name, Object resource) {
|
||||
this(name);
|
||||
this.subNavs.addAll(Arrays.asList(sub_nav));
|
||||
this.setResource(resource);
|
||||
}
|
||||
|
||||
|
||||
public void addSubNav(WANavigation subNav) {
|
||||
this.subNavs.add(subNav);
|
||||
this.sub_navs.add(subNav);
|
||||
subNav.setParentNav(this );
|
||||
}
|
||||
public List<WANavigation> getSubNav() {
|
||||
return subNavs;
|
||||
return sub_navs;
|
||||
}
|
||||
public Object getSubNav(String name) {
|
||||
int index = subNavs.indexOf(name);
|
||||
int index = sub_navs.indexOf(name);
|
||||
if(index >= 0)
|
||||
return subNavs.get(index);
|
||||
return sub_navs.get(index);
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object getResource(){
|
||||
return resource;
|
||||
}
|
||||
public void setResource(Object obj){
|
||||
resource = obj;
|
||||
}
|
||||
|
||||
private void setParentNav(WANavigation nav){
|
||||
this.parent_nav = nav;
|
||||
}
|
||||
|
||||
public boolean equals(Object o){
|
||||
if(o instanceof String)
|
||||
|
|
@ -67,9 +87,22 @@ public class WANavigation {
|
|||
}
|
||||
|
||||
|
||||
public static WANavigation getRootNav(){
|
||||
if(rootNav == null)
|
||||
rootNav = new WANavigation("root_nav");
|
||||
return rootNav;
|
||||
public static void addRootNav(WANavigation nav){
|
||||
getRootNav().add(nav);
|
||||
}
|
||||
public static List<WANavigation> getRootNav(){
|
||||
return root_nav;
|
||||
}
|
||||
|
||||
public static List<WANavigation> getNavResource(Map<String, String> request) {
|
||||
LinkedList list = new LinkedList();
|
||||
if(request.containsKey("i")){
|
||||
WANavigation current = nav_map.get(Integer.parseInt(request.get("i")));
|
||||
while(current != null){
|
||||
list.addFirst(current);
|
||||
current = current.parent_nav;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue