lttng: provide a system call column for in Latency Table
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.ui / src / org / eclipse / tracecompass / internal / analysis / os / linux / ui / views / latency / LatencyContentProvider.java
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 * France Lapointe Nguyen - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency;
14
15 import java.util.Arrays;
16 import java.util.Comparator;
17
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.eclipse.jface.viewers.TableViewer;
20 import org.eclipse.jface.viewers.Viewer;
21 import org.eclipse.tracecompass.segmentstore.core.ISegment;
22 import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
23 import org.eclipse.tracecompass.tmf.ui.viewers.table.ISortingLazyContentProvider;
24
25 import com.google.common.collect.Iterables;
26
27 /**
28 * Content provider for the latency table viewers.
29 *
30 * @author France Lapointe Nguyen
31 */
32 public class LatencyContentProvider implements ISortingLazyContentProvider {
33
34 /**
35 * Array of all the segments in the segment store of the current trace
36 */
37 private @Nullable ISegment[] fSegmentArray = null;
38
39 /**
40 * Table viewer of the latency table viewer
41 */
42 private @Nullable TableViewer fTableViewer = null;
43
44 /**
45 * Segment comparator
46 */
47 private @Nullable Comparator<ISegment> fComparator = null;
48
49 @Override
50 public void updateElement(int index) {
51 final TableViewer tableViewer = fTableViewer;
52 final ISegment[] segmentArray = fSegmentArray;
53 if (tableViewer != null && segmentArray != null) {
54 tableViewer.replace(segmentArray[index], index);
55 }
56 }
57
58 @Override
59 public void dispose() {
60 fSegmentArray = null;
61 fTableViewer = null;
62 fComparator = null;
63 }
64
65 @Override
66 public void inputChanged(@Nullable Viewer viewer, @Nullable Object oldInput, @Nullable Object newInput) {
67 fTableViewer = (TableViewer) viewer;
68 if (newInput instanceof ISegmentStore<?>) {
69 ISegmentStore<?> segmentStore = (ISegmentStore<?>) newInput;
70 fSegmentArray = Iterables.toArray(segmentStore, ISegment.class);
71 if (fComparator != null) {
72 Arrays.sort(fSegmentArray, fComparator);
73 }
74 } else {
75 fSegmentArray = null;
76 }
77 }
78
79 @Override
80 public void setSortOrder(@Nullable Comparator<?> comparator) {
81 if (comparator == null) {
82 return;
83 }
84 if (fSegmentArray == null) {
85 return;
86 }
87 final TableViewer tableViewer = fTableViewer;
88 if (tableViewer == null) {
89 return;
90 }
91 fComparator = (Comparator<ISegment>) comparator;
92 Arrays.sort(fSegmentArray, fComparator);
93 tableViewer.refresh();
94 }
95
96 /**
97 * Get the segment count
98 *
99 * @return the segment count
100 */
101 public int getSegmentCount() {
102 ISegment[] segmentArray = fSegmentArray;
103 return (segmentArray == null ? 0 : segmentArray.length);
104 }
105 }
This page took 0.032447 seconds and 5 git commands to generate.