1 /*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
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
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.provisional
.tmf
.core
.views
.timegraph2
;
12 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.nullToEmptyString
;
14 import java
.util
.HashSet
;
15 import java
.util
.List
;
18 import org
.eclipse
.jdt
.annotation
.Nullable
;
20 import com
.google
.common
.collect
.ImmutableList
;
21 import com
.google
.common
.collect
.ImmutableSet
;
23 public abstract class TimeGraphModelRenderProvider
implements ITimeGraphModelRenderProvider
{
25 protected static final SortingMode DEFAULT_SORTING_MODE
= new SortingMode(nullToEmptyString(Messages
.DefaultSortingModeName
));
27 private final List
<SortingMode
> fSortingModes
;
28 private final List
<FilterMode
> fFilterModes
;
30 private SortingMode fCurrentSortingMode
;
31 private Set
<FilterMode
> fActiveFilterModes
= new HashSet
<>();
33 private long fConfiguredTimeRangeStart
= 0L;
34 private long fConfiguredTimeRangeEnd
= Long
.MAX_VALUE
;
36 protected TimeGraphModelRenderProvider(@Nullable List
<SortingMode
> sortingModes
,
37 @Nullable List
<FilterMode
> filterModes
) {
38 if (sortingModes
== null || sortingModes
.isEmpty()) {
39 fSortingModes
= ImmutableList
.of(DEFAULT_SORTING_MODE
);
41 fSortingModes
= ImmutableList
.copyOf(sortingModes
);
44 fCurrentSortingMode
= fSortingModes
.get(0);
46 if (filterModes
== null || filterModes
.isEmpty()) {
47 fFilterModes
= ImmutableList
.of();
49 fFilterModes
= ImmutableList
.copyOf(filterModes
);
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
58 public List
<SortingMode
> getSortingModes() {
63 public SortingMode
getCurrentSortingMode() {
64 return fCurrentSortingMode
;
68 public void setCurrentSortingMode(int index
) {
69 fCurrentSortingMode
= fSortingModes
.get(index
);
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
77 public List
<FilterMode
> getFilterModes() {
82 public void enableFilterMode(int index
) {
83 fActiveFilterModes
.add(fFilterModes
.get(index
));
87 public void disableFilterMode(int index
) {
88 fActiveFilterModes
.remove(fFilterModes
.get(index
));
92 public Set
<FilterMode
> getActiveFilterModes() {
93 return ImmutableSet
.copyOf(fActiveFilterModes
);
96 // ------------------------------------------------------------------------
97 // Other configuration options
98 // ------------------------------------------------------------------------
100 public long getConfiguredTimeRangeStart() {
101 return fConfiguredTimeRangeStart
;
104 public long getConfiguredTimeRangeEnd() {
105 return fConfiguredTimeRangeEnd
;
109 public void setConfiguredTimeRange(long start
, long end
) {
110 if (start
< 0 || start
> end
) {
111 throw new IllegalArgumentException();
113 fConfiguredTimeRangeStart
= start
;
114 fConfiguredTimeRangeEnd
= end
;