*
* @param localNode a value of type 'DefaultMutableTreeNode'
*/
protected void createNodes(DefaultMutableTreeNode localNode) {
PropertyNode pNode = (PropertyNode)localNode.getUserObject();
Object localObject = pNode.value;
// Find all the properties of the object in the root node
PropertyDescriptor localProperties[];
try {
BeanInfo bi = Introspector.getBeanInfo(localObject.getClass());
localProperties = bi.getPropertyDescriptors();
} catch (IntrospectionException ex) {
System.err.println(Messages.getInstance().getString("PropertySelectorDialog_CreateNodes_Error_Text_First"));
return;
}
// Put their values into child nodes.
for (int i = 0; i < localProperties.length; i++) {
// Don't display hidden or expert properties.
if (localProperties[i].isHidden() || localProperties[i].isExpert()) {
continue;
}
String name = localProperties[i].getDisplayName();
Class type = localProperties[i].getPropertyType();
Method getter = localProperties[i].getReadMethod();
Method setter = localProperties[i].getWriteMethod();
Object value = null;
// Only display read/write properties.
if (getter == null || setter == null) {
continue;
}
try {
Object args[] = { };
value = getter.invoke(localObject, args);
PropertyEditor editor = null;
Class pec = localProperties[i].getPropertyEditorClass();
if (pec != null) {
try {
editor = (PropertyEditor)pec.newInstance();
} catch (Exception ex) {
}
}
if (editor == null) {
editor = PropertyEditorManager.findEditor(type);
}
if ((editor == null) || (value == null)) {
continue;
}
} catch (InvocationTargetException ex) {
System.err.println(Messages.getInstance().getString("PropertySelectorDialog_CreateNodes_Error_Text_Second") + name
+ Messages.getInstance().getString("PropertySelectorDialog_CreateNodes_Error_Text_Third")
+ ex.getTargetException());
ex.getTargetException().printStackTrace();
continue;
} catch (Exception ex) {
System.err.println(Messages.getInstance().getString("PropertySelectorDialog_CreateNodes_Error_Text_Fourth") + name
+ Messages.getInstance().getString("PropertySelectorDialog_CreateNodes_Error_Text_Fifth") + ex);
ex.printStackTrace();
continue;
}
// Make a child node
DefaultMutableTreeNode child = new DefaultMutableTreeNode(
new PropertyNode(value,
localProperties[i],
localObject.getClass()));
localNode.add(child);
createNodes(child);
}