public static final Color EXCEPTION_BG_COLOR = Color.red;
private TreeNodeInfo executingNodeInfo;
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if (value instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) value;
Object userObject = defaultMutableTreeNode.getUserObject();
if (userObject instanceof TreeNodeInfo) {
TreeNodeInfo treeNodeInfo = (TreeNodeInfo) userObject;
renderer.setToolTipText(null);
if ( treeNodeInfo.hasException() ) {
renderer.setForeground(EXCEPTION_COLOR);
renderer.setBackgroundNonSelectionColor(EXCEPTION_BG_COLOR);
String msg = treeNodeInfo.getException().getMessage();
renderer.setToolTipText(msg == null ? "Error" : msg);
} else {
renderer.setBackgroundNonSelectionColor(executingNodeInfo == treeNodeInfo ? RUNNING_BG_COLOR : Color.white);
if (!sel && executingNodeInfo != treeNodeInfo) {
if (treeNodeInfo.getExecutionCount() > 0) {
renderer.setForeground(EXECUTED_COLOR);
}
}
}
Icon icon = treeNodeInfo.getIcon();
if (icon != null) {
renderer.setIcon(icon);
}
}
}
return renderer;