X

Geertjan's Blog

  • February 11, 2009

Guus Hiddink on the NetBeans Platform

Geertjan Wielenga
Product Manager
Two days ago I read that Guus Hiddink (one of my favorite famous people, for many different reasons) and a few others were being considered as the next coach of Chelsea. As soon as I see "a few others" of anything (i.e., some kind of array), I can't help but think of child nodes. But this time I also knew about the ODF Toolkit, so I thought it would be fun to start with a spreadsheet, which is called "chelsea.ods" and is located within "/home/geertjan":

That's my spreadsheet. I want to display the first column as child nodes in the IDE:

Here's how to create it (i.e., this is literally all the required code):

public class RootNode extends AbstractNode {
public RootNode() {
super(Children.create(new RootChildrenFactory(), true));
setDisplayName("Root");
}
static class RootChildrenFactory extends ChildFactory<String> {
@Override
protected boolean createKeys(List toPopulate) {
try {
OdfDocument odfDoc = OdfDocument.loadDocument(new File("/home/geertjan/chelsea.ods"));
OdfFileDom odfContent = odfDoc.getContentDom();
XPath xpath = odfDoc.getXPath();
DTMNodeList nodeList = (DTMNodeList) xpath.evaluate("//table:table-row/table:table-cell[1]", odfContent, XPathConstants.NODESET);
for (int i = 0; i < nodeList.getLength(); i++) {
org.w3c.dom.Node cell = nodeList.item(i);
if (!cell.getTextContent().isEmpty()) {
toPopulate.add(cell.getTextContent());
}
}
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
return true;
}
@Override
protected Node createNodeForKey(String key) {
return new CoachNode(key);
}
}
static class CoachNode extends AbstractNode {
CoachNode(String key) {
super(Children.LEAF);
setDisplayName(key);
}
}
}

Make sure to put that ODF Toolkit into a library wrapper module and then onto your ui module's classpath, after putting both in a suite.

Then add this to your layer file and you're good to go:

<folder name="UI">
<folder name="Runtime">
<file name="org.odftoolkit.ods.RootNode.instance" />
</folder>
</folder>

Deploy and your specified ODS file (i.e., a spreadsheet) will have its first column displayed as nodes in the Services window. Welcome to the NetBeans Platform, Guus!

Join the discussion

Comments ( 4 )
  • Suhail Manzoor Wednesday, February 11, 2009

    Just for completion, Hiddink is the new Chelsea coach :-)


  • Geertjan Wednesday, February 11, 2009

    I know. :-) But I wish he'd chosen (or been allowed to) between Russia and Chelsea. I guess working for the owner of both has its ups and downs.


  • as Wednesday, February 11, 2009

    Slaven Bilic! :)


  • Varun Friday, February 13, 2009

    Lol :D


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha