Search in sources :

Example 1 with Task

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

the class MappingView method createViewControl.

@Override
public void createViewControl(Composite parent) {
    super.createViewControl(parent);
    updateLayout(false);
    getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if (!(selection instanceof SchemaSelection)) {
                // only react on schema selections
                return;
            }
            if (part != MappingView.this) {
                update((SchemaSelection) selection);
            }
        }
    });
    AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
    // update();
    as.addListener(alignmentListener = new AlignmentServiceAdapter() {

        @Override
        public void cellsRemoved(Iterable<Cell> cells) {
            updateViewWithCurrentSelection(cells);
        }

        @Override
        public void cellsReplaced(Map<? extends Cell, ? extends Cell> cells) {
            List<Cell> changedCells = new ArrayList<Cell>(2);
            changedCells.addAll(cells.keySet());
            changedCells.addAll(cells.values());
            updateViewWithCurrentSelection(changedCells);
        }

        @Override
        public void customFunctionsChanged() {
            SchemaSelection current = SchemaSelectionHelper.getSchemaSelection();
            if (current != null) {
                update(current);
            }
        }

        @Override
        public void cellsAdded(Iterable<Cell> cells) {
            updateViewWithCurrentSelection(cells);
        }

        @Override
        public void cellsPropertyChanged(Iterable<Cell> cells, String propertyName) {
            updateViewWithCurrentSelection(cells);
        }
    });
    TaskService taskService = PlatformUI.getWorkbench().getService(TaskService.class);
    taskService.addListener(new TaskServiceListener() {

        @Override
        public void tasksRemoved(Iterable<Task<?>> tasks) {
            updateViewWithCurrentSelection(getAffectedCells(tasks));
        }

        @Override
        public void tasksAdded(Iterable<Task<?>> tasks) {
            updateViewWithCurrentSelection(getAffectedCells(tasks));
        }

        @Override
        public void taskUserDataChanged(ResolvedTask<?> task) {
            updateViewWithCurrentSelection(getAffectedCells(Collections.singleton(task)));
        }

        private List<Cell> getAffectedCells(Iterable<Task<?>> tasks) {
            List<Cell> affectedCells = new ArrayList<>();
            tasks.forEach(t -> {
                if (t.getMainContext() instanceof Cell) {
                    affectedCells.add((Cell) t.getMainContext());
                }
            });
            return affectedCells;
        }
    });
    SchemaSelection current = SchemaSelectionHelper.getSchemaSelection();
    if (current != null) {
        update(current);
    }
    // listen on size changes
    getViewer().getControl().addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            updateLayout(true);
        }
    });
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Cell(eu.esdihumboldt.hale.common.align.model.Cell) Dimension(org.eclipse.draw2d.geometry.Dimension) ListMultimap(com.google.common.collect.ListMultimap) AlignmentServiceAdapter(eu.esdihumboldt.hale.ui.service.align.AlignmentServiceAdapter) HaleUI(eu.esdihumboldt.hale.ui.HaleUI) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) IToolBarManager(org.eclipse.jface.action.IToolBarManager) AlignmentUtil(eu.esdihumboldt.hale.common.align.model.AlignmentUtil) TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) MappingViewPlugin(eu.esdihumboldt.hale.ui.views.mapping.internal.MappingViewPlugin) ArrayList(java.util.ArrayList) ControlEvent(org.eclipse.swt.events.ControlEvent) GraphLabelProvider(eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider) HashSet(java.util.HashSet) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) Type(eu.esdihumboldt.hale.common.align.model.Type) GraphViewer(org.eclipse.zest.core.viewers.GraphViewer) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) ISelectionListener(org.eclipse.ui.ISelectionListener) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) Pair(eu.esdihumboldt.util.Pair) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) WorkbenchPart(org.eclipse.ui.part.WorkbenchPart) PlatformUI(org.eclipse.ui.PlatformUI) TaskServiceListener(eu.esdihumboldt.hale.common.tasks.TaskServiceListener) Collection(java.util.Collection) Set(java.util.Set) IBaseLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) Action(org.eclipse.jface.action.Action) SchemaSelection(eu.esdihumboldt.hale.ui.selection.SchemaSelection) LayoutAlgorithm(org.eclipse.zest.layouts.LayoutAlgorithm) TaskService(eu.esdihumboldt.hale.common.tasks.TaskService) List(java.util.List) AlignmentServiceListener(eu.esdihumboldt.hale.ui.service.align.AlignmentServiceListener) ControlAdapter(org.eclipse.swt.events.ControlAdapter) ISelection(org.eclipse.jface.viewers.ISelection) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Task(eu.esdihumboldt.hale.common.tasks.Task) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Collections(java.util.Collections) SchemaSelectionHelper(eu.esdihumboldt.hale.ui.selection.SchemaSelectionHelper) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) Task(eu.esdihumboldt.hale.common.tasks.Task) ControlAdapter(org.eclipse.swt.events.ControlAdapter) TaskService(eu.esdihumboldt.hale.common.tasks.TaskService) ArrayList(java.util.ArrayList) ISelectionListener(org.eclipse.ui.ISelectionListener) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) List(java.util.List) TaskServiceListener(eu.esdihumboldt.hale.common.tasks.TaskServiceListener) SchemaSelection(eu.esdihumboldt.hale.ui.selection.SchemaSelection) ControlEvent(org.eclipse.swt.events.ControlEvent) AlignmentServiceAdapter(eu.esdihumboldt.hale.ui.service.align.AlignmentServiceAdapter) Map(java.util.Map) Cell(eu.esdihumboldt.hale.common.align.model.Cell) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)

Example 2 with Task

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

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

Cell (eu.esdihumboldt.hale.common.align.model.Cell)3 ResolvedTask (eu.esdihumboldt.hale.common.tasks.ResolvedTask)3 Task (eu.esdihumboldt.hale.common.tasks.Task)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 TaskService (eu.esdihumboldt.hale.common.tasks.TaskService)2 DefaultTreeNode (eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode)2 MapTreeNode (eu.esdihumboldt.hale.ui.util.tree.MapTreeNode)2 SortedMapTreeNode (eu.esdihumboldt.hale.ui.util.tree.SortedMapTreeNode)2 ISelection (org.eclipse.jface.viewers.ISelection)2 TreeNode (org.eclipse.jface.viewers.TreeNode)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 ListMultimap (com.google.common.collect.ListMultimap)1 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)1 AlignmentUtil (eu.esdihumboldt.hale.common.align.model.AlignmentUtil)1 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 Type (eu.esdihumboldt.hale.common.align.model.Type)1 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)1 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)1 TaskServiceListener (eu.esdihumboldt.hale.common.tasks.TaskServiceListener)1 HaleUI (eu.esdihumboldt.hale.ui.HaleUI)1