Search in sources :

Example 1 with TreeNode

use of org.eclipse.jface.viewers.TreeNode 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;
}
Also used : TreeNode(org.eclipse.jface.viewers.TreeNode) MapTreeNode(eu.esdihumboldt.hale.ui.util.tree.MapTreeNode) DefaultTreeNode(eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode) DefaultTreeNode(eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) MapTreeNode(eu.esdihumboldt.hale.ui.util.tree.MapTreeNode)

Example 2 with TreeNode

use of org.eclipse.jface.viewers.TreeNode in project hale by halestudio.

the class TaskTreeView method createInput.

/**
 * Update the view
 */
private void createInput() {
    TaskService taskService = HaleUI.getServiceProvider().getService(TaskService.class);
    final Collection<TreeNode> input = new ArrayList<TreeNode>();
    cellNode = new MapTreeNode<Cell, MapTreeNode<ResolvedTask<Cell>, TreeNode>>("Cell messages");
    input.add(cellNode);
    Collection<ResolvedTask<?>> tasks = taskService.getResolvedTasks();
    for (ResolvedTask<?> task : tasks) {
        addTask(task);
    }
    tree.setInput(input);
}
Also used : TaskService(eu.esdihumboldt.hale.common.tasks.TaskService) DefaultTreeNode(eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode) MapTreeNode(eu.esdihumboldt.hale.ui.util.tree.MapTreeNode) TreeNode(org.eclipse.jface.viewers.TreeNode) SortedMapTreeNode(eu.esdihumboldt.hale.ui.util.tree.SortedMapTreeNode) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) ArrayList(java.util.ArrayList) MapTreeNode(eu.esdihumboldt.hale.ui.util.tree.MapTreeNode) SortedMapTreeNode(eu.esdihumboldt.hale.ui.util.tree.SortedMapTreeNode) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 3 with TreeNode

use of org.eclipse.jface.viewers.TreeNode 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();
        }
    }
}
Also used : DefaultTreeNode(eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode) DefaultTreeNode(eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode) MapTreeNode(eu.esdihumboldt.hale.ui.util.tree.MapTreeNode) TreeNode(org.eclipse.jface.viewers.TreeNode) SortedMapTreeNode(eu.esdihumboldt.hale.ui.util.tree.SortedMapTreeNode)

Example 4 with TreeNode

use of org.eclipse.jface.viewers.TreeNode 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();
                }
            }
        }
    }
}
Also used : DefaultTreeNode(eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) DefaultTreeNode(eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode) MapTreeNode(eu.esdihumboldt.hale.ui.util.tree.MapTreeNode) TreeNode(org.eclipse.jface.viewers.TreeNode) SortedMapTreeNode(eu.esdihumboldt.hale.ui.util.tree.SortedMapTreeNode) MapTreeNode(eu.esdihumboldt.hale.ui.util.tree.MapTreeNode) SortedMapTreeNode(eu.esdihumboldt.hale.ui.util.tree.SortedMapTreeNode) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 5 with TreeNode

use of org.eclipse.jface.viewers.TreeNode in project hale by halestudio.

the class TaskTreeView method update.

/**
 * Update the view with the given selection
 *
 * @param selection the selection
 */
public void update(ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof Cell) {
            Collection<Task<Cell>> tasks = taskService.getTasks((Cell) element);
            if (!tasks.isEmpty()) {
                ResolvedTask<Cell> rt = taskService.resolveTask(tasks.iterator().next());
                MapTreeNode<?, TreeNode> cellNode = getParentNode(rt, false);
                tree.setSelection(new StructuredSelection(cellNode));
                tree.expandToLevel(cellNode, TreeViewer.ALL_LEVELS);
            }
        }
    } else {
        tree.setInput(null);
    }
}
Also used : ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) Task(eu.esdihumboldt.hale.common.tasks.Task) DefaultTreeNode(eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode) MapTreeNode(eu.esdihumboldt.hale.ui.util.tree.MapTreeNode) TreeNode(org.eclipse.jface.viewers.TreeNode) SortedMapTreeNode(eu.esdihumboldt.hale.ui.util.tree.SortedMapTreeNode) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Aggregations

TreeNode (org.eclipse.jface.viewers.TreeNode)19 Match (net.sourceforge.pmd.cpd.Match)10 DefaultTreeNode (eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode)8 MapTreeNode (eu.esdihumboldt.hale.ui.util.tree.MapTreeNode)8 ResolvedTask (eu.esdihumboldt.hale.common.tasks.ResolvedTask)7 SortedMapTreeNode (eu.esdihumboldt.hale.ui.util.tree.SortedMapTreeNode)6 Cell (eu.esdihumboldt.hale.common.align.model.Cell)4 TokenEntry (net.sourceforge.pmd.cpd.TokenEntry)4 Point (org.eclipse.swt.graphics.Point)4 ArrayList (java.util.ArrayList)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)3 Task (eu.esdihumboldt.hale.common.tasks.Task)2 TaskService (eu.esdihumboldt.hale.common.tasks.TaskService)2 Image (org.eclipse.swt.graphics.Image)2 TaskSeverity (eu.esdihumboldt.hale.common.tasks.TaskType.TaskSeverity)1 TaskServiceAdapter (eu.esdihumboldt.hale.ui.service.tasks.TaskServiceAdapter)1 CollectionTreeNodeContentProvider (eu.esdihumboldt.hale.ui.util.tree.CollectionTreeNodeContentProvider)1 ReadOnlyEditingSupport (eu.esdihumboldt.hale.ui.util.viewer.ReadOnlyEditingSupport)1 PropertiesViewPart (eu.esdihumboldt.hale.ui.views.properties.PropertiesViewPart)1