1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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
10 * France Lapointe Nguyen - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.ui
.views
.latency
;
15 import java
.util
.Arrays
;
16 import java
.util
.Comparator
;
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
;
25 import com
.google
.common
.collect
.Iterables
;
28 * Content provider for the latency table viewers.
30 * @author France Lapointe Nguyen
32 public class LatencyContentProvider
implements ISortingLazyContentProvider
{
35 * Array of all the segments in the segment store of the current trace
37 private @Nullable ISegment
[] fSegmentArray
= null;
40 * Table viewer of the latency table viewer
42 private @Nullable TableViewer fTableViewer
= null;
47 private @Nullable Comparator
<ISegment
> fComparator
= null;
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
);
59 public void dispose() {
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
);
80 public void setSortOrder(@Nullable Comparator
<?
> comparator
) {
81 if (comparator
== null) {
84 if (fSegmentArray
== null) {
87 final TableViewer tableViewer
= fTableViewer
;
88 if (tableViewer
== null) {
91 fComparator
= (Comparator
<ISegment
>) comparator
;
92 Arrays
.sort(fSegmentArray
, fComparator
);
93 tableViewer
.refresh();
97 * Get the segment count
99 * @return the segment count
101 public int getSegmentCount() {
102 ISegment
[] segmentArray
= fSegmentArray
;
103 return (segmentArray
== null ?
0 : segmentArray
.length
);