Skip to content

Commit

Permalink
Scripting: support histogram chart
Browse files Browse the repository at this point in the history
Change-Id: I3abe736fd48fbfa2ee159e2c059c3c95bce37b11
Signed-off-by: Qing Chi <chiqing2010@163.com>
Reviewed-on: https://git.eclipse.org/r/160134
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
  • Loading branch information
chiqing authored and MatthewKhouzam committed Mar 31, 2020
1 parent c69f7e2 commit ac0abb4
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 0 deletions.
Expand Up @@ -29,6 +29,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.tracecompass.incubator.callstack.ui;resolution:=optional
Export-Package: org.eclipse.tracecompass.incubator.internal.scripting.ui;x-friends:="org.eclipse.tracecompass.incubator.scripting.ui.tests",
org.eclipse.tracecompass.incubator.internal.scripting.ui.project.handlers;x-internal:=true,
org.eclipse.tracecompass.incubator.internal.scripting.ui.views.histogram;x-internal:=true,
org.eclipse.tracecompass.incubator.internal.scripting.ui.views.timegraph;x-internal:=true,
org.eclipse.tracecompass.incubator.internal.scripting.ui.views.xychart;x-internal:=true,
org.eclipse.tracecompass.incubator.scripting.ui.callstack,
Expand Down
Expand Up @@ -12,6 +12,7 @@
Bundle-Vendor = Eclipse Trace Compass Incubator
Bundle-Name = Trace Compass Scripting UI Plug-in (Incubator)

view.scriptedHistogramChart = Scripted Histogram Chart
view.scriptedTimeGraph = Scripted Time Graph
view.scriptedXYChart = Scripted XY Chart

Expand Down
Expand Up @@ -25,6 +25,17 @@
visible="true">
</module>
</extension>
<extension
point="org.eclipse.ui.views">
<view
allowMultiple="true"
category="org.eclipse.linuxtools.lttng2.ui.views.category"
class="org.eclipse.tracecompass.incubator.internal.scripting.ui.views.histogram.ScriptedHistogramView"
id="org.eclipse.tracecompass.incubator.internal.scripting.ui.views.histogram"
name="%view.scriptedHistogramChart"
restorable="true">
</view>
</extension>
<extension
point="org.eclipse.ui.views">
<view
Expand Down
@@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2020 VMware
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/

package org.eclipse.tracecompass.incubator.internal.scripting.ui.views.histogram;

import org.eclipse.osgi.util.NLS;

/**
* Messages related to the {@link ScriptedHistogramView}
*
* @author Qing Chi
*/
public class Messages extends NLS {

private static final String BUNDLE_NAME = "org.eclipse.tracecompass.incubator.internal.scripting.ui.views.histogram.messages"; //$NON-NLS-1$

/** Default Viewer title */
public static String ScriptedHistogramTreeViewer_DefaultViewerTitle;
/** default x axis title */
public static String ScriptedHistogramTreeViewer_DefaultXAxis;
/** default y axis title */
public static String ScriptedHistogramTreeViewer_DefaultYAxis;

static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}

private Messages() {
}
}
@@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2020 VMware
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/

package org.eclipse.tracecompass.incubator.internal.scripting.ui.views.histogram;

import java.util.Objects;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.swt.widgets.Composite;

import org.eclipse.tracecompass.incubator.internal.scripting.ui.views.xychart.ScriptedXYTreeViewer;
import org.eclipse.tracecompass.tmf.ui.viewers.TmfViewer;
import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.TmfXYChartViewer;
import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.linecharts.TmfXYChartSettings;
import org.eclipse.tracecompass.tmf.ui.views.TmfChartView;

