1 package fr.improve.struts.taglib.layout.treeview; 2 3 import java.io.File ; 4 5 import fr.improve.struts.taglib.layout.menu.MenuComponent; 6 7 12 public class FileTreeMenuComponent extends MenuComponent { 13 private File file; 14 private boolean inited = false; 15 16 public FileTreeMenuComponent() { 17 this(new File ("/")); 18 } 19 20 public FileTreeMenuComponent(File in_file) { 21 file = in_file; 22 } 23 24 25 public MenuComponent[] getMenuComponents() { 26 synchronized(this) { 27 if (!inited) { 28 inited = true; 29 File [] files = file.listFiles(); 30 if (files!=null && files.length!=0) { 31 System.out.println("Loading childs of " + file.getAbsolutePath()); 32 for (int i = 0; i < files.length; i++) { 33 File subFile = files[i]; 34 addMenuComponent(new FileTreeMenuComponent(subFile)); 35 } 36 } 37 } 38 return super.getMenuComponents(); 39 } 40 } 41 42 45 public String getTitle() { 46 return file.getName(); 47 } 48 49 public boolean hasMenuComponents() { 50 return file.isDirectory(); 51 } 52 } 53 | Popular Tags |