Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f7385fe98b2bc49696b39ee1fbeaa9e5e1936b9f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*******************************************************************************
 * Copyright (c) 2015 Ericsson
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Patrick Tasse - Initial API and implementation
 *******************************************************************************/

package org.eclipse.tracecompass.tmf.ui.widgets.timegraph;

import java.util.List;

import org.eclipse.jface.viewers.Viewer;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;

/**
 * Base provider class for the time graph content provider
 * <p>
 * The default implementation accepts an ITimeGraphEntry[] or a List of
 * ITimeGraphEntry as input element.
 *
 * @author Patrick Tasse
 * @since 1.0
 */

public class TimeGraphContentProvider implements ITimeGraphContentProvider {

    @Override
    public ITimeGraphEntry[] getElements(Object inputElement) {
        if (inputElement instanceof ITimeGraphEntry[]) {
            return (ITimeGraphEntry[]) inputElement;
        } else if (inputElement instanceof List) {
            try {
                return ((List<?>) inputElement).toArray(new ITimeGraphEntry[0]);
            } catch (ClassCastException e) {
            }
        }
        return new ITimeGraphEntry[0];
    }

    @Override
    public boolean hasChildren(Object element) {
        ITimeGraphEntry entry = (ITimeGraphEntry) element;
        return entry.hasChildren();
    }

    @Override
    public ITimeGraphEntry[] getChildren(Object parentElement) {
        ITimeGraphEntry entry = (ITimeGraphEntry) parentElement;
        List<? extends ITimeGraphEntry> children = entry.getChildren();
        return children.toArray(new ITimeGraphEntry[children.size()]);
    }

    @Override
    public ITimeGraphEntry getParent(Object element) {
        ITimeGraphEntry entry = (ITimeGraphEntry) element;
        return entry.getParent();
    }

    @Override
    public void dispose() {
        // Do nothing
    }

    @Override
    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        // Do nothing
    }

}

Back to the top