Search in sources :

Example 1 with CellFigure

use of eu.esdihumboldt.hale.ui.common.graph.figures.CellFigure in project hale by halestudio.

the class CellFigureTaskLabelContribution method contribute.

// private TaskServiceListener taskServiceListener;
@Override
public void contribute(CellFigure figure, Cell cell) {
    TaskService taskService = HaleUI.getServiceProvider().getService(TaskService.class);
    Collection<ResolvedTask<Cell>> tasks = taskService.getTasks(cell).stream().map(t -> taskService.resolveTask(t)).collect(Collectors.toList());
    tasks = tasks.stream().filter(t -> t.isOpen()).collect(Collectors.toList());
    if (tasks.isEmpty()) {
        return;
    }
    Label tasksLabel = new Label();
    Image tasksImage = null;
    tasksImage = CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_TASKS);
    tasksLabel.setIcon(tasksImage);
    tasksLabel.addMouseListener(new MouseListener() {

        @Override
        public void mouseReleased(MouseEvent me) {
            try {
                IViewPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(TaskTreeView.ID);
                // the alignment/mapping view
                if (part instanceof TaskTreeView) {
                    ((TaskTreeView) part).update(new StructuredSelection(cell));
                }
                me.consume();
            } catch (PartInitException e) {
                log.error("Error creating task view", e);
            }
        }

        @Override
        public void mousePressed(MouseEvent me) {
        // ignore
        }

        @Override
        public void mouseDoubleClicked(MouseEvent me) {
        // ignore
        }
    });
    if (tasksImage != null) {
        Label priorityTip = new Label(MessageFormat.format("There {0} {1} open tasks for this cell. Please refer to the Tasks view for details.", (tasks.size() == 1) ? "is" : "are", tasks.size()));
        tasksLabel.setToolTip(priorityTip);
    }
    GridData tasksLabelGD = new GridData(GridData.CENTER, GridData.FILL, false, true);
    figure.add(tasksLabel, tasksLabelGD);
}
Also used : Cell(eu.esdihumboldt.hale.common.align.model.Cell) PlatformUI(org.eclipse.ui.PlatformUI) ALogger(de.fhg.igd.slf4jplus.ALogger) Collection(java.util.Collection) HaleUI(eu.esdihumboldt.hale.ui.HaleUI) Image(org.eclipse.swt.graphics.Image) CellFigure(eu.esdihumboldt.hale.ui.common.graph.figures.CellFigure) MouseEvent(org.eclipse.draw2d.MouseEvent) ALoggerFactory(de.fhg.igd.slf4jplus.ALoggerFactory) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) MouseListener(org.eclipse.draw2d.MouseListener) CommonSharedImages(eu.esdihumboldt.hale.ui.common.CommonSharedImages) CellFigureContribution(eu.esdihumboldt.hale.ui.common.graph.figures.CellFigureContribution) Collectors(java.util.stream.Collectors) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) MessageFormat(java.text.MessageFormat) TaskService(eu.esdihumboldt.hale.common.tasks.TaskService) GridData(org.eclipse.draw2d.GridData) PartInitException(org.eclipse.ui.PartInitException) Label(org.eclipse.draw2d.Label) IViewPart(org.eclipse.ui.IViewPart) IViewPart(org.eclipse.ui.IViewPart) MouseEvent(org.eclipse.draw2d.MouseEvent) TaskService(eu.esdihumboldt.hale.common.tasks.TaskService) Label(org.eclipse.draw2d.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Image(org.eclipse.swt.graphics.Image) MouseListener(org.eclipse.draw2d.MouseListener) ResolvedTask(eu.esdihumboldt.hale.common.tasks.ResolvedTask) GridData(org.eclipse.draw2d.GridData) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

ALogger (de.fhg.igd.slf4jplus.ALogger)1 ALoggerFactory (de.fhg.igd.slf4jplus.ALoggerFactory)1 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 ResolvedTask (eu.esdihumboldt.hale.common.tasks.ResolvedTask)1 TaskService (eu.esdihumboldt.hale.common.tasks.TaskService)1 HaleUI (eu.esdihumboldt.hale.ui.HaleUI)1 CommonSharedImages (eu.esdihumboldt.hale.ui.common.CommonSharedImages)1 CellFigure (eu.esdihumboldt.hale.ui.common.graph.figures.CellFigure)1 CellFigureContribution (eu.esdihumboldt.hale.ui.common.graph.figures.CellFigureContribution)1 MessageFormat (java.text.MessageFormat)1 Collection (java.util.Collection)1 Collectors (java.util.stream.Collectors)1 GridData (org.eclipse.draw2d.GridData)1 Label (org.eclipse.draw2d.Label)1 MouseEvent (org.eclipse.draw2d.MouseEvent)1 MouseListener (org.eclipse.draw2d.MouseListener)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Image (org.eclipse.swt.graphics.Image)1 IViewPart (org.eclipse.ui.IViewPart)1 PartInitException (org.eclipse.ui.PartInitException)1