* @param entity The {@link IEntity}
* @param recursive 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 BasicTreeNode();
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.small")));
}
else if (entity instanceof IConfig2D) {
node.setImage(ImageTool.getCometeImage((ImageIcon) Icons
.getIcon("salsa.scanconfig.2d.small")));
}
else if (entity instanceof IConfigK) {
node.setImage(ImageTool.getCometeImage((ImageIcon) Icons
.getIcon("salsa.scanconfig.k.small")));
}
else if (entity instanceof IConfigHCS) {
node.setImage(ImageTool.getCometeImage((ImageIcon) Icons
.getIcon("salsa.scanconfig.hcs.small")));
}
else if (entity instanceof IConfigEnergy) {
node.setImage(ImageTool.getCometeImage((ImageIcon) Icons
.getIcon("salsa.scanconfig.energy.small")));
}
}
return node;
}