diff options
author | Alexander Kurtakov | 2013-04-09 08:13:05 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2013-04-09 08:49:51 +0000 |
commit | 6f994a0b0a49bbe8e8bc3eac5914442c649a6b59 (patch) | |
tree | a8b1b16c1b27ee07a1ba867b21160e2c480a8c71 /systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org | |
parent | 947a79b2043487312e66138020b76194e35540d2 (diff) | |
download | org.eclipse.linuxtools-6f994a0b0a49bbe8e8bc3eac5914442c649a6b59.tar.gz org.eclipse.linuxtools-6f994a0b0a49bbe8e8bc3eac5914442c649a6b59.tar.xz org.eclipse.linuxtools-6f994a0b0a49bbe8e8bc3eac5914442c649a6b59.zip |
systemtap: Rename plugins.
o.e.l.systemtap.ui.graphingapi.[ui,nonui] is weird at least. Proper
naming is o.e.l.systemtap.graphingapi.core(ex nonui) and
o.e.l.systemtap.graphingapi.ui (ex ui.graphingapi.ui).
Change-Id: Id049b4ce32f0ee22a4a9eeb89a61477db01c72fd
Reviewed-on: https://git.eclipse.org/r/11741
Tested-by: Hudson CI
Reviewed-by: Alexander Kurtakov <akurtako@redhat.com>
IP-Clean: Alexander Kurtakov <akurtako@redhat.com>
Tested-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org')
53 files changed, 6202 insertions, 0 deletions
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/internal/systemtap/graphingapi/ui/GraphingAPIUIPlugin.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/internal/systemtap/graphingapi/ui/GraphingAPIUIPlugin.java new file mode 100644 index 0000000000..3a76e00878 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/internal/systemtap/graphingapi/ui/GraphingAPIUIPlugin.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.systemtap.graphingapi.ui; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class GraphingAPIUIPlugin extends AbstractUIPlugin { + + public static final String PLUGIN_ID = "org.eclipse.linuxtools.systemtap.ui.graphingapi.ui"; //$NON-NLS-1$ + //The shared instance. + private static GraphingAPIUIPlugin plugin; + + /** + * The constructor. + */ + public GraphingAPIUIPlugin() { + plugin = this; + } + + /** + * This method is called when the plug-in is stopped + */ + @Override + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + } + + /** + * Returns the shared instance. + */ + public static GraphingAPIUIPlugin getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path. + * + * @param path the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path); + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/internal/systemtap/graphingapi/ui/Localization.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/internal/systemtap/graphingapi/ui/Localization.java new file mode 100644 index 0000000000..f6f5e254de --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/internal/systemtap/graphingapi/ui/Localization.java @@ -0,0 +1,21 @@ +package org.eclipse.linuxtools.internal.systemtap.graphingapi.ui; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class Localization { + private static final String BUNDLE_NAME = "org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.localization"; //$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); + + private Localization() { + } + + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/internal/systemtap/graphingapi/ui/localization.properties b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/internal/systemtap/graphingapi/ui/localization.properties new file mode 100644 index 0000000000..696bc0073c --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/internal/systemtap/graphingapi/ui/localization.properties @@ -0,0 +1,148 @@ +#DataDisplay +DataGrid.Row=Row +DataGrid.FormatAs=Format as... +DataGrid.AddFilter=Add filter... +DataGrid.RemoveFilter=Remove filter... +DataGrid.ManualyResize=Manually Resize + +#Graphs +AChart.Title=Title +AChart.Legend=Legend + +AGraph.xAxis=x-axis +AGraph.yAxis=y-axis +AGraph.GridLines=Grid Lines +AGraph.Normalize=Normalize +AGraph.SeriesAxis=series axis + +#Preferences +GraphingAPIPreferencePage.GraphDisplayPreferences=GraphingAPI Details + +GraphPreferencePage.GraphDisplayPreferences=Basic preferences for graph display. +GraphPreferencePage.ShowXGridLines=&Show X grid lines: +GraphPreferencePage.ShowYGridLines=&Show Y grid lines: +GraphPreferencePage.MaxDataItems=&Max data items: +GraphPreferencePage.ViewableDataItems=&Viewable data items: +GraphPreferencePage.XSeriesTicks=&X series ticks: +GraphPreferencePage.YSeriesTicks=&Y series ticks: + +DataTablePreferencePage.GraphDisplayPreferences=Basic preferences for graph display. +DataTablePreferencePage.JumpNewestEntry=&Jump to newest entry: +DataTablePreferencePage.AutoResizeColumns=&Auto resize columns: +DataTablePreferencePage.MaxDataItems=&Max data items: + +#Wigets +GraphAxis.Kilo=K +GraphAxis.Mega=M +GraphAxis.Giga=G +GraphAxis.Tera=T +GraphAxis.Peta=P +GraphAxis.Exa=E +GraphAxis.Zetta=Z +GraphAxis.Yotta=Y + +GraphLegend.Legend=Legend + +GraphComposite.ScaleValue=x + +#Wizards.DataSet +DataSetFactory.RowDataSet=Row Data Set +DataSetFactory.TableDataSet=Table Data Set +DataSetFactory.RowDataSetDescription=Script outputs simple rows of values.\n\n +DataSetFactory.DataSetExample=ie:\n +DataSetFactory.DataSetHeader=Col1\tCol2\tCol3\n +DataSetFactory.TableDataSetDescription=Script periodicaly outputs preformated tables of the values\n\n + +DataSetWizard.CreateDataSet=Create Data Set + +ParsingWizardPage.NumberOfColumns=Number of Columns: +ParsingWizardPage.RegularExpression=Regular Expression: +ParsingWizardPage.Title=Title: +ParsingWizardPage.Delimiter=Delimiter: + +SelectDataSetWizardPage.SelectDataSetType=Select Data Set Type + +SelectTableParsingWizardPage.SelectTableDataSetParsing=Select Table Data Set Parsing +SelectTableParsingWizardPage.TableDelimiter=Table Delimiter: + +SelectRowParsingWizardPage.SelectRowDataSetParsing=Select Row Data Set Parsing + +#Wizards.Filter +AvailableFilterTypes.MatchFilter=Match Filter +AvailableFilterTypes.RangeFilter=Range Filter +AvailableFilterTypes.SortFilter=Sort Filter +AvailableFilterTypes.UniqueFilter=Unique Filter +AvailableFilterTypes.MatchFilterDescription=This filter removes everything from the data set where the selected column's value does not match the chosen value. +AvailableFilterTypes.RangeFilterDescription=This filter will remove everying that is not included in the selected range of values. +AvailableFilterTypes.SortFilterDescription=This filter will sort the entire data set based on the selected column. No data will be removed. +AvailableFilterTypes.UniqueFilterDescription=This filter will remove all merge all entries in the data set that share a common value in the selected column. Data for the removed rows will be aggregated together based on the chosed aggregation method. + +AggregateFactory.AverageAggregate=Average Aggregate +AggregateFactory.CountAggregate=Count Aggregate +AggregateFactory.MaxAggregate=Max Aggregate +AggregateFactory.MinAggregate=Min Aggregate +AggregateFactory.SumAggregate=Sum Aggregate +AggregateFactory.AverageDescription=This aggregate will return the average of all of the items consolidated. +AggregateFactory.CountDescription=This aggregate will return the number of items consolidated. +AggregateFactory.MaxDescription=This aggregate will return the maximum value of all the items consolidated. +AggregateFactory.MinDescription=This aggregate will return the minimum value of all the items consolidated. +AggregateFactory.SumDescription=This aggregate will return the sum of all of the items consolidated. + +MatchFilterWizardPage.CreateMatchFilter=Create Match Filter +MatchFilterWizardPage.Column=Column: +MatchFilterWizardPage.CompareTo=String to compare to: +MatchFilterWizardPage.KeepMatching=Keep Matching +MatchFilterWizardPage.RemoveMatching=Remove Matching + +RangeFilterWizardPage.CreateRangeFilter=Create Range Filter +RangeFilterWizardPage.Column=Column: +RangeFilterWizardPage.LowerBound=Lower bound: +RangeFilterWizardPage.UpperBound=Upper bound: +RangeFilterWizardPage.InsideBounds=Inside Bounds +RangeFilterWizardPage.OutsideBounds=Outside Bounds +RangeFilterWizardPage.Inclusive=Inclusive + +SelectFilterWizard.CreateFilter=Create Filter + +SelectFilterWizardPage.SelectFilter=Select Filter + +SortFilterWizardPage.CreateSortFilter=Create Sort Filter +SortFilterWizardPage.Column=Column: +SortFilterWizardPage.Ascending=Ascending +SortFilterWizardPage.Descending=Descending + +UniqueFilterWizardPage.CreateUniqueFilter=Create Unique Filter +UniqueFilterWizardPage.Column=Column: +UniqueFilterWizardPage.Aggregate=Aggregate: + + +#Wizards.Graph +GraphFactory.BarGraph=Bar Graph +GraphFactory.PieChart=Pie Chart +GraphFactory.ScatterGraph=Scatter Graph +GraphFactory.AreaGraph=Area Graph +GraphFactory.LineGraph=Line Graph +GraphFactory.MeterChart=Meter Graph +GraphFactory.LineDescription=This is a simple line graph of a single set of data. Each (x,y) pair will be plotted a a single dot and connected with a solid line on the graph. +GraphFactory.BarDescription=This is a histagram of data. One series represents the categories and the other represents the value assigned to that category. +GraphFactory.AreaDescription=This is an Area Graph +GraphFactory.PieDescription=This is a pie chart +GraphFactory.ScatterDescription=This is a simple plot of one series of data vs another set. Each (x,y) pair will be plotted as a single dot on the graph. +GraphFactory.MeterDescription=This is a meter chart. + + +SelectGraphWizard.CreateGraph=Create Graph + +SelectGraphWizardPage.SelectGraph=Select Graph + +SelectSeriesWizardPage.Title=Title: +SelectSeriesWizardPage.XSeries=X Series: +SelectSeriesWizardPage.RowID=Row ID +SelectSeriesWizardPage.YSeries=Y Series +SelectSeriesWizardPage.SelectSeries=Select Series +SelectSeriesWizardPage.TitleNotSet=Title not set +SelectSeriesWizardPage.KeyFilter=Key filter: +SelectSeriesWizardPage.KeyNotSet=Key not set +SelectSeriesWizardPage.NA=NA +SelectSeriesWizardPage.UseHistoricalData=Use historical data? +SelectSeriesWizardPage.SeriesNotSelected=Series not selected, or share the same selection diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartBuilder.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartBuilder.java new file mode 100644 index 0000000000..88a9565850 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartBuilder.java @@ -0,0 +1,197 @@ +/**************************************************************** + * Copyright (c) 2006-2013 IBM Corp. + * 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 + * + * Contributors: + * IBM - initial API and implementation + * + **************************************************************** + */ +package org.eclipse.linuxtools.systemtap.graphingapi.ui.charts; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.GraphingAPIUIPlugin; +import org.eclipse.linuxtools.systemtap.graphingapi.core.adapters.IAdapter; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.preferences.GraphingAPIPreferenceConstants; +import org.eclipse.linuxtools.systemtap.structures.listeners.IUpdateListener; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.swtchart.Chart; +import org.swtchart.ITitle; + +/** + * Provides the common members and the framework to build one chart. + * + * @author Qi Liang + */ +public abstract class AbstractChartBuilder extends Composite implements IUpdateListener{ + + /** + * Font name for all titles, labels, and values. + */ + protected final static String FONT_NAME = "MS Sans Serif"; //$NON-NLS-1$ + protected int maxItems; + protected double scale = 1.0; + + /** + * Provides data for chart. + */ + protected IAdapter adapter = null; + protected int xseries; + protected int[] yseries; + + protected static final Color WHITE = new Color(Display.getDefault(), 255, 255, 255); + protected static final Color BLACK = new Color(Display.getDefault(), 0, 0, 0); + protected static final Color RED = new Color(Display.getDefault(), 255, 0, 0); + + protected static final Color[] COLORS = { + new Color(Display.getDefault(), 255, 0, 0), + new Color(Display.getDefault(), 0, 255, 0), + new Color(Display.getDefault(), 0, 0, 255), + new Color(Display.getDefault(), 255, 255, 0), + new Color(Display.getDefault(), 255, 0, 255), + new Color(Display.getDefault(), 0, 255, 255), + new Color(Display.getDefault(), 0, 0, 0), + new Color(Display.getDefault(), 64, 128, 128), + new Color(Display.getDefault(), 255, 165, 0), + new Color(Display.getDefault(), 128, 128, 128), + }; + /** + * Chart instance. + */ + protected Chart chart = null; + + /** + * Chart title. + */ + protected String title = null; + + public abstract void updateDataSet(); + + /** + * Constructs one chart builder and associate it to one data set. + * + * @param dataSet + * data set + */ + + public AbstractChartBuilder(IAdapter adapter, Composite parent, int style, String title) { + super(parent, style); + this.adapter = adapter; + this.title = title; + this.setLayout(new FillLayout()); + IPreferenceStore store = GraphingAPIUIPlugin.getDefault().getPreferenceStore(); + maxItems = Math.min(store.getInt(GraphingAPIPreferenceConstants.P_VIEWABLE_DATA_ITEMS), + store.getInt(GraphingAPIPreferenceConstants.P_MAX_DATA_ITEMS)); + } + + /** + * Builds one chart. + */ + public void build() { + createChart(); + buildPlot(); + buildLegend(); + buildTitle(); + buildXAxis(); + buildYAxis(); + buildXSeries(); + buildYSeries(); + updateDataSet(); + } + + /** + * Creates chart instance. + */ + protected void createChart() { + this.chart = new Chart(this, getStyle()); + } + + /** + * Builds plot. + */ + protected void buildPlot() { + this.chart.setBackground(WHITE); + this.chart.setBackgroundInPlotArea(WHITE); + } + + /** + * Builds X axis. + */ + protected void buildXAxis() {} + + /** + * Builds Y axis. + */ + protected void buildYAxis() {} + + /** + * Builds X series. + */ + protected void buildXSeries() {} + + /** + * Builds Y series. + */ + protected void buildYSeries() {} + + /** + * Builds legend. + * + */ + protected void buildLegend() { + chart.getLegend().setPosition(SWT.RIGHT); + } + + /** + * Builds the chart title. + */ + protected void buildTitle() { + ITitle ctitle = chart.getTitle(); + ctitle.setForeground(BLACK); + ctitle.setText(this.title); + } + + /** + * Returns the chart instance. + * + * @return the chart instance + */ + public Chart getChart() { + return chart; + } + + public void setScale(double scale) { + this.scale = scale; + handleUpdateEvent(); + } + + protected double getDoubleValue(Object o) { + if (o instanceof Integer) + return ((Integer)o).intValue(); + if (o instanceof Double) + return ((Double)o).doubleValue(); + return new Double(o.toString()).doubleValue(); + } + + @Override + public void handleUpdateEvent() { + repaint(); + } + + protected void repaint() { + getDisplay().syncExec(new Runnable() { + @Override + public void run() { + updateDataSet(); + } + }); + } + +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartWithAxisBuilder.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartWithAxisBuilder.java new file mode 100644 index 0000000000..734da829e6 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartWithAxisBuilder.java @@ -0,0 +1,121 @@ +package org.eclipse.linuxtools.systemtap.graphingapi.ui.charts; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.GraphingAPIUIPlugin; +import org.eclipse.linuxtools.systemtap.graphingapi.core.adapters.IAdapter; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.preferences.GraphingAPIPreferenceConstants; +import org.eclipse.swt.widgets.Composite; +import org.swtchart.IAxis; +import org.swtchart.ISeries; +import org.swtchart.ITitle; +import org.swtchart.LineStyle; + +/** + * Builds the chart with axis. + * + * @author Qi Liang + */ +public abstract class AbstractChartWithAxisBuilder extends AbstractChartBuilder { + + /** + * Title of X axis. + */ + protected String xTitle = null; + protected boolean xLineGrid, yLineGrid; + + /** + * Create a chart series for that chart. + */ + protected abstract ISeries createChartISeries(int i); + + /** + * Constructor. + * + * @param dataSet + * data for chart + */ + + public AbstractChartWithAxisBuilder(IAdapter adapter, Composite parent, int style, String title) { + super(adapter, parent, style, title); + IPreferenceStore store = GraphingAPIUIPlugin.getDefault().getPreferenceStore(); + xLineGrid = store.getBoolean(GraphingAPIPreferenceConstants.P_SHOW_X_GRID_LINES); + yLineGrid = store.getBoolean(GraphingAPIPreferenceConstants.P_SHOW_Y_GRID_LINES); + } + + /** + * Builds X axis. + */ + @Override + protected void buildXAxis() { + String labels[] = adapter.getLabels(); + IAxis xAxis = this.chart.getAxisSet().getXAxis(0); + if (xLineGrid) + xAxis.getGrid().setStyle(LineStyle.SOLID); + else + xAxis.getGrid().setStyle(LineStyle.NONE); + xAxis.getTick().setForeground(BLACK); + ITitle xTitle = xAxis.getTitle(); + xTitle.setForeground(BLACK); + + if (labels.length > 0) + xTitle.setText(labels[0]); + else + xTitle.setText(""); //$NON-NLS-1$ + } + + /** + * Builds Y axis. + */ + @Override + protected void buildYAxis() { + IAxis yAxis = this.chart.getAxisSet().getYAxis(0); + yAxis.getTitle().setText(""); //$NON-NLS-1$ + if (yLineGrid) + yAxis.getGrid().setStyle(LineStyle.SOLID); + else + yAxis.getGrid().setStyle(LineStyle.NONE); + yAxis.getTick().setForeground(BLACK); + } + + /** + * Builds X series. + */ + @Override + protected void buildXSeries() { + Object data[][] = adapter.getData(); + if (data == null || data.length == 0) + return; + + int totalMaxItems = (int)Math.round(this.maxItems * scale); + int start = 0, len = Math.min(totalMaxItems, data.length); + if (totalMaxItems < data.length) { + start = data.length - totalMaxItems; + } + + double[] valx = new double[len]; + double[][] valy = new double[data[0].length-1][len]; + + ISeries allSeries[] = chart.getSeriesSet().getSeries(); + for (int i = 0; i < valx.length; i++) + for (int j = 0; j < data[start + i].length; j++) { + if (j == 0) + valx[i] = getDoubleValue(data[start + i][j]); + else + valy[j-1][i] = getDoubleValue(data[start + i][j]); + } + + for (int i = 0; i < valy.length; i++) { + ISeries series; + if (i >= allSeries.length) { + series = createChartISeries(i); + } else { + series = chart.getSeriesSet().getSeries()[i]; + } + series.setXSeries(valx); + series.setYSeries(valy[i]); + } + + chart.getAxisSet().adjustRange(); + chart.redraw(); + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartWithoutAxisBuilder.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartWithoutAxisBuilder.java new file mode 100644 index 0000000000..f953cba62b --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AbstractChartWithoutAxisBuilder.java @@ -0,0 +1,25 @@ +package org.eclipse.linuxtools.systemtap.graphingapi.ui.charts; + +import org.eclipse.swt.widgets.Composite; + +import org.eclipse.linuxtools.systemtap.graphingapi.core.adapters.IAdapter; + + +/** + * Builds the chart with axis. + * + * @author Qi Liang + */ +public abstract class AbstractChartWithoutAxisBuilder extends AbstractChartBuilder { + + /** + * Constructor. + * + * @param dataSet + * data for chart + */ + + public AbstractChartWithoutAxisBuilder(IAdapter adapter, Composite parent, int style, String title) { + super(adapter, parent, style, title); + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AreaChartBuilder.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AreaChartBuilder.java new file mode 100644 index 0000000000..ba909eb8e6 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/AreaChartBuilder.java @@ -0,0 +1,40 @@ +/**************************************************************** + * Copyright (c) 2006-2013 IBM Corp. + * 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 + * + * Contributors: + * IBM - initial API and implementation + * + **************************************************************** + */ +package org.eclipse.linuxtools.systemtap.graphingapi.ui.charts; + +import org.eclipse.linuxtools.systemtap.graphingapi.core.adapters.IAdapter; +import org.eclipse.swt.widgets.Composite; +import org.swtchart.ILineSeries; +import org.swtchart.ISeries; + +/** + * Builds bar chart. + * + * @author Qi Liang + */ + +public class AreaChartBuilder extends LineChartBuilder { + + public static final String ID = "org.eclipse.linuxtools.systemtap.graphingapi.ui.charts.areachartbuilder"; //$NON-NLS-1$ + + public AreaChartBuilder(Composite parent, int style, String title,IAdapter adapter) { + super(parent, style, title, adapter); + } + + @Override + protected ISeries createChartISeries(int i) { + ILineSeries series = (ILineSeries) super.createChartISeries(i); + series.enableArea(true); + return series; + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/BarChartBuilder.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/BarChartBuilder.java new file mode 100644 index 0000000000..c3d80e77ee --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/BarChartBuilder.java @@ -0,0 +1,48 @@ +/**************************************************************** + * Copyright (c) 2006-2013 IBM Corp. + * 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 + * + * Contributors: + * IBM - initial API and implementation + * + **************************************************************** + */ +package org.eclipse.linuxtools.systemtap.graphingapi.ui.charts; + +import org.eclipse.swt.widgets.Composite; + +import org.eclipse.linuxtools.systemtap.graphingapi.core.adapters.IAdapter; + +import org.swtchart.IBarSeries; +import org.swtchart.ISeries; +import org.swtchart.ISeries.SeriesType; + +/** + * Builds bar chart. + * + * @author Qi Liang + */ + +public class BarChartBuilder extends AbstractChartWithAxisBuilder { + public static final String ID = "org.eclipse.linuxtools.systemtap.graphingapi.ui.charts.barchartbuilder"; //$NON-NLS-1$ + + public BarChartBuilder(Composite parent, int style, String title,IAdapter adapter) { + super(adapter, parent, style, title); + } + + @Override + protected ISeries createChartISeries(int i) { + IBarSeries series = (IBarSeries)chart.getSeriesSet(). + createSeries(SeriesType.BAR, adapter.getLabels()[i+1]); + series.setBarColor(COLORS[i % COLORS.length]); + return series; + } + + @Override + public void updateDataSet() { + buildXSeries(); + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/LineChartBuilder.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/LineChartBuilder.java new file mode 100644 index 0000000000..4b88cfd4c7 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/LineChartBuilder.java @@ -0,0 +1,52 @@ +/**************************************************************** + * Copyright (c) 2006-2013 IBM Corp. + * 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 + * + * Contributors: + * IBM - initial API and implementation + * + **************************************************************** + */ +package org.eclipse.linuxtools.systemtap.graphingapi.ui.charts; + +import org.eclipse.swt.widgets.Composite; + +import org.eclipse.linuxtools.systemtap.graphingapi.core.adapters.IAdapter; + +import org.swtchart.ILineSeries; +import org.swtchart.ISeries; +import org.swtchart.ISeries.SeriesType; +import org.swtchart.LineStyle; + +/** + * Builds bar chart. + * + * @author Qi Liang + */ + +public class LineChartBuilder extends AbstractChartWithAxisBuilder { + + public static final String ID = "org.eclipse.linuxtools.systemtap.graphingapi.ui.charts.linechartbuilder"; //$NON-NLS-1$ + + public LineChartBuilder(Composite parent, int style, String title,IAdapter adapter) { + super(adapter, parent, style, title); + } + + @Override + public void updateDataSet() { + buildXSeries(); + } + + @Override + protected ISeries createChartISeries(int i) { + ILineSeries series = (ILineSeries) chart.getSeriesSet(). + createSeries(SeriesType.LINE, adapter.getLabels()[i+1]); + series.setSymbolColor(COLORS[i % COLORS.length]); + series.setLineColor(COLORS[i % COLORS.length]); + series.setLineStyle(LineStyle.SOLID); + return series; + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/PieChartBuilder.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/PieChartBuilder.java new file mode 100644 index 0000000000..c1e6223aac --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/PieChartBuilder.java @@ -0,0 +1,64 @@ +/**************************************************************** + * Copyright (c) 2006-2013 IBM Corp. + * 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 + * + * Contributors: + * IBM - initial API and implementation + * + **************************************************************** + */ +package org.eclipse.linuxtools.systemtap.graphingapi.ui.charts; + +import org.eclipse.linuxtools.dataviewers.piechart.PieChart; +import org.eclipse.linuxtools.systemtap.graphingapi.core.adapters.IAdapter; +import org.eclipse.swt.widgets.Composite; + +/** + * Builds Pie chart. + */ +public class PieChartBuilder extends AbstractChartWithoutAxisBuilder { + public static final String ID = "org.eclipse.linuxtools.systemtap.graphingapi.ui.charts.piechartbuilder"; //$NON-NLS-1$ + + public PieChartBuilder(Composite parent, int style, String title,IAdapter adapter) { + super(adapter, parent, style, title); + } + + @Override + protected void createChart() { + this.chart = new PieChart(this, getStyle()); + } + + @Override + protected void buildXSeries() { + Object data[][] = adapter.getData(); + if (data == null || data.length == 0 || data[0].length == 0) + return; + + int start = 0, len = Math.min(this.maxItems, data.length); + if (this.maxItems < data.length) { + start = data.length - this.maxItems; + } + + double[][] values = new double[len][data[0].length-1]; + String[] labels = new String[len]; + + for (int i = 0; i < labels.length; i++) { + if (data[i].length < 2) + return; + labels[i] = data[start + i][0].toString(); + for (int j = 1; j < data[start + i].length; j++) + values[i][j-1] = getDoubleValue(data[start + i][j]); + } + + ((PieChart)this.chart).addPieChartSeries(labels, values); + chart.redraw(); + } + + @Override + public void updateDataSet() { + buildXSeries(); + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/ScatterChartBuilder.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/ScatterChartBuilder.java new file mode 100644 index 0000000000..24789f7d59 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/charts/ScatterChartBuilder.java @@ -0,0 +1,41 @@ +/**************************************************************** + * Copyright (c) 2006-2013 IBM Corp. + * 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 + * + * Contributors: + * IBM - initial API and implementation + * + **************************************************************** + */ +package org.eclipse.linuxtools.systemtap.graphingapi.ui.charts; + +import org.eclipse.linuxtools.systemtap.graphingapi.core.adapters.IAdapter; +import org.eclipse.swt.widgets.Composite; +import org.swtchart.ILineSeries; +import org.swtchart.ISeries; +import org.swtchart.LineStyle; + +/** + * Builds bar chart. + * + * @author Qi Liang + */ + +public class ScatterChartBuilder extends LineChartBuilder { + public static final String ID = "org.eclipse.linuxtools.systemtap.graphingapi.ui.charts.scatterchartbuilder"; //$NON-NLS-1$ + + public ScatterChartBuilder(Composite parent, int style, String title,IAdapter adapter) { + super(parent, style, title, adapter); + } + + @Override + protected ISeries createChartISeries(int i) { + ILineSeries series = (ILineSeries)super.createChartISeries(i); + series.setSymbolColor(COLORS[i % COLORS.length]); + series.setLineStyle(LineStyle.NONE); + return series; + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/datadisplay/DataGrid.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/datadisplay/DataGrid.java new file mode 100644 index 0000000000..2f0ddf4a46 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/datadisplay/DataGrid.java @@ -0,0 +1,343 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.datadisplay; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.GraphingAPIUIPlugin; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.IDataSet; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.IFilteredDataSet; +import org.eclipse.linuxtools.systemtap.graphingapi.core.filters.IDataSetFilter; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.preferences.GraphingAPIPreferenceConstants; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.dataset.DataSetFactory; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.filter.AvailableFilterTypes; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.filter.SelectFilterWizard; +import org.eclipse.linuxtools.systemtap.structures.IFormattingStyles; +import org.eclipse.linuxtools.systemtap.structures.StringFormatter; +import org.eclipse.linuxtools.systemtap.structures.listeners.IUpdateListener; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MenuAdapter; +import org.eclipse.swt.events.MenuEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.PlatformUI; + + + +public class DataGrid implements IUpdateListener { + public DataGrid(Composite composite, IDataSet set, int style) { + prefs = GraphingAPIUIPlugin.getDefault().getPreferenceStore(); + manualResize = !prefs.getBoolean(GraphingAPIPreferenceConstants.P_AUTO_RESIZE); + + dataSet = set; + filteredDataSet = (dataSet instanceof IFilteredDataSet) + ? (IFilteredDataSet)dataSet + : DataSetFactory.createFilteredDataSet(dataSet); + this.style = style; + clickLocation = new Point(-1, -1); + removedItems = 0; + createPartControl(composite); + } + + public void setLayoutData(Object data) { + table.setLayoutData(data); + } + + public IDataSet getDataSet() { return dataSet; } + public Control getControl() { return table; } + + public void createPartControl(Composite parent) { + table = new Table(parent, SWT.SINGLE | SWT.FULL_SELECTION); + table.setHeaderVisible(true); + table.setLinesVisible(true); + table.getVerticalBar().setVisible(true); + + String[] names = dataSet.getTitles(); + TableColumn column = new TableColumn(table, SWT.LEFT); + column.setText(Localization.getString("DataGrid.Row")); //$NON-NLS-1$ + column.pack(); + column.setMoveable(false); + column.setResizable(false); + + columnFormat = new IFormattingStyles[names.length]; + for(int i=0; i<names.length; i++) { + column = new TableColumn(table, SWT.LEFT); + column.setText(names[i]); + column.pack(); + column.setMoveable(true); + + columnFormat[i] = new StringFormatter(); + } + + table.setMenu(this.initMenus()); + + table.addListener(SWT.MouseDown, new Listener() { + @Override + public void handleEvent(Event event) { + clickLocation.x = event.x; + clickLocation.y = event.y; + } + }); + handleUpdateEvent(); + } + + public Menu initMenus() { + Menu menu = new Menu(table.getShell(), SWT.POP_UP); + menu.addMenuListener(new MainMenuListener()); + + Menu formatMenu = new Menu(menu); + MenuItem item = new MenuItem(menu, SWT.CASCADE); + item.setText(Localization.getString("DataGrid.FormatAs")); //$NON-NLS-1$ + item.setMenu(formatMenu); + + filterMenu = new Menu(menu); + item = new MenuItem(menu, SWT.CASCADE); + item.setText(Localization.getString("DataGrid.AddFilter")); //$NON-NLS-1$ + item.addSelectionListener(new AddFilterSelection()); + + item = new MenuItem(menu, SWT.CASCADE); + item.setText(Localization.getString("DataGrid.RemoveFilter")); //$NON-NLS-1$ + item.setMenu(filterMenu); + + IDataSetFilter[] filters = filteredDataSet.getFilters(); + if(null != filters) { + for(int i=0; i<filters.length; i++) { + item = new MenuItem(filterMenu, SWT.CASCADE); + item.setText(AvailableFilterTypes.getFilterName(filters[i].getID())); + item.setData(filters[i]); + item.addSelectionListener(new RemoveFilterSelection()); + } + } + + item = new MenuItem(menu, SWT.CHECK); + item.setText(Localization.getString("DataGrid.ManualyResize")); //$NON-NLS-1$ + item.addSelectionListener(new MenuManualyResizedSelection()); + + for(int i=0; i<IFormattingStyles.FORMAT_TITLES.length; i++) { + item = new MenuItem(formatMenu, SWT.RADIO); + item.setText(IFormattingStyles.FORMAT_TITLES[i]); + item.addSelectionListener(new MenuFormatSelection()); + } + + formatMenu.addMenuListener(new FormatMenuListener()); + return menu; + } + + private int getSelectedColumn() { + TableColumn[] cols = table.getColumns(); + int location = 0; + for(int i=0; i<cols.length; i++) + if(clickLocation.x > location && clickLocation.x < (location+=cols[i].getWidth())) + return i; + + return cols.length-1; + } + + public class MainMenuListener extends MenuAdapter { + @Override + public void menuShown(MenuEvent e) { + MenuItem item = ((Menu)e.widget).getItem(1); + item.setSelection(manualResize); + } + } + + public class MenuManualyResizedSelection extends SelectionAdapter { + @Override + public void widgetSelected(SelectionEvent e) { + manualResize = !manualResize; + } + } + + public class AddFilterSelection extends SelectionAdapter { + @Override + public void widgetSelected(SelectionEvent e) { + SelectFilterWizard wizard = new SelectFilterWizard(dataSet.getTitles()); + IWorkbench workbench = PlatformUI.getWorkbench(); + wizard.init(workbench, null); + WizardDialog dialog = new WizardDialog(workbench.getActiveWorkbenchWindow().getShell(), wizard); + dialog.create(); + dialog.open(); + + IDataSetFilter filter = wizard.getFilter(); + wizard.dispose(); + + if(null != filter) { + filteredDataSet.addFilter(filter); + table.removeAll(); + handleUpdateEvent(); + + MenuItem item = new MenuItem(filterMenu, SWT.CASCADE); + item.setText(AvailableFilterTypes.getFilterName(filter.getID())); + item.setData(filter); + item.addSelectionListener(new RemoveFilterSelection()); + } + } + } + + public class RemoveFilterSelection implements SelectionListener { + @Override + public void widgetSelected(SelectionEvent e) { + IDataSetFilter idsf = (IDataSetFilter)((MenuItem)e.widget).getData(); + e.widget.dispose(); + + if(filteredDataSet.removeFilter(idsf)) { + table.removeAll(); + handleUpdateEvent(); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) {} + } + + public class FormatMenuListener extends MenuAdapter { + @Override + public void menuShown(MenuEvent e) { + MenuItem[] items = ((Menu)e.widget).getItems(); + boolean doubleValid = false, longValid = false; + String itemText; + + int selectedCol = Math.max(1, getSelectedColumn()); + + for(int i=0; i<items.length; i++) + items[i].setSelection(false); + items[columnFormat[selectedCol-1].getFormat()].setSelection(true); + + itemText = dataSet.getRow(0)[selectedCol-1].toString(); + items[IFormattingStyles.UNFORMATED].setEnabled(true); + items[IFormattingStyles.STRING].setEnabled(true); + + try { + Double.parseDouble(itemText); + doubleValid = true; + + try { + Long.parseLong(itemText); + longValid = true; + } catch(NumberFormatException nfe2) {} + } catch(NumberFormatException nfe) {} + + items[IFormattingStyles.DOUBLE].setEnabled(doubleValid); + items[IFormattingStyles.HEX].setEnabled(longValid); + items[IFormattingStyles.OCTAL].setEnabled(longValid); + items[IFormattingStyles.BINARY].setEnabled(longValid); + items[IFormattingStyles.DATE].setEnabled(longValid); + } + } + + public class MenuFormatSelection extends SelectionAdapter { + @Override + public void widgetSelected(SelectionEvent e) { + int format = IFormattingStyles.UNFORMATED; + int column = Math.max(1, getSelectedColumn()); + int i; + for(i=0; i<IFormattingStyles.FORMAT_TITLES.length; i++) + if(IFormattingStyles.FORMAT_TITLES[i].equals(((MenuItem)e.getSource()).getText())) + format = i; + + Object[] data = dataSet.getColumn(column-1); + columnFormat[column-1].setFormat(format); + for(i=0; i<table.getItemCount(); i++) + table.getItem(i).setText(column, columnFormat[column-1].format(data[i].toString())); + table.redraw(); + } + } + + @Override + public void handleUpdateEvent() { + if(table.isDisposed()) return; + + table.getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + TableItem item; + int startLocation, endLocation = filteredDataSet.getRowCount(); + + if(FULL_UPDATE == (style & FULL_UPDATE)) { + //Remove extra items so save memory. + removedItems += table.getItemCount(); + table.removeAll(); + startLocation = 0; + } else { + startLocation = table.getItemCount()+removedItems; + } + + //Add all the new items to the table + Object[] os; + for(int j,i=startLocation; i<endLocation; i++) { + item = new TableItem(table, SWT.NONE); + os = filteredDataSet.getRow(i); + + item.setText(0, "" + i); //$NON-NLS-1$ + for(j=0; j<os.length; j++) + item.setText(j+1, columnFormat[j].format(os[j].toString())); + } + + if(FULL_UPDATE != (style & FULL_UPDATE)) { + //Remove extra items so save memory. + if(table.getItemCount() > prefs.getInt(GraphingAPIPreferenceConstants.P_MAX_DATA_ITEMS)) { + int items = table.getItemCount()-prefs.getInt(GraphingAPIPreferenceConstants.P_MAX_DATA_ITEMS); + table.remove(0, items-1); + removedItems += items; + } + } + + //Resize the columns + TableColumn col = table.getColumn(0); + col.pack(); + if(!manualResize) { + TableColumn[] cols = table.getColumns(); + for(int i=1; i<cols.length; i++) + cols[i].pack(); + } + //Use if we want to set focus to newly added item + if(prefs.getBoolean(GraphingAPIPreferenceConstants.P_JUMP_NEW_TABLE_ENTRY)) + table.showItem(table.getItem(table.getItemCount()-1)); + } + }); + } + + public void dispose() { + dataSet = null; + table.dispose(); + table = null; + clickLocation = null; + columnFormat = null; + } + + protected IDataSet dataSet; + protected IFilteredDataSet filteredDataSet; + protected IFormattingStyles columnFormat[]; + protected int removedItems; + protected Table table; + protected Point clickLocation; + protected IPreferenceStore prefs; + protected boolean manualResize; + protected Menu filterMenu; + protected int style; + + public static final int NONE = 0; + public static final int FULL_UPDATE = 1; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/AChart.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/AChart.java new file mode 100644 index 0000000000..4d49a55433 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/AChart.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs; + +import java.util.LinkedList; + +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.core.IGraphColorConstants; +import org.eclipse.linuxtools.systemtap.graphingapi.core.adapters.IAdapter; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets.GraphCanvas; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets.GraphComposite; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets.GraphLabel; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets.GraphLegend; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.widgets.Button; + + + +public abstract class AChart extends GraphCanvas implements IGraph { + @SuppressWarnings("unchecked") + public AChart(GraphComposite parent, int style, String title, IAdapter adapt) { + super(parent, style); + adapter = adapt; + + elementList = new LinkedList[adapt.getSeriesCount()]; + for(int i=0; i<elementList.length; i++) + elementList[i] = new LinkedList<Object>(); + + createLegend(); + createTitle(title); + + this.addPaintListener(paintListener); + + parent.addCheckOption(Localization.getString("AChart.Title"), titleListener); //$NON-NLS-1$ + parent.addCheckOption(Localization.getString("AChart.Legend"), legendListener); //$NON-NLS-1$ + } + + protected void createTitle(String title) { + this.title = new GraphLabel(this, title, this, 0.1f, SWT.BOLD); + } + + protected void createLegend() { + String[] labels = adapter.getLabels(); + String[] labels2 = new String[labels.length-1]; + Color[] colors = new Color[labels2.length]; + + for(int i=0; i<labels2.length; i++) { + labels2[i] = labels[i+1]; + colors[i] = new Color(this.getDisplay(), IGraphColorConstants.COLORS[i]); + } + + legend = new GraphLegend(this, labels2, colors); + } + + protected void paintAll(GC gc) { + paintElementList(gc); + if(showLegend && legend != null) + legend.paint(gc); + if(showTitle && title != null) + title.paint(gc); + } + + @Override + public void dispose() { + this.removePaintListener(paintListener); + parent.removeCheckOption(Localization.getString("AChart.Title")); //$NON-NLS-1$ + parent.removeCheckOption(Localization.getString("AChart.Legend")); //$NON-NLS-1$ + + legendListener = null; + titleListener = null; + + super.dispose(); + } + + /* + * Listeners are below: + * paintListener - A PaintListener for making sure everything is drawn + * titleListener - A SelectionListener for the title button + * legendListener - A SelectionListener for the legend checkbox + */ + private final PaintListener paintListener = new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + paintAll(e.gc); + } + }; + + private SelectionListener titleListener = new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent e) {} + @Override + public void widgetSelected(SelectionEvent e) { + showTitle = ((Button)e.getSource()).getSelection(); + repaint(); + } + }; + + private SelectionListener legendListener = new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent e) {} + @Override + public void widgetSelected(SelectionEvent e) { + showLegend = ((Button)e.getSource()).getSelection(); + repaint(); + } + }; + + public abstract boolean isMultiGraph(); + @Override + public abstract void handleUpdateEvent(); + public abstract void paintElementList(GC gc); + + protected GraphComposite parent; + protected GraphLegend legend; + protected GraphLabel title; + protected LinkedList<Object>[] elementList; + + public boolean showTitle, showLegend; + + private IAdapter adapter; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/AGraph.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/AGraph.java new file mode 100644 index 0000000000..191a7786b3 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/AGraph.java @@ -0,0 +1,242 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs; + +import java.util.LinkedList; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.GraphingAPIUIPlugin; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.core.IGraphColorConstants; +import org.eclipse.linuxtools.systemtap.graphingapi.core.adapters.IAdapter; +import org.eclipse.linuxtools.systemtap.graphingapi.core.structures.DataPoint; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.preferences.GraphingAPIPreferenceConstants; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets.GraphAxis; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets.GraphAxis2; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets.GraphComposite; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Button; + + + +public abstract class AGraph extends AChart { + public AGraph(GraphComposite parent, int style, String title, IAdapter adapt) { + super(parent, style, title, adapt); + adapter = adapt; + axes = new LinkedList<GraphAxis>(); + + IPreferenceStore store = GraphingAPIUIPlugin.getDefault().getPreferenceStore(); + xSeriesTicks = store.getInt(GraphingAPIPreferenceConstants.P_X_SERIES_TICKS); + ySeriesTicks = store.getInt(GraphingAPIPreferenceConstants.P_Y_SERIES_TICKS); + maxItems = store.getInt(GraphingAPIPreferenceConstants.P_MAX_DATA_ITEMS); + viewableItems = store.getInt(GraphingAPIPreferenceConstants.P_VIEWABLE_DATA_ITEMS); + + createAxis(Localization.getString("AGraph.xAxis"), xSeriesTicks, GraphAxis.HORIZONTAL); //$NON-NLS-1$ + createAxis(Localization.getString("AGraph.yAxis"), ySeriesTicks, GraphAxis.VERTICAL); //$NON-NLS-1$ + + GraphingAPIUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(propertyChangeListener); + + parent.addCheckOption(Localization.getString("AGraph.GridLines"), gridListener); //$NON-NLS-1$ + if(adapter.getSeriesCount() > 1) + parent.addCheckOption(Localization.getString("AGraph.Normalize"), normalizeListener); //$NON-NLS-1$ + } + + protected void createAxis(String title, int tickCount, int style) { + axes.add(new GraphAxis(this, title, tickCount, style)); + } + + protected void createAxis2(String title, int tickCount, int style) { + axes.add(new GraphAxis2(this, title, tickCount, style, this.axisColor)); + } + + //******************************************************Please remove + public Rectangle getArea(int items) { + int uBound = elementList[0].size(); + int lBound = (uBound > items) ? (uBound-items) : 0; + + int maxX = Integer.MIN_VALUE; + int minX = Integer.MAX_VALUE; + int maxY = Integer.MIN_VALUE; + int minY = Integer.MAX_VALUE; + + DataPoint p; + Object o; + + for(int j=0; j<elementList.length; j++) { + for(int i=lBound; i<uBound; i++) { + o = elementList[j].get(i); + p = (DataPoint)o; + if(p.x < minX) minX = (int)p.x; + if(p.x > maxX) maxX = (int)p.x; + if(p.y < minY) minY = (int)p.y; + if(p.y > maxY) maxY = (int)p.y; + } + } + + return new Rectangle(minX, minY, maxX-minX, maxY-minY); + } + + private synchronized void rebound() { + getDisplay().syncExec(new Runnable() { + @Override + public void run() { + setGlobalArea(getArea(maxItems)); + setLocalArea(getArea(viewableItems)); + } + }); + } + + @Override + public synchronized void repaint() { + rebound(); + super.repaint(); + } + //*******************************************************End remove + + + /** + * Sets the category axis that is displayed to the axis belonging to the input series index. + * @param series Series to display the axis for. + */ + public void addSeriesAxis(int series) { + if(selectedSeries != (series+1)) { + removeSeriesAxis(); + seriesAxis = new GraphAxis2(this, Localization.getString("AGraph.SeriesAxis"), ySeriesTicks, //$NON-NLS-1$ + GraphAxis2.ALIGN_RIGHT | + GraphAxis2.HIDE_GRID_LINES | + GraphAxis2.UNNORMALIZED | + GraphAxis2.HIDE_TITLE, + new Color(this.getDisplay(), IGraphColorConstants.COLORS[series])); + selectedSeries = series+1; + axes.add(seriesAxis); + this.repaint(); + } + } + + /** + * Removes the series axis from the graph. + */ + public void removeSeriesAxis() { + if(null != seriesAxis) { + axes.remove(seriesAxis); + seriesAxis = null; + selectedSeries = -1; + this.repaint(); + } + } + + @Override + protected void paintAll(GC gc) { + for(GraphAxis axis: axes) { + axis.paint(gc); + } + super.paintAll(gc); + } + + @Override + public void dispose() { + GraphingAPIUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(propertyChangeListener); + + parent.removeCheckOption(Localization.getString("AGraph.Normalize")); //$NON-NLS-1$ + parent.removeCheckOption(Localization.getString("AGraph.GridLines")); //$NON-NLS-1$ + + normalizeListener = null; + gridListener = null; + + parent = null; + + super.dispose(); + } + + /* + * Listeners are below: + * gridListener - A SelectionListener for the Grid checkbox + * normalizeListener - A SelectionListener for the normalization checkbox + * propertyChangeListener - Detects changes in user preferences and applies them + */ + private final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent event) { + IPreferenceStore store = GraphingAPIUIPlugin.getDefault().getPreferenceStore(); + if(event.getProperty().equals(GraphingAPIPreferenceConstants.P_MAX_DATA_ITEMS)) + maxItems = store.getInt(GraphingAPIPreferenceConstants.P_MAX_DATA_ITEMS); + else if(event.getProperty().equals(GraphingAPIPreferenceConstants.P_VIEWABLE_DATA_ITEMS)) + viewableItems = store.getInt(GraphingAPIPreferenceConstants.P_VIEWABLE_DATA_ITEMS); + else if(event.getProperty().equals(GraphingAPIPreferenceConstants.P_X_SERIES_TICKS)) { + xSeriesTicks = store.getInt(GraphingAPIPreferenceConstants.P_X_SERIES_TICKS); + for(GraphAxis a: axes) { + if(GraphAxis.HORIZONTAL == a.getType()) { + a.setTickCount(xSeriesTicks); + } + } + } else if(event.getProperty().equals(GraphingAPIPreferenceConstants.P_Y_SERIES_TICKS)) { + ySeriesTicks = store.getInt(GraphingAPIPreferenceConstants.P_Y_SERIES_TICKS); + for(GraphAxis a:axes) { + if(GraphAxis.VERTICAL == a.getType()) { + a.setTickCount(ySeriesTicks); + } + } + } else if(event.getProperty().equals(GraphingAPIPreferenceConstants.P_SHOW_X_GRID_LINES)) { + showXGrid = store.getBoolean(GraphingAPIPreferenceConstants.P_SHOW_X_GRID_LINES); + showGrid = showXGrid || showYGrid; + } else if(event.getProperty().equals(GraphingAPIPreferenceConstants.P_SHOW_X_GRID_LINES)) { + showYGrid = store.getBoolean(GraphingAPIPreferenceConstants.P_SHOW_X_GRID_LINES); + showGrid = showXGrid || showYGrid; + } + + repaint(); + } + }; + + private SelectionListener gridListener = new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent e) {} + @Override + public void widgetSelected(SelectionEvent e) { + showGrid = ((Button)e.getSource()).getSelection(); + repaint(); + } + }; + + private SelectionListener normalizeListener = new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent e) {} + @Override + public void widgetSelected(SelectionEvent e) { + normalize = ((Button)e.getSource()).getSelection(); + if(!normalize) removeSeriesAxis(); + handleUpdateEvent(); + } + }; + + protected LinkedList<GraphAxis> axes; + + private IAdapter adapter; + private boolean showYGrid, showXGrid; + + protected static int xSeriesTicks; + protected static int ySeriesTicks; + protected static int maxItems; + protected static int viewableItems; + protected int removedItems; + + public boolean showGrid, normalize; + + protected int selectedSeries; + protected GraphAxis seriesAxis; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/BarGraph.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/BarGraph.java new file mode 100644 index 0000000000..ec568cba72 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/BarGraph.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs; + +import org.eclipse.linuxtools.systemtap.graphingapi.core.IGraphColorConstants; +import org.eclipse.linuxtools.systemtap.graphingapi.core.adapters.BlockAdapter; +import org.eclipse.linuxtools.systemtap.graphingapi.core.adapters.IAdapter; +import org.eclipse.linuxtools.systemtap.graphingapi.core.structures.DataPoint; +import org.eclipse.linuxtools.systemtap.graphingapi.core.structures.NumberType; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets.GraphComposite; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; + + + +/** + * A Bar Graph implementation for the Graphing system. + * @author Henry Hughes + * @author Ryan Morse + */ +public class BarGraph extends AGraph implements IBlockGraph, IScrollGraph { + /** + * Default constructor for the bar graph. + * @param title Title of the graph. + * @param style Style code to use. + * @param adapt Dataset Adapter for the graph. + */ + public BarGraph(GraphComposite parent, int style, String title, IAdapter adapter) { + super(parent, style, title, adapter); + this.adapter = adapter; + fullUpdate = (adapter instanceof BlockAdapter) ? true : false; + handleUpdateEvent(); + } + + /** + * Paints all of the data elements to the screen + */ + @Override + public void paintElementList(GC gc) { + DataPoint[] points = new DataPoint[0]; + + Color temp = gc.getForeground(); + Color temp1 = gc.getBackground(); + + Color c; + Color c1; + + double xSize = super.getSize().x - (super.getXPadding()<<1); + xSize /= (super.getLocalWidth()+1); + xSize /= (elementList.length); + double ySize = super.getSize().y - (super.getYPadding()<<1); + ySize /= (super.getLocalHeight()); + + double px, py; + double pw=0, ph; + + for(int j=0; j<elementList.length; j++) { + points = elementList[j].toArray(points); + + c = new Color(getDisplay(), IGraphColorConstants.COLORS[j]); + c1 = new Color(getDisplay(), c.getRed()>>1, c.getGreen()>>1, c.getBlue()>>1); + gc.setForeground(c); + gc.setBackground(c1); + double width = WIDTH_PERCENT; + for(DataPoint point :points) { + px = super.getLocation().x + (((point.x * (elementList.length))-super.getLocalXMin()) * xSize) + super.getXPadding(); + px = px + ((j - elementList.length/2) * (xSize * width)); + pw = (xSize * width); + + py = super.getSize().y - super.getYPadding(); + ph = ((super.getLocalYMax() - point.y) * ySize) + super.getYPadding()-py; + gc.fillGradientRectangle((int)(px), (int)py, (int)pw, (int)ph, true); + } + } + + gc.setForeground(temp); + gc.setBackground(temp1); + } + + @Override + public boolean isMultiGraph() { + return adapter.getSeriesCount() > 0; + } + + /** + * Handles an update notification for new data in the Data Set. Causes the graph to add + * all new samples to the graph, and then repaint itself. + */ + @Override + public void handleUpdateEvent() { + if(null == adapter) return; + + this.getDisplay().syncExec(new Runnable() { + @Override + public void run() { + Object[][] data; + if(fullUpdate) { + for(int i=0; i<elementList.length; i++) + elementList[i].clear(); + data = adapter.getData(); + } else + data = adapter.getData(removedItems, adapter.getRecordCount()); + + if(normalize) { + double max; + for(int j,i=0; i<adapter.getSeriesCount(); i++) { + elementList[i].clear(); //TODO: Only temparary + max = adapter.getYSeriesMax(i, removedItems, adapter.getRecordCount()).doubleValue() / 100; + for(j=0; j<data.length; j++) { + elementList[i].add(new DataPoint(adapter instanceof BlockAdapter ? j : NumberType.obj2num(data[j][0]).doubleValue(), + NumberType.obj2num(data[j][i+1]).doubleValue() / max)); + } + } + } else { + for(int j,i=0; i<adapter.getSeriesCount(); i++) { + elementList[i].clear(); //TODO: Only temparary + for(j=0; j<data.length; j++) { + elementList[i].add(new DataPoint(adapter instanceof BlockAdapter ? j : NumberType.obj2num(data[j][0]).doubleValue(), + NumberType.obj2num(data[j][i+1]).doubleValue())); + } + } + } + } + }); + this.repaint(); + } + + private IAdapter adapter; + private boolean fullUpdate; + public static final String ID = "org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs.bargraph"; //$NON-NLS-1$ + private static final double WIDTH_PERCENT = 0.8; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/IBlockGraph.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/IBlockGraph.java new file mode 100644 index 0000000000..428ff2c37a --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/IBlockGraph.java @@ -0,0 +1,16 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs; + +public interface IBlockGraph extends IGraph { + +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/IGraph.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/IGraph.java new file mode 100644 index 0000000000..66891f6d54 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/IGraph.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs; + +import org.eclipse.linuxtools.systemtap.structures.listeners.IUpdateListener; + + + +public interface IGraph extends IUpdateListener { + //public boolean isMultiGraph(); + //public void repaint(); + //public void dispose(); + //public void setBackground(Color c); + //public void setForeground(Color c); + //public void setLayoutData(Object layout); + //public void setScale(double scale); +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/IScrollGraph.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/IScrollGraph.java new file mode 100644 index 0000000000..e0fc654c23 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/IScrollGraph.java @@ -0,0 +1,16 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs; + +public interface IScrollGraph extends IGraph { + +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/LineGraph.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/LineGraph.java new file mode 100644 index 0000000000..77c65e1ce8 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/LineGraph.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs; + +import org.eclipse.linuxtools.systemtap.graphingapi.core.IGraphColorConstants; +import org.eclipse.linuxtools.systemtap.graphingapi.core.adapters.ScrollAdapter; +import org.eclipse.linuxtools.systemtap.graphingapi.core.structures.DataPoint; +import org.eclipse.linuxtools.systemtap.graphingapi.core.structures.NumberType; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets.GraphComposite; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; + + + +/** + * A line graph implementation for the graphing system. + * @author Ryan Morse + * @author Henry Hughes + */ +public class LineGraph extends AGraph implements IScrollGraph { + /** + * Default constructor for LineGraph. Simply invokes the constructor from <code>ScatterGraph</code> + * and fires the Update Event when its done, causing the graph to draw itself. + */ + public LineGraph(GraphComposite parent, int style, String title, ScrollAdapter adapter) { + super(parent, style, title, adapter); + this.adapter = adapter; + handleUpdateEvent(); + } + + @Override + public void paintElementList(GC gc) { + DataPoint[] points = new DataPoint[0]; + + Color temp = gc.getForeground(); + Color c; + + double xSize = super.getSize().x - (super.getXPadding()<<1); + xSize /= (super.getLocalWidth()); + double ySize = super.getSize().y - (super.getYPadding()<<1); + ySize /= (super.getLocalHeight()); + + double px, py; + double px2, py2; + + for(int j=0; j<elementList.length; j++) { + points = elementList[j].toArray(points); + c = new Color(getDisplay(), IGraphColorConstants.COLORS[j]); + gc.setForeground(c); + + px2 = 0; + py2 = super.getSize().y - super.getYPadding(); + for(DataPoint point: points) { + px = (point.x-super.getLocalXMin()); + px *= xSize; + px += super.getXPadding(); + + py = super.getLocalYMax() - point.y; + py *= ySize; + py += super.getYPadding(); + + gc.drawLine((int)px, (int)py, (int)px2, (int)py2); + px2 = px; + py2 = py; + } + } + + gc.setForeground(temp); + } + + @Override + public boolean isMultiGraph() { + return adapter.getSeriesCount() > 0; + } + + /** + * Updates the graph when the <code>DataSet</code> has more data, adding the new samples to the graph. + */ + @Override + public void handleUpdateEvent() { + if(null == adapter) return; + + this.getDisplay().syncExec(new Runnable() { + @Override + public void run() { + Object[][] data = adapter.getData(removedItems, adapter.getRecordCount()); + if(normalize) { + double max; + for(int j,i=0; i<adapter.getSeriesCount(); i++) { + elementList[i].clear(); //TODO: Only temparary + max = adapter.getYSeriesMax(i, removedItems, adapter.getRecordCount()).doubleValue() / 100; + for(j=0; j<data.length; j++) { + elementList[i].add(new DataPoint(NumberType.obj2num(data[j][0]).doubleValue(), + NumberType.obj2num(data[j][i+1]).doubleValue() / max)); + } + } + } else { + for(int j,i=0; i<adapter.getSeriesCount(); i++) { + elementList[i].clear(); //TODO: Only temparary + for(j=0; j<data.length; j++) { + elementList[i].add(new DataPoint(NumberType.obj2num(data[j][0]).doubleValue(), + NumberType.obj2num(data[j][i+1]).doubleValue())); + } + } + } + } + }); + this.repaint(); + } + + private ScrollAdapter adapter; + public static final String ID = "org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs.linegraph"; //$NON-NLS-1$ +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/PieChart.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/PieChart.java new file mode 100644 index 0000000000..03ae247aae --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/PieChart.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs; + +import org.eclipse.linuxtools.systemtap.graphingapi.core.IGraphColorConstants; +import org.eclipse.linuxtools.systemtap.graphingapi.core.adapters.BlockAdapter; +import org.eclipse.linuxtools.systemtap.graphingapi.core.structures.NumberType; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets.GraphComposite; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets.GraphLegend; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; + + + +public class PieChart extends AChart implements IBlockGraph { + public PieChart(GraphComposite parent, int style, String title, BlockAdapter adapt) { + super(parent, style, title, adapt); + adapter = adapt; + handleUpdateEvent(); + } + + private void updateLegend() { + Object [][] l = adapter.getData(); + String [] labels = new String[adapter.getRecordCount()]; + Color[] colors = new Color[labels.length]; + + for(int i=0; i<labels.length; i++) { + labels[i] = l[i][0].toString(); + colors[i] = new Color(this.getDisplay(), IGraphColorConstants.COLORS[i]); + } + + legend = new GraphLegend(this, labels, colors); + } + + @Override + public void paintElementList(GC gc) { + updateLegend(); //Make sure legend has current keys + Color temp = gc.getForeground(); + Color temp1 = gc.getBackground(); + Color c; + + int pw = Math.min(super.getSize().x - (super.getXPadding()<<1), super.getSize().y - (super.getYPadding()<<1)); + int px = (super.getSize().x - super.getXPadding() - pw)>>1; + int py = (super.getSize().y - super.getYPadding() - pw)>>1; + + int angle1, angle0 = 0; + Number[] points = new Number[0]; + points = elementList[0].toArray(points); + for(int i=0; i<points.length; i++) { + c = new Color(getDisplay(), IGraphColorConstants.COLORS[i]); + gc.setForeground(c); + gc.setBackground(c); + angle1 = (int)((MAX_ANGLE*(points[i].doubleValue()/sum))+0.51); + gc.fillArc(px, py, pw, pw, angle0, angle1); + angle0 += angle1; + } + + //If there is no data to display draw a crossed out circle + if(0 == points.length) { + gc.drawArc(px, py, pw, pw, 0, 360); + gc.drawLine(px, py, px+pw, py+pw); + gc.drawLine(px, py+pw, px+pw, py); + } + + gc.setForeground(temp); + gc.setBackground(temp1); + } + + @Override + public boolean isMultiGraph() { + return false; + } + + @Override + public void handleUpdateEvent() { + if(null == adapter) return; + + this.getDisplay().syncExec(new Runnable() { + @Override + public void run() { + Object[][] data; + elementList[0].clear(); + data = adapter.getData(); + + Number n; + sum = 0; + for(int i=0; i<data.length; i++) { + n = NumberType.obj2num(data[i][1]); + elementList[0].add(n); + sum += n.doubleValue(); + } + } + }); + this.repaint(); + } + + public static final String ID = "org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs.piechart"; //$NON-NLS-1$ + private BlockAdapter adapter; + private double sum; + private static final int MAX_ANGLE = 360; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/ScatterGraph.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/ScatterGraph.java new file mode 100644 index 0000000000..16ccb48003 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/graphs/ScatterGraph.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs; + +import org.eclipse.linuxtools.systemtap.graphingapi.core.IGraphColorConstants; +import org.eclipse.linuxtools.systemtap.graphingapi.core.adapters.ScrollAdapter; +import org.eclipse.linuxtools.systemtap.graphingapi.core.structures.DataPoint; +import org.eclipse.linuxtools.systemtap.graphingapi.core.structures.NumberType; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets.GraphComposite; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; + + + +/** + * A generic scatter plot implementation. + * @author Ryan Morse + * @author Henry Hughes + */ +public class ScatterGraph extends AGraph implements IScrollGraph { + /** + * Default constructor for ScatterGraph. Simply invokes the constructor from <code>Graph</code> + * and fires the Update Event when its done, causing the graph to draw itself. + */ + public ScatterGraph(GraphComposite parent, int style, String title, ScrollAdapter adapter) { + super(parent, style, title, adapter); + this.adapter = adapter; + handleUpdateEvent(); + } + + @Override + public void paintElementList(GC gc) { + DataPoint[] points = new DataPoint[0]; + + Color temp = gc.getForeground(); + Color temp1 = gc.getBackground(); + Color c; + + double xSize = super.getSize().x - (super.getXPadding()<<1); + xSize /= (super.getLocalWidth()); + double ySize = super.getSize().y - (super.getYPadding()<<1); + ySize /= (super.getLocalHeight()); + + double px, py; + + for(int j=0; j<elementList.length; j++) { + points = elementList[j].toArray(points); + + c = new Color(getDisplay(), IGraphColorConstants.COLORS[j]); + gc.setForeground(c); + gc.setBackground(c); + + for(DataPoint point:points) { + px = (point.x-super.getLocalXMin()); + px *= xSize; + px += super.getXPadding() - (DIAMETER>>1); + + py = super.getLocalYMax() - point.y; + py *= ySize; + py += super.getYPadding() - (DIAMETER>>1); + + gc.fillOval((int)px, (int)py, DIAMETER, DIAMETER); + } + } + + gc.setForeground(temp); + gc.setBackground(temp1); + } + + @Override + public boolean isMultiGraph() { + return adapter.getSeriesCount() > 0; + } + + /** + * Updates the graph when the <code>IDataSet</code> has more data, adding the new samples to the graph. + */ + @Override + public void handleUpdateEvent() { + if(null == adapter) return; + + this.getDisplay().syncExec(new Runnable() { + @Override + public void run() { + Object[][] data = adapter.getData(removedItems, adapter.getRecordCount()); + + if(normalize) { + double max; + for(int j,i=0; i<adapter.getSeriesCount(); i++) { + elementList[i].clear(); //TODO: Only temparary + max = adapter.getYSeriesMax(i, removedItems, adapter.getRecordCount()).doubleValue() / 100; + for(j=0; j<data.length; j++) { + elementList[i].add(new DataPoint(NumberType.obj2num(data[j][0]).doubleValue(), + NumberType.obj2num(data[j][i+1]).doubleValue() / max)); + } + } + } else { + for(int j,i=0; i<adapter.getSeriesCount(); i++) { + elementList[i].clear(); //TODO: Only temparary + for(j=0; j<data.length; j++) { + elementList[i].add(new DataPoint(NumberType.obj2num(data[j][0]).doubleValue(), + NumberType.obj2num(data[j][i+1]).doubleValue())); + } + } + } + } + }); + this.repaint(); + } + + private ScrollAdapter adapter; + public static final String ID = "org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs.scattergraph"; //$NON-NLS-1$ + private static final int DIAMETER = 5; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/preferences/DataTablePreferencePage.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/preferences/DataTablePreferencePage.java new file mode 100644 index 0000000000..cebd6f7e41 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/preferences/DataTablePreferencePage.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.preferences; + +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.preference.IntegerFieldEditor; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.GraphingAPIUIPlugin; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.preferences.GraphingAPIPreferenceConstants; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + + + +public class DataTablePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + public DataTablePreferencePage() { + super(GRID); + setPreferenceStore(GraphingAPIUIPlugin.getDefault().getPreferenceStore()); + setDescription(Localization.getString("DataTablePreferencePage.GraphDisplayPreferences")); //$NON-NLS-1$ + } + + @Override + public void createFieldEditors() { + addField(new BooleanFieldEditor( + GraphingAPIPreferenceConstants.P_JUMP_NEW_TABLE_ENTRY, + Localization.getString("DataTablePreferencePage.JumpNewestEntry"), //$NON-NLS-1$ + getFieldEditorParent())); + + addField(new BooleanFieldEditor( + GraphingAPIPreferenceConstants.P_AUTO_RESIZE, + Localization.getString("DataTablePreferencePage.AutoResizeColumns"), //$NON-NLS-1$ + getFieldEditorParent())); + + addField( + new IntegerFieldEditor( + GraphingAPIPreferenceConstants.P_MAX_DATA_ITEMS, + Localization.getString("DataTablePreferencePage.MaxDataItems"), //$NON-NLS-1$ + getFieldEditorParent())); + } + + @Override + public void init(IWorkbench workbench) {} + +} + diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/preferences/GraphPreferencePage.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/preferences/GraphPreferencePage.java new file mode 100644 index 0000000000..8e4a40708d --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/preferences/GraphPreferencePage.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.preferences; + +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.preference.IntegerFieldEditor; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.GraphingAPIUIPlugin; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.preferences.GraphingAPIPreferenceConstants; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + + + +public class GraphPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + public GraphPreferencePage() { + super(GRID); + setPreferenceStore(GraphingAPIUIPlugin.getDefault().getPreferenceStore()); + setDescription(Localization.getString("GraphPreferencePage.GraphDisplayPreferences")); //$NON-NLS-1$ + } + + @Override + public void createFieldEditors() { + addField(new BooleanFieldEditor( + GraphingAPIPreferenceConstants.P_SHOW_X_GRID_LINES, + Localization.getString("GraphPreferencePage.ShowXGridLines"), //$NON-NLS-1$ + getFieldEditorParent())); + + addField(new BooleanFieldEditor( + GraphingAPIPreferenceConstants.P_SHOW_Y_GRID_LINES, + Localization.getString("GraphPreferencePage.ShowYGridLines"), //$NON-NLS-1$ + getFieldEditorParent())); + + addField( + new IntegerFieldEditor( + GraphingAPIPreferenceConstants.P_MAX_DATA_ITEMS, + Localization.getString("GraphPreferencePage.MaxDataItems"), //$NON-NLS-1$ + getFieldEditorParent())); + + addField( + new IntegerFieldEditor( + GraphingAPIPreferenceConstants.P_VIEWABLE_DATA_ITEMS, + Localization.getString("GraphPreferencePage.ViewableDataItems"), //$NON-NLS-1$ + getFieldEditorParent())); + + addField( + new IntegerFieldEditor( + GraphingAPIPreferenceConstants.P_X_SERIES_TICKS, + Localization.getString("GraphPreferencePage.XSeriesTicks"), //$NON-NLS-1$ + getFieldEditorParent())); + + addField( + new IntegerFieldEditor( + GraphingAPIPreferenceConstants.P_Y_SERIES_TICKS, + Localization.getString("GraphPreferencePage.YSeriesTicks"), //$NON-NLS-1$ + getFieldEditorParent())); + } + + @Override + public void init(IWorkbench workbench) {} + +} + diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/preferences/GraphingAPIPreferenceConstants.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/preferences/GraphingAPIPreferenceConstants.java new file mode 100644 index 0000000000..10cc395f07 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/preferences/GraphingAPIPreferenceConstants.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.preferences; + +public class GraphingAPIPreferenceConstants { + //graphing.datatable + public static final String P_JUMP_NEW_TABLE_ENTRY = "JumpNewTableEntry"; //$NON-NLS-1$ + public static final String P_AUTO_RESIZE = "AutoResizeColumns"; //$NON-NLS-1$ + + //graphing.graph + public static final String P_SHOW_X_GRID_LINES = "ShowXGridLines"; //$NON-NLS-1$ + public static final String P_SHOW_Y_GRID_LINES = "ShowYGridLines"; //$NON-NLS-1$ + public static final String P_MAX_DATA_ITEMS = "MaxDataItems"; //$NON-NLS-1$ + public static final String P_VIEWABLE_DATA_ITEMS = "ViewableDataItems"; //$NON-NLS-1$ + public static final String P_X_SERIES_TICKS = "XSeriesTicks"; //$NON-NLS-1$ + public static final String P_Y_SERIES_TICKS = "YSeriesTicks"; //$NON-NLS-1$ +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/preferences/PreferenceInitializer.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/preferences/PreferenceInitializer.java new file mode 100644 index 0000000000..09b4d646c0 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/preferences/PreferenceInitializer.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.preferences; + +import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.GraphingAPIUIPlugin; + + + +public class PreferenceInitializer extends AbstractPreferenceInitializer { + @Override + public void initializeDefaultPreferences() { + IPreferenceStore store = GraphingAPIUIPlugin.getDefault().getPreferenceStore(); + + store.setDefault(GraphingAPIPreferenceConstants.P_SHOW_X_GRID_LINES, true); + store.setDefault(GraphingAPIPreferenceConstants.P_SHOW_Y_GRID_LINES, true); + store.setDefault(GraphingAPIPreferenceConstants.P_AUTO_RESIZE, true); + store.setDefault(GraphingAPIPreferenceConstants.P_JUMP_NEW_TABLE_ENTRY, false); + store.setDefault(GraphingAPIPreferenceConstants.P_VIEWABLE_DATA_ITEMS, 100); + store.setDefault(GraphingAPIPreferenceConstants.P_MAX_DATA_ITEMS, 250); + store.setDefault(GraphingAPIPreferenceConstants.P_X_SERIES_TICKS, 10); + store.setDefault(GraphingAPIPreferenceConstants.P_Y_SERIES_TICKS, 4); + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/ExceptionErrorDialog.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/ExceptionErrorDialog.java new file mode 100644 index 0000000000..858f4aa099 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/ExceptionErrorDialog.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2013 Red Hat. + * 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.linuxtools.systemtap.graphingapi.ui.widgets; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.GraphingAPIUIPlugin; +import org.eclipse.ui.PlatformUI; + +/** + * A convenience class for showing error dialogs which display the full stack + * trace in the details section. + * @since 2.0 + * + */ +public class ExceptionErrorDialog { + + public static int openError(String message, Exception e){ + StringWriter writer = new StringWriter(); + e.printStackTrace(new PrintWriter(writer)); + Status status = new Status(IStatus.ERROR, GraphingAPIUIPlugin.PLUGIN_ID, e.toString(), new Throwable(writer.toString())); + return ErrorDialog.openError(PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getShell(), message, + message, status); + } + +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphAxis.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphAxis.java new file mode 100644 index 0000000000..764a194e34 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphAxis.java @@ -0,0 +1,207 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets; + +import java.text.DecimalFormat; + +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs.AGraph; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Point; + + + +/** + * The Axis primitive, used to draw gridlines and axes on graphs. + * @author Henry Hughes + * @author Ryan Morse + */ +public class GraphAxis implements IGraphPrimitive { + public GraphAxis(AGraph graph, String title, int tickCount, int type) { + this.graph = graph; + this.type = type&1; //Ensure type matches one of the possible values + this.tickCount = tickCount; + this.title = title; + this.color = graph.axisColor; + } + + public void setTickCount(int count) { + tickCount = count; + } + + public int getType() { + return type; + } + + @Override + public boolean isVisible() { + return true; + } + + /** + * Determines if the given point is inside this axis' bounds. + */ + @Override + public boolean isUnder(Point loc) { + if(type==VERTICAL && loc.x < graph.getXPadding() || + type==HORIZONTAL && loc.y > graph.getSize().y-graph.getYPadding()) + return true; + return false; + } + + @Override + public void calculateBounds() { + x1 = graph.getXPadding(); + y2 = graph.getSize().y-graph.getYPadding(); + locationX = graph.getXPadding(); + tickAmount = 0; + + if(type == HORIZONTAL) { + locationY = graph.getYPadding(); + y1 = graph.getSize().y-graph.getYPadding(); + x2 = graph.getSize().x-graph.getXPadding(); + x2a = (int)locationX; + y2a = graph.getSize().y-graph.getYPadding(); + + widthX = graph.getSize().x - (graph.getXPadding()<<1); + widthY = 0; + tickIncrament = ((graph.getLocalXMax()-graph.getLocalXMin())/(double)tickCount); + range = graph.getLocalXMax() - graph.getLocalXMin(); + localMin = graph.getLocalXMin(); + } else { + locationY = graph.getSize().y - graph.getYPadding(); + y1 = graph.getYPadding(); + x2 = graph.getXPadding(); + x2a = graph.getSize().x-graph.getXPadding(); + y2a = (int)locationY; + + widthX = 0; + widthY = graph.getSize().y - (graph.getYPadding()<<1); + tickIncrament = ((graph.getLocalYMax()-graph.getLocalYMin())/(double)tickCount); + range = graph.getLocalYMax() - graph.getLocalYMin(); + localMin = graph.getLocalYMin(); + } + } + + /** + * Calculates the width, in pixels, of the input string. + * @param gc GC to use for the calculation. + * @param s String to calculate. + * @return Width of the string in pixels. + */ + protected int stringWidth(GC gc, String s) { + int width = 0; + for(int i=0; i<s.length(); i++) + width += gc.getCharWidth(s.charAt(i)); + + return width; + } + + /** + * Draws the grid line for the given coordinates if grid lines are enabled. + */ + protected void drawGridLine(GC gc, int x1, int y1, int x2, int y2) { + if(graph.showGrid) { + gc.setLineStyle(SWT.LINE_DOT); + gc.drawLine(x1,y1,x2,y2); + } + } + + /** + * Graphs the tick at the given location. Places the given string near the tick. + */ + protected void drawTick(GC gc, int x, int y, String val) { + gc.setLineStyle(SWT.LINE_SOLID); + int strWidth = stringWidth(gc, val); + int strHeight = gc.getFontMetrics().getHeight(); + gc.drawLine(x, y, x+((HORIZONTAL==type) ? 0 : strWidth), y+((HORIZONTAL==type) ? -strHeight : 0)); + + x -= (strWidth>>1); + if(x < 0) + x = 0; + else if(x > graph.getSize().x-strWidth) + x = graph.getSize().x-strWidth; + + y -= (strHeight>>1); + if(y < 0) + y = 0; + else if(y > graph.getSize().y-strHeight) + y = graph.getSize().y-strHeight; + gc.drawText(val, x, y); + } + + protected void drawTitle(GC gc) { + //TODO: Implement this function. Has to rotate text for vertical bars + //http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/Rotateandflipanimage.htm + } + + /** + * Converts units on the input value using SI prefixes (1 million becomes 1M, etc) + */ + protected String getLabel(double val, int range) { + int metric = 0; + String pattern=".0"; //$NON-NLS-1$ + range /= tickCount; + while(val > 1000) { + val /= 1000; + metric++; + + range /= 10; + if(range < 1) + pattern += "0"; //$NON-NLS-1$ + } + + DecimalFormat format = new DecimalFormat(pattern); + return format.format(val) + PREFIXES[metric]; + } + + @Override + public void paint(GC gc) { + calculateBounds(); + + Color foreground = gc.getForeground(); + gc.setForeground(color); + + gc.drawLine(x1, y1, x2, y2); + drawTitle(gc); + for(int i=0; i<=tickCount; i++) { + drawGridLine(gc, (int)locationX, (int)locationY, (int)x2a, (int)y2a); + drawTick(gc, (int)locationX, (int)y2a, getLabel(localMin+tickAmount, range)); + + locationX += (widthX/(double)tickCount); + x2a += (widthX/(double)tickCount); + locationY -= (widthY/(double)tickCount); + y2a -= (widthY/(double)tickCount); + tickAmount += tickIncrament; + + } + gc.setForeground(foreground); + } + + public static final int VERTICAL = 0; + public static final int HORIZONTAL = 1; + //kilo, mega, giga, tera, peta, exa, zetta, yotta + protected static final String[] PREFIXES = { "", Localization.getString("GraphAxis.Kilo"), Localization.getString("GraphAxis.Mega"), Localization.getString("GraphAxis.Giga"), Localization.getString("GraphAxis.Tera"), Localization.getString("GraphAxis.Peta"), Localization.getString("GraphAxis.Exa"), Localization.getString("GraphAxis.Zetta"), Localization.getString("GraphAxis.Yotta") } ; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ + + protected int type; + protected int tickCount; + protected final AGraph graph; + protected Color color; + @SuppressWarnings("unused") + private String title; + + protected int x1, y1, x2, y2; + protected int widthX, widthY, range, localMin; + protected double locationX, locationY, x2a, y2a, tickAmount, tickIncrament; +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphAxis2.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphAxis2.java new file mode 100644 index 0000000000..6f97183aa8 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphAxis2.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets; + +import org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs.AGraph; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; + + + +/** + * An extension to GraphAxis. + * @author Ryan Morse + */ +public class GraphAxis2 extends GraphAxis { + public GraphAxis2(AGraph graph, String title, int tickCount, int type, Color color) { + super(graph, title, tickCount, type&1); + this.type = type; + this.color = color; + } + + @Override + public void calculateBounds() { + x1 = graph.getXPadding(); + y1 = graph.getYPadding(); + x2 = graph.getSize().x-graph.getXPadding(); + y2 = graph.getSize().y-graph.getYPadding(); + locationX = graph.getXPadding(); + locationY = graph.getSize().y - graph.getYPadding(); + tickAmount = 0; + + switch(type&1) { + case VERTICAL: + widthX = 0; + widthY = graph.getSize().y - (graph.getYPadding()<<1); + tickIncrament = ((graph.getLocalYMax()-graph.getLocalYMin())/(double)tickCount); + range = graph.getLocalYMax() - graph.getLocalYMin(); + localMin = graph.getLocalYMin(); + break; + case HORIZONTAL: + widthX = graph.getSize().x - (graph.getXPadding()<<1); + widthY = 0; + tickIncrament = ((graph.getLocalXMax()-graph.getLocalXMin())/(double)tickCount); + range = graph.getLocalXMax() - graph.getLocalXMin(); + localMin = graph.getLocalXMin(); + break; + } + + switch(type&3) { + case ALIGN_BOTTOM: + locationY = graph.getYPadding(); + y1 = graph.getSize().y-graph.getYPadding(); + y2a = graph.getSize().y - graph.getYPadding(); + x2a = (int)locationX; + break; + case ALIGN_TOP: + y2 = graph.getYPadding(); + y2a = graph.getYPadding(); + x2a = (int)locationX; + break; + case ALIGN_LEFT: + x2 = graph.getXPadding(); + y2a = (int)locationY; + x2a = graph.getSize().x-graph.getXPadding(); + break; + case ALIGN_RIGHT: + locationX = graph.getSize().x-graph.getXPadding(); + x1 = graph.getSize().x-graph.getXPadding(); + y2a = (int)locationY; + x2a = graph.getXPadding(); + break; + } + } + + @Override + protected void drawGridLine(GC gc, int x1, int y1, int x2, int y2) { + if(HIDE_GRID_LINES != (HIDE_GRID_LINES&type)) + super.drawGridLine(gc, x1, y1, x2, y2); + } + + @Override + protected void drawTick(GC gc, int x, int y, String val) { + if(HIDE_TICKS != (HIDE_TICKS&type)) + super.drawTick(gc, x, y, val); + } + + @Override + protected void drawTitle(GC gc) { + if(HIDE_TITLE != (HIDE_TITLE&type)) + super.drawTitle(gc); + } + + public static final int ALIGN_LEFT = VERTICAL; //0 + public static final int ALIGN_TOP = HORIZONTAL; //1 + public static final int ALIGN_RIGHT = VERTICAL | 2; //2 + public static final int ALIGN_BOTTOM = HORIZONTAL | 2; //3 + + public static final int HIDE_GRID_LINES = 4; + public static final int HIDE_TITLE = 8; + public static final int HIDE_TICKS = 16; + public static final int UNNORMALIZED = 32; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphCanvas.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphCanvas.java new file mode 100644 index 0000000000..90300ffcd9 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphCanvas.java @@ -0,0 +1,216 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.ScrollBar; + +/** + * The Graph Canvas class provides a Canvas type object that renders IGraphPrimitive objects on itself. + * It is an implementation of the IWidgetContainer interface and can be used by Graph Primitives to scale + * themselves. + * + * This class is the parent class of the entire Graph system, all of the decendents from Graph are + * based upon this class. + * @author Henry Hughes + * @author Ryan Morse + * @see org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs.Graph + * + */ +public class GraphCanvas extends Canvas { + /** + * The default constructor for GraphCanvas. Creates a canvas of the appropriate size, then + * sets the internal area rectangles, the internal padding and scaling levels, enables scrolling, + * and sets the default axis color. + * @param parent Parent composite for this canvas. + * @param style SWT Style flags for this canvas (use SWT.NONE) + */ + public GraphCanvas(Composite parent, int style) { + super(parent, style | SWT.V_SCROLL | SWT.H_SCROLL); + + globalArea = new Rectangle(0, 0, 0, 0); + localArea = new Rectangle(0, 0, 0, 0); + + xpad = 10; + ypad = 10; + scale = 1.0; + autoScroll = true; + + axisColor = parent.getDisplay().getSystemColor(SWT.COLOR_GRAY); + + hBar = this.getHorizontalBar(); + vBar = this.getVerticalBar(); + hBar.addListener (SWT.Selection, new Listener () { + @Override + public void handleEvent (Event e) { + if(hBar.getSelection()+hBar.getThumb() == hBar.getMaximum()) + autoScroll = true; + else + autoScroll = false; + + setLocalArea(new Rectangle(hBar.getSelection(), localArea.y, localArea.width, localArea.height), true); + redraw(); + } + }); + + vBar.addListener (SWT.Selection, new Listener () { + @Override + public void handleEvent (Event e) { + autoScroll = false; + + setLocalArea(new Rectangle(localArea.x, vBar.getMaximum()-(vBar.getSelection()+vBar.getThumb())+vBar.getMinimum(), localArea.width, localArea.height), true); + redraw(); + } + }); + + } + /** + * An accessor to set the X padding width. Padding is defined as pixels inside the bounds + * of the drawable area that are left blank when rendering the graph. Valid values are integers + * greater than 0. The canvas will silently ignore requests to set the padding width to <=0. + * @param xpad New X padding value. + */ + public void setXPadding(int xpad) { this.xpad = xpad > 0 ? xpad : this.xpad; } + /** + * An accessor to set the Y padding width. Padding is defined as pixels inside the bounds + * of the drawable area that are left blank when rendering the graph. Valid values are integers + * greater than 0. The canvas will silently ignore requests to set the padding width to <=0. + * @param xpad New Y padding value. + */ + public void setYPadding(int ypad) { this.ypad = ypad > 0 ? ypad : this.ypad; } + /** + * Returns the current X padding value. + * @return The X padding width value, in pixels. + */ + public int getXPadding() { return xpad; } + /** + * Returns the current Y padding value. + * @return The Y padding width value, in pixels. + */ + public int getYPadding() { return ypad; } + + /** + * The repaint method is called when the graph is out of date and needs to be redrawn. This is an + * abstraction method around <code>Canvas.redraw</code> that synchronously executes the request + * on the display thread, blocking the calling thread until the repaint is completed. + */ + public synchronized void repaint() { + getDisplay().syncExec(new Runnable() { + @Override + public void run() { + redraw(); + } + }); + } + + /** + * Returns the size of the graphing area of the canvas. + */ + @Override + public Point getSize() { + Point p = new Point(super.getSize().x, super.getSize().y); + p.x -= vBar.getSize().x+5; + p.y -= hBar.getSize().y+5; + return p; + } + + /** + * Resets the canvas size to the specified area. + */ + public void setGlobalArea(Rectangle area) { + globalArea = area; + + hBar.setMinimum(getGlobalXMin()); + hBar.setMaximum (getGlobalXMax()); + vBar.setMinimum(getGlobalYMin()); + vBar.setMaximum (getGlobalYMax()); + } + + /** + * Sets the size of the graphing area to the specified area. + */ + public void setLocalArea(Rectangle area) { + setLocalArea(area, false); + } + + public void setLocalArea(Rectangle area, boolean force) { + if(autoScroll || force) { + localArea = area; + + hBar.setThumb (getLocalWidth()); + vBar.setThumb (getLocalHeight()); + + hBar.setIncrement(getLocalWidth()>>3); + hBar.setPageIncrement(getLocalWidth()); + vBar.setIncrement(getLocalHeight()>>3); + vBar.setPageIncrement(getLocalHeight()); + } + if(autoScroll) { + hBar.setSelection(hBar.getMaximum()); + vBar.setSelection(getGlobalYMax() - Math.min(getLocalYMax(), getGlobalYMax()) + getGlobalYMin()); + } + } + + public int getGlobalXMin() { + return globalArea.x; + } + + public int getLocalXMin() { + return localArea.x; + } + + public int getGlobalXMax() { + return globalArea.x+globalArea.width; + } + + public int getLocalXMax() { + return getLocalXMin() + getLocalWidth(); + } + + public int getGlobalYMin() { + return globalArea.y; + } + + public int getLocalYMin() { + return localArea.y; + } + + public int getGlobalYMax() { + return globalArea.y+globalArea.height; + } + + public int getLocalYMax() { + return getLocalYMin() + getLocalHeight(); + } + + public int getLocalWidth() { + return (int)(localArea.width / scale); + } + + public int getLocalHeight() { + return (int)(localArea.height / scale); + } + + protected Color axisColor; + private int xpad, ypad; + private ScrollBar hBar, vBar; + private Rectangle globalArea, localArea; + private boolean autoScroll; + private double scale; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphComposite.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphComposite.java new file mode 100644 index 0000000000..15ea21d0de --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphComposite.java @@ -0,0 +1,231 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets; + +import java.util.ArrayList; + +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.IDataSet; +import org.eclipse.linuxtools.systemtap.graphingapi.core.structures.GraphData; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.charts.AbstractChartBuilder; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.charts.AbstractChartWithoutAxisBuilder; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.graph.GraphFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Scale; + +/** + * A Composite type to contain a Graph object. + * @author Henry Hughes + * @author Ryan Morse + */ +public class GraphComposite extends Composite { + /** + * The default constructor: creates an internal composite for the Graph to render on, asks GraphFactory + * to create the graph from the given GraphData and DataSet, then initializes all buttons and listeners. + */ + public GraphComposite(Composite parent, int style, GraphData gd, IDataSet ds) { + super(parent, style); + FormLayout layout = new FormLayout(); + layout.marginWidth = 5; + layout.marginHeight = 5; + this.setLayout(layout); + checkOptions = new ArrayList<Button>(); + + label = new Label(this, SWT.HORIZONTAL | SWT.BORDER | SWT.BOLD | SWT.CENTER); + scale = scales[7]; + label.setText("-"); //$NON-NLS-1$ + FormData data = new FormData(); + data.bottom = new FormAttachment(100,-4); + data.left = new FormAttachment(0, 2); + data.width = 15; + label.setLayoutData(data); + label.setFont(new Font(parent.getDisplay(), "Arial", 10, SWT.BOLD )); //$NON-NLS-1$ + zoomScale = new Scale(this,SWT.HORIZONTAL); + zoomScale.setMinimum(0); + zoomScale.setMaximum(14); + zoomScale.setIncrement(1); + zoomScale.setPageIncrement(1); + zoomScale.setSelection(7); + zoomScale.setToolTipText("Increase/Decrease the no of X axis ticks"); //$NON-NLS-1$ + data = new FormData(); + data.left = new FormAttachment(label,2); + data.bottom = new FormAttachment(100, -4); + data.right = new FormAttachment(100, -20); + zoomScale.setLayoutData(data); + + pluslabel = new Label(this, SWT.HORIZONTAL | SWT.BOLD | SWT.BORDER | SWT.CENTER); + pluslabel.setText("+"); //$NON-NLS-1$ + pluslabel.setFont(new Font(parent.getDisplay(), "Arial", 10, SWT.BOLD)); //$NON-NLS-1$ + data = new FormData(); + data.left = new FormAttachment(zoomScale,2); + data.bottom = new FormAttachment(100,-4); + data.width = 15; + pluslabel.setLayoutData(data); + + builder = GraphFactory.createGraph(this, style,gd, ds); + data = new FormData(); + data.top = new FormAttachment(0,0); + data.bottom = new FormAttachment(label,-5); + data.right = new FormAttachment(100,0); + data.left = new FormAttachment(0,0); + builder.build(); + + + + builder.setLayoutData(data); + + zoomScale.addSelectionListener(scaleListener); + + //The scale zoom scrool doesn't make sense for charts without axis + if (builder instanceof AbstractChartWithoutAxisBuilder) { + this.configure(false); + } + } + + /** + * Toggles sidebar visible or not visible. + * @param withSidebar Enables or disables the sidebar. + */ + public void configure(boolean withSidebar) { + sidebarVisible = withSidebar; + + for(Button b:checkOptions) { + b.setVisible(sidebarVisible); + } + + zoomScale.setVisible(sidebarVisible); + label.setVisible(sidebarVisible); + pluslabel.setVisible(sidebarVisible); + + FormData data = new FormData(); + data.top = new FormAttachment(0,0); + data.bottom = (withSidebar ? new FormAttachment(label,-7) : new FormAttachment(100, 0)); + data.left = new FormAttachment(0,0); + data.right = new FormAttachment(100,0); + builder.setLayoutData(data); + + layout(true, true); + } + + public void addCheckOption(String title, SelectionListener listener) { + Button b = new Button(this, SWT.CHECK); + b.setText(title); + + Button old = null; + if(checkOptions.size() > 0) { + old = checkOptions.get(checkOptions.size()-1); + } + + FormData data = new FormData(); + data.bottom = (null != old) ? new FormAttachment(old,0) : new FormAttachment(100, 0); + data.right = new FormAttachment(100,0); + data.width = 85; + b.setLayoutData(data); + b.addSelectionListener(listener); + + checkOptions.add(b); + + if(checkOptions.size() == 1) { + ((FormData)label.getLayoutData()).right = new FormAttachment(b, 0); + ((FormData)zoomScale.getLayoutData()).right = new FormAttachment(b, 0); + } + } + + public void removeCheckOption(String title) { + for(Button b :checkOptions) { + if(b.getText().equals(title)) { + checkOptions.remove(b); + + if(checkOptions.size() == 0) { + ((FormData)label.getLayoutData()).right = new FormAttachment(100, 0); + } + + return; + } + } + } + + /** + * Returns the graph that is rendering to this composite. + */ + public AbstractChartBuilder getCanvas() { + return builder; + } + + /** + * Returns the current sidebar visibility state. + */ + public boolean isSidebarVisible() { + return sidebarVisible; + } + + /** + * Dispose is overriden in order to dispose of the listeners attached to this Composite on disposal. + */ + @Override + public void dispose() { + scaleListener = null; + + if(null != zoomScale) { + zoomScale.dispose(); + } + zoomScale = null; + + if(null != label) { + label.dispose(); + } + label = null; + super.dispose(); + } + + /** + * Listeners are below: + * scaleListener - detects movement in the Scale widget and rescales the graph on change + * titleListener - A SelectionListener for the title button + * legendListener - A SelectionListener for the legend checkbox + * gridListener - A SelectionListener for the Grid checkbox + * normalizeListener - A SelectionListener for the normalization checkbox + * propertyChangeListener - Detects changes in user preferences and applies them + */ + private SelectionListener scaleListener = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + + Scale scaler = (Scale) e.widget; + int index = scaler.getSelection(); + if(scale != scales[index]) { + scale = scales[index]; + builder.setScale(scale); + } + } + }; + + private boolean sidebarVisible = true; + private AbstractChartBuilder builder; + private Scale zoomScale; + public double scale; + private static final double[] scales = { .0625, .125, .25, .33 , .5, .66, .8, 1.0, 1.25, 1.5, 2, 3, 4, 8, 16 }; + private Label label; + private Label pluslabel; + + private ArrayList<Button> checkOptions; + +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphLabel.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphLabel.java new file mode 100644 index 0000000000..a6368f45f2 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphLabel.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; + +/** + * The GraphLabel primitive is used to draw a string of text at an arbitrary point on the graph. + * @author Ryan Morse + * + */ +public class GraphLabel implements IGraphPrimitive { + public GraphLabel(GraphCanvas canvas, String title, Point center, float size, int style) { + this.canvas = canvas; + this.title = title; + this.center = center; + this.size = size; + this.style = style; + this.parent = null; + } + + public GraphLabel(GraphCanvas canvas, String title, Point center, int size, int style) { + this(canvas, title, center, (float)size, style); + } + + public GraphLabel(GraphCanvas canvas, String title, Composite parent, float size, int style) { + this(canvas, title, parent.getSize(), size, style); + this.parent = parent; + } + + public GraphLabel(GraphCanvas canvas, String title, Composite parent, int size, int style) { + this(canvas, title, parent, (float)size, style); + } + + public int calculateSize(GC gc) { + int width = 0; + for (int i=0; i<title.length(); i++) + width += gc.getCharWidth(title.charAt(i)); + return width; + } + + @Override + public void calculateBounds() { + if(null != parent) { + Point size = parent.getSize(); + x = (size.x - width)>>1; + y = parent.getBounds().y; + } else { + x = center.x - (width>>1); + y = center.y - (height>>1); + } + } + + @Override + public boolean isVisible() { + return true; + } + + @Override + public boolean isUnder(Point loc) { + if(loc.x >= x && loc.y >= y && loc.x <= x+width && loc.y <=y+height) + return true; + return false; + } + + @Override + public void paint(GC gc) { + if(staticSize) + gc.setFont(new Font(canvas.getDisplay(), "Times", (int)size, style)); //$NON-NLS-1$ + else + gc.setFont(new Font(canvas.getDisplay(), "Times", (int)(canvas.getSize().y * size), style)); //$NON-NLS-1$ + + width = calculateSize(gc); + height = gc.getFontMetrics().getHeight(); + calculateBounds(); + + Color temp = gc.getForeground(); + gc.setForeground(canvas.axisColor); + gc.drawText(title, x, y); + + gc.setForeground(temp); + } + + private GraphCanvas canvas; + private String title; + private int width; + private int height; + private Point center; + private Composite parent; + + private int x, y; + private float size; + private int style; + private boolean staticSize; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphLegend.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphLegend.java new file mode 100644 index 0000000000..7ec3c3a420 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/GraphLegend.java @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets; + +import java.util.Arrays; + +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; + + + +/** + * A legend primitive for the Graphing system. Used to display a list of + * all the series that are on this graph, and to change the current axis on a + * normalized multi-series graph. + * @author Jeff Briggs + * @author Ryan Morse + */ +public class GraphLegend implements IGraphPrimitive { + public GraphLegend(GraphCanvas graph, String[] keysPassed, Color[] colorsPassed) { + this.graph = graph; + colors = Arrays.copyOf(colorsPassed, colorsPassed.length); + keys = Arrays.copyOf(keysPassed, keysPassed.length); + bounds = new Rectangle[keys.length]; + + width = 0; + height = 0; + } + + @Override + public boolean isVisible() { + return true; + } + + @Override + public void calculateBounds() { + x = graph.getSize().x - width; + y = 0; + } + + private void getSize(GC gc) { + textHeight = gc.getFontMetrics().getHeight(); + height = textHeight * (keys.length + 1) + (BORDER<<1); + + for (int i=0; i<TITLE.length(); i++) + width += gc.getCharWidth(TITLE.charAt(i)); + + int currWidth; + for(int i=0; i<keys.length; i++) { + currWidth = 0; + for (int j=0; j<keys[i].length(); j++) + currWidth += gc.getCharWidth(keys[i].charAt(j)); + + if (currWidth > width) + width = currWidth; + } + width += BOX_SIZE + 3*BORDER; + } + + @Override + public boolean isUnder(Point loc) { + if(loc.x >=x && loc.y >= y && loc.x <= x+width && loc.y <= y+height) + return true; + return false; + } + + @Override + public void paint(GC gc) { + if(width == 0 || height ==0) + getSize(gc); + calculateBounds(); + + Color temp = gc.getForeground(); + gc.setForeground(graph.axisColor); + gc.drawRectangle(x, y, width, height); + gc.fillRectangle(x+1, y+1, width-1, height-1); + gc.drawText(TITLE, x+BORDER, y+BORDER); + + for (int i=0; i<keys.length; i++) { + gc.setForeground(colors[i]); + + bounds[i] = new Rectangle(x+BORDER, y+BORDER+((i+1)*textHeight), BOX_SIZE, BOX_SIZE); + gc.fillGradientRectangle(bounds[i].x, bounds[i].y, BOX_SIZE, BOX_SIZE, true); + + gc.setForeground(graph.axisColor); + gc.drawText(keys[i], x+(BORDER<<1)+BOX_SIZE, bounds[i].y); + } + + gc.setForeground(temp); + } + + private final GraphCanvas graph; + private int x, y, width, height, textHeight; + + private String[] keys; + private Color[] colors; + private Rectangle[] bounds; + + private static final int BORDER = 5; + private static final int BOX_SIZE = 15; + private static final String TITLE = Localization.getString("GraphLegend.Legend"); //$NON-NLS-1$ +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/IGraphPrimitive.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/IGraphPrimitive.java new file mode 100644 index 0000000000..6ee2efb34a --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/widgets/IGraphPrimitive.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets; + +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Point; + +/** + * Graphing Primitive Interface, defines the basic mechanism through which graph objects are drawn + * to a Graph type. + * @author Henry Hughes + * @author Ryan Morse + * + */ +public interface IGraphPrimitive { + /** + * Paint method, called by the Graph object to paint the graph. + * @param gc GC object to render with. + */ + public void paint(GC gc); + + /** + * CalculateBounds method, called by the Graph object when the graph's bounds changed (say + * if a data sample was added) in order to allow the primitives to update their locations. + * + * The behavior of this method is entirely left up to the primitive author, but it is ideally + * used to take care of location and bounds calculations for graph objects, rather than performing + * such calculations during the paint method. + */ + public void calculateBounds(); + + /** + * This method determines if the graph primitive is currently shown on the Graph surface. + * @return True if the primitive is currently displayed on the graph surface. + */ + public boolean isVisible(); + + /** + * This method determines if the primitive covers the given point. If the point is inside the + * bounds of the graph primitive, the point is defined as isUnder=true. + * @param loc Location to test. + * @return True if the location is inside the bounds of the primitive. + */ + public boolean isUnder(Point loc); +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/dataset/DataSetFactory.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/dataset/DataSetFactory.java new file mode 100644 index 0000000000..63c499bfe8 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/dataset/DataSetFactory.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.dataset; + +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.IDataSet; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.IDataSetParser; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.IFilteredDataSet; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.row.FilteredRowDataSet; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.row.RowDataSet; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.row.RowParser; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.table.FilteredTableDataSet; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.table.TableDataSet; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.table.TableParser; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.datadisplay.DataGrid; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IMemento; + + + +public final class DataSetFactory { + public static IDataSet createDataSet(String id, String[] labels) { + if(id.equals(RowDataSet.ID)) { + return new RowDataSet(labels); + } else if(id.equals(TableDataSet.ID)) { + return new TableDataSet(labels); + } + return null; + } + + public static IFilteredDataSet createFilteredDataSet(String id, String[] labels) { + if(id.equals(RowDataSet.ID)) { + return new FilteredRowDataSet(labels); + } else if(id.equals(TableDataSet.ID)) { + return new FilteredTableDataSet(labels); + } + return new FilteredRowDataSet(labels); + } + + public static IFilteredDataSet createFilteredDataSet(IDataSet set) { + if(set instanceof RowDataSet) { + return new FilteredRowDataSet((RowDataSet)set); + } else if(set instanceof TableDataSet) { + return new FilteredTableDataSet((TableDataSet)set); + } + return null; + } + + public static String[] getIDs() { + return ids; + } + + public static String getName(String id) { + int index = getIndex(id); + if(index >= 0) { + return names[index]; + } + return null; + } + + public static String getDescription(String id) { + int index = getIndex(id); + if(index >= 0) { + return descriptions[index]; + } + return null; + } + + public static ParsingWizardPage getParsingWizardPage(String id) { + ParsingWizardPage page = null; + + int index = getIndex(id); + if(index >=0 && index < dataSetWizards.length) { + return dataSetWizards[index]; + } + + return page; + } + + public static IDataSetParser createParserXML(String id, IMemento source) { + if(id.equals(ids[0])) { + return new RowParser(source); + } else if(id.equals(ids[1])) { + return new TableParser(source); + } + + return null; + } + + public static DataGrid getDataGrid(Composite composite, IDataSet set) { + if(set instanceof RowDataSet) { + return new DataGrid(composite, set, DataGrid.NONE); + } else if(set instanceof TableDataSet) { + return new DataGrid(composite, set, DataGrid.FULL_UPDATE); + } + + return null; + } + + private static int getIndex(String id) { + for(int i=0; i<ids.length; i++) { + if(id.equals(ids[i])) { + return i; + } + } + return -1; + } + + private static final String[] ids = { + RowDataSet.ID, + TableDataSet.ID + }; + + private static final String[] names = { + Localization.getString("DataSetFactory.RowDataSet"), //$NON-NLS-1$ + Localization.getString("DataSetFactory.TableDataSet") //$NON-NLS-1$ + }; + + private static final String[] descriptions = { + Localization.getString("DataSetFactory.RowDataSetDescription") + //$NON-NLS-1$ + Localization.getString("DataSetFactory.DataSetExample") + //$NON-NLS-1$ + Localization.getString("DataSetFactory.DataSetHeader") + //$NON-NLS-1$ + "1305 2309 4233\n" + //$NON-NLS-1$ + "2322 3234 4223\n" + //$NON-NLS-1$ + "2321 3123 4533\n" + //$NON-NLS-1$ + "2343 2931 4423\n" + //$NON-NLS-1$ + "1356 2984 3850\n", //$NON-NLS-1$ + + Localization.getString("DataSetFactory.TableDataSetDescription") + //$NON-NLS-1$ + Localization.getString("DataSetFactory.DataSetExample") + //$NON-NLS-1$ + Localization.getString("DataSetFactory.DataSetHeader") + //$NON-NLS-1$ + "2322 3232 3453\n" + //$NON-NLS-1$ + "2321 3123 4533\n" + //$NON-NLS-1$ + "2145 2135 5921\n" + //$NON-NLS-1$ + "-------------------\n" + //$NON-NLS-1$ + Localization.getString("DataSetFactory.DataSetHeader") + //$NON-NLS-1$ + "2343 2931 4423\n" + //$NON-NLS-1$ + "2234 2723 5233\n" + //$NON-NLS-1$ + "3215 3565 4922\n" + //$NON-NLS-1$ + "-------------------\n" //$NON-NLS-1$ + }; + + private static final ParsingWizardPage[] dataSetWizards = new ParsingWizardPage[] { + new SelectRowParsingWizardPage(), + new SelectTableParsingWizardPage() + }; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/dataset/DataSetWizard.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/dataset/DataSetWizard.java new file mode 100644 index 0000000000..56f2175888 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/dataset/DataSetWizard.java @@ -0,0 +1,203 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.dataset; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +import org.eclipse.jface.dialogs.IPageChangedListener; +import org.eclipse.jface.dialogs.PageChangedEvent; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.IDataSet; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.IDataSetParser; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.WorkbenchException; +import org.eclipse.ui.XMLMemento; + +public class DataSetWizard extends Wizard implements INewWizard { + public DataSetWizard(File metaFile, String scriptFile) { + this.metaFile = metaFile; + this.scriptFile = scriptFile; + } + + @Override + public void init(IWorkbench workbench, IStructuredSelection selection) {} + + @Override + public void addPages() { + setWindowTitle(Localization.getString("DataSetWizard.CreateDataSet")); //$NON-NLS-1$ + dataSetPage = new SelectDataSetWizardPage(); + addPage(dataSetPage); + + String[] ids = DataSetFactory.getIDs(); + parsingPages = new ParsingWizardPage[ids.length]; + for(int i=0; i<ids.length; i++) { + parsingPages[i] = DataSetFactory.getParsingWizardPage(ids[i]); + addPage(parsingPages[i]); + } + + ((WizardDialog)getContainer()).addPageChangedListener(pageListener); + } + + @Override + public boolean canFinish() { + IWizardPage page = this.getContainer().getCurrentPage(); + if((null != dataSet) && (null != parser) && (page instanceof ParsingWizardPage)) { + return true; + } + return false; + } + + @Override + public boolean performCancel() { + parser = null; + dataSet = null; + return true; + } + + @Override + public boolean performFinish() { + writeParsingExpression(); + return true; + } + + public IDataSetParser getParser() { + return parser; + } + + public IDataSet getDataSet() { + return dataSet; + } + + private boolean writeParsingExpression() { + XMLMemento data = copyExisting(); + if(null == data) { + data = XMLMemento.createWriteRoot(IDataSetParser.XMLDataSetSettings); + } + + try { + IMemento child = data.createChild(IDataSetParser.XMLFile, scriptFile); + + saveColumns(child, dataSet.getTitles()); + parser.saveXML(child); + + FileWriter writer = new FileWriter(metaFile); + data.save(writer); + writer.close(); + } catch(FileNotFoundException fnfe) { + return false; + } catch(IOException e) { + return false; + } + + return true; + } + + protected XMLMemento copyExisting() { + XMLMemento data = null; + try { + FileReader reader = new FileReader(metaFile); + if(!reader.ready()) { + reader.close(); + return null; + } + + data = XMLMemento.createReadRoot(reader, IDataSetParser.XMLDataSetSettings); + IMemento[] children = data.getChildren(IDataSetParser.XMLFile); + + data = XMLMemento.createWriteRoot(IDataSetParser.XMLDataSetSettings); + + IMemento child; + String dataSetID; + for(int i=0; i<children.length; i++) { + if(!scriptFile.equals(children[i].getID())) { + child = data.createChild(IDataSetParser.XMLFile, children[i].getID()); + dataSetID = children[i].getString(IDataSetParser.XMLdataset); + child.putString(IDataSetParser.XMLdataset, dataSetID); + + DataSetFactory.getParsingWizardPage(dataSetID).copyExisting(children[i], child); + } + } + } catch(FileNotFoundException fnfe) { + } catch(IOException ioe) { + } catch(WorkbenchException we) {} + + return data; + } + + protected boolean saveColumns(IMemento target, String[] columns) { + IMemento child; + for(String column: columns) { + child = target.createChild(IDataSetParser.XMLColumn); + child.putString(IDataSetParser.XMLname, column); + } + return true; + } + + protected boolean openFile() { + try { + if (!metaFile.exists()) { + metaFile.createNewFile(); + } + } catch(IOException ioe) { + return false; + } + + return true; + } + + @Override + public void dispose() { + if(null != getContainer()) { + ((WizardDialog)getContainer()).removePageChangedListener(pageListener); + } + if(null != dataSetPage) { + dataSetPage.dispose(); + } + if(null != parsingPages) { + for(int i=0; i<parsingPages.length; i++) { + if(null != parsingPages[i]) { + parsingPages[i].dispose(); + parsingPages[i] = null; + } + } + parsingPages = null; + } + } + + private IPageChangedListener pageListener = new IPageChangedListener() { + @Override + public void pageChanged(PageChangedEvent e) { + if(e.getSelectedPage() instanceof ParsingWizardPage) { + ((ParsingWizardPage)e.getSelectedPage()).checkComplete(); + getContainer().updateButtons(); + } + } + }; + + private SelectDataSetWizardPage dataSetPage; + + private ParsingWizardPage[] parsingPages; + public String scriptFile; + public File metaFile; + public IDataSet dataSet; + public IDataSetParser parser; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/dataset/ParsingWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/dataset/ParsingWizardPage.java new file mode 100644 index 0000000000..3a49c9929e --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/dataset/ParsingWizardPage.java @@ -0,0 +1,232 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.dataset; + +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IMemento; + + + +public abstract class ParsingWizardPage extends WizardPage { + public ParsingWizardPage(String title) { + super(title); + } + + @Override + public void createControl(Composite parent) { + wizard = (DataSetWizard)super.getWizard(); + } + + protected void createColumnSelector(Composite parent) { + Label lblSeries = new Label(parent, SWT.NONE); + lblSeries.setText(Localization.getString("ParsingWizardPage.NumberOfColumns")); //$NON-NLS-1$ + lblSeries.setBounds(0, 5, 130, 25); + + txtSeries = new Text(parent, SWT.BORDER); + txtSeries.setBounds(135, 0, 100, 25); + txtSeries.setText("2"); //$NON-NLS-1$ + txtSeries.setTextLimit(2); + txtSeries.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + if(!"".equals(txtSeries.getText().trim())) { //$NON-NLS-1$ + displayTextBoxes(); + refreshRegEx(); + } + } + }); + txtSeries.addKeyListener(new KeyListener() { + @Override + public void keyPressed(KeyEvent e) { + if(('0' > e.character || '9' < e.character) && 31 < e.character && 127 > e.character) { + e.doit = false; + } + } + + @Override + public void keyReleased(KeyEvent e) {} + }); + + + Label lblRegExTitle = new Label(parent, SWT.NONE); + lblRegExTitle.setText(Localization.getString("ParsingWizardPage.RegularExpression")); //$NON-NLS-1$ + lblRegExTitle.setBounds(5, 325, 150, 20); + + lblRegEx = new Label(parent, SWT.NONE); + lblRegEx.setBounds(155, 325, 300, 20); + + + Label lblTitle = new Label(parent, SWT.NONE); + lblTitle.setText(Localization.getString("ParsingWizardPage.Title")); //$NON-NLS-1$ + lblTitle.setBounds(0, 45, 150, 25); + Label lblExpr = new Label(parent, SWT.NONE); + lblExpr.setText(Localization.getString("ParsingWizardPage.RegularExpression")); //$NON-NLS-1$ + lblExpr.setBounds(160, 45, 150, 25); + Label lblSpace = new Label(parent, SWT.NONE); + lblSpace.setText(Localization.getString("ParsingWizardPage.Delimiter")); //$NON-NLS-1$ + lblSpace.setBounds(310, 45, 150, 25); + + ScrolledComposite sc1 = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); + sc1.setBounds(0, 70, 475, 250); + cmpTextFields = new Composite(sc1, SWT.NONE); + sc1.setContent(cmpTextFields); + + txtRegExpr = new Text[MAX_SERIES*COLUMNS]; + for(int i=0; i<txtRegExpr.length; i++) { + txtRegExpr[i] = new Text(cmpTextFields, SWT.BORDER); + txtRegExpr[i].setBounds(150*(i%COLUMNS), 30*(i/COLUMNS), 140, 25); + + if(2 == i%COLUMNS) { + txtRegExpr[i].setText("\\D+"); //$NON-NLS-1$ + } else if(1 == i%COLUMNS) + { + txtRegExpr[i].setText("\\d+"); //$NON-NLS-1$ + } + } + + readParsingExpression(); + + //Do this after readingParsingExpressions so events arn't fired + for(int i=0; i<txtRegExpr.length; i++) { + if(0 != i%COLUMNS) { + txtRegExpr[i].addModifyListener(regExListener); + } else { + txtRegExpr[i].addModifyListener(textListener); + } + } + + displayTextBoxes(); + refreshRegEx(); + } + + private void displayTextBoxes() { + int series = Integer.parseInt(txtSeries.getText()); + if(series > MAX_SERIES) { + txtSeries.setText("" +MAX_SERIES); //$NON-NLS-1$ + return; + } + cmpTextFields.setSize(450, series * 30); + series *= COLUMNS; + + for(int i=0; i<txtRegExpr.length; i++) { + if(i < series) { + txtRegExpr[i].setVisible(true); + } else { + txtRegExpr[i].setVisible(false); + } + } + } + + private void refreshRegEx() { + int series = Integer.parseInt(txtSeries.getText()); + series *= COLUMNS; + StringBuilder s = new StringBuilder(); + for(int i=0; i<series; i++) { + if(0 != i%COLUMNS) { + s.append(txtRegExpr[i].getText()); + } + } + lblRegEx.setText(s.toString()); + } + + @Override + public boolean canFlipToNextPage() { + return false; + } + + @Override + public void dispose() { + if(null != txtRegExpr) { + for(int i=0; i<txtRegExpr.length; i++) { + if(null != txtRegExpr[i]) { + if(0 != i%COLUMNS) { + txtRegExpr[i].removeModifyListener(regExListener); + } else { + txtRegExpr[i].removeModifyListener(textListener); + } + txtRegExpr[i].dispose(); + } + txtRegExpr[i] = null; + } + txtRegExpr = null; + } + super.dispose(); + } + + public boolean checkComplete() { + int series = Integer.parseInt(txtSeries.getText()); + labels = new String[series]; + regEx = new String[series*(COLUMNS-1)]; + + for(int i=0, j=0, k=0; i<(series*COLUMNS); i++) { + if("".equals(txtRegExpr[i].getText())) { //$NON-NLS-1$ + regEx = null; + wizard.parser = null; + wizard.dataSet = null; + return false; + } + + if(0 == i%COLUMNS) { + labels[j] = txtRegExpr[i].getText(); + j++; + } else { + regEx[k] = txtRegExpr[i].getText(); + k++; + } + } + return true; + } + + abstract boolean readParsingExpression(); + abstract void copyExisting(IMemento oldMeta, IMemento newMeta); + + protected class TextModifyListener implements ModifyListener { + @Override + public void modifyText(ModifyEvent e) { + checkComplete(); + wizard.getContainer().updateButtons(); + } + } + + private class RegExModifyListener extends TextModifyListener { + @Override + public void modifyText(ModifyEvent e) { + super.modifyText(e); + refreshRegEx(); + } + } + + protected ModifyListener textListener = new TextModifyListener(); + protected ModifyListener regExListener = new RegExModifyListener(); + + protected DataSetWizard wizard; + public static final int COLUMNS = 3; + private static final int MAX_SERIES = 24; + + protected Text txtSeries; + protected Text[] txtRegExpr; + protected Label lblRegEx; + private Composite cmpTextFields; + + protected String[] labels; + protected String[] regEx; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/dataset/SelectDataSetWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/dataset/SelectDataSetWizardPage.java new file mode 100644 index 0000000000..823500fde7 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/dataset/SelectDataSetWizardPage.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.dataset; + +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + + + +public class SelectDataSetWizardPage extends WizardPage { + public SelectDataSetWizardPage() { + super("selectDataSetType"); //$NON-NLS-1$ + setTitle(Localization.getString("SelectDataSetWizardPage.SelectDataSetType")); //$NON-NLS-1$ + dataSetID = ""; //$NON-NLS-1$ + btnDataSets = null; + } + + @Override + public void createControl(Composite parent) { + wizard = (DataSetWizard)super.getWizard(); + + Composite comp = new Composite(parent, SWT.NULL); + GridData layoutData = new GridData(GridData.FILL_BOTH); + layoutData.grabExcessHorizontalSpace = true; + layoutData.horizontalAlignment = SWT.FILL; + GridLayout gridLayout = new GridLayout(2, false); + comp.setLayout(gridLayout); + + String[] ids = DataSetFactory.getIDs(); + btnDataSets = new Button[ids.length]; + Label lblDesc; + for(int i=0; i<btnDataSets.length; i++) { + btnDataSets[i] = new Button(comp, SWT.RADIO); + btnDataSets[i].setText(DataSetFactory.getName(ids[i])); + btnDataSets[i].addSelectionListener(buttonListener); + btnDataSets[i].setData(ids[i]); + lblDesc = new Label(comp, SWT.WRAP); + lblDesc.setText(DataSetFactory.getDescription(btnDataSets[i].getData().toString())); + Label separator = new Label(comp, SWT.HORIZONTAL | SWT.SEPARATOR); + GridData separatorData = new GridData(GridData.FILL_HORIZONTAL); + separatorData.horizontalSpan=2; + separator.setLayoutData(separatorData); + } + + setControl(comp); + } + + @Override + public boolean canFlipToNextPage() { + return !dataSetID.isEmpty(); + } + + @Override + public IWizardPage getNextPage() { + return DataSetFactory.getParsingWizardPage(dataSetID); + } + + @Override + public void dispose() { + super.dispose(); + if(null != btnDataSets) { + for(int i=0; i<btnDataSets.length; i++) { + btnDataSets[i].removeSelectionListener(buttonListener); + btnDataSets[i].dispose(); + btnDataSets[i] = null; + } + } + btnDataSets = null; + } + + private SelectionListener buttonListener = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if(e.widget instanceof Button) { + Button target = (Button)e.widget; + + for(Button button: btnDataSets) { + if(target == button) { + dataSetID = button.getData().toString(); + wizard.getContainer().updateButtons(); + } + } + } + } + }; + + private Button[] btnDataSets; + private String dataSetID; + private DataSetWizard wizard; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/dataset/SelectRowParsingWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/dataset/SelectRowParsingWizardPage.java new file mode 100644 index 0000000000..f22792834c --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/dataset/SelectRowParsingWizardPage.java @@ -0,0 +1,133 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.dataset; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.regex.PatternSyntaxException; + +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.IDataSetParser; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.row.RowDataSet; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.row.RowParser; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.WorkbenchException; +import org.eclipse.ui.XMLMemento; + + + +public class SelectRowParsingWizardPage extends ParsingWizardPage { + public SelectRowParsingWizardPage() { + super("selectRowDataSetParsing"); //$NON-NLS-1$ + setTitle(Localization.getString("SelectRowParsingWizardPage.SelectRowDataSetParsing")); //$NON-NLS-1$ + } + + @Override + public void createControl(Composite parent) { + super.createControl(parent); + + Composite comp = new Composite(parent, SWT.NONE); + createColumnSelector(comp); + + setControl(comp); + } + + @Override + protected boolean readParsingExpression() { + if(null == wizard.metaFile && !wizard.openFile()) + return false; + + try { + FileReader reader = new FileReader(wizard.metaFile); + + if(!reader.ready()) { + reader.close(); + return false; + } + + XMLMemento data = XMLMemento.createReadRoot(reader, IDataSetParser.XMLDataSetSettings); + + IMemento[] children = data.getChildren(IDataSetParser.XMLFile); + int i; + for(i=0; i<children.length; i++) { + if(children[i].getID().equals(wizard.scriptFile)) + break; + } + + if(i>=children.length) //Didn't find file + return false; + + if(0 != children[i].getString(IDataSetParser.XMLdataset).compareTo(RowDataSet.ID)) + return false; + + IMemento[] children2 = children[i].getChildren(IDataSetParser.XMLColumn); + txtSeries.setText("" + children2.length); //$NON-NLS-1$ + for(int j=0; j<children2.length; j++) + txtRegExpr[j*COLUMNS].setText(children2[j].getString(IDataSetParser.XMLname)); + + children2 = children[i].getChildren(IDataSetParser.XMLSeries); + txtSeries.setText("" + children2.length); //$NON-NLS-1$ + for(int j=0; j<children2.length; j++) { + txtRegExpr[j*COLUMNS+1].setText(children2[j].getString(IDataSetParser.XMLparsingExpression)); + txtRegExpr[j*COLUMNS+2].setText(children2[j].getString(IDataSetParser.XMLparsingSpacer)); + } + + reader.close(); + } catch(FileNotFoundException fnfe) { + return false; + } catch(WorkbenchException we) { + return false; + } catch(IOException ioe) { + return false; + } + + return true; + } + + @Override + protected void copyExisting(IMemento oldMeta, IMemento newMeta) { + IMemento[] children = oldMeta.getChildren(IDataSetParser.XMLColumn); + IMemento child; + for(IMemento memento :children) { + child = newMeta.createChild(IDataSetParser.XMLColumn); + child.putString(IDataSetParser.XMLname, memento.getString(IDataSetParser.XMLname)); + } + children = oldMeta.getChildren(IDataSetParser.XMLSeries); + for(IMemento memento :children) { + child = newMeta.createChild(IDataSetParser.XMLSeries); + child.putString(IDataSetParser.XMLparsingExpression, memento.getString(IDataSetParser.XMLparsingExpression)); + child.putString(IDataSetParser.XMLparsingSpacer, memento.getString(IDataSetParser.XMLparsingSpacer)); + } + } + + @Override + public boolean checkComplete() { + if(super.checkComplete()) { + try { + wizard.parser = new RowParser(regEx); + wizard.dataSet = DataSetFactory.createDataSet(RowDataSet.ID, labels); + return true; + } catch(PatternSyntaxException pse) {} + } + wizard.parser = null; + wizard.dataSet = null; + return false; + } + + @Override + public void dispose() { + super.dispose(); + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/dataset/SelectTableParsingWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/dataset/SelectTableParsingWizardPage.java new file mode 100644 index 0000000000..c246c6f429 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/dataset/SelectTableParsingWizardPage.java @@ -0,0 +1,157 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.dataset; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.regex.PatternSyntaxException; + +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.IDataSetParser; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.table.TableDataSet; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.table.TableParser; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.WorkbenchException; +import org.eclipse.ui.XMLMemento; + + + +public class SelectTableParsingWizardPage extends ParsingWizardPage { + public SelectTableParsingWizardPage() { + super("selectTableDataSetParsing"); //$NON-NLS-1$ + setTitle(Localization.getString("SelectTableParsingWizardPage.SelectTableDataSetParsing")); //$NON-NLS-1$ + } + + @Override + public void createControl(Composite parent) { + super.createControl(parent); + + Composite comp = new Composite(parent, SWT.NONE); + Label l = new Label(comp, SWT.NONE); + l.setText(Localization.getString("SelectTableParsingWizardPage.TableDelimiter")); //$NON-NLS-1$ + l.setBounds(5, 350, 150, 25); + txtDelim = new Text(comp, SWT.SINGLE | SWT.BORDER); + + createColumnSelector(comp); + + txtDelim.setBounds(160, 350, 200, 25); + txtDelim.addModifyListener(textListener); + + setControl(comp); + } + + @Override + protected boolean readParsingExpression() { + if(null == wizard.metaFile && !wizard.openFile()) { + return false; + } + + try { + FileReader reader = new FileReader(wizard.metaFile); + + if(!reader.ready()) { + reader.close(); + return false; + } + + XMLMemento data = XMLMemento.createReadRoot(reader, IDataSetParser.XMLDataSetSettings); + + IMemento[] children = data.getChildren(IDataSetParser.XMLFile); + int i; + for(i=0; i<children.length; i++) { + if(children[i].getID().equals(wizard.scriptFile)) { + break; + } + } + + if(i>=children.length) { + return false; + } + + if(0 != children[i].getString(IDataSetParser.XMLdataset).compareTo(TableDataSet.ID)) { + return false; + } + + IMemento[] children2 = children[i].getChildren(IDataSetParser.XMLColumn); + txtSeries.setText("" + children2.length); //$NON-NLS-1$ + for(int j=0; j<children2.length; j++) { + txtRegExpr[j*COLUMNS].setText(children2[j].getString(IDataSetParser.XMLname)); + } + + children2 = children[i].getChildren(IDataSetParser.XMLSeries); + txtSeries.setText("" + children2.length); //$NON-NLS-1$ + for(int j=0; j<children2.length; j++) { + txtRegExpr[j*COLUMNS+1].setText(children2[j].getString(IDataSetParser.XMLparsingExpression)); + txtRegExpr[j*COLUMNS+2].setText(children2[j].getString(IDataSetParser.XMLparsingSpacer)); + } + txtDelim.setText(children[i].getChild(IDataSetParser.XMLDelimiter).getString(IDataSetParser.XMLparsingExpression)); + + reader.close(); + } catch(FileNotFoundException fnfe) { + return false; + } catch(WorkbenchException we) { + return false; + } catch(IOException ioe) { + return false; + } + + return true; + } + + @Override + protected void copyExisting(IMemento oldMeta, IMemento newMeta) { + IMemento[] children = oldMeta.getChildren(IDataSetParser.XMLColumn); + IMemento child; + for(IMemento memento:children) { + child = newMeta.createChild(IDataSetParser.XMLColumn); + child.putString(IDataSetParser.XMLname, memento.getString(IDataSetParser.XMLname)); + } + children = oldMeta.getChildren(IDataSetParser.XMLSeries); + for(IMemento memento:children) { + child = newMeta.createChild(IDataSetParser.XMLSeries); + child.putString(IDataSetParser.XMLparsingExpression, memento.getString(IDataSetParser.XMLparsingExpression)); + child.putString(IDataSetParser.XMLparsingSpacer, memento.getString(IDataSetParser.XMLparsingSpacer)); + } + newMeta.createChild(IDataSetParser.XMLDelimiter).putString(IDataSetParser.XMLparsingExpression, oldMeta.getChild(IDataSetParser.XMLDelimiter).getString(IDataSetParser.XMLparsingExpression)); + } + + @Override + public boolean checkComplete() { + if(super.checkComplete() && txtDelim.getText().length() > 0) { + try { + wizard.parser = new TableParser(regEx, txtDelim.getText()); + wizard.dataSet = DataSetFactory.createDataSet(TableDataSet.ID, labels); + return true; + } catch(PatternSyntaxException pse) {} + } + wizard.parser = null; + wizard.dataSet = null; + return false; + } + + @Override + public void dispose() { + super.dispose(); + if(null != txtDelim) { + txtDelim.removeModifyListener(textListener); + txtDelim.dispose(); + txtDelim = null; + } + } + + protected Text txtDelim; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/AggregateFactory.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/AggregateFactory.java new file mode 100644 index 0000000000..d3e73d4fe8 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/AggregateFactory.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.filter; + + +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.core.aggregates.AverageAggregate; +import org.eclipse.linuxtools.systemtap.graphingapi.core.aggregates.CountAggregate; +import org.eclipse.linuxtools.systemtap.graphingapi.core.aggregates.IDataAggregate; +import org.eclipse.linuxtools.systemtap.graphingapi.core.aggregates.MaxAggregate; +import org.eclipse.linuxtools.systemtap.graphingapi.core.aggregates.MinAggregate; +import org.eclipse.linuxtools.systemtap.graphingapi.core.aggregates.SumAggregate; + + + +public final class AggregateFactory { + private static final String[] aggregateNames = new String[] { + Localization.getString("AggregateFactory.AverageAggregate"), //$NON-NLS-1$ + Localization.getString("AggregateFactory.CountAggregate"), //$NON-NLS-1$ + Localization.getString("AggregateFactory.MaxAggregate"), //$NON-NLS-1$ + Localization.getString("AggregateFactory.MinAggregate"), //$NON-NLS-1$ + Localization.getString("AggregateFactory.SumAggregate") //$NON-NLS-1$ + }; + + private static final String[] aggregateDescriptions = new String[] { + Localization.getString("AggregateFactory.AverageDescription"), //$NON-NLS-1$ + Localization.getString("AggregateFactory.CountDescription"), //$NON-NLS-1$ + Localization.getString("AggregateFactory.MaxDescription"), //$NON-NLS-1$ + Localization.getString("AggregateFactory.MinDescription"), //$NON-NLS-1$ + Localization.getString("AggregateFactory.SumDescription") //$NON-NLS-1$ + }; + + public static final String[] aggregateIDs = new String[] { + AverageAggregate.ID, + CountAggregate.ID, + MaxAggregate.ID, + MinAggregate.ID, + SumAggregate.ID + }; + + public static String getAggregateName(String id) { + int index = getIndex(id); + if(index >= 0) + return aggregateNames[index]; + return null; + } + + public static String getAggregateDescription(String id) { + int index = getIndex(id); + if(index >= 0) + return aggregateDescriptions[index]; + return null; + } + + private static int getIndex(String id) { + for(int i=0; i< aggregateIDs.length; i++) + if(id.equals(aggregateIDs[i])) + return i; + + return -1; + } + + public static final IDataAggregate createAggregate(String id) { + switch(getIndex(id)) { + case 0: + return new AverageAggregate(); + case 1: + return new CountAggregate(); + case 2: + return new MaxAggregate(); + case 3: + return new MinAggregate(); + case 4: + return new SumAggregate(); + } + return null; + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/AvailableFilterTypes.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/AvailableFilterTypes.java new file mode 100644 index 0000000000..034469ae0f --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/AvailableFilterTypes.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.filter; + +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.core.filters.IDataSetFilter; +import org.eclipse.linuxtools.systemtap.graphingapi.core.filters.MatchFilter; +import org.eclipse.linuxtools.systemtap.graphingapi.core.filters.RangeFilter; +import org.eclipse.linuxtools.systemtap.graphingapi.core.filters.SortFilter; +import org.eclipse.linuxtools.systemtap.graphingapi.core.filters.UniqueFilter; +import org.eclipse.ui.IMemento; + + + +public final class AvailableFilterTypes { + private static final String[] filterNames = new String[] { + Localization.getString("AvailableFilterTypes.MatchFilter"), //$NON-NLS-1$ + Localization.getString("AvailableFilterTypes.RangeFilter"), //$NON-NLS-1$ + Localization.getString("AvailableFilterTypes.SortFilter"), //$NON-NLS-1$ + Localization.getString("AvailableFilterTypes.UniqueFilter") //$NON-NLS-1$ + }; + + private static final String[] filterDescriptions = new String[] { + Localization.getString("AvailableFilterTypes.MatchFilterDescription"), //$NON-NLS-1$ + Localization.getString("AvailableFilterTypes.RangeFilterDescription"), //$NON-NLS-1$ + Localization.getString("AvailableFilterTypes.SortFilterDescription"), //$NON-NLS-1$ + Localization.getString("AvailableFilterTypes.UniqueFilterDescription") //$NON-NLS-1$ + }; + + private static final FilterWizardPage[] filterWizards = new FilterWizardPage[] { + new MatchFilterWizardPage(), + new RangeFilterWizardPage(), + new SortFilterWizardPage(), + new UniqueFilterWizardPage() + }; + + public static final String[] filterIDs = new String[] { + MatchFilter.ID, + RangeFilter.ID, + SortFilter.ID, + UniqueFilter.ID + }; + + public static FilterWizardPage getFilterWizardPage(String id) { + FilterWizardPage page = null; + + int index = getIndex(id); + if(index >=0 && index < filterWizards.length) + return filterWizards[index]; + + return page; + } + + public static String getFilterName(String id) { + int index = getIndex(id); + if(index >= 0) + return filterNames[index]; + return null; + } + + public static String getFilterDescription(String id) { + int index = getIndex(id); + if(index >= 0) + return filterDescriptions[index]; + return null; + } + + public static IDataSetFilter getDataSetFilter(IMemento xml) { + String id = xml.getID(); + int column = xml.getInteger("column").intValue(); //$NON-NLS-1$ + int style; + + switch(getIndex(id)) { + case 0: + String val = xml.getString("value"); //$NON-NLS-1$ + style = xml.getInteger("style").intValue(); //$NON-NLS-1$ + return new MatchFilter(column, val, style); + case 1: + style = xml.getInteger("style").intValue(); //$NON-NLS-1$ + String l = xml.getString("low"); //$NON-NLS-1$ + String h = xml.getString("high"); //$NON-NLS-1$ + + Number low, high; + if(l.contains(".")) //$NON-NLS-1$ + low = Double.valueOf(l); + else + low = Long.valueOf(l); + if(h.contains(".")) //$NON-NLS-1$ + high = Double.valueOf(h); + else + high = Long.valueOf(h); + + return new RangeFilter(column, low, high, style); + case 2: + style = xml.getInteger("style").intValue(); //$NON-NLS-1$ + return new SortFilter(column, style); + case 3: + String agg = xml.getString("aggregate"); //$NON-NLS-1$ + style = xml.getInteger("style").intValue(); //$NON-NLS-1$ + return new UniqueFilter(column, AggregateFactory.createAggregate(agg), style); + } + return null; + } + + private static int getIndex(String id) { + for(int i=0; i< filterIDs.length; i++) { + if(id.equals(filterIDs[i])) { + return i; + } + } + + return -1; + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/FilterWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/FilterWizardPage.java new file mode 100644 index 0000000000..7e12912e7e --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/FilterWizardPage.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.filter; + +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Composite; + +public abstract class FilterWizardPage extends WizardPage { + public FilterWizardPage(String title) { + super("selectFilterOptions"); //$NON-NLS-1$ + setTitle(title); + } + + @Override + public void createControl(Composite parent) { + wizard = (SelectFilterWizard)super.getWizard(); + } + + @Override + public boolean canFlipToNextPage() { + return false; + } + + abstract void createFilter(); + + @Override + public void dispose() { + wizard = null; + super.dispose(); + } + + protected final SelectionListener selectionListener = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + createFilter(); + wizard.getContainer().updateButtons(); + } + }; + + protected final ModifyListener modifyListener = new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + createFilter(); + wizard.getContainer().updateButtons(); + } + }; + + protected SelectFilterWizard wizard; +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/MatchFilterWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/MatchFilterWizardPage.java new file mode 100644 index 0000000000..e6f85c9c7e --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/MatchFilterWizardPage.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.filter; + +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.core.filters.MatchFilter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.widgets.ColumnLayout; + + + +public class MatchFilterWizardPage extends FilterWizardPage { + public MatchFilterWizardPage() { + super("selectFilterOptions"); //$NON-NLS-1$ + setTitle(Localization.getString("MatchFilterWizardPage.CreateMatchFilter")); //$NON-NLS-1$ + } + + @Override + public void createControl(Composite parent) { + super.createControl(parent); + + Composite comp = new Composite(parent, SWT.NULL); + comp.setLayout(new FormLayout()); + FormData data1 = new FormData(); + data1.left = new FormAttachment(0, 0); + data1.top = new FormAttachment(0, 0); + data1.right = new FormAttachment(40, 0); + data1.bottom = new FormAttachment(100, 0); + + Composite cmpFilterOpts = new Composite(comp, SWT.NONE); + cmpFilterOpts.setLayoutData(data1); + ColumnLayout colLayout = new ColumnLayout(); + colLayout.maxNumColumns = 1; + cmpFilterOpts.setLayout(colLayout); + + //Column + Label lblColumn = new Label(cmpFilterOpts, SWT.NONE); + lblColumn.setText(Localization.getString("MatchFilterWizardPage.Column")); //$NON-NLS-1$ + cboColumn = new Combo(cmpFilterOpts, SWT.DROP_DOWN); + cboColumn.addSelectionListener(selectionListener); + for(int i=0; i<wizard.series.length; i++) + cboColumn.add(wizard.series[i]); + + new Label(cmpFilterOpts, SWT.NONE); //Spacer + + //String to compare to + Label lblCompare = new Label(cmpFilterOpts, SWT.NONE); + lblCompare.setText(Localization.getString("MatchFilterWizardPage.CompareTo")); //$NON-NLS-1$ + txtCompare = new Text(cmpFilterOpts, SWT.BORDER); + txtCompare.addModifyListener(modifyListener); + + new Label(cmpFilterOpts, SWT.NONE); //Spacer + + //Style + radKeepMatch = new Button(cmpFilterOpts, SWT.RADIO); + radKeepMatch.setText(Localization.getString("MatchFilterWizardPage.KeepMatching")); //$NON-NLS-1$ + radKeepMatch.addSelectionListener(selectionListener); + radKeepMatch.setSelection(true); + radRemoveMatch = new Button(cmpFilterOpts, SWT.RADIO); + radRemoveMatch.setText(Localization.getString("MatchFilterWizardPage.RemoveMatching")); //$NON-NLS-1$ + radRemoveMatch.addSelectionListener(selectionListener); + + setControl(comp); + } + + @Override + public boolean canFlipToNextPage() { + return false; + } + + @Override + protected void createFilter() { + int selected = cboColumn.getSelectionIndex(); + String compare = txtCompare.getText().trim(); + int style = (radKeepMatch.getSelection() ? MatchFilter.KEEP_MATCHING : MatchFilter.REMOVE_MATCHING); + if(selected >=0 && selected < cboColumn.getItemCount()) { + if(compare.length() > 0) { + wizard.filter = new MatchFilter(selected, compare, style); + } + } + } + + @Override + public void dispose() { + if(null != txtCompare) { + txtCompare.removeModifyListener(modifyListener); + txtCompare.dispose(); + txtCompare = null; + } + + if(null != cboColumn) { + cboColumn.removeSelectionListener(selectionListener); + cboColumn.dispose(); + cboColumn = null; + } + + if(null != radKeepMatch) { + radKeepMatch.removeSelectionListener(selectionListener); + radKeepMatch.dispose(); + radKeepMatch = null; + } + + if(null != radRemoveMatch) { + radRemoveMatch.removeSelectionListener(selectionListener); + radRemoveMatch.dispose(); + radRemoveMatch = null; + } + + super.dispose(); + } + + private Combo cboColumn; + private Text txtCompare; + private Button radKeepMatch, radRemoveMatch; +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/RangeFilterWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/RangeFilterWizardPage.java new file mode 100644 index 0000000000..981bb7720f --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/RangeFilterWizardPage.java @@ -0,0 +1,182 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.filter; + +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.core.filters.RangeFilter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.widgets.ColumnLayout; + + + +public class RangeFilterWizardPage extends FilterWizardPage { + public RangeFilterWizardPage() { + super("selectFilterOptions"); //$NON-NLS-1$ + setTitle(Localization.getString("RangeFilterWizardPage.CreateRangeFilter")); //$NON-NLS-1$ + } + + @Override + public void createControl(Composite parent) { + super.createControl(parent); + + Composite comp = new Composite(parent, SWT.NULL); + comp.setLayout(new FormLayout()); + FormData data1 = new FormData(); + data1.left = new FormAttachment(0, 0); + data1.top = new FormAttachment(0, 0); + data1.right = new FormAttachment(40, 0); + data1.bottom = new FormAttachment(100, 0); + + Composite cmpFilterOpts = new Composite(comp, SWT.NONE); + cmpFilterOpts.setLayoutData(data1); + ColumnLayout colLayout = new ColumnLayout(); + colLayout.maxNumColumns = 1; + cmpFilterOpts.setLayout(colLayout); + + //Column + Label lblColumn = new Label(cmpFilterOpts, SWT.NONE); + lblColumn.setText(Localization.getString("RangeFilterWizardPage.Column")); //$NON-NLS-1$ + cboColumn = new Combo(cmpFilterOpts, SWT.DROP_DOWN); + cboColumn.addSelectionListener(selectionListener); + for(int i=0; i<wizard.series.length; i++) + cboColumn.add(wizard.series[i]); + + new Label(cmpFilterOpts, SWT.NONE); //Spacer + + //Low + Label lblLow = new Label(cmpFilterOpts, SWT.NONE); + lblLow.setText(Localization.getString("RangeFilterWizardPage.LowerBound")); //$NON-NLS-1$ + txtLow = new Text(cmpFilterOpts, SWT.BORDER); + txtLow.addModifyListener(modifyListener); + txtLow.addKeyListener(numberKeyListener); + + new Label(cmpFilterOpts, SWT.NONE); //Spacer + + //High + Label lblHigh = new Label(cmpFilterOpts, SWT.NONE); + lblHigh.setText(Localization.getString("RangeFilterWizardPage.UpperBound")); //$NON-NLS-1$ + txtHigh = new Text(cmpFilterOpts, SWT.BORDER); + txtHigh.addModifyListener(modifyListener); + txtHigh.addKeyListener(numberKeyListener); + + new Label(cmpFilterOpts, SWT.NONE); //Spacer + + //Style + radInside = new Button(cmpFilterOpts, SWT.RADIO); + radInside.setText(Localization.getString("RangeFilterWizardPage.InsideBounds")); //$NON-NLS-1$ + radInside.addSelectionListener(selectionListener); + radInside.setSelection(true); + radOutside = new Button(cmpFilterOpts, SWT.RADIO); + radOutside.setText(Localization.getString("RangeFilterWizardPage.OutsideBounds")); //$NON-NLS-1$ + radOutside.addSelectionListener(selectionListener); + + chkInclusive = new Button(cmpFilterOpts, SWT.CHECK); + chkInclusive.setText(Localization.getString("RangeFilterWizardPage.Inclusive")); //$NON-NLS-1$ + + setControl(comp); + } + + @Override + public boolean canFlipToNextPage() { + return false; + } + + @Override + protected void createFilter() { + int selected = cboColumn.getSelectionIndex(); + + try { + double high = Double.parseDouble(txtHigh.getText().trim()); + double low = Double.parseDouble(txtLow.getText().trim()); + int style = (radInside.getSelection() ? RangeFilter.INSIDE_BOUNDS : RangeFilter.OUTSIDE_BOUNDS); + if(chkInclusive.getSelection()) + style |= RangeFilter.INCLUSIVE; + + if(selected >=0 && selected < cboColumn.getItemCount()) { + if(low <= high) + wizard.filter = new RangeFilter(selected, new Double(low), new Double(high), style); + } + } catch(NumberFormatException nfe) {} + } + + @Override + public void dispose() { + super.dispose(); + if(null != cboColumn) { + cboColumn.removeSelectionListener(selectionListener); + cboColumn.dispose(); + cboColumn = null; + } + + if(null != txtLow) { + txtLow.removeModifyListener(modifyListener); + txtLow.removeKeyListener(numberKeyListener); + txtLow.dispose(); + txtLow = null; + } + + if(null != txtHigh) { + txtHigh.removeModifyListener(modifyListener); + txtHigh.removeKeyListener(numberKeyListener); + txtHigh.dispose(); + txtHigh = null; + } + + if(null != chkInclusive) { + chkInclusive.removeSelectionListener(selectionListener); + chkInclusive.dispose(); + chkInclusive = null; + } + + if(null != radInside) { + radInside.removeSelectionListener(selectionListener); + radInside.dispose(); + radInside = null; + } + + if(null != radOutside) { + radOutside.removeSelectionListener(selectionListener); + radOutside.dispose(); + radOutside = null; + } + } + + private final KeyListener numberKeyListener = new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if((e.character >= ' ' && e.character <= '~') + && (e.character > '9' || e.character < '0')) { + e.doit = false; + } + if(e.character == '.' && !((Text)e.widget).getText().contains(".")) { //$NON-NLS-1$ + e.doit = true; + } + } + + }; + + private Combo cboColumn; + private Text txtLow, txtHigh; + private Button chkInclusive; + private Button radInside, radOutside; +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/SelectFilterWizard.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/SelectFilterWizard.java new file mode 100644 index 0000000000..36472fe366 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/SelectFilterWizard.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.filter; + +import java.util.Arrays; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.core.filters.IDataSetFilter; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; + + + +public class SelectFilterWizard extends Wizard implements INewWizard { + public SelectFilterWizard(String[] series) { + filter = null; + this.series = Arrays.copyOf(series, series.length); + } + + @Override + public void init(IWorkbench workbench, IStructuredSelection selection) { + } + + @Override + public void addPages() { + setWindowTitle(Localization.getString("SelectFilterWizard.CreateFilter")); //$NON-NLS-1$ + selectFilterPage = new SelectFilterWizardPage(); + addPage(selectFilterPage); + + filterOptionsPages = new FilterWizardPage[AvailableFilterTypes.filterIDs.length]; + for(int i=0; i<AvailableFilterTypes.filterIDs.length; i++) { + filterOptionsPages[i] = AvailableFilterTypes.getFilterWizardPage(AvailableFilterTypes.filterIDs[i]); + addPage(filterOptionsPages[i]); + } + } + + @Override + public boolean canFinish() { + IWizardPage page = this.getContainer().getCurrentPage(); + if((null != filter) && (page instanceof FilterWizardPage)) { + return true; + } + return false; + } + + @Override + public boolean performCancel() { + return true; + } + + @Override + public boolean performFinish() { + return true; + } + + public IDataSetFilter getFilter() { + return filter; + } + + @Override + public void dispose() { + if(null != selectFilterPage) { + selectFilterPage.dispose(); + } + selectFilterPage = null; + if(null != filterOptionsPages) { + for(int i=0; i<filterOptionsPages.length; i++) { + filterOptionsPages[i].dispose(); + filterOptionsPages[i] = null; + } + } + filterOptionsPages = null; + series = null; + + super.dispose(); + } + + private SelectFilterWizardPage selectFilterPage; + private FilterWizardPage[] filterOptionsPages; + public String[] series; + + public IDataSetFilter filter; +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/SelectFilterWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/SelectFilterWizardPage.java new file mode 100644 index 0000000000..03a2414713 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/SelectFilterWizardPage.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.filter; + +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.forms.widgets.ColumnLayout; + + + +public class SelectFilterWizardPage extends WizardPage { + public SelectFilterWizardPage() { + super("selectFilter"); //$NON-NLS-1$ + setTitle(Localization.getString("SelectFilterWizardPage.SelectFilter")); //$NON-NLS-1$ + filterID = ""; //$NON-NLS-1$ + btnFilters = null; + buttonListener = new ButtonSelectionListener(); + } + + @Override + public void createControl(Composite parent) { + wizard = (SelectFilterWizard)super.getWizard(); + + Composite comp = new Composite(parent, SWT.NULL); + comp.setLayout(new FormLayout()); + FormData data1 = new FormData(); + data1.left = new FormAttachment(0, 0); + data1.top = new FormAttachment(0, 0); + data1.right = new FormAttachment(40, 0); + data1.bottom = new FormAttachment(100, 0); + + Composite cmpFilterOpts = new Composite(comp, SWT.NONE); + cmpFilterOpts.setLayoutData(data1); + ColumnLayout colLayout = new ColumnLayout(); + colLayout.maxNumColumns = 1; + cmpFilterOpts.setLayout(colLayout); + + btnFilters = new Button[AvailableFilterTypes.filterIDs.length]; + for(int i=0; i<btnFilters.length; i++) { + btnFilters[i] = new Button(cmpFilterOpts, SWT.NONE); + btnFilters[i].setText(AvailableFilterTypes.getFilterName(AvailableFilterTypes.filterIDs[i])); + btnFilters[i].addSelectionListener(buttonListener); + btnFilters[i].setData(AvailableFilterTypes.filterIDs[i]); + } + + FormData data2 = new FormData(); + data2.left = new FormAttachment(cmpFilterOpts); + data2.top = new FormAttachment(0, 0); + data2.right = new FormAttachment(100, 0); + data2.bottom = new FormAttachment(100, 0); + + lblDesc = new Label(comp, SWT.WRAP); + lblDesc.setLayoutData(data2); + setControl(comp); + } + + @Override + public IWizardPage getNextPage() { + return AvailableFilterTypes.getFilterWizardPage(filterID); + } + + @Override + public boolean canFlipToNextPage() { + return (filterID.length() > 0); + } + + @Override + public void dispose() { + super.dispose(); + if(null != btnFilters) + for(int i=0; i<btnFilters.length; i++) { + btnFilters[i].removeSelectionListener(buttonListener); + btnFilters[i].dispose(); + btnFilters[i] = null; + } + btnFilters = null; + lblDesc = null; + } + + private class ButtonSelectionListener extends SelectionAdapter { + + @Override + public void widgetSelected(SelectionEvent e) { + if(e.widget instanceof Button) { + Button target = (Button)e.widget; + + for(int i=0; i<btnFilters.length; i++) { + if(target == btnFilters[i]) { + filterID = btnFilters[i].getData().toString(); + lblDesc.setText(AvailableFilterTypes.getFilterName(filterID) + "\n\n" + //$NON-NLS-1$ + AvailableFilterTypes.getFilterDescription(filterID)); + wizard.getContainer().updateButtons(); + } + } + } + } + } + + private Button[] btnFilters; + private Label lblDesc; + private String filterID; + private SelectFilterWizard wizard; + private ButtonSelectionListener buttonListener; +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/SortFilterWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/SortFilterWizardPage.java new file mode 100644 index 0000000000..0467af0269 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/SortFilterWizardPage.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.filter; + +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.core.filters.SortFilter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.forms.widgets.ColumnLayout; + + + +public class SortFilterWizardPage extends FilterWizardPage { + public SortFilterWizardPage() { + super("selectFilterOptions"); //$NON-NLS-1$ + setTitle(Localization.getString("SortFilterWizardPage.CreateSortFilter")); //$NON-NLS-1$ + } + + @Override + public void createControl(Composite parent) { + super.createControl(parent); + + Composite comp = new Composite(parent, SWT.NULL); + comp.setLayout(new FormLayout()); + FormData data1 = new FormData(); + data1.left = new FormAttachment(0, 0); + data1.top = new FormAttachment(0, 0); + data1.right = new FormAttachment(40, 0); + data1.bottom = new FormAttachment(100, 0); + + Composite cmpFilterOpts = new Composite(comp, SWT.NONE); + cmpFilterOpts.setLayoutData(data1); + ColumnLayout colLayout = new ColumnLayout(); + colLayout.maxNumColumns = 1; + cmpFilterOpts.setLayout(colLayout); + + //Column + Label lblColumn = new Label(cmpFilterOpts, SWT.NONE); + lblColumn.setText(Localization.getString("SortFilterWizardPage.Column")); //$NON-NLS-1$ + cboColumn = new Combo(cmpFilterOpts, SWT.DROP_DOWN); + cboColumn.addSelectionListener(selectionListener); + for(int i=0; i<wizard.series.length; i++) + cboColumn.add(wizard.series[i]); + + new Label(cmpFilterOpts, SWT.NONE); //Spacer + + //Style + radAscending = new Button(cmpFilterOpts, SWT.RADIO); + radAscending.setText(Localization.getString("SortFilterWizardPage.Ascending")); //$NON-NLS-1$ + radAscending.addSelectionListener(selectionListener); + radAscending.setSelection(true); + radDescending = new Button(cmpFilterOpts, SWT.RADIO); + radDescending.setText(Localization.getString("SortFilterWizardPage.Descending")); //$NON-NLS-1$ + radDescending.addSelectionListener(selectionListener); + + setControl(comp); + } + + @Override + public boolean canFlipToNextPage() { + return false; + } + + @Override + protected void createFilter() { + int selected = cboColumn.getSelectionIndex(); + int style = (radAscending.getSelection() ? SortFilter.ASCENDING : SortFilter.DESCENDING); + if(selected >=0 && selected < cboColumn.getItemCount()) + wizard.filter = new SortFilter(selected, style); + } + + @Override + public void dispose() { + if(null != cboColumn) { + cboColumn.removeSelectionListener(selectionListener); + cboColumn.dispose(); + cboColumn = null; + } + + if(null != radAscending) { + radAscending.removeSelectionListener(selectionListener); + radAscending.dispose(); + radAscending = null; + } + + if(null != radDescending) { + radDescending.removeSelectionListener(selectionListener); + radDescending.dispose(); + radDescending = null; + } + + super.dispose(); + } + + private Combo cboColumn; + private Button radAscending, radDescending; +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/UniqueFilterWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/UniqueFilterWizardPage.java new file mode 100644 index 0000000000..4ba755bcd5 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/filter/UniqueFilterWizardPage.java @@ -0,0 +1,159 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.filter; + +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.core.filters.UniqueFilter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.forms.widgets.ColumnLayout; + + + +public class UniqueFilterWizardPage extends FilterWizardPage { + public UniqueFilterWizardPage() { + super("selectFilterOptions"); //$NON-NLS-1$ + setTitle(Localization.getString("UniqueFilterWizardPage.CreateUniqueFilter")); //$NON-NLS-1$ + aggregateID = ""; //$NON-NLS-1$ + } + + @Override + public void createControl(Composite parent) { + super.createControl(parent); + + Composite comp = new Composite(parent, SWT.NULL); + comp.setLayout(new FormLayout()); + FormData data1 = new FormData(); + data1.left = new FormAttachment(0, 0); + data1.top = new FormAttachment(0, 0); + data1.right = new FormAttachment(40, 0); + data1.bottom = new FormAttachment(100, 0); + + Composite cmpFilterOpts = new Composite(comp, SWT.NONE); + cmpFilterOpts.setLayoutData(data1); + ColumnLayout colLayout = new ColumnLayout(); + colLayout.maxNumColumns = 1; + cmpFilterOpts.setLayout(colLayout); + + //Column + Label lblColumn = new Label(cmpFilterOpts, SWT.NONE); + lblColumn.setText(Localization.getString("UniqueFilterWizardPage.Column")); //$NON-NLS-1$ + cboColumn = new Combo(cmpFilterOpts, SWT.DROP_DOWN); + cboColumn.addSelectionListener(selectionListener); + for (String series : wizard.series) { + cboColumn.add(series); + } + + new Label(cmpFilterOpts, SWT.NONE); //Spacer + + //String to compare to + Label lblAggregate = new Label(cmpFilterOpts, SWT.NONE); + lblAggregate.setText(Localization.getString("UniqueFilterWizardPage.Aggregate")); //$NON-NLS-1$ + + btnAggregates = new Button[AggregateFactory.aggregateIDs.length]; + for(int i=0; i<btnAggregates.length; i++) { + btnAggregates[i] = new Button(cmpFilterOpts, SWT.NONE); + btnAggregates[i].setText(AggregateFactory.getAggregateName(AggregateFactory.aggregateIDs[i])); + btnAggregates[i].addSelectionListener(btnSelectionListener); + btnAggregates[i].setData(AggregateFactory.aggregateIDs[i]); + } + + FormData data2 = new FormData(); + data2.left = new FormAttachment(cmpFilterOpts); + data2.top = new FormAttachment(0, 0); + data2.right = new FormAttachment(100, 0); + data2.bottom = new FormAttachment(100, 0); + + lblDesc = new Label(comp, SWT.WRAP); + lblDesc.setLayoutData(data2); + setControl(comp); + } + + @Override + public boolean canFlipToNextPage() { + return false; + } + + @Override + protected void createFilter() { + int selected = cboColumn.getSelectionIndex(); + int style = 0; + if(selected >=0 && selected < cboColumn.getItemCount()) { + if(null != aggregateID && aggregateID.length() > 0) { + ((SelectFilterWizard) super.getWizard()).filter = new UniqueFilter( + selected, + AggregateFactory.createAggregate(aggregateID), style); + } + } + } + + @Override + public void dispose() { + if(null != cboColumn) { + cboColumn.removeSelectionListener(selectionListener); + cboColumn.dispose(); + cboColumn = null; + } + + if(null != lblDesc) { + lblDesc.dispose(); + } + lblDesc = null; + + if(null != btnAggregates) { + for(int i=0; i<btnAggregates.length; i++) { + btnAggregates[i].removeSelectionListener(btnSelectionListener); + btnAggregates[i].dispose(); + btnAggregates[i] = null; + } + btnAggregates = null; + } + + aggregateID = null; + + super.dispose(); + } + + private final SelectionListener btnSelectionListener = new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + if(e.widget instanceof Button) { + Button target = (Button)e.widget; + + for (Button button : btnAggregates) { + if(target == button) { + lblDesc.setText(AggregateFactory.getAggregateName(button.getData().toString()) + "\n\n" + //$NON-NLS-1$ + AggregateFactory.getAggregateDescription(button.getData().toString())); + aggregateID = button.getData().toString(); + createFilter(); + wizard.getContainer().updateButtons(); + } + } + } + } + }; + + private Combo cboColumn; + private Button[] btnAggregates; + private Label lblDesc; + private String aggregateID; +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/graph/GraphFactory.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/graph/GraphFactory.java new file mode 100644 index 0000000000..ce94cdca3d --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/graph/GraphFactory.java @@ -0,0 +1,176 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.graph; + +import java.util.LinkedList; + +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.GraphingAPIUIPlugin; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.core.adapters.BlockAdapter; +import org.eclipse.linuxtools.systemtap.graphingapi.core.adapters.ScrollAdapter; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.IBlockDataSet; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.IDataSet; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.IHistoricalDataSet; +import org.eclipse.linuxtools.systemtap.graphingapi.core.structures.GraphData; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.charts.AbstractChartBuilder; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.charts.AreaChartBuilder; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.charts.BarChartBuilder; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.charts.LineChartBuilder; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.charts.PieChartBuilder; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.charts.ScatterChartBuilder; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.graphs.PieChart; +import org.eclipse.linuxtools.systemtap.graphingapi.ui.widgets.GraphComposite; +import org.eclipse.swt.graphics.Image; + + + +public final class GraphFactory { + private static final String[] graphNames = new String[] { + Localization.getString("GraphFactory.ScatterGraph"), //$NON-NLS-1$ + Localization.getString("GraphFactory.LineGraph"), //$NON-NLS-1$ + Localization.getString("GraphFactory.BarGraph"), //$NON-NLS-1$ + Localization.getString("GraphFactory.AreaGraph"), //$NON-NLS-1$ + Localization.getString("GraphFactory.PieChart"), //$NON-NLS-1$ + }; + + private static final String[] graphDescriptions = new String[] { + Localization.getString("GraphFactory.ScatterDescription"), //$NON-NLS-1$ + Localization.getString("GraphFactory.LineDescription"), //$NON-NLS-1$ + Localization.getString("GraphFactory.BarDescription"), //$NON-NLS-1$ + Localization.getString("GraphFactory.AreaDescription"), //$NON-NLS-1$ + Localization.getString("GraphFactory.PieDescription"), //$NON-NLS-1$ + }; + + private static final Image[] graphImages = new Image[] { + GraphingAPIUIPlugin.getImageDescriptor("icons/graphs/ScatterGraph.gif").createImage(), //$NON-NLS-1$ + GraphingAPIUIPlugin.getImageDescriptor("icons/graphs/LineGraph.gif").createImage(), //$NON-NLS-1$ + GraphingAPIUIPlugin.getImageDescriptor("icons/graphs/BarGraph.gif").createImage(), //$NON-NLS-1$ + GraphingAPIUIPlugin.getImageDescriptor("icons/graphs/AreaChart.gif").createImage(), //$NON-NLS-1$ + GraphingAPIUIPlugin.getImageDescriptor("icons/graphs/PieChart.gif").createImage(), //$NON-NLS-1$ + }; + + private static final String[] graphIDs = new String[] { + ScatterChartBuilder.ID, + LineChartBuilder.ID, + BarChartBuilder.ID, + AreaChartBuilder.ID, + PieChartBuilder.ID, + }; + + public static String[] getAvailableGraphs(IDataSet data) { + LinkedList<String> ids = new LinkedList<String>(); + if(data instanceof IHistoricalDataSet) { + ids.add(ScatterChartBuilder.ID); + ids.add(LineChartBuilder.ID); + ids.add(AreaChartBuilder.ID); + ids.add(BarChartBuilder.ID); + ids.add(PieChartBuilder.ID); + } + if(data instanceof IBlockDataSet) { + if(!ids.contains(BarChartBuilder.ID)) + ids.add(BarChartBuilder.ID); + ids.add(PieChartBuilder.ID); + } + + String[] id = new String[0]; + return ids.toArray(id); + } + + public static String getGraphName(String id) { + int index = getIndex(id); + if(index >= 0) + return graphNames[index]; + return null; + } + + public static String getGraphDescription(String id) { + int index = getIndex(id); + if(index >= 0) + return graphDescriptions[index]; + return null; + } + + public static Image getGraphImage(String id) { + int index = getIndex(id); + if(index >= 0) + return graphImages[index]; + return null; + } + + public static boolean isMultiGraph(String id) { + if(id.equals(PieChart.ID)) + return false; + return true; + } + + public static boolean isKeyRequired(String graphID, IDataSet data) { + switch(getIndex(graphID)) { + case 0: + case 1: + if(data instanceof IBlockDataSet) //Has to be IHistoricalDataSet + return true; + default: + return false; + } + } + + public static boolean isKeyOptional(String graphID, IDataSet data) { + switch(getIndex(graphID)) { + case 2: + if(data instanceof IBlockDataSet) //Has to be IHistoricalDataSet + return true; + default: + return false; + } + } + + public static final AbstractChartBuilder createGraph(GraphComposite comp, int style, GraphData gd, IDataSet data) { + AbstractChartBuilder builder = null; + + switch(getIndex(gd.graphID)) { + case 0: + builder = new ScatterChartBuilder(comp, style, gd.title, new ScrollAdapter((IHistoricalDataSet)data, gd.xSeries, gd.ySeries, gd.key)); + break; + case 1: + builder = new LineChartBuilder(comp, style, gd.title, new ScrollAdapter((IHistoricalDataSet)data, gd.xSeries, gd.ySeries, gd.key)); + break; + case 2: + if(!(data instanceof IBlockDataSet) || (null != gd.key)) + { + builder = new BarChartBuilder(comp, style, gd.title, new ScrollAdapter((IHistoricalDataSet)data, gd.xSeries, gd.ySeries, gd.key)); + + } + else + { + builder = new BarChartBuilder(comp, style, gd.title, new BlockAdapter((IBlockDataSet)data, gd.xSeries, gd.ySeries)); + + } + break; + case 3: + builder = new AreaChartBuilder(comp, style, gd.title, new ScrollAdapter((IHistoricalDataSet)data, gd.xSeries, gd.ySeries, gd.key)); + break; + case 4: + builder = new PieChartBuilder(comp, style, gd.title, new ScrollAdapter((IHistoricalDataSet)data, gd.xSeries, gd.ySeries, gd.key)); + + break; + } + return builder; + } + + private static int getIndex(String id) { + + for(int i=0; i<graphIDs.length; i++) + if(id.equals(graphIDs[i])) + return i; + return -1; + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/graph/GraphModel.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/graph/GraphModel.java new file mode 100644 index 0000000000..e560be9f13 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/graph/GraphModel.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.graph; + +import java.util.Arrays; + +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.IDataSet; +import org.eclipse.linuxtools.systemtap.graphingapi.core.structures.GraphData; + +public class GraphModel { + public GraphModel(IDataSet d) { + graph = new GraphData(); + graph.graphID = ""; //$NON-NLS-1$ + graph.title = ""; //$NON-NLS-1$ + graph.xSeries = -1; + graph.ySeries = null; + data = d; + } + + public void destroy() { + graph = null; + } + + public GraphData getGraphData() { + return graph; + } + + public IDataSet getDataSet() { + return data; + } + + public String[] getSeries() { + return data.getTitles(); + } + + public String getGraphID() { + return graph.graphID; + } + + public int getXSeries() { + return graph.xSeries; + } + + public int[] getYSeries() { + return graph.ySeries; + } + + public void setTitle(String title) { + graph.title = title; + } + + public void setKey(String key) { + graph.key = key; + } + + public void setGraph(String g) { + graph.graphID = g; + } + + public void setXSeries(int x) { + graph.xSeries = x; + } + + public void setYSeries(int[] y) { + graph.ySeries = Arrays.copyOf(y, y.length); + } + + public boolean isGraphSet() { + return !graph.graphID.isEmpty(); + } + + public boolean isSeriesSet() { + return ((-1 <= graph.xSeries) && (null != graph.ySeries) && graph.ySeries.length > 0); + } + + public boolean isTitleSet() { + return !graph.title.isEmpty(); + } + + private GraphData graph; + private IDataSet data; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/graph/SelectGraphWizard.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/graph/SelectGraphWizard.java new file mode 100644 index 0000000000..3bf024551a --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/graph/SelectGraphWizard.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.graph; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.linuxtools.systemtap.graphingapi.core.datasets.IDataSet; +import org.eclipse.linuxtools.systemtap.graphingapi.core.structures.GraphData; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; + + + +public class SelectGraphWizard extends Wizard implements INewWizard { + public SelectGraphWizard(IDataSet data) { + model = new GraphModel(data); + } + + @Override + public void init(IWorkbench workbench, IStructuredSelection selection) { + } + + @Override + public void addPages() { + setWindowTitle(Localization.getString("SelectGraphWizard.CreateGraph")); //$NON-NLS-1$ + selectGraphPage = new SelectGraphWizardPage(); + addPage(selectGraphPage); + selectSeriesPage = new SelectSeriesWizardPage(); + addPage(selectSeriesPage); + } + + @Override + public boolean canFinish() { + if (this.getContainer().getCurrentPage() == selectSeriesPage && + selectSeriesPage.isPageComplete()) + return true; + return false; + } + + @Override + public boolean performCancel() { + model.destroy(); + return true; + } + + @Override + public boolean performFinish() { + return true; + } + + public GraphData getGraphData() { + return model.getGraphData(); + } + + @Override + public void dispose() { + if(null != selectGraphPage) + selectGraphPage.dispose(); + if(null != selectSeriesPage) + selectSeriesPage.dispose(); + super.dispose(); + } + + public SelectGraphWizardPage selectGraphPage; + public SelectSeriesWizardPage selectSeriesPage; + public GraphModel model; +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/graph/SelectGraphWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/graph/SelectGraphWizardPage.java new file mode 100644 index 0000000000..87fe0c6849 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/graph/SelectGraphWizardPage.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.graph; + +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.ui.forms.widgets.ColumnLayout; + +public class SelectGraphWizardPage extends WizardPage implements Listener { + public SelectGraphWizardPage() { + super("selectGraph"); //$NON-NLS-1$ + setTitle(Localization.getString("SelectGraphWizardPage.SelectGraph")); //$NON-NLS-1$ + } + + @Override + public void createControl(Composite parent) { + wizard = (SelectGraphWizard)getWizard(); + + Composite cmpGraphOpts = new Composite(parent, SWT.NONE); + ColumnLayout colLayout = new ColumnLayout(); + colLayout.maxNumColumns = 1; + cmpGraphOpts.setLayout(colLayout); + + String[] graphIDs = GraphFactory.getAvailableGraphs(wizard.model.getDataSet()); + btnGraphs = new Button[graphIDs.length]; + for(int i=0; i<btnGraphs.length; i++) { + btnGraphs[i] = new Button(cmpGraphOpts, SWT.TOGGLE); + btnGraphs[i].setImage(GraphFactory.getGraphImage(graphIDs[i])); + btnGraphs[i].addListener(SWT.Selection, this); + btnGraphs[i].setData(graphIDs[i]); + btnGraphs[i].setToolTipText(GraphFactory.getGraphName(btnGraphs[i].getData().toString()) + "\n\n" + //$NON-NLS-1$ + GraphFactory.getGraphDescription(btnGraphs[i].getData().toString())); + } + setControl(cmpGraphOpts); + } + + @Override + public void handleEvent(Event event) { + if(event.widget instanceof Button) { + Button target = (Button)event.widget; + for(int i=0; i<btnGraphs.length; i++) + if(target == btnGraphs[i]) { + saveDataToModel(btnGraphs[i].getData().toString()); + wizard.getContainer().updateButtons(); + } else { + btnGraphs[i].setSelection(false); + } + } + } + + @Override + public IWizardPage getNextPage() { + return wizard.selectSeriesPage; + } + + @Override + public boolean canFlipToNextPage() { + return wizard.model.isGraphSet(); + } + + private void saveDataToModel(String selected) { + GraphModel model = wizard.model; + model.setGraph(selected); + wizard.selectSeriesPage.setKeyEnablement( + GraphFactory.isKeyRequired(model.getGraphID(), model.getDataSet()), + GraphFactory.isKeyOptional(model.getGraphID(), model.getDataSet())); + } + + @Override + public void dispose() { + super.dispose(); + if(null != btnGraphs) + for(int i=0; i<btnGraphs.length; i++) + btnGraphs[i] = null; + btnGraphs = null; + } + + private Button[] btnGraphs; + private SelectGraphWizard wizard; +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/graph/SelectSeriesWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/graph/SelectSeriesWizardPage.java new file mode 100644 index 0000000000..c5b82cefd5 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/graphingapi/ui/wizards/graph/SelectSeriesWizardPage.java @@ -0,0 +1,338 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * 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 + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.graphingapi.ui.wizards.graph; + +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.linuxtools.internal.systemtap.graphingapi.ui.Localization; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.widgets.ColumnLayout; + + + + +public class SelectSeriesWizardPage extends WizardPage { + public SelectSeriesWizardPage() { + super("selectSeries"); //$NON-NLS-1$ + setTitle(Localization.getString("SelectSeriesWizardPage.SelectSeries")); //$NON-NLS-1$ + } + + @Override + public void createControl(Composite parent) { + model = ((SelectGraphWizard)super.getWizard()).model; + + //Set the layout data + Composite comp = new Composite(parent, SWT.NULL); + comp.setLayout(new FormLayout()); + FormData data1 = new FormData(); + data1.left = new FormAttachment(0, 0); + data1.top = new FormAttachment(0, 0); + data1.right = new FormAttachment(40, 0); + data1.bottom = new FormAttachment(100, 0); + + //Add the title wigets + Label lblTitle = new Label(comp, SWT.NONE); + lblTitle.setText(Localization.getString("SelectSeriesWizardPage.Title")); //$NON-NLS-1$ + txtTitle = new Text(comp, SWT.BORDER); + txtTitle.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + getWizard().getContainer().updateButtons(); + if(txtTitle.getText().length() == 0) { + setErrorMessage(Localization.getString("SelectSeriesWizardPage.TitleNotSet")); //$NON-NLS-1$ + setMessage(null); + } else { + setErrorMessage(null); + setMessage(""); //$NON-NLS-1$ + } + } + }); + data1 = new FormData(); + data1.left = new FormAttachment(0,0); + data1.top = new FormAttachment(0,0); + data1.width = 200; + lblTitle.setLayoutData(data1); + + data1 = new FormData(); + data1.left = new FormAttachment(0,0); + data1.top = new FormAttachment(lblTitle,0); + data1.width = 200; + txtTitle.setLayoutData(data1); + + + //Add the data series widgets + data1 = new FormData(); + data1.left = new FormAttachment(0, 0); + data1.top = new FormAttachment(txtTitle, 20); + data1.right = new FormAttachment(40, 0); + data1.bottom = new FormAttachment(100, 0); + + Composite cmpGraphOpts = new Composite(comp, SWT.NONE); + cmpGraphOpts.setLayoutData(data1); + ColumnLayout colLayout = new ColumnLayout(); + colLayout.maxNumColumns = 1; + cmpGraphOpts.setLayout(colLayout); + + String[] labels = model.getSeries(); + + cboYItems = new Combo[labels.length]; + lblYItems = new Label[cboYItems.length]; + + Label lblXItem = new Label(cmpGraphOpts, SWT.NONE); + lblXItem.setText(Localization.getString("SelectSeriesWizardPage.XSeries")); //$NON-NLS-1$ + cboXItem = new Combo(cmpGraphOpts, SWT.DROP_DOWN); + cboXItem.addSelectionListener(new ComboSelectionListener()); + cboXItem.add(Localization.getString("SelectSeriesWizardPage.RowID")); //$NON-NLS-1$ + cboXItem.select(0); + + new Label(cmpGraphOpts, SWT.NONE); //Spacer + + for(int i=0; i<cboYItems.length; i++) { + lblYItems[i] = new Label(cmpGraphOpts, SWT.NONE); + lblYItems[i].setText(Localization.getString("SelectSeriesWizardPage.YSeries") + i + ":"); //$NON-NLS-1$ //$NON-NLS-2$ + cboYItems[i] = new Combo(cmpGraphOpts, SWT.DROP_DOWN); + cboYItems[i].addSelectionListener(new ComboSelectionListener()); + + if(i>0) { + cboYItems[i].add(Localization.getString("SelectSeriesWizardPage.NA")); //$NON-NLS-1$ + cboYItems[i].select(0); + cboYItems[i].setVisible(false); + lblYItems[i].setVisible(false); + } + } + + for(int j,i=0; i<labels.length; i++) { + cboXItem.add(labels[i]); + for(j=0; j<lblYItems.length; j++) + cboYItems[j].add(labels[i]); + } + + + //Add the key filter wigets + btnKey = new Button(comp, SWT.CHECK); + btnKey.setText(Localization.getString("SelectSeriesWizardPage.UseHistoricalData")); //$NON-NLS-1$ + btnKey.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent e) {} + @Override + public void widgetSelected(SelectionEvent e) { + txtKey.setEnabled(btnKey.getSelection()); + } + }); + + data1 = new FormData(); + data1.left = new FormAttachment(cmpGraphOpts, 20); + data1.top = new FormAttachment(txtTitle, 0); + data1.right = new FormAttachment(100, 0); + btnKey.setLayoutData(data1); + + lblKey = new Label(comp, SWT.NONE); + lblKey.setText(Localization.getString("SelectSeriesWizardPage.KeyFilter")); //$NON-NLS-1$ + txtKey = new Text(comp, SWT.BORDER); + + if(null != txtKey) { + txtKey.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + getWizard().getContainer().updateButtons(); + if(txtTitle.getText().length() == 0) { + setErrorMessage(Localization.getString("SelectSeriesWizardPage.KeyNotSet")); //$NON-NLS-1$ + setMessage(null); + } else { + setErrorMessage(null); + setMessage(""); //$NON-NLS-1$ + } + } + }); + } + + data1 = new FormData(); + data1.left = new FormAttachment(cmpGraphOpts, 20); + data1.top = new FormAttachment(btnKey, 0); + data1.right = new FormAttachment(80, 0); + lblKey.setLayoutData(data1); + + data1 = new FormData(); + data1.left = new FormAttachment(cmpGraphOpts, 20); + data1.top = new FormAttachment(lblKey, 2); + data1.right = new FormAttachment(80, 0); + txtKey.setLayoutData(data1); + + //Make comp visible + setControl(comp); + } + + public void setKeyEnablement(boolean required, boolean optional) { + btnKey.setVisible(optional); + txtKey.setVisible(required || optional); + lblKey.setVisible(required || optional); + txtKey.setEnabled(required); + } + + @Override + public boolean canFlipToNextPage() { + return false; + } + + @Override + public boolean isPageComplete() { + return saveDataToModel(); + } + + private boolean saveDataToModel() { + if(isSeriesUnique()) { + model.setTitle(txtTitle.getText()); + + if(null != txtKey && txtKey.isEnabled()) + model.setKey(txtKey.getText()); + else + model.setKey(null); + + model.setXSeries(cboXItem.getSelectionIndex()-1); + + int i, count; + for(i=1, count=1; i<cboYItems.length; i++) + if(cboYItems[i].isVisible() && 0 != cboYItems[i].getSelectionIndex()) + count++; + + int[] ySeries = new int[count]; + ySeries[0] = cboYItems[0].getSelectionIndex(); + for(i=1; i<count; i++) + ySeries[i] = cboYItems[i].getSelectionIndex()-1; + model.setYSeries(ySeries); + return true; + } + return false; + } + + private boolean isSeriesUnique() { + if("".equals(txtTitle.getText().trim())) //$NON-NLS-1$ + return false; + if(null != txtKey && txtKey.isEnabled() && txtKey.getText().length() <= 0) + return false; + + for(int j,i=0; i<cboYItems.length; i++) { + if(cboYItems[i].isVisible()) { + for(j=i+1; j<cboYItems.length; j++) { + if(cboYItems[j].isVisible()) { + if(0 > cboYItems[i].getSelectionIndex()) + return false; + else if(0 > cboYItems[j].getSelectionIndex()) + return false; + else if(cboYItems[i].getItem(cboYItems[i].getSelectionIndex()).equals(cboYItems[j].getItem(cboYItems[j].getSelectionIndex()))) { + return false; + } + } + } + if(0 > cboYItems[i].getSelectionIndex()) + return false; + else if(0 > cboXItem.getSelectionIndex()) + return false; + else if(cboYItems[i].getItem(cboYItems[i].getSelectionIndex()).equals(cboXItem.getItem(cboXItem.getSelectionIndex()))) { + return false; + } + } + } + return true; + } + + @Override + public void dispose() { + super.dispose(); + if(null != txtTitle) + txtTitle.dispose(); + txtTitle = null; + + if(null != txtKey) + txtKey.dispose(); + txtKey = null; + if(null != btnKey) + btnKey.dispose(); + btnKey = null; + if(null != lblKey) + lblKey.dispose(); + lblKey = null; + + if(null != cboXItem) + cboXItem.dispose(); + cboXItem = null; + if(null != cboYItems) { + for(int i=0; i<cboYItems.length; i++) { + if(null != cboYItems[i]) + cboYItems[i].dispose(); + cboYItems[i] = null; + if(null != lblYItems[i]) + lblYItems[i].dispose(); + lblYItems[i] = null; + } + } + cboYItems = null; + lblYItems = null; + model = null; + } + + private class ComboSelectionListener implements SelectionListener { + @Override + public void widgetDefaultSelected(SelectionEvent e) {} + + @Override + public void widgetSelected(SelectionEvent e) { + if(!cboXItem.equals(e.getSource())) { + boolean setVisible = true; + if(GraphFactory.isMultiGraph(model.getGraphID())) { + for(int i=1; i<cboYItems.length; i++) { + cboYItems[i].setVisible(setVisible); + lblYItems[i].setVisible(setVisible); + if(cboYItems[i].getSelectionIndex() > 0 && cboYItems[i].isVisible()) + setVisible = true; + else + setVisible = false; + } + } + } + + if(!isSeriesUnique()) { + setErrorMessage(Localization.getString("SelectSeriesWizardPage.SeriesNotSelected")); //$NON-NLS-1$ + setMessage(null); + } else { + setErrorMessage(null); + setMessage(""); //$NON-NLS-1$ + } + if(txtTitle.getText().length() == 0) { + setErrorMessage(Localization.getString("SelectSeriesWizardPage.TitleNotSet")); //$NON-NLS-1$ + setMessage(null); + } + + getWizard().getContainer().updateButtons(); + } + } + + private Text txtTitle; //TODO: Move this to another page once graphs get more detail + private Text txtKey; + private Button btnKey; + private Label lblKey; + private Combo cboXItem; + private Combo[] cboYItems; + private Label[] lblYItems; + private GraphModel model; +}
\ No newline at end of file |