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
.table
;
16 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNullContents
;
18 import java
.util
.Arrays
;
19 import java
.util
.Collection
;
20 import java
.util
.Comparator
;
22 import org
.eclipse
.jdt
.annotation
.NonNull
;
23 import org
.eclipse
.jdt
.annotation
.Nullable
;
24 import org
.eclipse
.jface
.viewers
.TableViewer
;
25 import org
.eclipse
.jface
.viewers
.Viewer
;
26 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegment
;
27 import org
.eclipse
.tracecompass
.segmentstore
.core
.ISegmentStore
;
28 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.table
.ISortingLazyContentProvider
;
30 import com
.google
.common
.collect
.Iterables
;
33 * Content provider for the latency table viewers.
35 * @author France Lapointe Nguyen
38 public class SegmentStoreContentProvider
implements ISortingLazyContentProvider
{
41 * Array of all the segments in the segment store of the current trace
43 private ISegment
@Nullable [] fSegmentArray
= null;
46 * Table viewer of the latency table viewer
48 private @Nullable TableViewer fTableViewer
= null;
53 private @Nullable Comparator
<ISegment
> fComparator
= null;
56 public void updateElement(int index
) {
57 final TableViewer tableViewer
= fTableViewer
;
58 final ISegment
@Nullable [] segmentArray
= fSegmentArray
;
59 if (tableViewer
!= null && segmentArray
!= null) {
60 tableViewer
.replace(segmentArray
[index
], index
);
65 public void dispose() {
72 public void inputChanged(@Nullable Viewer viewer
, @Nullable Object oldInput
, @Nullable Object newInput
) {
73 fTableViewer
= (TableViewer
) viewer
;
74 if (newInput
instanceof Collection
<?
> || newInput
instanceof ISegmentStore
) {
75 @SuppressWarnings("unchecked")
76 Collection
<ISegment
> segmentStore
= (Collection
<@NonNull ISegment
>) newInput
;
77 ISegment
[] array
= Iterables
.toArray(segmentStore
, ISegment
.class);
78 @NonNull ISegment
[] checkedArray
= checkNotNullContents(array
);
79 if (fComparator
!= null) {
80 Arrays
.sort(checkedArray
, fComparator
);
82 fSegmentArray
= checkedArray
;
83 } else if (newInput
instanceof ISegment
[]) {
85 * Ensure that there are no null elements in the array, so we can
86 * set it back to fSegmentArray, which does not allow nulls.
88 @NonNull ISegment
[] checkedArray
= checkNotNullContents((@Nullable ISegment
[]) newInput
);
89 if (fComparator
!= null) {
90 Arrays
.sort(checkedArray
, fComparator
);
92 fSegmentArray
= checkedArray
;
99 public void setSortOrder(@Nullable Comparator
<?
> comparator
) {
100 @NonNull ISegment
@Nullable [] segmentArray
= fSegmentArray
;
101 if (comparator
== null) {
104 if (segmentArray
== null) {
107 final TableViewer tableViewer
= fTableViewer
;
108 if (tableViewer
== null) {
111 @SuppressWarnings("unchecked")
112 Comparator
<ISegment
> comp
= (Comparator
<ISegment
>) comparator
;
114 Arrays
.sort(segmentArray
, fComparator
);
115 tableViewer
.refresh();
119 * Get the segment count
121 * @return the segment count
123 public int getSegmentCount() {
124 ISegment
[] segmentArray
= fSegmentArray
;
125 return (segmentArray
== null ?
0 : segmentArray
.length
);