charts: Add swtbot for bar chart maker dialog
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Tue, 14 Mar 2017 15:06:16 +0000 (11:06 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Wed, 31 May 2017 18:32:33 +0000 (14:32 -0400)
Change-Id: I52ceb2f656f35f1931d961427ec1e8491ea699a1
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/93032
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.chart.core/META-INF/MANIFEST.MF
tmf/org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests/.classpath
tmf/org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests/META-INF/MANIFEST.MF
tmf/org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests/build.properties
tmf/org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests/plugin.xml [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/chart/ui/swtbot/tests/shared/SWTBotCustomChartUtils.java
tmf/org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/chart/ui/swtbot/tests/dialog/ChartMakerDialogTest.java
tmf/org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests/stubs/org/eclipse/tracecompass/tmf/chart/ui/swtbot/stubs/CustomChartStubView.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.chart.ui/META-INF/MANIFEST.MF

index 4b36262bdd0cde667d5a09b1316305db4c1f508b..15bf8712c4ad47011822b249549a7c19a200a9bf 100644 (file)
@@ -21,6 +21,7 @@ Export-Package: org.eclipse.tracecompass.internal.provisional.tmf.chart.core.cha
  org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor;
   x-friends:="org.eclipse.tracecompass.tmf.chart.ui,
    org.eclipse.tracecompass.tmf.chart.core.tests,
+   org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests,
    org.eclipse.tracecompass.analysis.lami.core,
    org.eclipse.tracecompass.analysis.lami.ui",
  org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver;x-friends:="org.eclipse.tracecompass.tmf.chart.ui,org.eclipse.tracecompass.tmf.chart.core.tests,org.eclipse.tracecompass.analysis.lami.core",
index ec049229cf4b46098f180801fdcea37951784c92..218ed4ce75b3078192c407523aad4fee6ce76aa0 100644 (file)
@@ -2,6 +2,7 @@
 <classpath>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="src" path="shared"/>
+       <classpathentry kind="src" path="stubs"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
                <attributes>
                        <attribute name="annotationpath" value="/org.eclipse.tracecompass.common.core/annotations"/>
index a64ce01611cf523800140aa8b645808ce2820efe..a618b87b908cb6f380ead10916a84386b315a7da 100644 (file)
@@ -7,7 +7,8 @@ Bundle-Localization: plugin
 Bundle-SymbolicName: org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests;singleton:=true
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
-Export-Package: org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests.dialog,
+Export-Package: org.eclipse.tracecompass.tmf.chart.ui.swtbot.stubs,
+ org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests.dialog,
  org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests.shared
 Require-Bundle: org.apache.log4j,
  org.eclipse.core.resources,
@@ -26,6 +27,7 @@ Require-Bundle: org.apache.log4j,
  org.eclipse.swt,
  org.eclipse.tracecompass.tmf.ui,
  org.eclipse.tracecompass.tmf.chart.ui,
- org.eclipse.tracecompass.tmf.chart.core
+ org.eclipse.tracecompass.tmf.chart.core,
+ org.eclipse.tracecompass.tmf.chart.core.tests
 Import-Package: com.google.common.collect,
  org.swtchart
index 6e554b802ffb1506f284a243434241065c4b8b7c..f6291fe9a3288785621d347bec0863a369b2c2e5 100644 (file)
@@ -8,12 +8,14 @@
 ###############################################################################
 
 source.. = src/,\
-           shared/
+           shared/,\
+           stubs/
 output.. = bin/
 bin.includes = META-INF/,\
                .,\
                plugin.properties,\
-               about.html
+               about.html,\
+               plugin.xml
 src.includes = about.html
 additional.bundles = org.eclipse.jdt.annotation
 jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation
diff --git a/tmf/org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests/plugin.xml b/tmf/org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests/plugin.xml
new file mode 100644 (file)
index 0000000..9b38960
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+   <extension
+         point="org.eclipse.ui.views">
+      <view
+            allowMultiple="false"
+            class="org.eclipse.tracecompass.tmf.chart.ui.swtbot.stubs.CustomChartStubView"
+            id="org.eclipse.tracecompass.tmf.chart.ui.swtbot.view.stub"
+            name="Custom Chart Stub View"
+            restorable="true">
+      </view>
+   </extension>
+
+</plugin>
index fc95d4fcce3f735d418843244ddfdd63309199cf..2617bdc3a3e5a3bdbee012e5b599110c3181dd01 100644 (file)
@@ -46,6 +46,24 @@ import org.swtchart.ISeriesSet;
  */
 public final class SWTBotCustomChartUtils {
 
+    /**
+     * The index in the dialog for the table to select the chart type
+     */
+    public static final int CHART_TYPE_TABLE_INDEX = 0;
+    /**
+     * The index in the dialog for the table containing the selected series
+     */
+    public static final int SERIES_SELECTION_TABLE_INDEX = 1;
+    /**
+     * The index in the dialog for the table with the choices for the X axis
+     */
+    public static final int X_SERIES_TABLE_INDEX = 2;
+    /**
+     * The index in the dialog for the table with the choices for the X axis
+     */
+    public static final int Y_SERIES_TABLE_INDEX = 3;
+
+
     /**
      * An enum for the chart axis
      */
@@ -95,7 +113,7 @@ public final class SWTBotCustomChartUtils {
             throw new IllegalStateException("Unsupported chart type: " + chartType.name());
         }
         // The chart selection table is the first
-        SWTBotTable table = bot.table(0);
+        SWTBotTable table = bot.table(CHART_TYPE_TABLE_INDEX);
         // Click on the row corresponding to the chart type
         table.click(index, 0);
     }
@@ -119,10 +137,10 @@ public final class SWTBotCustomChartUtils {
     public static void addSeries(SWTWorkbenchBot bot, String xSerie, Set<String> ySeries) {
         ensureDialogFocus(bot);
         // The X and Y tables are the 3rd and 4th respectively
-        SWTBotTable xTable = bot.table(2);
+        SWTBotTable xTable = bot.table(X_SERIES_TABLE_INDEX);
         xTable.getTableItem(xSerie).click();
 
-        SWTBotTable yTable = bot.table(3);
+        SWTBotTable yTable = bot.table(Y_SERIES_TABLE_INDEX);
         ySeries.stream().forEach(s -> yTable.getTableItem(s).check());
 
         bot.buttonInGroup("Series Creator", 0).click();
index 50d7f3d8fa7ede1abccda08e89cdf1b95158e812..3d786a541404f9c23616def95168b9c91814c8b1 100644 (file)
@@ -9,12 +9,47 @@
 
 package org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests.dialog;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
 import org.apache.log4j.ConsoleAppender;
 import org.apache.log4j.Logger;
 import org.apache.log4j.SimpleLayout;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.swt.widgets.TableItem;
 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.results.Result;
 import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotRootMenu;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.chart.ChartType;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartDurationDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartNumericalDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartStringDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartTimestampDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.IDataChartDescriptor;
+import org.eclipse.tracecompass.tmf.chart.core.model.IDataChartProvider;
+import org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubChartProviderFull;
+import org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubObject;
+import org.eclipse.tracecompass.tmf.chart.ui.swtbot.stubs.CustomChartStubView;
+import org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests.shared.SWTBotCustomChartUtils;
+import org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests.shared.SWTBotCustomChartUtils.AxisType;
 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
 import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
 import org.junit.BeforeClass;
@@ -26,11 +61,16 @@ import org.junit.runner.RunWith;
  *
  * @author Geneviève Bastien
  */
+@NonNullByDefault
 @RunWith(SWTBotJunit4ClassRunner.class)
 public class ChartMakerDialogTest {
 
     /** The Log4j logger instance. */
-    private static final Logger fLogger = Logger.getRootLogger();
+    private static final Logger fLogger = NonNullUtils.checkNotNull(Logger.getRootLogger());
+
+    private final SWTWorkbenchBot fBot = new SWTWorkbenchBot();
+
+    private static final IDataChartProvider<StubObject> CHART_PROVIDER = new StubChartProviderFull();
 
     /**
      * Things to setup
@@ -51,7 +91,42 @@ public class ChartMakerDialogTest {
         SWTBotUtils.switchToTracingPerspective();
         /* Finish waiting for eclipse to load */
         WaitUtils.waitForJobs();
+        SWTBotUtils.openView(CustomChartStubView.ID);
+        CustomChartStubView.setChartProvider(CHART_PROVIDER);
+    }
 
+    private void openDialog() {
+        // Open the new custom chart dialog
+        SWTBotView viewBot = fBot.viewById(CustomChartStubView.ID);
+        SWTBotRootMenu viewMenu = viewBot.viewMenu();
+        SWTBotMenu menu = viewMenu.menu(CustomChartStubView.MENU_TITLE);
+        menu.click();
+    }
+
+    private List<IDataChartDescriptor<?, ?>> getDescriptors(int tblIndex) {
+        SWTBotTable table = fBot.table(tblIndex);
+
+        List<IDataChartDescriptor<?, ?>> items = UIThreadRunnable.syncExec((Result<@Nullable List<IDataChartDescriptor<?, ?>>>) () -> {
+            List<IDataChartDescriptor<?, ?>> list = new ArrayList<>();
+            for (TableItem item : table.widget.getItems()) {
+                Object data = item.getData();
+                if (data instanceof IDataChartDescriptor<?, ?>) {
+                    IDataChartDescriptor<?, ?> desc = (IDataChartDescriptor<?, ?>) data;
+                    list.add(desc);
+                }
+            }
+            return list;
+        });
+        assertNotNull(items);
+        return items;
+    }
+
+    private void assertDescriptors(String msg, Collection<@NonNull IDataChartDescriptor<@NonNull StubObject, ?>> expected, int tblIndex) {
+        List<IDataChartDescriptor<?, ?>> descriptors = getDescriptors(tblIndex);
+        assertEquals(msg + " descriptors count", expected.size(), descriptors.size());
+        for (IDataChartDescriptor<?, ?> desc : descriptors) {
+            assertTrue(msg + " contains", expected.contains(desc));
+        }
     }
 
     /**
@@ -59,20 +134,109 @@ public class ChartMakerDialogTest {
      * unit test.
      */
     @Test
-    public void testDialog() {
-        /**
-         * TODO
-         *
-         * <pre>
-         *
-         * 1- Create a stub view to put the viewer in
-         * 2- Create a stub model and data of all kinds to test various stuff
-         * 3- Test the dialog for each chart type
-         * 3.1- Data filtering when adding series X and Y
-         * 3.2- Log scale enabled X and Y
-         *
-         * </pre>
+    public void testBarChartSeries() {
+        openDialog();
+
+        SWTBotCustomChartUtils.selectChartType(fBot, ChartType.BAR_CHART);
+
+        /* Test initial descriptors */
+        // Only string descriptors should be in X
+        List<IDataChartDescriptor<StubObject, ?>> expectedXDescriptors = CHART_PROVIDER.getDataDescriptors().stream().filter(d -> d instanceof DataChartStringDescriptor<?>).collect(Collectors.toList());
+        assertDescriptors("Initial X", expectedXDescriptors, SWTBotCustomChartUtils.X_SERIES_TABLE_INDEX);
+
+        // Only numerical descriptors should be in Y
+        List<IDataChartDescriptor<StubObject, ?>> expectedYDescriptors = CHART_PROVIDER.getDataDescriptors().stream().filter(d -> d instanceof DataChartNumericalDescriptor<?, ?>).collect(Collectors.toList());
+        assertDescriptors("Initial Y", expectedYDescriptors, SWTBotCustomChartUtils.Y_SERIES_TABLE_INDEX);
+
+        SWTBotTable yTable = fBot.table(SWTBotCustomChartUtils.Y_SERIES_TABLE_INDEX);
+        SWTBotCheckBox chkLogX = fBot.checkBox("Logarithmic Scale " + AxisType.X);
+        SWTBotCheckBox chkLogY = fBot.checkBox("Logarithmic Scale " + AxisType.Y);
+
+        /* Test selection and filter of Y descriptors */
+        /*
+         * In Y, check one of each type, make sure the other types are filtered
+         * out, and uncheck
          */
+        /* Check a numerical descriptor */
+        String toCheck = expectedYDescriptors.stream()
+                .filter(d -> d.getClass() == DataChartNumericalDescriptor.class)
+                .map(d -> d.getLabel())
+                .findFirst().get();
+        yTable.getTableItem(toCheck).check();
+        List<IDataChartDescriptor<StubObject, ?>> subset = expectedYDescriptors.stream()
+                .filter(d -> d.getClass() == DataChartNumericalDescriptor.class)
+                .collect(Collectors.toList());
+        assertDescriptors("Checked numerical Y descriptors", subset, SWTBotCustomChartUtils.Y_SERIES_TABLE_INDEX);
+        yTable.getTableItem(toCheck).uncheck();
+        assertDescriptors("Unchecked numerical Y descriptors", expectedYDescriptors, SWTBotCustomChartUtils.Y_SERIES_TABLE_INDEX);
+        assertFalse(chkLogX.isEnabled());
+        assertTrue(chkLogY.isEnabled());
+
+        /* Check a duration descriptor */
+        toCheck = expectedYDescriptors.stream()
+                .filter(d -> d.getClass() == DataChartDurationDescriptor.class)
+                .map(d -> d.getLabel())
+                .findFirst().get();
+        yTable.getTableItem(toCheck).check();
+        subset = expectedYDescriptors.stream()
+                .filter(d -> d.getClass() == DataChartDurationDescriptor.class)
+                .collect(Collectors.toList());
+        assertDescriptors("Checked duration Y descriptors", subset, SWTBotCustomChartUtils.Y_SERIES_TABLE_INDEX);
+        yTable.getTableItem(toCheck).uncheck();
+        assertDescriptors("Unchecked duration Y descriptors", expectedYDescriptors, SWTBotCustomChartUtils.Y_SERIES_TABLE_INDEX);
+        assertFalse(chkLogX.isEnabled());
+        assertTrue(chkLogY.isEnabled());
+
+        /* Check a timestamp descriptor */
+        toCheck = expectedYDescriptors.stream()
+                .filter(d -> d.getClass() == DataChartTimestampDescriptor.class)
+                .map(d -> d.getLabel())
+                .findFirst().get();
+        yTable.getTableItem(toCheck).check();
+        subset = expectedYDescriptors.stream()
+                .filter(d -> d.getClass() == DataChartTimestampDescriptor.class)
+                .collect(Collectors.toList());
+        assertDescriptors("Checked timestamp Y descriptors", subset, SWTBotCustomChartUtils.Y_SERIES_TABLE_INDEX);
+        yTable.getTableItem(toCheck).uncheck();
+        assertDescriptors("Unchecked timestamp Y descriptors", expectedYDescriptors, SWTBotCustomChartUtils.Y_SERIES_TABLE_INDEX);
+        assertFalse(chkLogX.isEnabled());
+        assertTrue(chkLogY.isEnabled());
+
+        /* Actually add series */
+
+        // Add a series with a timestamp descriptor, log scale in Y is not available for timestamps
+        SWTBotCustomChartUtils.addSeries(fBot, expectedXDescriptors.get(0).getLabel(), Collections.singleton(toCheck));
+
+        // Only one descriptor is allowed in X, the other one should be filtered
+        assertDescriptors("After add X", Collections.singleton(expectedXDescriptors.get(0)), SWTBotCustomChartUtils.X_SERIES_TABLE_INDEX);
+
+        // Only timestamps should be available in Y
+        assertDescriptors("After add Y", subset, SWTBotCustomChartUtils.Y_SERIES_TABLE_INDEX);
+        assertFalse(chkLogX.isEnabled());
+        assertFalse(chkLogY.isEnabled());
+
+        // The selected descriptor should be checked, all others not
+        for (IDataChartDescriptor<StubObject, ?> descriptor : subset) {
+            String label = descriptor.getLabel();
+            if (label.equals(toCheck)) {
+                assertTrue(yTable.getTableItem(label).isChecked());
+            } else {
+                assertFalse(yTable.getTableItem(label).isChecked());
+            }
+        }
+        yTable.getTableItem(toCheck).check();
+
+        // Check that one series is selected
+        SWTBotTable selectedTable = fBot.table(SWTBotCustomChartUtils.SERIES_SELECTION_TABLE_INDEX);
+        assertEquals("Selected rows after one addition", 1, selectedTable.rowCount());
+
+        // Add all timestamp series
+        SWTBotCustomChartUtils.addSeries(fBot, expectedXDescriptors.get(0).getLabel(),
+                subset.stream().map(d -> d.getLabel()).collect(Collectors.toSet()));
+        assertEquals("Selected rows after all added", subset.size(), selectedTable.rowCount());
+        assertFalse(chkLogX.isEnabled());
+        assertFalse(chkLogY.isEnabled());
+
     }
 
 }
diff --git a/tmf/org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests/stubs/org/eclipse/tracecompass/tmf/chart/ui/swtbot/stubs/CustomChartStubView.java b/tmf/org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests/stubs/org/eclipse/tracecompass/tmf/chart/ui/swtbot/stubs/CustomChartStubView.java
new file mode 100644 (file)
index 0000000..efb689a
--- /dev/null
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (c) 2017 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.chart.ui.swtbot.stubs;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.chart.ChartData;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.chart.ChartModel;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.ui.chart.IChartViewer;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.ui.dialog.ChartMakerDialog;
+import org.eclipse.tracecompass.tmf.chart.core.model.IDataChartProvider;
+import org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubObject;
+import org.eclipse.tracecompass.tmf.ui.views.TmfView;
+
+/**
+ * A stub view to test custom charts
+ *
+ * @author Geneviève Bastien
+ */
+@NonNullByDefault
+public class CustomChartStubView extends TmfView {
+
+    /**
+     * ID of the stub view
+     */
+    public static final String ID = "org.eclipse.tracecompass.tmf.chart.ui.swtbot.view.stub";
+    /**
+     * Text for the menu item to create a custom chart
+     */
+    public static final String MENU_TITLE = "Create custom chart";
+
+    private static final String VIEW_NAME = "Stub View for Chart Tests";
+
+    private static @Nullable IDataChartProvider<StubObject> sfChartProvider = null;
+
+    private @Nullable Composite fContainer;
+
+    /**
+     * Set the data chart provider that should be used for the chart maker
+     * dialog
+     *
+     * @param provider The data chart provider
+     */
+    public static void setChartProvider(IDataChartProvider<StubObject> provider) {
+        sfChartProvider = provider;
+    }
+
+    /**
+     * Constructor
+     */
+    public CustomChartStubView() {
+        super(VIEW_NAME);
+    }
+
+    @Override
+    public void setFocus() {
+
+    }
+
+    @Override
+    public void createPartControl(@Nullable Composite parent) {
+        super.createPartControl(parent);
+        SashForm sf = new SashForm(parent, SWT.NONE);
+        fContainer = sf;
+
+        /* Add a menu for adding charts */
+        Action addChart = new NewChartAction();
+        addChart.setText(MENU_TITLE);
+
+        IMenuManager menuMgr = getViewSite().getActionBars().getMenuManager();
+        menuMgr.add(addChart);
+    }
+
+    /**
+     * Method that returns the composite to put a chart in
+     *
+     * @return The composite to put more widget
+     */
+    private @Nullable Composite getContainer() {
+        return fContainer;
+    }
+
+    // ------------------------------------------------------------------------
+    // Anonymous classes
+    // ------------------------------------------------------------------------
+
+    private class NewChartAction extends Action {
+        @Override
+        public void run() {
+
+            /* Get the composite for putting the chart */
+            Composite composite = CustomChartStubView.this.getContainer();
+            if (composite == null) {
+                return;
+            }
+
+            /* Open the chart maker dialog */
+            IDataChartProvider<StubObject> chartProvider = sfChartProvider;
+            if (chartProvider == null) {
+                throw new NullPointerException("no chart provider set. Need to call CustomChartStubView.setChartProvider() before clicking the menu item");
+            }
+            ChartMakerDialog dialog = new ChartMakerDialog(NonNullUtils.checkNotNull(composite.getShell()), chartProvider);
+            if (dialog.open() != Window.OK) {
+                return;
+            }
+
+            /* Make sure the data for making a chart was generated */
+            ChartData data = dialog.getDataSeries();
+            ChartModel model = dialog.getChartModel();
+            if (data == null || model == null) {
+                return;
+            }
+
+            /* Make a chart with the factory constructor */
+            IChartViewer.createChart(composite, data, model);
+
+        }
+    }
+
+}
index 1be52948806f3aef3c2c39dc2bf2a349b1090a3e..b81b5582cf7b1886c8d4efe8eb83bb24fa5ce526 100644 (file)
@@ -15,7 +15,7 @@ Require-Bundle: org.eclipse.ui,
  org.eclipse.tracecompass.tmf.chart.core,
  org.eclipse.tracecompass.tmf.core,
  org.eclipse.tracecompass.tmf.ui
-Export-Package: org.eclipse.tracecompass.internal.provisional.tmf.chart.ui.chart;x-friends:="org.eclipse.tracecompass.analysis.lami.ui",
+Export-Package: org.eclipse.tracecompass.internal.provisional.tmf.chart.ui.chart;x-friends:="org.eclipse.tracecompass.analysis.lami.ui,org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests",
  org.eclipse.tracecompass.internal.provisional.tmf.chart.ui.dialog;x-friends:="org.eclipse.tracecompass.analysis.lami.ui,org.eclipse.tracecompass.tmf.chart.ui.swtbot.tests",
  org.eclipse.tracecompass.internal.tmf.chart.ui;x-internal:=true,
  org.eclipse.tracecompass.internal.tmf.chart.ui.aggregator;x-internal:=true,
This page took 0.032291 seconds and 5 git commands to generate.