* Whether to build children {@link ITreeNode}s, when concerned
* @return An {@link ITreeNode}. <code>null</code> if the entity is
* <code>null</code>
*/
public static ITreeNode buildNode(IEntity entity, boolean recursive) {
ITreeNode node = null;
if (entity != null) {
node = new EqualityBasicTreeNode();
node.setData(entity);
node.setName(entity.getName());
if (entity instanceof IDirectory) {
// node.setImage(ImageTool.getCometeImage((ImageIcon) Icons
// .getIcon("salsa.scanconfig.folder")));
if (recursive) {
IDirectory directory = (IDirectory) entity;
List<IEntity> entityList = new ArrayList<IEntity>();
entityList.addAll(directory.getSubDirectoriesList());
entityList.addAll(directory.getConfigList());
Collections.sort(entityList, new EntityPositionComparator());
ITreeNode[] nodes = new ITreeNode[entityList.size()];
int index = 0;
for (IEntity child : entityList) {
nodes[index++] = buildNode(child, recursive);
}
node.addNodes(nodes);
}
} else if (entity instanceof IConfig1D) {
node.setImage(ImageTool.getCometeImage((ImageIcon) Icons.getIcon("salsa.scanconfig.1d.big")));
} else if (entity instanceof IConfig2D) {
node.setImage(ImageTool.getCometeImage((ImageIcon) Icons.getIcon("salsa.scanconfig.2d.big")));
} else if (entity instanceof IConfigK) {
node.setImage(ImageTool.getCometeImage((ImageIcon) Icons.getIcon("salsa.scanconfig.k.big")));
} else if (entity instanceof IConfigHCS) {
node.setImage(ImageTool.getCometeImage((ImageIcon) Icons.getIcon("salsa.scanconfig.hcs.big")));
} else if (entity instanceof IConfigEnergy) {
node.setImage(ImageTool.getCometeImage((ImageIcon) Icons.getIcon("salsa.scanconfig.energy.big")));
}
}
return node;
}