Skip to content

Commit 155c4b4

Browse files
committed
Added fetchStyle for state system
1 parent 9be98d9 commit 155c4b4

File tree

2 files changed

+60
-19
lines changed

2 files changed

+60
-19
lines changed

tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/statesystem/provider/StateSystemDataProvider.java

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.concurrent.ConcurrentHashMap;
2727
import java.util.concurrent.atomic.AtomicLong;
2828
import java.util.function.Predicate;
29-
29+
import com.google.common.collect.ImmutableMap;
3030
import org.eclipse.core.runtime.IProgressMonitor;
3131
import org.eclipse.jdt.annotation.NonNull;
3232
import org.eclipse.jdt.annotation.Nullable;
@@ -36,8 +36,13 @@
3636
import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
3737
import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
3838
import org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderParameterUtils;
39+
import org.eclipse.tracecompass.tmf.core.dataprovider.X11ColorUtils;
3940
import org.eclipse.tracecompass.tmf.core.model.AbstractTmfTraceDataProvider;
4041
import org.eclipse.tracecompass.tmf.core.model.CommonStatusMessage;
42+
import org.eclipse.tracecompass.tmf.core.model.IOutputStyleProvider;
43+
import org.eclipse.tracecompass.tmf.core.model.OutputElementStyle;
44+
import org.eclipse.tracecompass.tmf.core.model.OutputStyleModel;
45+
import org.eclipse.tracecompass.tmf.core.model.StyleProperties;
4146
import org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphArrow;
4247
import org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphDataProvider;
4348
import org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel;
@@ -47,7 +52,11 @@
4752
import org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphRowModel;
4853
import org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphState;
4954
import org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel;
55+
import org.eclipse.tracecompass.tmf.core.presentation.IPaletteProvider;
56+
import org.eclipse.tracecompass.tmf.core.presentation.RGBAColor;
57+
import org.eclipse.tracecompass.tmf.core.presentation.RotatingPaletteProvider;
5058
import org.eclipse.tracecompass.tmf.core.response.ITmfResponse.Status;
59+
import org.eclipse.tracecompass.tmf.core.response.ITmfResponse;
5160
import org.eclipse.tracecompass.tmf.core.response.TmfModelResponse;
5261
import org.eclipse.tracecompass.tmf.core.signal.TmfStartAnalysisSignal;
5362
import org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems;
@@ -70,8 +79,7 @@
7079
* @author Loic Prieur-Drevon
7180
*
7281
*/
73-
public class StateSystemDataProvider extends AbstractTmfTraceDataProvider implements ITimeGraphDataProvider<@NonNull TimeGraphEntryModel> {
74-
82+
public class StateSystemDataProvider extends AbstractTmfTraceDataProvider implements ITimeGraphDataProvider<@NonNull TimeGraphEntryModel>, IOutputStyleProvider {
7583
/**
7684
* Extension point ID.
7785
*/
@@ -107,6 +115,35 @@ public class StateSystemDataProvider extends AbstractTmfTraceDataProvider implem
107115
*/
108116
private final Set<ITmfAnalysisModuleWithStateSystems> fStartedAnalysis = Objects.requireNonNull(ConcurrentHashMap.newKeySet());
109117

118+
/** Number of colors used for State system time events */
119+
private static final int NUM_COLORS = 9;
120+
121+
private static final String UNKNOWN = "Unknown"; //$NON-NLS-1$
122+
123+
private static final String COLOR_UNKOWN = X11ColorUtils.toHexColor(192, 192, 192);
124+
125+
private static final @NonNull Map<@NonNull String, @NonNull OutputElementStyle> STYLE_MAP;
126+
127+
static {
128+
ImmutableMap.Builder<@NonNull String, @NonNull OutputElementStyle> builder = new ImmutableMap.Builder<>();
129+
IPaletteProvider fPalette = new RotatingPaletteProvider.Builder().setNbColors(NUM_COLORS).build();
130+
List<RGBAColor> colors = fPalette.get();
131+
for (int i = 0; i < colors.size(); i++) {
132+
RGBAColor rgbaColor = colors.get(i);
133+
String hexColor = X11ColorUtils.toHexColor(rgbaColor.getRed(), rgbaColor.getGreen(), rgbaColor.getBlue());
134+
Map<String, Object> fMap = ImmutableMap.of(
135+
StyleProperties.BACKGROUND_COLOR, hexColor);
136+
String key = Integer.toString(i);
137+
OutputElementStyle outputStyle = new OutputElementStyle(null, fMap);
138+
builder.put(key, outputStyle);
139+
}
140+
141+
Map<String, Object> fMapUNKOWN = ImmutableMap.of(StyleProperties.BACKGROUND_COLOR, COLOR_UNKOWN);
142+
OutputElementStyle unknownoutputStyle = new OutputElementStyle(null, fMapUNKOWN);
143+
builder.put(UNKNOWN, unknownoutputStyle);
144+
STYLE_MAP = builder.build();
145+
}
146+
110147
/**
111148
* Constructor
112149
*
@@ -184,7 +221,7 @@ private static String getQuarkValue(Map<String, Object> fetchParameters, ITmfSta
184221
return NonNullUtils.nullToEmptyString(valueString);
185222
}
186223

187-
private abstract static class EntryModelBuilder {
224+
private abstract static class EntryModelBuilder {
188225
private final long fId;
189226
private final long fParentId;
190227
private final String fName;
@@ -455,12 +492,11 @@ public int getQuark() {
455492
return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
456493
}
457494
}
458-
List<TimeGraphEntryModel> entryList = buildEntryList(monitor);
459495

496+
List<TimeGraphEntryModel> entryList = buildEntryList(monitor);
460497
Status status = fetchTreeIsComplete ? Status.COMPLETED : Status.RUNNING;
461498
String msg = fetchTreeIsComplete ? CommonStatusMessage.COMPLETED : CommonStatusMessage.RUNNING;
462-
463-
TmfTreeModel<TimeGraphEntryModel> treeModel =new TmfTreeModel<>(Collections.emptyList(), entryList);
499+
TmfTreeModel<TimeGraphEntryModel> treeModel = new TmfTreeModel<>(Collections.emptyList(), entryList);
464500
treeModel.setAutoExpandLevel(1);
465501

466502
return new TmfModelResponse<>(treeModel, status, msg);
@@ -726,6 +762,7 @@ private void waitForInitialization(ITmfTrace trace, ITmfAnalysisModuleWithStateS
726762
}
727763
}
728764
}
765+
729766
if (monitor != null && monitor.isCanceled()) {
730767
return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
731768
}
@@ -792,17 +829,20 @@ private static TimeGraphState getStateFromInterval(ITmfStateInterval statusInter
792829
long time = statusInterval.getStartTime();
793830
long duration = Math.min(statusInterval.getEndTime(), currentEndTime - 1) + 1 - time;
794831
Object o = statusInterval.getValue();
832+
// Set style for States w/ and w/o labels
833+
OutputElementStyle style = (o != null) ? new OutputElementStyle(Integer.toString(String.valueOf(o).hashCode() % NUM_COLORS)) : new OutputElementStyle(UNKNOWN);
834+
795835
if (o instanceof Integer) {
796-
return new TimeGraphState(time, duration, ((Integer) o).intValue(), String.valueOf(o));
836+
return new TimeGraphState(time, duration, ((Integer) o).intValue(), String.valueOf(o), style);
797837
} else if (o instanceof Long) {
798838
long l = (long) o;
799-
return new TimeGraphState(time, duration, (int) l, "0x" + Long.toHexString(l)); //$NON-NLS-1$
839+
return new TimeGraphState(time, duration, (int) l, "0x" + Long.toHexString(l), style); //$NON-NLS-1$
800840
} else if (o instanceof String) {
801-
return new TimeGraphState(time, duration, Integer.MIN_VALUE, (String) o);
841+
return new TimeGraphState(time, duration, Integer.MIN_VALUE, (String) o, style);
802842
} else if (o instanceof Double) {
803-
return new TimeGraphState(time, duration, ((Double) o).intValue());
843+
return new TimeGraphState(time, duration, ((Double) o).intValue(), null, style);
804844
}
805-
return new TimeGraphState(time, duration, Integer.MIN_VALUE);
845+
return new TimeGraphState(time, duration, Integer.MIN_VALUE, null, style);
806846
}
807847

808848
/**
@@ -819,4 +859,9 @@ public void startedAnalysisSignalHandler(ITmfAnalysisModuleWithStateSystems modu
819859
}
820860
}
821861

862+
@Override
863+
public TmfModelResponse<OutputStyleModel> fetchStyle(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
864+
return new TmfModelResponse<>(new OutputStyleModel(STYLE_MAP), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
865+
}
866+
822867
}

tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/statesystem/provider/StateSystemDataProviderFactory.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,15 @@ public class StateSystemDataProviderFactory implements IDataProviderFactory {
4444

4545
@Override
4646
public @Nullable ITmfTreeDataProvider<? extends ITmfTreeDataModel> createProvider(@NonNull ITmfTrace trace) {
47-
48-
if ( trace instanceof TmfExperiment) {
49-
return TmfTimeGraphCompositeDataProvider.create(TmfTraceManager.getTraceSet(trace), StateSystemDataProvider.ID);
50-
47+
if (trace instanceof TmfExperiment) {
48+
return TmfTimeGraphCompositeDataProvider.create(TmfTraceManager.getTraceSet(trace), StateSystemDataProvider.ID);
5149
}
5250

5351
return new StateSystemDataProvider(trace);
54-
5552
}
5653

5754
@Override
5855
public Collection<IDataProviderDescriptor> getDescriptors(@NonNull ITmfTrace trace) {
59-
return Collections.singletonList(DESCRIPTOR) ;
56+
return Collections.singletonList(DESCRIPTOR);
6057
}
61-
6258
}

0 commit comments

Comments
 (0)