Search in sources :

Example 6 with ResolvedTask

use of eu.esdihumboldt.hale.common.tasks.ResolvedTask 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 7 with ResolvedTask

use of eu.esdihumboldt.hale.common.tasks.ResolvedTask 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)

Example 8 with ResolvedTask

use of eu.esdihumboldt.hale.common.tasks.ResolvedTask in project hale by halestudio.

the class TaskColorProvider method getForeground.

/**
 * @see IColorProvider#getForeground(Object)
 */
@Override
public Color getForeground(Object element) {
    if (element instanceof DefaultTreeNode) {
        DefaultTreeNode node = (DefaultTreeNode) element;
        Object value = node.getFirstValue();
        if (value instanceof ResolvedTask<?>) {
            ResolvedTask<?> task = (ResolvedTask<?>) value;
            if (task.isOpen()) {
                return getDefaultColor();
            } else {
                return getLightColor();
            }
        }
    }
    return getDefaultColor();
}
Also used : DefaultTreeNode(eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask)

Example 9 with ResolvedTask

use of eu.esdihumboldt.hale.common.tasks.ResolvedTask 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;
}
Also used : TaskSeverity(eu.esdihumboldt.hale.common.tasks.TaskType.TaskSeverity) 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 10 with ResolvedTask

use of eu.esdihumboldt.hale.common.tasks.ResolvedTask in project hale by halestudio.

the class TaskTreeView method createPartControl.

/**
 * @see WorkbenchPart#createPartControl(Composite)
 */
