Last updated April 25, 2010 13:45, by eppleton
Feedicon  

BeanInfo Annotations Wiki

The Mission

There’s a lot of boilerplate code if you want to display PropertySheets for a Bean in NetBeans. You need to create a Node and write code to create the PropertySheet. There are some classes like the BeanNode to make things easier, but the functionality is very basic, unless you want to write BeanInfo classes.

This project aims to make it easier to display your Beans in NetBeans by defining some annotations and a specialized Node that can handle them. Add these Annotations to your Bean, wrap your Object in AnnotatedBeanNode and your done.

Hello World

Let's assume you've got a simple class like this:

  import java.awt.Color;
  import org.netbeans.platformx.api.beaninfoannotations.ABean;
  
  public class TestClass {
  
    private String id;
    protected String hidden;
    private Color color;
  
    public TestClass(String id, String hidden, Color color) {
        this.id = id;
        this.hidden = hidden;
        this.color = color;
    }
  
    public String getId() {
        return id;
    }
  
    public void setId(String string) {
        this.id = string;
    }
  
    public Color getColor() {
        return color;
    }
  
    public void setColor(Color Color) {
        this.color = Color;
    }
  
    public String getHidden() {
        return hidden;
    }
  
    public void setHidden(String hidden) {
        this.hidden = hidden;
    }
  
    @Override
    public String toString() {
        return id;
    }
  }

If you create an instance of this and want to display as a Node you could use BeanNode:

  Node node = new BeanNode(new TestClass( "Toni", "Do not display me", Color.BLACK ) );

The problem with this approach is, that reflection identifies all the public Properties of this class and display them, but sometimes we don't want that, e.g. we might want to prevent our Users from seeing or changeing the "hidden" Property. Using AnnotatedBeanNode you simply add this to the Class:

  @ABean(simpleProperties={"color","id"})
  public class TestClass {

If you wrap it in a AnnotatedBeanNode it will now only display the two Properties defined as "simpleProperties":

  Node node = new AnnotatedBeanNode(new TestClass( "Toni", "Do not display me", Color.BLACK ) );

This is the simplest example how BeanInfo Annotations can help you.

  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close