Commit | Line | Data |
---|---|---|
d8a230f8 PT |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Patrick Tasse - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.tracecompass.tmf.ui.widgets.timegraph; | |
14 | ||
15 | import java.util.List; | |
16 | ||
17 | import org.eclipse.jface.viewers.Viewer; | |
18 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; | |
19 | ||
20 | /** | |
21 | * Base provider class for the time graph content provider | |
22 | * <p> | |
23 | * The default implementation accepts an ITimeGraphEntry[] or a List of | |
24 | * ITimeGraphEntry as input element. | |
25 | * | |
26 | * @author Patrick Tasse | |
27 | * @since 1.0 | |
28 | */ | |
29 | ||
30 | public class TimeGraphContentProvider implements ITimeGraphContentProvider { | |
31 | ||
32 | @Override | |
33 | public ITimeGraphEntry[] getElements(Object inputElement) { | |
34 | if (inputElement instanceof ITimeGraphEntry[]) { | |
35 | return (ITimeGraphEntry[]) inputElement; | |
36 | } else if (inputElement instanceof List) { | |
37 | try { | |
38 | return ((List<?>) inputElement).toArray(new ITimeGraphEntry[0]); | |
39 | } catch (ClassCastException e) { | |
40 | } | |
41 | } | |
42 | return new ITimeGraphEntry[0]; | |
43 | } | |
44 | ||
45 | @Override | |
46 | public boolean hasChildren(Object element) { | |
47 | ITimeGraphEntry entry = (ITimeGraphEntry) element; | |
48 | return entry.hasChildren(); | |
49 | } | |
50 | ||
51 | @Override | |
52 | public ITimeGraphEntry[] getChildren(Object parentElement) { | |
53 | ITimeGraphEntry entry = (ITimeGraphEntry) parentElement; | |
54 | List<? extends ITimeGraphEntry> children = entry.getChildren(); | |
55 | return children.toArray(new ITimeGraphEntry[children.size()]); | |
56 | } | |
57 | ||
58 | @Override | |
59 | public ITimeGraphEntry getParent(Object element) { | |
60 | ITimeGraphEntry entry = (ITimeGraphEntry) element; | |
61 | return entry.getParent(); | |
62 | } | |
63 | ||
64 | @Override | |
65 | public void dispose() { | |
66 | } | |
67 | ||
68 | @Override | |
69 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { | |
70 | } | |
71 | ||
72 | } |