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 * Bernd Hufmann - MOve abstract class to TMF
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.internal
.analysis
.timing
.ui
.views
.segmentstore
;
16 import java
.util
.Arrays
;
17 import java
.util
.Comparator
;
19 import org
.eclipse
.jdt
.annotation
.Nullable
;
20 import org
.eclipse
.jface
.viewers
.TableViewer
;
21 import org
.eclipse
.jface
.viewers
.Viewer
;
22 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegment
;
23 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegmentStore
;
24 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.table
.ISortingLazyContentProvider
;
26 import com
.google
.common
.collect
.Iterables
;
29 * Content provider for the latency table viewers.
31 * @author France Lapointe Nguyen
34 public class SegmentStoreContentProvider
implements ISortingLazyContentProvider
{
37 * Array of all the segments in the segment store of the current trace
39 private @Nullable ISegment
[] fSegmentArray
= null;
42 * Table viewer of the latency table viewer
44 private @Nullable TableViewer fTableViewer
= null;
49 private @Nullable Comparator
<ISegment
> fComparator
= null;
52 public void updateElement(int index
) {
53 final TableViewer tableViewer
= fTableViewer
;
54 final ISegment
[] segmentArray
= fSegmentArray
;
55 if (tableViewer
!= null && segmentArray
!= null) {
56 tableViewer
.replace(segmentArray
[index
], index
);
61 public void dispose() {
68 public void inputChanged(@Nullable Viewer viewer
, @Nullable Object oldInput
, @Nullable Object newInput
) {
69 fTableViewer
= (TableViewer
) viewer
;
70 if (newInput
instanceof ISegmentStore
<?
>) {
71 ISegmentStore
<?
> segmentStore
= (ISegmentStore
<?
>) newInput
;
72 fSegmentArray
= Iterables
.toArray(segmentStore
, ISegment
.class);
73 if (fComparator
!= null) {
74 Arrays
.sort(fSegmentArray
, fComparator
);
82 public void setSortOrder(@Nullable Comparator
<?
> comparator
) {
83 if (comparator
== null) {
86 if (fSegmentArray
== null) {
89 final TableViewer tableViewer
= fTableViewer
;
90 if (tableViewer
== null) {
93 fComparator
= (Comparator
<ISegment
>) comparator
;
94 Arrays
.sort(fSegmentArray
, fComparator
);
95 tableViewer
.refresh();
99 * Get the segment count
101 * @return the segment count
103 public int getSegmentCount() {
104 ISegment
[] segmentArray
= fSegmentArray
;
105 return (segmentArray
== null ?
0 : segmentArray
.length
);