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 ISegment
@Nullable [] 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
<ISegment
> segmentStore
= (ISegmentStore
<ISegment
>) newInput
;
72 fSegmentArray
= Iterables
.toArray(segmentStore
, ISegment
.class);
73 if (fComparator
!= null) {
74 Arrays
.sort(fSegmentArray
, fComparator
);
76 } else if (newInput
instanceof ISegment
[]) {
77 fSegmentArray
= ((ISegment
[]) newInput
).clone();
78 if (fComparator
!= null) {
79 Arrays
.sort(fSegmentArray
, fComparator
);
87 public void setSortOrder(@Nullable Comparator
<?
> comparator
) {
88 if (comparator
== null) {
91 if (fSegmentArray
== null) {
94 final TableViewer tableViewer
= fTableViewer
;
95 if (tableViewer
== null) {
98 fComparator
= (Comparator
<ISegment
>) comparator
;
99 Arrays
.sort(fSegmentArray
, fComparator
);
100 tableViewer
.refresh();
104 * Get the segment count
106 * @return the segment count
108 public int getSegmentCount() {
109 ISegment
[] segmentArray
= fSegmentArray
;
110 return (segmentArray
== null ?
0 : segmentArray
.length
);