/**
* A data provider view to display the results of a scripted analysis. It uses
* the secondary ID as the data provider ID to display
*
* @author Qing Chi
*/
public class ScriptedHistogramView extends TmfChartView {

/**
* Because colons are not allowed in secondary IDs, but can be present in
* data provider IDs, they can be replaced upstream by this string and it
* will be replaced again when getting the data provider ID.
*/
public static final String COLON = "[COLON]"; //$NON-NLS-1$

/** The view ID. */
public static final String ID = "org.eclipse.tracecompass.incubator.internal.scripting.ui.views.histogram"; //$NON-NLS-1$

/**
* Default Constructor
*/
public ScriptedHistogramView() {
super(ID);
}

@Override
protected TmfXYChartViewer createChartViewer(Composite parent) {
TmfXYChartSettings settings = new TmfXYChartSettings(Messages.ScriptedHistogramTreeViewer_DefaultViewerTitle, Messages.ScriptedHistogramTreeViewer_DefaultXAxis, Messages.ScriptedHistogramTreeViewer_DefaultYAxis, 1);
return new ScriptedHistogramViewer(parent, settings, getSecondaryIdName());
}

@Override
protected @NonNull TmfViewer createLeftChildViewer(@Nullable Composite parent) {
return new ScriptedXYTreeViewer(Objects.requireNonNull(parent), getSecondaryIdName());
}

private String getSecondaryIdName() {
return getViewSite().getSecondaryId().replace(ScriptedHistogramView.COLON, ":"); //$NON-NLS-1$
}
}
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2020 VMware
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/

package org.eclipse.tracecompass.incubator.internal.scripting.ui.views.histogram;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.tracecompass.tmf.core.presentation.IYAppearance;
import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.linecharts.TmfFilteredXYChartViewer;
import org.eclipse.tracecompass.tmf.ui.viewers.xycharts.linecharts.TmfXYChartSettings;

/**
* Viewer for the {@link ScriptedHistogramView}
*
* @author Qing Chi
*/
public class ScriptedHistogramViewer extends TmfFilteredXYChartViewer {

private static final int DEFAULT_SERIES_WIDTH = 1;

public ScriptedHistogramViewer(Composite parent, TmfXYChartSettings settings, String providerId) {
super(parent, settings, providerId);
}

@Override
public IYAppearance getSeriesAppearance(@NonNull String seriesName) {
return getPresentationProvider().getAppearance(seriesName, IYAppearance.Type.BAR, DEFAULT_SERIES_WIDTH);
}

}
@@ -0,0 +1,14 @@
###############################################################################
# Copyright (c) 2020 VMware
#
# All rights reserved. This program and the accompanying materials are
# made available under the terms of the Eclipse Public License 2.0 which
# accompanies this distribution, and is available at
# https://www.eclipse.org/legal/epl-2.0
#
# SPDX-License-Identifier: EPL-2.0
###############################################################################

ScriptedHistogramTreeViewer_DefaultViewerTitle=Scripted Histogram Viewer
ScriptedHistogramTreeViewer_DefaultXAxis=Time
ScriptedHistogramTreeViewer_DefaultYAxis=Unit
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.ease.modules.WrapToScript;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.swt.widgets.Display;
import org.eclipse.tracecompass.incubator.internal.scripting.ui.views.histogram.ScriptedHistogramView;
import org.eclipse.tracecompass.incubator.internal.scripting.ui.views.timegraph.ScriptedTimeGraphView;
import org.eclipse.tracecompass.incubator.internal.scripting.ui.views.xychart.ScriptedXYView;
import org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphDataProvider;
Expand Down Expand Up @@ -149,4 +150,34 @@ public void run() {

return activePage.showView(ScriptedXYView.ID, name.replace(":", ScriptedXYView.COLON), IWorkbenchPage.VIEW_ACTIVATE); //$NON-NLS-1$
}

/**
* Open a histogram chart for a scripted XY data provider
*
* @param dataProvider
* The data provider used to populate the view
*/
@WrapToScript
public void openHistogramChartView(ITmfTreeXYDataProvider<ITmfTreeDataModel> dataProvider) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
IViewPart view = openHistogramView(dataProvider.getId());
if (view == null) {
return;
}
} catch (final PartInitException e) {
// Do nothing
}
}
});
}

private static @Nullable IViewPart openHistogramView(String name) throws PartInitException {
final IWorkbench wb = PlatformUI.getWorkbench();
final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();

return activePage.showView(ScriptedHistogramView.ID, name.replace(":", ScriptedHistogramView.COLON), IWorkbenchPage.VIEW_ACTIVATE); //$NON-NLS-1$
}
}

0 comments on commit ac0abb4

Please sign in to comment.