Friday November 21, 2008
Children.Keys for Presenting Layer Folders & Files
Here's what's in my layer.xml:
<folder name="Words">
<file name="ajva">
<attr name="unscrambled" stringvalue="java"/>
</file>
<file name="ynamicd">
<attr name="unscrambled" stringvalue="dynamic"/>
</file>
</folder>
And here's a Children.Keys class for creating a presentation layer on top of the folders and files above:
public class WordChildren extends Children.Keys<String> {
@Override
protected void addNotify() {
FileObject words = Repository.getDefault().getDefaultFileSystem().findResource("Words");
FileObject[] fos = words.getChildren();
String[] s = new String[fos.length];
for (int i = 0; i < s.length; i++) {
s[i] = fos[i].getName() + " (" + fos[i].getAttribute("unscrambled") + ")";
}
setKeys(s);
}
@Override
protected Node[] createNodes(String name) {
AbstractNode WordChildrenNode = new AbstractNode(Children.LEAF) {
@Override
public String getHtmlDisplayName() {
String normal = getDisplayName().substring(0, getDisplayName().indexOf("("));
String greyed = getDisplayName().substring(getDisplayName().indexOf("("));
return "<b>" + normal + "</b><i><font color=\"#808080\">" + greyed + "</font></i>";
}
};
WordChildrenNode.setDisplayName(name);
return new Node[]{WordChildrenNode};
}
}
Here's the result, when you instantiate the above via an Explorer Manager, while an explorer view is available to it:
One of the cool things about putting your data in the layer.xml is that then other modules can add their own data to those same folders and they can even be ordered relative to each other. Then the code above will load that data, which is why there are FOUR word combinations in the screenshot above, because the NetBeans runtime container merges all the layer.xml files into one single hierarchical filesystem. Hurray for the NetBeans runtime container!
Nov 21 2008, 12:36:51 PM PST Permalink


