Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 37b2480e05aa72cdbfbaf9055d69ba753e27bdac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*******************************************************************************
 * Copyright (c) 2019 Ericsson
 *
 * 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.ui.swtbot.tests.shared;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType;
import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
import org.swtchart.Chart;
import org.swtchart.ISeries;

/**
 * SWTBot class representing a SwtChart
 *
 * @author Bernd Hufmann
 */
public class SWTBotSwtChart extends AbstractSWTBotControl<Chart> {

    /**
     * Constructor
     *
     * @param w the widget
     * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed.
     */
    public SWTBotSwtChart(Chart w) throws WidgetNotFoundException {
        super(w);
    }

    /**
     * Constructor
     *
     * @param bot
     *            a SWTBot instance with which to find a SwtChart
     * @throws WidgetNotFoundException
     *             if the widget is <code>null</code> or widget has been
     *             disposed.
     */
    public SWTBotSwtChart(SWTBot bot) throws WidgetNotFoundException {
        super(bot.widget(WidgetOfType.widgetOfType(Chart.class)));
    }

    @Override
    public AbstractSWTBotControl<Chart> moveMouseToWidget() {
        return super.moveMouseToWidget();
    }

    /**
     * Returns the list of series
     *
     * @return the list of series
     */
    public List<SWTBotSwtChartSeries> getSeries() {
        List<SWTBotSwtChartSeries> list = new ArrayList<>();
        for (ISeries series : widget.getSeriesSet().getSeries()) {
            list.add(new SWTBotSwtChartSeries(widget, series));
        }
        return list;
    }

    /**
     * Returns the series with the specified id
     *
     * @param id
     *            the id
     * @return the series
     */
    public SWTBotSwtChartSeries getSeries(String id) {
        AtomicReference<ISeries> series = new AtomicReference<>();
        SWTBotUtils.waitUntil(chart -> {
            series.set(widget.getSeriesSet().getSeries(id));
            return series.get() != null;
        }, widget, () -> "Timed out waiting for series " + id);
        return new SWTBotSwtChartSeries(widget, series.get());
    }
}

Back to the top