Skip to content

Commit

Permalink
Add configurable default view for the trace overview
Browse files Browse the repository at this point in the history
Currently, the trace overview default view is hard-coded in the trace
viewer. This commit allows users/developers to set an XY view as the
default view for the trace overview (using its name).

Users can set the default view for the trace overview using the
Preference UI (File > Preferences > Open Settings or Ctrl + ,).

Developers can also set the default view for a specific Theia build by
adding the "trace Viewer.trace Overview.defaultView" property to the
"preferences" object in the package.json file of the build and indicate
the name of the default view.

Fixes #840.

Signed-off-by: Hoang Thuan Pham <hoang.pham@calian.ca>
  • Loading branch information
hoangphamEclipse authored and Rodrigoplp-work committed Oct 27, 2022
1 parent d85e56b commit 5d8c66e
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { interfaces } from 'inversify';
import { PreferenceService, createPreferenceProxy, PreferenceContribution } from '@theia/core/lib/browser';
import { OverviewPreferences, OverviewSchema } from './trace-overview-preference';

export function bindTraceOverviewPreferences(bind: interfaces.Bind): void {
bind(OverviewPreferences).toDynamicValue(ctx => {
const preferences = ctx.container.get<PreferenceService>(PreferenceService);
return createPreferenceProxy(preferences, OverviewSchema);
}).inSingletonScope();
bind(PreferenceContribution).toConstantValue({
schema: OverviewSchema,
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { PreferenceProxy, PreferenceSchema, PreferenceScope } from '@theia/core/lib/browser';

export const TRACE_OVERVIEW_DEFAULT_VIEW_KEY = 'trace Viewer.trace Overview.defaultView';
export const DEFAULT_OVERVIEW_OUTPUT_NAME = 'Histogram';

export function getSwitchToDefaultViewErrorMessage(preferredName: string, defaultName: string): string {
return `The ${preferredName} view cannot be opened as the trace overview. ` +
`Opening ${defaultName} instead. ` +
'Please set the Default View preference (Ctrl + ,) of the Trace Overview to an XY view, ' +
'or make sure the name is spelled correctly.';
}

export function getOpenTraceOverviewFailErrorMessage(): string {
return 'An error has occurred while opening the trace overview.';
}

export const OverviewSchema: PreferenceSchema = {
scope: PreferenceScope.Folder,
type: 'object',
properties: {
[TRACE_OVERVIEW_DEFAULT_VIEW_KEY]: {
type: 'string',
default: DEFAULT_OVERVIEW_OUTPUT_NAME,
description: 'Specify the name of the view that will be used as the default view for the Trace Overview. ' +
'Use the same name displayed in the Available Views list. E.g: For the Histogram view, enter Histogram.'
}
},
};

interface OverviewContribution {
[TRACE_OVERVIEW_DEFAULT_VIEW_KEY]: string
}

export const OverviewPreferences = Symbol('OverviewPreferences');
export type OverviewPreferences = PreferenceProxy<OverviewContribution>;
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { LazyTspClientFactory } from 'traceviewer-base/lib/lazy-tsp-client';
import { BackendFileService, backendFileServicePath } from '../../common/backend-file-service';
import { ChartShortcutsDialog, ChartShortcutsDialogProps } from '../trace-explorer/trace-explorer-sub-widgets/trace-explorer-keyboard-shortcuts/charts-cheatsheet-component';
import { TraceServerConnectionStatusService } from '../trace-server-status';
import { bindTraceOverviewPreferences } from '../trace-overview-binding';

export default new ContainerModule(bind => {
bind(TraceServerUrlProviderImpl).toSelf().inSingletonScope();
Expand Down Expand Up @@ -69,6 +70,8 @@ export default new ContainerModule(bind => {
}).inSingletonScope();
bindTraceServerPreferences(bind);

bindTraceOverviewPreferences(bind);

bind(BackendFileService).toDynamicValue(ctx => {
const connection = ctx.container.get(WebSocketConnectionProvider);
return connection.createProxy<BackendFileService>(backendFileServicePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { BackendFileService } from '../../common/backend-file-service';
import { CancellationTokenSource } from '@theia/core';
import * as React from 'react';
import 'animate.css';
import { DEFAULT_OVERVIEW_OUTPUT_NAME, TRACE_OVERVIEW_DEFAULT_VIEW_KEY,
getOpenTraceOverviewFailErrorMessage, getSwitchToDefaultViewErrorMessage, OverviewPreferences } from '../trace-overview-preference';

export const TraceViewerWidgetOptions = Symbol('TraceViewerWidgetOptions');
export interface TraceViewerWidgetOptions {
Expand All @@ -32,7 +34,6 @@ export interface TraceViewerWidgetOptions {
export class TraceViewerWidget extends ReactWidget implements StatefulWidget {
static ID = 'trace-viewer';
static LABEL = 'Trace Viewer';
static DEFAULT_OVERVIEW_DATA_PROVIDER_ID = 'org.eclipse.tracecompass.internal.tmf.core.histogram.HistogramDataProvider';

protected uri: Path;
protected openedExperiment: Experiment | undefined;
Expand Down Expand Up @@ -83,6 +84,7 @@ export class TraceViewerWidget extends ReactWidget implements StatefulWidget {
@inject(TraceExplorerContribution) protected readonly traceExplorerContribution: TraceExplorerContribution;
@inject(WidgetManager) protected readonly widgetManager!: WidgetManager;
@inject(ThemeService) protected readonly themeService: ThemeService;
@inject(OverviewPreferences) protected overviewPreferences: OverviewPreferences;

@postConstruct()
async init(): Promise<void> {
Expand Down Expand Up @@ -583,7 +585,27 @@ export class TraceViewerWidget extends ReactWidget implements StatefulWidget {
*/
protected async getDefaultTraceOverviewOutputDescriptor(): Promise<OutputDescriptor | undefined> {
const availableDescriptors = await this.getAvailableTraceOverviewOutputDescriptor();
return availableDescriptors?.find(output => output.id === TraceViewerWidget.DEFAULT_OVERVIEW_DATA_PROVIDER_ID);

// First, check if there is a preferred view
const preferredViewName: string | undefined = this.overviewPreferences[TRACE_OVERVIEW_DEFAULT_VIEW_KEY];
let descriptor: OutputDescriptor | undefined = availableDescriptors?.find(output => output.name.toLowerCase() === preferredViewName?.toLowerCase());

// Failed to find an output that matches the user preference, fallback to default
if (!descriptor) {
const defaultViewName = DEFAULT_OVERVIEW_OUTPUT_NAME;
descriptor = availableDescriptors?.find(output => output.name.toLowerCase() === defaultViewName?.toLowerCase());

if (descriptor && preferredViewName) {
this.messageService.error(getSwitchToDefaultViewErrorMessage(preferredViewName, descriptor.name));
}
}

// For the current implementation of the overview, we only support XY views
if (descriptor?.type === 'TREE_TIME_XY') {
return descriptor;
}

this.messageService.error(getOpenTraceOverviewFailErrorMessage());
}

/**
Expand Down

0 comments on commit 5d8c66e

Please sign in to comment.