@Override
public void createPartControl(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    page.setLayoutData(data);
    // tree column layout
    TreeColumnLayout layout = new TreeColumnLayout();
    page.setLayout(layout);
    // tree viewer
    tree = new TreeViewer(page, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
    tree.setContentProvider(new CollectionTreeNodeContentProvider());
    tree.setUseHashlookup(true);
    tree.getTree().setHeaderVisible(true);
    tree.getTree().setLinesVisible(true);
    tree.setComparator(new TaskTreeComparator());
    taskService = HaleUI.getServiceProvider().getService(TaskService.class);
    // columns
    IColorProvider colorProvider = new TaskColorProvider(Display.getCurrent());
    // title/description
    TreeViewerColumn description = new TreeViewerColumn(tree, SWT.LEFT);
    description.getColumn().setText(Messages.TaskTreeView_TitleDescriptionText);
    description.getColumn().setToolTipText(Messages.TaskTreeView_description_tooltip);
    TreeColumnViewerLabelProvider descriptionLabelProvider = new TreeColumnViewerLabelProvider(new TaskDescriptionLabelProvider(0));
    descriptionLabelProvider.setProviders(colorProvider);
    description.setLabelProvider(descriptionLabelProvider);
    description.setEditingSupport(new ReadOnlyEditingSupport(tree, descriptionLabelProvider));
    layout.setColumnData(description.getColumn(), new ColumnWeightData(4));
    // number of tasks
    TreeViewerColumn number = new TreeViewerColumn(tree, SWT.RIGHT);
    // $NON-NLS-1$
    number.getColumn().setText("#");
    number.getColumn().setToolTipText(Messages.TaskTreeView_NumberText);
    TreeColumnViewerLabelProvider numberLabelProvider = new TreeColumnViewerLabelProvider(new TaskCountLabelProvider(0));
    numberLabelProvider.setProviders(colorProvider);
    number.setLabelProvider(numberLabelProvider);
    layout.setColumnData(number.getColumn(), new ColumnWeightData(0, 48));
    // user data: status
    TreeViewerColumn status = new TreeViewerColumn(tree, SWT.LEFT);
    status.getColumn().setText(Messages.TaskTreeView_StatusText);
    TreeColumnViewerLabelProvider statusLabelProvider = new TreeColumnViewerLabelProvider(new TaskStatusLabelProvider(0));
    statusLabelProvider.setProviders(colorProvider);
    status.setLabelProvider(statusLabelProvider);
    layout.setColumnData(status.getColumn(), new ColumnWeightData(1));
    status.setEditingSupport(new TaskStatusEditingSupport(tree, taskService));
    // user data: comment
    // TreeViewerColumn comment = new TreeViewerColumn(tree, SWT.LEFT);
    // comment.getColumn().setText(Messages.TaskTreeView_CommentText);
    // TreeColumnViewerLabelProvider commentLabelProvider = new TreeColumnViewerLabelProvider(
    // new TaskCommentLabelProvider(0));
    // commentLabelProvider.setProviders(colorProvider);
    // comment.setLabelProvider(commentLabelProvider);
    // layout.setColumnData(comment.getColumn(), new ColumnWeightData(4));
    // comment.setEditingSupport(new TaskCommentEditingSupport(tree, taskService));
    // listeners
    taskService.addListener(taskListener = new TaskServiceAdapter() {

        @Override
        public void tasksRemoved(final Iterable<Task<?>> tasks) {
            if (Display.getCurrent() != null) {
                removeTasks(tasks);
            } else {
                final Display display = PlatformUI.getWorkbench().getDisplay();
                display.syncExec(new Runnable() {

                    @Override
                    public void run() {
                        removeTasks(tasks);
                    }
                });
            }
        }

        @Override
        public void tasksAdded(final Iterable<Task<?>> tasks) {
            if (Display.getCurrent() != null) {
                addTasks(tasks);
            } else {
                final Display display = PlatformUI.getWorkbench().getDisplay();
                display.syncExec(new Runnable() {

                    @Override
                    public void run() {
                        addTasks(tasks);
                    }
                });
            }
        }

        @Override
        public void taskUserDataChanged(final ResolvedTask<?> task) {
            if (Display.getCurrent() != null) {
                updateNode(task);
            } else {
                final Display display = PlatformUI.getWorkbench().getDisplay();
                display.syncExec(new Runnable() {

                    @Override
                    public void run() {
                        updateNode(task);
                    }
                });
            }
        }
    });
    getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if (!(part instanceof PropertiesViewPart)) {
                // selections
                return;
            }
            if (part != TaskTreeView.this) {
                update(selection);
            }
        }
    });
    createInput();
    configureActions();
    // interaction
    tree.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            ISelection selection = event.getSelection();
            if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
                Object selected = ((IStructuredSelection) selection).getFirstElement();
                if (selected instanceof TreeNode) {
                    // determine value
                    Object tmp = ((TreeNode) selected).getValue();
                    Object value;
                    if (tmp.getClass().isArray()) {
                        value = ((Object[]) tmp)[0];
                    } else {
                        value = tmp;
                    }
                    if (value instanceof Task) {
                        // node is task node
                        Task<?> task = (Task<?>) value;
                        onDoubleClick(task.getMainContext());
                    } else if (value instanceof Cell) {
                        onDoubleClick(value);
                    }
                }
            }
        }
    });
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) Task(eu.esdihumboldt.hale.common.tasks.Task) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) CollectionTreeNodeContentProvider(eu.esdihumboldt.hale.ui.util.tree.CollectionTreeNodeContentProvider) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISelectionListener(org.eclipse.ui.ISelectionListener) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) 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) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ISelection(org.eclipse.jface.viewers.ISelection) PropertiesViewPart(eu.esdihumboldt.hale.ui.views.properties.PropertiesViewPart) Cell(eu.esdihumboldt.hale.common.align.model.Cell) TreeColumnViewerLabelProvider(org.eclipse.jface.viewers.TreeColumnViewerLabelProvider) Composite(org.eclipse.swt.widgets.Composite) TaskService(eu.esdihumboldt.hale.common.tasks.TaskService) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) IColorProvider(org.eclipse.jface.viewers.IColorProvider) TaskServiceAdapter(eu.esdihumboldt.hale.ui.service.tasks.TaskServiceAdapter) ReadOnlyEditingSupport(eu.esdihumboldt.hale.ui.util.viewer.ReadOnlyEditingSupport) GridData(org.eclipse.swt.layout.GridData) Display(org.eclipse.swt.widgets.Display)

Aggregations

ResolvedTask (eu.esdihumboldt.hale.common.tasks.ResolvedTask)11 DefaultTreeNode (eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode)8 Cell (eu.esdihumboldt.hale.common.align.model.Cell)7 MapTreeNode (eu.esdihumboldt.hale.ui.util.tree.MapTreeNode)7 TreeNode (org.eclipse.jface.viewers.TreeNode)7 TaskService (eu.esdihumboldt.hale.common.tasks.TaskService)5 SortedMapTreeNode (eu.esdihumboldt.hale.ui.util.tree.SortedMapTreeNode)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 Task (eu.esdihumboldt.hale.common.tasks.Task)3 ISelection (org.eclipse.jface.viewers.ISelection)3 Composite (org.eclipse.swt.widgets.Composite)3 ISelectionListener (org.eclipse.ui.ISelectionListener)3 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)3 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)2 TaskServiceListener (eu.esdihumboldt.hale.common.tasks.TaskServiceListener)2 HaleUI (eu.esdihumboldt.hale.ui.HaleUI)2 SchemaSelection (eu.esdihumboldt.hale.ui.selection.SchemaSelection)2 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)2 AlignmentServiceAdapter (eu.esdihumboldt.hale.ui.service.align.AlignmentServiceAdapter)2 ArrayList (java.util.ArrayList)2