Search in sources :

Example 1 with IColorProvider

use of org.eclipse.jface.viewers.IColorProvider in project polymap4-core by Polymap4.

the class NavigatorContentServiceLabelProvider method getBackground.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
	 */
public Color getBackground(Object anElement) {
    ILabelProvider[] labelProviders = contentService.findRelevantLabelProviders(anElement);
    for (int i = 0; i < labelProviders.length; i++) {
        ILabelProvider provider = labelProviders[i];
        if (provider instanceof IColorProvider) {
            IColorProvider colorProvider = (IColorProvider) provider;
            Color color = colorProvider.getBackground(anElement);
            if (color != null) {
                return color;
            }
        }
    }
    return null;
}
Also used : IColorProvider(org.eclipse.jface.viewers.IColorProvider) Color(org.eclipse.swt.graphics.Color) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider)

Example 2 with IColorProvider

use of org.eclipse.jface.viewers.IColorProvider in project polymap4-core by Polymap4.

the class NavigatorContentServiceLabelProvider method getForeground.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
	 */
public Color getForeground(Object anElement) {
    ILabelProvider[] labelProviders = contentService.findRelevantLabelProviders(anElement);
    for (int i = 0; i < labelProviders.length; i++) {
        ILabelProvider provider = labelProviders[i];
        if (provider instanceof IColorProvider) {
            IColorProvider colorProvider = (IColorProvider) provider;
            Color color = colorProvider.getForeground(anElement);
            if (color != null) {
                return color;
            }
        }
    }
    return null;
}
Also used : IColorProvider(org.eclipse.jface.viewers.IColorProvider) Color(org.eclipse.swt.graphics.Color) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider)

Example 3 with IColorProvider

use of org.eclipse.jface.viewers.IColorProvider 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)

Example 4 with IColorProvider

use of org.eclipse.jface.viewers.IColorProvider in project archi by archimatetool.

the class GraphItemStyler method styleItem.

public static void styleItem(GraphItem item, final IBaseLabelProvider labelProvider) {
    if (item instanceof GraphNode) {
        GraphNode node = (GraphNode) item;
        // set defaults.
        if (node.getGraphModel().getNodeStyle() != ZestStyles.NONE) {
            node.setNodeStyle(node.getGraphModel().getNodeStyle());
        } else {
            node.setNodeStyle(SWT.NONE);
        }
        Object entity = node.getData();
        if (labelProvider instanceof IEntityStyleProvider) {
            styleNode(node, (IEntityStyleProvider) labelProvider);
        }
        if (labelProvider instanceof IColorProvider) {
            IColorProvider colorProvider = (IColorProvider) labelProvider;
            node.setForegroundColor(colorProvider.getForeground(entity));
            node.setBackgroundColor(colorProvider.getBackground(entity));
        }
        if (labelProvider instanceof IFontProvider) {
            IFontProvider fontProvider = (IFontProvider) labelProvider;
            node.setFont(fontProvider.getFont(entity));
        }
        if (labelProvider instanceof ILabelProvider) {
            String text = ((ILabelProvider) labelProvider).getText(node.getData());
            // $NON-NLS-1$
            node.setText((text != null) ? text : "");
            node.setImage(((ILabelProvider) labelProvider).getImage(node.getData()));
        }
        if (labelProvider instanceof ISelfStyleProvider) {
            ((ISelfStyleProvider) labelProvider).selfStyleNode(entity, node);
        }
    } else if (item instanceof GraphConnection) {
        GraphConnection conn = (GraphConnection) item;
        // set defaults
        if (conn.getGraphModel().getConnectionStyle() != ZestStyles.NONE) {
            int s = conn.getGraphModel().getConnectionStyle();
            conn.setConnectionStyle(s);
        } else {
            conn.setConnectionStyle(SWT.NONE);
        }
        if (labelProvider instanceof ILabelProvider) {
            String text = ((ILabelProvider) labelProvider).getText(conn.getExternalConnection());
            // $NON-NLS-1$
            conn.setText((text != null) ? text : "");
            conn.setImage(((ILabelProvider) labelProvider).getImage(conn.getExternalConnection()));
        }
        if (labelProvider instanceof IEntityConnectionStyleProvider) {
            styleEntityConnection(conn, (IEntityConnectionStyleProvider) labelProvider);
        } else if (labelProvider instanceof IConnectionStyleProvider) {
            styleConnection(conn, (IConnectionStyleProvider) labelProvider);
        }
        int swt = getLineStyleForZestStyle(conn.getConnectionStyle());
        conn.setLineStyle(swt);
        if (labelProvider instanceof ISelfStyleProvider) {
            ((ISelfStyleProvider) labelProvider).selfStyleConnection(conn.getData(), conn);
        }
    }
}
Also used : IColorProvider(org.eclipse.jface.viewers.IColorProvider) IFontProvider(org.eclipse.jface.viewers.IFontProvider) IEntityConnectionStyleProvider(org.eclipse.zest.core.viewers.IEntityConnectionStyleProvider) IConnectionStyleProvider(org.eclipse.zest.core.viewers.IConnectionStyleProvider) GraphConnection(org.eclipse.zest.core.widgets.GraphConnection) ISelfStyleProvider(org.eclipse.zest.core.viewers.ISelfStyleProvider) GraphNode(org.eclipse.zest.core.widgets.GraphNode) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) IEntityStyleProvider(org.eclipse.zest.core.viewers.IEntityStyleProvider)

Aggregations

IColorProvider (org.eclipse.jface.viewers.IColorProvider)4 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)3 Color (org.eclipse.swt.graphics.Color)2 Cell (eu.esdihumboldt.hale.common.align.model.Cell)1 ResolvedTask (eu.esdihumboldt.hale.common.tasks.ResolvedTask)1 Task (eu.esdihumboldt.hale.common.tasks.Task)1 TaskService (eu.esdihumboldt.hale.common.tasks.TaskService)1 TaskServiceAdapter (eu.esdihumboldt.hale.ui.service.tasks.TaskServiceAdapter)1 CollectionTreeNodeContentProvider (eu.esdihumboldt.hale.ui.util.tree.CollectionTreeNodeContentProvider)1 DefaultTreeNode (eu.esdihumboldt.hale.ui.util.tree.DefaultTreeNode)1 MapTreeNode (eu.esdihumboldt.hale.ui.util.tree.MapTreeNode)1 SortedMapTreeNode (eu.esdihumboldt.hale.ui.util.tree.SortedMapTreeNode)1 ReadOnlyEditingSupport (eu.esdihumboldt.hale.ui.util.viewer.ReadOnlyEditingSupport)1 PropertiesViewPart (eu.esdihumboldt.hale.ui.views.properties.PropertiesViewPart)1 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)1 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 IFontProvider (org.eclipse.jface.viewers.IFontProvider)1 ISelection (org.eclipse.jface.viewers.ISelection)1