Build Treeview based on layer.xml

"electron36" <[email protected]>
Newsgroups gmane.comp.java.netbeans.modules.openide.devel
Message-ID <[email protected]>
Hi. Can someone please help me building the treeview based on layer.xml

The layer.xml custom filesystem, folder and files are as follow.

 
Code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
<filesystem>
    <folder name="Explorer">
        <attr name="icon" stringvalue="no/demo/explorer.png"/>
        <folder name="System">
            <folder name="Users">
                <attr name="icon" stringvalue="no/demo/player.png"/>
                <file name="UserListAction.shadow">
                    <attr name="originalFile"
                          stringvalue="Actions/Edit/no-demo-UserListAction.instance"/>
                </file>
            </folder>
            
            <attr name="icon" stringvalue="no/demo/player.png"/>
            <file name="PlaylistAction.shadow">
                <attr name="originalFile"
                      stringvalue="Actions/Edit/no-demo-PlaylistAction.instance"/>
            </file>
        </folder>
        <folder name="Views">
            <folder name="SubView">
            <attr name="icon" stringvalue="no/demo/views.png"/>
            <file name="OutputAction.shadow">
                <attr name="originalFile"
                      stringvalue="Actions/Window/org-netbeans-core-io-ui-IOWindowAction.instance"/>
            </file>
            <file name="UsersAction.shadow">
                    <attr name="originalFile"
                          stringvalue="Actions/Edit/no-demo-UsersAction.instance"/>
            </file>
            </folder>
        </folder>
        <folder name="Favorites">
            <attr name="icon" stringvalue="no/demo/favorites.png"/>
            <file name="FavoritesAction.shadow">
                <attr name="originalFile"
                      stringvalue="Actions/Window/org-netbeans-modules-favorites-View.instance"/>
            </file>
        </folder>
    </folder>
</filesystem>





The source code for building the tree folders is as follow:


Code:

public class ExplorerFolderFactory extends ChildFactory<FileObject> {

   private FileObject folder = null;

   public ExplorerFolderFactory(FileObject folder) {
      this.folder = folder;
      
   }

   @Override
   protected boolean createKeys(List<FileObject> toPopulate) {
      System.out.println("createKeys:folder");
      toPopulate.addAll(Arrays.asList(folder.getChildren()));

      return true;
   }

   @Override
   protected Node[] createNodesForKey(FileObject key) {
      List<Node> children = new ArrayList<Node>();
      System.out.println("createNodeForKey:folder");
      FileObject folderFO = (FileObject) key.getLookup().lookup(FileObject.class);
      DataFolder folder = null;
      if(folderFO.isFolder()){
          folder = DataFolder.findFolder(folderFO); 
      }
      
      FileObject daoFO = (FileObject) key.getLookup().lookup(FileObject.class);
      DataObject dao = null;
      
       try {
           dao = DataObject.find(daoFO);
       } catch (DataObjectNotFoundException ex) {
           Exceptions.printStackTrace(ex);
       }
      
       if(folder != null){
           String name = folder.getName();
                
            children.add(new ExplorerFolderNode(key, Children.create(new ExplorerFolderFactory(key), false)));
            return children.toArray(new Node[0]);
       }
              
       if (dao instanceof DataObject) {
           //new ExplorerChildFactory(key);
           ExplorerLeafNode leaf = new ExplorerLeafNode(dao.getNodeDelegate());
           children.add(leaf);
       }
       return children.toArray(new Node[0]);
       
   }
}




What I tried to, is to check if the FileObject isFolder, if this is the case run the ExplorerFolderNode again to go to subfolder.
When I comes to the file I want to get an handler to execute the attribute "Actions/Window/org-netbeans-modules-favorites-View.instance" as an example.

The ExplorerLeafNode Object is as follow:

 
Code:

public class ExplorerLeafNode extends AbstractNode {
   
   private Action action = null;

   public ExplorerLeafNode(Action action) {
      super(Children.LEAF);
      this.action = action;
      setDisplayName(Actions.cutAmpersand((String)action.getValue(Action.NAME)));
   }
   
   @Override
   public Action getPreferredAction() {
      return action;
   }
   
   @Override
   public Image getIcon(int type) {
      ImageIcon img = (ImageIcon) action.getValue(Action.SMALL_ICON);
      
      if(img != null) {
         return img.getImage();
      } else {
         return null;
      }
   }
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.