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
37 public class SegmentStoreContentProvider
implements ISortingLazyContentProvider
{
40 * Array of all the segments in the segment store of the current trace
42 private ISegment
@Nullable [] fSegmentArray
= null;
45 * Table viewer of the latency table viewer
47 private @Nullable TableViewer fTableViewer
= null;
52 private @Nullable Comparator
<ISegment
> fComparator
= null;
55 public void updateElement(int index
) {
56 final TableViewer tableViewer
= fTableViewer
;
57 final ISegment
@Nullable [] segmentArray
= fSegmentArray
;
58 if (tableViewer
!= null && segmentArray
!= null) {
59 tableViewer
.replace(segmentArray
[index
], index
);
64 public void dispose() {
71 public void inputChanged(@Nullable Viewer viewer
, @Nullable Object oldInput
, @Nullable Object newInput
) {
72 fTableViewer
= (TableViewer
) viewer
;
73 if (newInput
instanceof Collection
<?
> || newInput
instanceof ISegmentStore
) {
74 @SuppressWarnings("unchecked")
75 Collection
<ISegment
> segmentStore
= (Collection
<@NonNull ISegment
>) newInput
;
76 ISegment
[] array
= Iterables
.toArray(segmentStore
, ISegment
.class);
77 @NonNull ISegment
[] checkedArray
= checkNotNullContents(array
);
78 if (fComparator
!= null) {
79 Arrays
.sort(checkedArray
, fComparator
);
81 fSegmentArray
= checkedArray
;
82 } else if (newInput
instanceof ISegment
[]) {
84 * Ensure that there are no null elements in the array, so we can
85 * set it back to fSegmentArray, which does not allow nulls.
87 @NonNull ISegment
[] checkedArray
= checkNotNullContents((@Nullable ISegment
[]) newInput
);
88 if (fComparator
!= null) {
89 Arrays
.sort(checkedArray
, fComparator
);
91 fSegmentArray
= checkedArray
;
98 public void setSortOrder(@Nullable Comparator
<?
> comparator
) {
99 @NonNull ISegment
@Nullable [] segmentArray
= fSegmentArray
;
100 if (comparator
== null) {
103 if (segmentArray
== null) {
106 final TableViewer tableViewer
= fTableViewer
;
107 if (tableViewer
== null) {
110 @SuppressWarnings("unchecked")
111 Comparator
<ISegment
> comp
= (Comparator
<ISegment
>) comparator
;
113 Arrays
.sort(segmentArray
, fComparator
);
114 tableViewer
.refresh();
118 * Get the segment count
120 * @return the segment count
122 public int getSegmentCount() {
123 ISegment
[] segmentArray
= fSegmentArray
;
124 return (segmentArray
== null ?
0 : segmentArray
.length
);