use of eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode in project hale by halestudio.
the class TaskCountLabelProvider method getTaskCount.
/**
* Get the given node's task count
*
* @param node the node
*
* @return the task count
*/
private int getTaskCount(MapTreeNode<?, ?> node) {
int count = 0;
TreeNode[] children = node.getChildren();
for (TreeNode child : children) {
if (child instanceof DefaultTreeNode) {
// child is task node
DefaultTreeNode childNode = (DefaultTreeNode) child;
Object tmp = childNode.getValue();
// get value
Object value;
if (tmp.getClass().isArray()) {
value = ((Object[]) tmp)[index];
} else {
value = tmp;
}
// add task to count if it is open
if (value instanceof ResolvedTask && ((ResolvedTask<?>) value).isOpen()) {
count++;
}
} else if (child instanceof MapTreeNode<?, ?>) {
// child is map node
MapTreeNode<?, ?> childNode = (MapTreeNode<?, ?>) child;
count += getTaskCount(childNode);
}
}
return count;
}
use of eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode in project hale by halestudio.
the class TaskTreeView method updateNode.
/**
* Update the node label for the given task
*
* @param task the task
*/
protected void updateNode(ResolvedTask<?> task) {
DefaultTreeNode node = taskNodes.get(task.getTask());
if (node != null) {
node.setValues(task);
// refresh parent instead of update node (sorting) -
// tree.update(node, null);
// update parent nodes
TreeNode parent = node.getParent();
if (parent != null) {
tree.refresh(parent, true);
parent = parent.getParent();
} else {
tree.update(node, null);
}
while (parent != null) {
tree.update(parent, null);
parent = parent.getParent();
}
}
}
use of eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode in project hale by halestudio.
the class TaskTreeView method removeTask.
/**
* Remove a task
*
* @param task the task to remove
*/
@SuppressWarnings("unchecked")
private void removeTask(Task<?> task) {
DefaultTreeNode node = taskNodes.get(task);
if (node != null) {
// remove task from model
MapTreeNode<ResolvedTask<?>, TreeNode> parent = (MapTreeNode<ResolvedTask<?>, TreeNode>) node.getParent();
if (parent != null) {
parent.removeChildNode(node);
taskNodes.remove(task);
// remove empty nodes
if (!parent.hasChildren()) {
MapTreeNode<Cell, MapTreeNode<ResolvedTask<?>, TreeNode>> root = (MapTreeNode<Cell, MapTreeNode<ResolvedTask<?>, TreeNode>>) parent.getParent();
root.removeChildNode(parent);
tree.refresh(root, true);
} else {
tree.refresh(parent, true);
// update icons
TreeNode updateNode = parent.getParent();
while (updateNode != null) {
tree.update(updateNode, null);
updateNode = updateNode.getParent();
}
}
}
}
}
use of eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode in project hale by halestudio.
the class TaskDescriptionLabelProvider method getNodeLevel.
/**
* Get the given node's severity level
*
* @param node the node
*
* @return the severity level or <code>null</code>
*/
private TaskSeverity getNodeLevel(MapTreeNode<?, ?> node) {
TaskSeverity level = null;
TreeNode[] children = node.getChildren();
for (TreeNode child : children) {
if (child instanceof DefaultTreeNode) {
// child is task node
DefaultTreeNode childNode = (DefaultTreeNode) child;
Object tmp = childNode.getValue();
// get value
Object value;
if (tmp.getClass().isArray()) {
value = ((Object[]) tmp)[index];
} else {
value = tmp;
}
// determine level
if (value instanceof ResolvedTask) {
ResolvedTask<?> task = (ResolvedTask<?>) value;
if (task.isOpen()) {
// only inspect open tasks
level = TaskSeverity.max(level, task.getSeverityLevel());
}
}
} else if (child instanceof MapTreeNode<?, ?>) {
// child is map node
MapTreeNode<?, ?> childNode = (MapTreeNode<?, ?>) child;
TaskSeverity childLevel = getNodeLevel(childNode);
level = TaskSeverity.max(level, childLevel);
}
}
return level;
}
use of eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode in project hale by halestudio.
the class TaskTreeView method addTask.
/**
* Add a resolved task
*
* @param task the task to add
*/
@SuppressWarnings("unchecked")
private <C> void addTask(ResolvedTask<C> task) {
// add task to model
MapTreeNode<ResolvedTask<C>, TreeNode> parent = (MapTreeNode<ResolvedTask<C>, TreeNode>) getParentNode(task, true);
if (parent != null) {
DefaultTreeNode node = new DefaultTreeNode(task);
parent.addChild(task, node);
taskNodes.put(task.getTask(), node);
// update viewer
tree.refresh(parent, true);
// update icons
TreeNode updateNode = parent.getParent();
while (updateNode != null) {
tree.update(updateNode, null);
updateNode = updateNode.getParent();
}
}
}
Aggregations