2626import java .util .concurrent .ConcurrentHashMap ;
2727import java .util .concurrent .atomic .AtomicLong ;
2828import java .util .function .Predicate ;
29-
29+ import com . google . common . collect . ImmutableMap ;
3030import org .eclipse .core .runtime .IProgressMonitor ;
3131import org .eclipse .jdt .annotation .NonNull ;
3232import org .eclipse .jdt .annotation .Nullable ;
3636import org .eclipse .tracecompass .statesystem .core .exceptions .TimeRangeException ;
3737import org .eclipse .tracecompass .statesystem .core .interval .ITmfStateInterval ;
3838import org .eclipse .tracecompass .tmf .core .dataprovider .DataProviderParameterUtils ;
39+ import org .eclipse .tracecompass .tmf .core .dataprovider .X11ColorUtils ;
3940import org .eclipse .tracecompass .tmf .core .model .AbstractTmfTraceDataProvider ;
4041import 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 ;
4146import org .eclipse .tracecompass .tmf .core .model .timegraph .ITimeGraphArrow ;
4247import org .eclipse .tracecompass .tmf .core .model .timegraph .ITimeGraphDataProvider ;
4348import org .eclipse .tracecompass .tmf .core .model .timegraph .ITimeGraphRowModel ;
4752import org .eclipse .tracecompass .tmf .core .model .timegraph .TimeGraphRowModel ;
4853import org .eclipse .tracecompass .tmf .core .model .timegraph .TimeGraphState ;
4954import 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 ;
5058import org .eclipse .tracecompass .tmf .core .response .ITmfResponse .Status ;
59+ import org .eclipse .tracecompass .tmf .core .response .ITmfResponse ;
5160import org .eclipse .tracecompass .tmf .core .response .TmfModelResponse ;
5261import org .eclipse .tracecompass .tmf .core .signal .TmfStartAnalysisSignal ;
5362import org .eclipse .tracecompass .tmf .core .statesystem .ITmfAnalysisModuleWithStateSystems ;
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}
0 commit comments