Posts Tagged ‘platform’

Using NetBeans Parser API with Navigator API

Sunday, May 30th, 2010

So, you created a new language on you NBP-based application and associated it with a new file type. Now, you need to show your parse result on your Navigator panel. I haven’t found a standard way to do so, but the best shot so far was adding the parser result to the DataObject’s CookieSet. This way you can lookup it in your NavigationPanel’s panelActivated. Easy and fast.

File attributes on layer.xml

Tuesday, December 15th, 2009

When registering files on NBM’s layer file, you can define attributes, too:

<file name="my-pkg-MyClass.instance">
  <attr name="mystr" stringvalue="value"/>
  <attr name="myint" intvalue="1"/>
  <attr name="mymethod"
    methodvalue="my.pkg.MyClass.myMethod"/>
</file>

They are avaliable as attributes of FileObject (through getAttribute). You can also use special attributes “instanceClass” to define a different class to instantiate or “instanceCreate” to define a factory method. This factory method can receive a map of attributes. I’m using it to customize a generic DataLoader:

public class MyLoader extends MultiDataLoader {
  private MyDataLoader(String secondaryExt) {
    super("MyObject");
    this.secondaryExt = secondaryExt;
  }
  public static build(Map<String, Object> attrs) {
    return new MyLoader(attrs.get("ext").toString());
  }
  ...
}

NetBeans Platform + JPA + Derby embedded

Friday, March 27th, 2009

If you want to use NetBeans Platform and JPA together, there’s a great tutorial on NB’s site. Unfortunatelly, it explains how to do it with an external database and using an external JAR for your entities.

If you want to have a entity module with your classes (instead of an external JAR and a library wrapper), no big deal - it works! You can follow GJ’s tutorial, but you will create a module project instead and you will not have NB’s wizards to help creating entity classes.

I also created a module install on my Derby wrapper, with this line:

FileUtil configRoot = FileUtil.getConfigRoot();
System.setProperty("derby.system.home",
    FileUtil.toFile(configRoot).getCanonicalPath());

This defines where Derby will create database files (user’s dir, in this case).

BTW, if a “no suitable driver found” is thrown, you forgot to add a dependency between JPA wrapper (EclipseLink, TopLink, OpenJPA or Hibernate) and JDBC wrapper.