diff options
Diffstat (limited to 'systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org')
45 files changed, 5495 insertions, 0 deletions
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/datadisplay/DataGrid.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/datadisplay/DataGrid.java new file mode 100644 index 0000000000..cd4e9bb2a2 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/datadisplay/DataGrid.java @@ -0,0 +1,344 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.datadisplay; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IFilteredDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.filters.IDataSetFilter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.GraphingAPIUIPlugin; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.preferences.GraphingAPIPreferenceConstants; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.wizards.dataset.DataSetFactory; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.wizards.filter.AvailableFilterTypes; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.wizards.filter.SelectFilterWizard; +import org.eclipse.linuxtools.systemtap.ui.structures.IFormattingStyles; +import org.eclipse.linuxtools.systemtap.ui.structures.StringFormatter; +import org.eclipse.linuxtools.systemtap.ui.structures.listeners.IUpdateListener; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MenuEvent; +import org.eclipse.swt.events.MenuListener; +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")); + 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() { + 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")); + item.setMenu(formatMenu); + + //if(dataSet instanceof IFilteredDataSet) { + filterMenu = new Menu(menu); + item = new MenuItem(menu, SWT.CASCADE); + item.setText(Localization.getString("DataGrid.AddFilter")); + item.addSelectionListener(new AddFilterSelection()); + + item = new MenuItem(menu, SWT.CASCADE); + item.setText(Localization.getString("DataGrid.RemoveFilter")); + 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")); + 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 implements MenuListener { + public void menuHidden(MenuEvent e) {} + + public void menuShown(MenuEvent e) { + MenuItem item = ((Menu)e.widget).getItem(1); + item.setSelection(manualResize); + } + } + + public class MenuManualyResizedSelection implements SelectionListener { + public void widgetSelected(SelectionEvent e) { + manualResize = !manualResize; + } + + public void widgetDefaultSelected(SelectionEvent e) {} + } + + public class AddFilterSelection implements SelectionListener { + 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 void widgetDefaultSelected(SelectionEvent e) {} + } + + public class RemoveFilterSelection implements SelectionListener { + public void widgetSelected(SelectionEvent e) { + IDataSetFilter idsf = (IDataSetFilter)((MenuItem)e.widget).getData(); + e.widget.dispose(); + + if(filteredDataSet.removeFilter(idsf)) { + table.removeAll(); + handleUpdateEvent(); + } + } + + public void widgetDefaultSelected(SelectionEvent e) {} + } + + public class FormatMenuListener implements MenuListener { + public void menuHidden(MenuEvent e) {} + + 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 implements SelectionListener { + 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(); + } + + public void widgetDefaultSelected(SelectionEvent e) {} + } + + public void handleUpdateEvent() { + if(table.isDisposed()) return; + + table.getDisplay().asyncExec(new Runnable() { + 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); + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/AChart.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/AChart.java new file mode 100644 index 0000000000..ba04aae690 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/AChart.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.graphs; + +import java.util.LinkedList; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.IGraphColorConstants; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.adapters.IAdapter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.widgets.GraphCanvas; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.widgets.GraphComposite; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.widgets.GraphLabel; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.widgets.GraphLegend; +import org.eclipse.linuxtools.systemtap.ui.structures.listeners.IUpdateListener; +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, IUpdateListener { + 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); + parent.addCheckOption(Localization.getString("AChart.Legend"), legendListener); + } + + 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); + } + + public void dispose() { + this.removePaintListener(paintListener); + parent.removeCheckOption(Localization.getString("AChart.Title")); + parent.removeCheckOption(Localization.getString("AChart.Legend")); + + 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() { + public void paintControl(PaintEvent e) { + paintAll(e.gc); + } + }; + + private SelectionListener titleListener = new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) {} + public void widgetSelected(SelectionEvent e) { + showTitle = ((Button)e.getSource()).getSelection(); + repaint(); + } + }; + + private SelectionListener legendListener = new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) {} + public void widgetSelected(SelectionEvent e) { + showLegend = ((Button)e.getSource()).getSelection(); + repaint(); + } + }; + + public abstract boolean isMultiGraph(); + public abstract void handleUpdateEvent(); + public abstract void paintElementList(GC gc); + + protected GraphComposite parent; + protected GraphLegend legend; + protected GraphLabel title; + @SuppressWarnings("unchecked") + protected LinkedList[] elementList; + + public boolean showTitle, showLegend; + + private IAdapter adapter; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/AGraph.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/AGraph.java new file mode 100644 index 0000000000..dbf2519d47 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/AGraph.java @@ -0,0 +1,241 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.graphs; + +import java.util.LinkedList; + +import org.eclipse.core.runtime.Preferences.IPropertyChangeListener; +import org.eclipse.core.runtime.Preferences.PropertyChangeEvent; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.IGraphColorConstants; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.adapters.IAdapter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.DataPoint; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.GraphingAPIUIPlugin; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.preferences.GraphingAPIPreferenceConstants; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.widgets.GraphAxis; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.widgets.GraphAxis2; +import org.eclipse.linuxtools.systemtap.ui.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 implements IGraph { + 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); + createAxis(Localization.getString("AGraph.yAxis"), ySeriesTicks, GraphAxis.VERTICAL); + + GraphingAPIUIPlugin.getDefault().getPluginPreferences().addPropertyChangeListener(propertyChangeListener); + + parent.addCheckOption(Localization.getString("AGraph.GridLines"), gridListener); + if(adapter.getSeriesCount() > 1) + parent.addCheckOption(Localization.getString("AGraph.Normalize"), normalizeListener); + } + + 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; + + //System.out.println("defaults:" + minX + " " + minY + " " + maxX + " " + maxY); + + 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; + } + } + + //This is to attempt to keep the data series a constant width apart + //if(uBound < viewableItems && adapter instanceof ScrollAdapter) + //minX = maxX - (int)(((maxX-minX)/(uBound-1.0))*(viewableItems-1)); + + + return new Rectangle(minX, minY, maxX-minX, maxY-minY); + } + + private synchronized void rebound() { + getDisplay().syncExec(new Runnable() { + boolean stop = false; + public void run() { + if(stop) return; + try { + setGlobalArea(getArea(maxItems)); + setLocalArea(getArea(viewableItems)); + } catch (Exception e) { + stop = true; + } + } + }); + } + + 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, + 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(); + } + } + + protected void paintAll(GC gc) { + for(int i = 0; i < axes.size(); i++) + ((GraphAxis)axes.get(i)).paint(gc); + super.paintAll(gc); + } + + public void dispose() { + GraphingAPIUIPlugin.getDefault().getPluginPreferences().removePropertyChangeListener(propertyChangeListener); + + parent.removeCheckOption(Localization.getString("AGraph.Normalize")); + parent.removeCheckOption(Localization.getString("AGraph.GridLines")); + + 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() { + 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); + GraphAxis a; + for(int i=0; i<axes.size(); i++) { + a = ((GraphAxis)axes.get(i)); + 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); + GraphAxis a; + for(int i=0; i<axes.size(); i++) { + a = ((GraphAxis)axes.get(i)); + if(GraphAxis.VERTICAL == a.getType()) + a.setTickCount(ySeriesTicks); + } + } else if(event.getProperty().equals(GraphingAPIPreferenceConstants.P_SHOW_GRID_LINES)) + showGrid = store.getBoolean(GraphingAPIPreferenceConstants.P_SHOW_GRID_LINES); + + repaint(); + } + }; + + private SelectionListener gridListener = new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) {} + public void widgetSelected(SelectionEvent e) { + showGrid = ((Button)e.getSource()).getSelection(); + repaint(); + } + }; + + private SelectionListener normalizeListener = new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) {} + public void widgetSelected(SelectionEvent e) { + normalize = ((Button)e.getSource()).getSelection(); + if(!normalize) removeSeriesAxis(); + handleUpdateEvent(); + } + }; + + protected LinkedList<GraphAxis> axes; + + private IAdapter adapter; + + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/BarGraph.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/BarGraph.java new file mode 100644 index 0000000000..8a8358717a --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/BarGraph.java @@ -0,0 +1,140 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.graphs; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.IGraphColorConstants; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.adapters.BlockAdapter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.adapters.IAdapter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.DataPoint; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.NumberType; +import org.eclipse.linuxtools.systemtap.ui.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 + */ + @SuppressWarnings("unchecked") + 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 = (DataPoint[])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(int i=0; i<points.length; i++) { + px = super.getLocation().x + (((points[i].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() - points[i].y) * ySize) + super.getYPadding()-py; + //System.out.println("rectangle area:" + j + " " + px + " " + pw + " " + py + " " + ph + " " + points[i].x + " " + points[i].y ); + gc.fillGradientRectangle((int)(px), (int)py, (int)pw, (int)ph, true); + } + } + + gc.setForeground(temp); + gc.setBackground(temp1); + } + + 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. + */ + public void handleUpdateEvent() { + if(null == adapter) return; + + this.getDisplay().syncExec(new Runnable() { + @SuppressWarnings("unchecked") + 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.ui.graphingapi.ui.graphs.bargraph"; + private static final double WIDTH_PERCENT = 0.8; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/IBlockGraph.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/IBlockGraph.java new file mode 100644 index 0000000000..50b4f7d209 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/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.ui.graphingapi.ui.graphs; + +public interface IBlockGraph extends IGraph { + +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/IGraph.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/IGraph.java new file mode 100644 index 0000000000..7de3c6ad70 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/IGraph.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.graphs; + +import org.eclipse.linuxtools.systemtap.ui.structures.listeners.IUpdateListener; +import org.eclipse.swt.graphics.Color; + + + +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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/IScrollGraph.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/IScrollGraph.java new file mode 100644 index 0000000000..00b30a3e38 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/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.ui.graphingapi.ui.graphs; + +public interface IScrollGraph extends IGraph { + +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/LineGraph.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/LineGraph.java new file mode 100644 index 0000000000..247fc7f13d --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/LineGraph.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.graphs; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.IGraphColorConstants; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.adapters.ScrollAdapter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.DataPoint; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.NumberType; +import org.eclipse.linuxtools.systemtap.ui.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(); + } + + @SuppressWarnings("unchecked") + 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 = (DataPoint[])elementList[j].toArray(points); + c = new Color(getDisplay(), IGraphColorConstants.COLORS[j]); + gc.setForeground(c); + + px2 = 0; + py2 = super.getSize().y - super.getYPadding(); + for(int i=0; i<points.length; i++) { + px = (points[i].x-super.getLocalXMin()); + px *= xSize; + px += super.getXPadding(); + + py = super.getLocalYMax() - points[i].y; + py *= ySize; + py += super.getYPadding(); + + gc.drawLine((int)px, (int)py, (int)px2, (int)py2); + px2 = px; + py2 = py; + } + } + + gc.setForeground(temp); + } + + 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. + */ + public void handleUpdateEvent() { + if(null == adapter) return; + + this.getDisplay().syncExec(new Runnable() { + @SuppressWarnings("unchecked") + 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.ui.graphingapi.ui.graphs.linegraph"; +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/PieChart.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/PieChart.java new file mode 100644 index 0000000000..866c660dee --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/PieChart.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.ui.graphingapi.ui.graphs; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.IGraphColorConstants; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.adapters.BlockAdapter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.NumberType; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.widgets.GraphComposite; +import org.eclipse.linuxtools.systemtap.ui.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); + } + + @SuppressWarnings("unchecked") + 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 = (Number[])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); + } + + public boolean isMultiGraph() { + return false; + } + + public void handleUpdateEvent() { + if(null == adapter) return; + + this.getDisplay().syncExec(new Runnable() { + @SuppressWarnings("unchecked") + 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.ui.graphingapi.ui.graphs.piechart"; + private BlockAdapter adapter; + private double sum; + private static final int MAX_ANGLE = 360; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/ScatterGraph.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/ScatterGraph.java new file mode 100644 index 0000000000..d91c400b1b --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/graphs/ScatterGraph.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.graphs; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.IGraphColorConstants; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.adapters.ScrollAdapter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.DataPoint; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.NumberType; +import org.eclipse.linuxtools.systemtap.ui.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(); + } + + @SuppressWarnings("unchecked") + 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 = (DataPoint[])elementList[j].toArray(points); + + c = new Color(getDisplay(), IGraphColorConstants.COLORS[j]); + gc.setForeground(c); + gc.setBackground(c); + + for(int i=0; i<points.length; i++) { + px = (points[i].x-super.getLocalXMin()); + px *= xSize; + px += super.getXPadding() - (DIAMETER>>1); + + py = super.getLocalYMax() - points[i].y; + py *= ySize; + py += super.getYPadding() - (DIAMETER>>1); + + gc.fillOval((int)px, (int)py, DIAMETER, DIAMETER); + } + } + + gc.setForeground(temp); + gc.setBackground(temp1); + } + + 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. + */ + public void handleUpdateEvent() { + if(null == adapter) return; + + this.getDisplay().syncExec(new Runnable() { + @SuppressWarnings("unchecked") + 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.ui.graphingapi.ui.graphs.scattergraph"; + private static final int DIAMETER = 5; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/internal/GraphingAPIUIPlugin.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/internal/GraphingAPIUIPlugin.java new file mode 100644 index 0000000000..55ac08ed41 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/internal/GraphingAPIUIPlugin.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.internal; + +import org.eclipse.ui.plugin.*; +import org.eclipse.jface.resource.ImageDescriptor; +import org.osgi.framework.BundleContext; + +/** + * The main plugin class to be used in the desktop. + */ +public class GraphingAPIUIPlugin extends AbstractUIPlugin { + + //The shared instance. + private static GraphingAPIUIPlugin plugin; + + /** + * The constructor. + */ + public GraphingAPIUIPlugin() { + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + } + + /** + * This method is called when the plug-in is stopped + */ + 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("org.eclipse.linuxtools.systemtap.ui.graphingapi.ui", path); + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/internal/Localization.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/internal/Localization.java new file mode 100644 index 0000000000..70eea68919 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/internal/Localization.java @@ -0,0 +1,21 @@ +package org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class Localization { + private static final String BUNDLE_NAME = "org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.localization"; + + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/internal/localization.properties b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/internal/localization.properties new file mode 100644 index 0000000000..aef74faf23 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/internal/localization.properties @@ -0,0 +1,142 @@ +#DataDisplay +DataGrid.Row=Row +DataGrid.FormatAs=Format as... +DataGrid.AddFilter=Add filter... +DataGrid.RemoveFilter=Remove filter... +DataGrid.ManualyResize=Manualy 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.ShowGridLines=&Show 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.LineGraph=Line Graph +GraphFactory.LineDescription=This is a simple line graph of a single set of data. Each (x,y) pair will be pltted 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.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. + +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
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/preferences/DataTablePreferencePage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/preferences/DataTablePreferencePage.java new file mode 100644 index 0000000000..da84a634cc --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/preferences/DataTablePreferencePage.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * 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.ui.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.systemtap.ui.graphingapi.ui.internal.GraphingAPIUIPlugin; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +import org.eclipse.linuxtools.systemtap.ui.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")); + } + + public void createFieldEditors() { + addField(new BooleanFieldEditor( + GraphingAPIPreferenceConstants.P_JUMP_NEW_TABLE_ENTRY, + Localization.getString("DataTablePreferencePage.JumpNewestEntry"), + getFieldEditorParent())); + + addField(new BooleanFieldEditor( + GraphingAPIPreferenceConstants.P_AUTO_RESIZE, + Localization.getString("DataTablePreferencePage.AutoResizeColumns"), + getFieldEditorParent())); + + addField( + new IntegerFieldEditor( + GraphingAPIPreferenceConstants.P_MAX_DATA_ITEMS, + Localization.getString("DataTablePreferencePage.MaxDataItems"), + getFieldEditorParent())); + } + + public void init(IWorkbench workbench) {} + + public void dispose() { + super.dispose(); + } +} + diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/preferences/GraphPreferencePage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/preferences/GraphPreferencePage.java new file mode 100644 index 0000000000..e4d4f1962d --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/preferences/GraphPreferencePage.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * 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.ui.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.systemtap.ui.graphingapi.ui.internal.GraphingAPIUIPlugin; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +import org.eclipse.linuxtools.systemtap.ui.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")); + } + + public void createFieldEditors() { + addField(new BooleanFieldEditor( + GraphingAPIPreferenceConstants.P_SHOW_GRID_LINES, + Localization.getString("GraphPreferencePage.ShowGridLines"), + getFieldEditorParent())); + + addField( + new IntegerFieldEditor( + GraphingAPIPreferenceConstants.P_MAX_DATA_ITEMS, + Localization.getString("GraphPreferencePage.MaxDataItems"), + getFieldEditorParent())); + + addField( + new IntegerFieldEditor( + GraphingAPIPreferenceConstants.P_VIEWABLE_DATA_ITEMS, + Localization.getString("GraphPreferencePage.ViewableDataItems"), + getFieldEditorParent())); + + addField( + new IntegerFieldEditor( + GraphingAPIPreferenceConstants.P_X_SERIES_TICKS, + Localization.getString("GraphPreferencePage.XSeriesTicks"), + getFieldEditorParent())); + + addField( + new IntegerFieldEditor( + GraphingAPIPreferenceConstants.P_Y_SERIES_TICKS, + Localization.getString("GraphPreferencePage.YSeriesTicks"), + getFieldEditorParent())); + } + + public void init(IWorkbench workbench) {} + + public void dispose() { + super.dispose(); + } +} + diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/preferences/GraphingAPIPreferenceConstants.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/preferences/GraphingAPIPreferenceConstants.java new file mode 100644 index 0000000000..0f7af298ae --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/preferences/GraphingAPIPreferenceConstants.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.preferences; + +public class GraphingAPIPreferenceConstants { + //graphing.datatable + public static final String P_JUMP_NEW_TABLE_ENTRY = "JumpNewTableEntry"; + public static final String P_AUTO_RESIZE = "AutoResizeColumns"; + + //graphing.graph + public static final String P_SHOW_GRID_LINES = "ShowGridLines"; + public static final String P_MAX_DATA_ITEMS = "MaxDataItems"; + public static final String P_VIEWABLE_DATA_ITEMS = "ViewableDataItems"; + public static final String P_X_SERIES_TICKS = "XSeriesTicks"; + public static final String P_Y_SERIES_TICKS = "YSeriesTicks"; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/preferences/GraphingAPIPreferencePage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/preferences/GraphingAPIPreferencePage.java new file mode 100644 index 0000000000..c162c5b5fe --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/preferences/GraphingAPIPreferencePage.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.preferences; + +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.GraphingAPIUIPlugin; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + + + +public class GraphingAPIPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + public GraphingAPIPreferencePage() { + super(GRID); + setPreferenceStore(GraphingAPIUIPlugin.getDefault().getPreferenceStore()); + setDescription(Localization.getString("GraphingAPIPreferencePage.GraphDisplayPreferences")); + } + + public void createFieldEditors() { + } + + public void init(IWorkbench workbench) {} + + public void dispose() { + super.dispose(); + } +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/preferences/PreferenceInitializer.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/preferences/PreferenceInitializer.java new file mode 100644 index 0000000000..5b3f025a4a --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/preferences/PreferenceInitializer.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.preferences; + +import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.GraphingAPIUIPlugin; + + + +public class PreferenceInitializer extends AbstractPreferenceInitializer { + public void initializeDefaultPreferences() { + IPreferenceStore store = GraphingAPIUIPlugin.getDefault().getPreferenceStore(); + + store.setDefault(GraphingAPIPreferenceConstants.P_SHOW_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, 8); + store.setDefault(GraphingAPIPreferenceConstants.P_Y_SERIES_TICKS, 4); + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/GraphAxis.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/GraphAxis.java new file mode 100644 index 0000000000..9714b789e4 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/GraphAxis.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.ui.graphingapi.ui.widgets; + +import java.text.DecimalFormat; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.graphs.AGraph; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +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; + } + + public boolean isVisible() { + return true; + } + + /** + * Determines if the given point is inside this axis' bounds. + */ + 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; + } + + 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"; + range /= tickCount; + while(val > 1000) { + val /= 1000; + metric++; + + range /= 10; + if(range < 1) + pattern += "0"; + } + + DecimalFormat format = new DecimalFormat(pattern); + return format.format(val) + PREFIXES[metric]; + } + + 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") } ; + + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/GraphAxis2.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/GraphAxis2.java new file mode 100644 index 0000000000..07233ecb5a --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/GraphAxis2.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.ui.graphingapi.ui.widgets; + +import org.eclipse.linuxtools.systemtap.ui.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 implements IGraphPrimitive { + public GraphAxis2(AGraph graph, String title, int tickCount, int type, Color color) { + super(graph, title, tickCount, type&1); + this.type = type; + this.color = color; + } + + 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; + } + } + + 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); + } + + protected void drawTick(GC gc, int x, int y, String val) { + if(HIDE_TICKS != (HIDE_TICKS&type)) + super.drawTick(gc, x, y, val); + } + + protected void drawTitle(GC gc) { + if(HIDE_TITLE != (HIDE_TITLE&type)) + super.drawTitle(gc); + } + /*TODO: This should be reimplemented for viewing true values when normalized + protected String getLabel(double val, int range) { + if(UNNORMALIZED == (UNNORMALIZED&type)) + val = graph.unscaleValue(val); + + return super.getLabel(val, range); + } + */ + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/GraphCanvas.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/GraphCanvas.java new file mode 100644 index 0000000000..b7ffcd0edf --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/GraphCanvas.java @@ -0,0 +1,256 @@ +/******************************************************************************* + * 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.ui.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.ui.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 () { + 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 () { + 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 both the X and Y padding widths simultaneously. + * @param xpad X padding width. + * @param ypad Y padding width. + */ + public void setPadding(int xpad, int ypad) { + setXPadding(xpad); + setYPadding(ypad); + } + /** + * 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() { + boolean stop = false; + public void run() { + if(stop) return; + try { + redraw(); + } catch (Exception e) { + stop = true; + } + } + }); + } + + /** + * Returns the size of the graphing area of the canvas. + */ + 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; + } + + /** + * Returns the actual bounding area of the canvas, including the width of the scroll bars. + */ + public Point getTrueSize() { + return super.getSize(); + } + + /** + * Sets the scaling value for the canvas. This causes graph primitive sizes to change. + * The default scaling value is 1.0, and the larger the scaling value, the larger the graph area's + * numerical bounds are. For example, if the graph was set from 0 < x < 10, and the scaling value + * is reset to 2.0, the new X range is from 0 < x < 20. + * @param s The new scaling value. + */ + public void setScale(double s) { + scale = s; + setLocalArea(localArea, true); + + redraw(); + } + + /** + * 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 getGlobalWidth() { + return globalArea.width; + } + + public int getLocalWidth() { + return (int)(localArea.width / scale); + } + + public int getGlobalHeight() { + return globalArea.height; + } + + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/GraphComposite.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/GraphComposite.java new file mode 100644 index 0000000000..f4d74e1217 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/GraphComposite.java @@ -0,0 +1,210 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.widgets; + +import java.util.ArrayList; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.GraphData; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.graphs.IGraph; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.wizards.graph.GraphFactory; +import org.eclipse.swt.SWT; +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.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.CENTER); + scale = scales[7]; + label.setText(scale + Localization.getString("GraphComposite.ScaleValue")); + FormData data = new FormData(); + data.top = new FormAttachment(0,0); + data.right = new FormAttachment(100, 0); + data.width = 40; + label.setLayoutData(data); + + zoomScale = new Scale(this,SWT.VERTICAL | SWT.BORDER); + zoomScale.setMinimum(0); + zoomScale.setMaximum(14); + zoomScale.setIncrement(1); + zoomScale.setPageIncrement(1); + zoomScale.setSelection(7); + data = new FormData(); + data.top = new FormAttachment(label, 10); + data.bottom = new FormAttachment(100, 5); + data.right = new FormAttachment(100,-10); + zoomScale.setLayoutData(data); + + graph = GraphFactory.createGraph(this, gd, ds); + data = new FormData(); + data.top = new FormAttachment(0,0); + data.bottom = new FormAttachment(100,0); + data.right = new FormAttachment(label,-10); + data.left = new FormAttachment(0,0); + graph.setLayoutData(data); + + graph.setBackground(this.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + graph.setForeground(this.getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND)); + this.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); + zoomScale.addSelectionListener(scaleListener); + } + + /** + * Toggles sidebar visible or not visible. + * @param withSidebar Enables or disables the sidebar. + */ + public void configure(boolean withSidebar) { + sidebarVisible = withSidebar; + + for(int i=0; i<checkOptions.size(); i++) + ((Button)checkOptions.get(i)).setVisible(sidebarVisible); + + zoomScale.setVisible(sidebarVisible); + label.setVisible(sidebarVisible); + + FormData data = new FormData(); + data.top = new FormAttachment(0,0); + data.bottom = new FormAttachment(100,0); + data.left = new FormAttachment(0,0); + data.right = (withSidebar ? new FormAttachment(label,-10) : new FormAttachment(100, 0)); + graph.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 = (Button)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) { + Button b; + for(int i=0; i<checkOptions.size(); i++) { + b = (Button)checkOptions.get(i); + 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 IGraph getGraph() { + return graph; + } + + /** + * 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. + */ + public void dispose() { + scaleListener = null; + + if(null != graph) graph.dispose(); + graph = 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 SelectionListener() { + public void widgetSelected(SelectionEvent e) { + Scale scaler = (Scale) e.widget; + int index = scaler.getSelection(); + if(scale != scales[index]) { + scale = scales[index]; + label.setText(scale + Localization.getString("GraphComposite.ScaleValue")); + graph.setScale(scale); + } + } + + public void widgetDefaultSelected(SelectionEvent e) {} + }; + + private boolean sidebarVisible = true; + private IGraph graph; + 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 ArrayList<Button> checkOptions; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/GraphLabel.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/GraphLabel.java new file mode 100644 index 0000000000..6d20382ac8 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/GraphLabel.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * 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.ui.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; + } + + 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); + } + } + + public boolean isVisible() { + return true; + } + + public boolean isUnder(Point loc) { + if(loc.x >= x && loc.y >= y && loc.x <= x+width && loc.y <=y+height) + return true; + return false; + } + + public void paint(GC gc) { + if(staticSize) + gc.setFont(new Font(canvas.getDisplay(), "Times", (int)size, style)); + else + gc.setFont(new Font(canvas.getDisplay(), "Times", (int)(canvas.getSize().y * size), style)); + + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/GraphLegend.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/GraphLegend.java new file mode 100644 index 0000000000..178b169d4e --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/GraphLegend.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.ui.graphingapi.ui.widgets; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.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 = colorsPassed; + keys = keysPassed; + bounds = new Rectangle[keys.length]; + + width = 0; + height = 0; + } + + public boolean isVisible() { + return true; + } + + 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; + } + + public boolean isUnder(Point loc) { + if(loc.x >=x && loc.y >= y && loc.x <= x+width && loc.y <= y+height) + return true; + return false; + } + + 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"); +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/IGraphPrimitive.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/widgets/IGraphPrimitive.java new file mode 100644 index 0000000000..64b950004d --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/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.ui.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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/dataset/DataSetFactory.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/dataset/DataSetFactory.java new file mode 100644 index 0000000000..c98213c927 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/dataset/DataSetFactory.java @@ -0,0 +1,146 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.wizards.dataset; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IDataSetParser; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IFilteredDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.row.FilteredRowDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.row.RowDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.row.RowParser; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.table.FilteredTableDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.table.TableDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.table.TableParser; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.datadisplay.DataGrid; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +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, (RowDataSet)set, DataGrid.NONE); + else if(set instanceof TableDataSet) + return new DataGrid(composite, (TableDataSet)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"), + Localization.getString("DataSetFactory.TableDataSet") + }; + + private static final String[] descriptions = { + Localization.getString("DataSetFactory.RowDataSetDescription") + + Localization.getString("DataSetFactory.DataSetExample") + + Localization.getString("DataSetFactory.DataSetHeader") + + "1305 2309 4233\n" + + "2322 3234 4223\n" + + "2321 3123 4533\n" + + "2343 2931 4423\n" + + "1356 2984 3850\n", + + Localization.getString("DataSetFactory.TableDataSetDescription") + + Localization.getString("DataSetFactory.DataSetExample") + + Localization.getString("DataSetFactory.DataSetHeader") + + "2322 3232 3453\n" + + "2321 3123 4533\n" + + "2145 2135 5921\n" + + "-------------------\n" + + Localization.getString("DataSetFactory.DataSetHeader") + + "2343 2931 4423\n" + + "2234 2723 5233\n" + + "3215 3565 4922\n" + + "-------------------\n" + }; + + private static final ParsingWizardPage[] dataSetWizards = new ParsingWizardPage[] { + new SelectRowParsingWizardPage(), + new SelectTableParsingWizardPage() + }; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/dataset/DataSetWizard.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/dataset/DataSetWizard.java new file mode 100644 index 0000000000..c667b11219 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/dataset/DataSetWizard.java @@ -0,0 +1,191 @@ +/******************************************************************************* + * 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.ui.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.systemtap.ui.graphingapi.nonui.datasets.IDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IDataSetParser; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +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; + } + + public void init(IWorkbench workbench, IStructuredSelection selection) {} + + public void addPages() { + setWindowTitle(Localization.getString("DataSetWizard.CreateDataSet")); + 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); + } + + public boolean canFinish() { + IWizardPage page = this.getContainer().getCurrentPage(); + if((null != dataSet) && (null != parser) && (page instanceof ParsingWizardPage)) + return true; + return false; + } + + public boolean performCancel() { + parser = null; + dataSet = null; + return true; + } + + 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(Exception e) { + return false; + } + + return true; + } + + protected XMLMemento copyExisting() { + XMLMemento data = null; + try { + FileReader reader = new FileReader(metaFile); + if(!reader.ready()) + 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(int i=0; i<columns.length; i++) { + child = target.createChild(IDataSetParser.XMLColumn); + child.putString(IDataSetParser.XMLname, columns[i]); + } + return true; + } + + protected boolean openFile() { + try { + if (!metaFile.exists()) + metaFile.createNewFile(); + } catch(IOException ioe) { + return false; + } + + return true; + } + + 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() { + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/dataset/ParsingWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/dataset/ParsingWizardPage.java new file mode 100644 index 0000000000..8c8a8e3da3 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/dataset/ParsingWizardPage.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.ui.graphingapi.ui.wizards.dataset; + +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.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); + } + + 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")); + lblSeries.setBounds(0, 5, 120, 25); + + txtSeries = new Text(parent, SWT.BORDER); + txtSeries.setBounds(125, 0, 100, 25); + txtSeries.setText("2"); //$NON-NLS-1$ + txtSeries.setTextLimit(2); + txtSeries.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + if(!"".equals(txtSeries.getText().trim())) { + displayTextBoxes(); + refreshRegEx(); + } + } + }); + txtSeries.addKeyListener(new KeyListener() { + public void keyPressed(KeyEvent e) { + if(('0' > e.character || '9' < e.character) && 31 < e.character && 127 > e.character) + e.doit = false; + } + + public void keyReleased(KeyEvent e) {} + }); + + + Label lblRegExTitle = new Label(parent, SWT.NONE); + lblRegExTitle.setText(Localization.getString("ParsingWizardPage.RegularExpression")); + 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")); + lblTitle.setBounds(0, 45, 150, 25); + Label lblExpr = new Label(parent, SWT.NONE); + lblExpr.setText(Localization.getString("ParsingWizardPage.RegularExpression")); + lblExpr.setBounds(160, 45, 150, 25); + Label lblSpace = new Label(parent, SWT.NONE); + lblSpace.setText(Localization.getString("ParsingWizardPage.Delimiter")); + 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+"); + else if(1 == i%COLUMNS) + txtRegExpr[i].setText("\\d+"); + } + + 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); + 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()); + } + + public boolean canFlipToNextPage() { + return false; + } + + 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())) { + 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 { + public void modifyText(ModifyEvent e) { + checkComplete(); + wizard.getContainer().updateButtons(); + } + } + + private class RegExModifyListener extends TextModifyListener { + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/dataset/SelectDataSetWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/dataset/SelectDataSetWizardPage.java new file mode 100644 index 0000000000..4cb8e712ef --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/dataset/SelectDataSetWizardPage.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.wizards.dataset; + +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +import org.eclipse.swt.SWT; +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.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.forms.widgets.ColumnLayout; + + + +public class SelectDataSetWizardPage extends WizardPage { + public SelectDataSetWizardPage() { + super("selectDataSetType"); + setTitle(Localization.getString("SelectDataSetWizardPage.SelectDataSetType")); + dataSetID = ""; + btnDataSets = null; + } + + public void createControl(Composite parent) { + wizard = (DataSetWizard)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); + + String[] ids = DataSetFactory.getIDs(); + btnDataSets = new Button[ids.length]; + for(int i=0; i<btnDataSets.length; i++) { + btnDataSets[i] = new Button(cmpFilterOpts, SWT.NONE); + btnDataSets[i].setText(DataSetFactory.getName(ids[i])); + btnDataSets[i].addSelectionListener(buttonListener); + btnDataSets[i].setData(ids[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); + } + + public boolean canFlipToNextPage() { + return (dataSetID.length() > 0); + } + + public IWizardPage getNextPage() { + return DataSetFactory.getParsingWizardPage(dataSetID); + } + + 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; + lblDesc = null; + } + + private SelectionListener buttonListener = new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) {} + + public void widgetSelected(SelectionEvent e) { + if(e.widget instanceof Button) { + Button target = (Button)e.widget; + + for(int i=0; i<btnDataSets.length; i++) { + if(target == btnDataSets[i]) { + dataSetID = btnDataSets[i].getData().toString(); + lblDesc.setText(DataSetFactory.getName(dataSetID) + "\n\n" + + DataSetFactory.getDescription(dataSetID)); + wizard.getContainer().updateButtons(); + } + } + } + } + }; + + private Button[] btnDataSets; + private Label lblDesc; + private String dataSetID; + private DataSetWizard wizard; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/dataset/SelectRowParsingWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/dataset/SelectRowParsingWizardPage.java new file mode 100644 index 0000000000..4db4b481c5 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/dataset/SelectRowParsingWizardPage.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * 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.ui.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.systemtap.ui.graphingapi.nonui.datasets.IDataSetParser; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.row.RowDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.row.RowParser; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +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"); + setTitle(Localization.getString("SelectRowParsingWizardPage.SelectRowDataSetParsing")); + } + + public void createControl(Composite parent) { + super.createControl(parent); + + Composite comp = new Composite(parent, SWT.NONE); + createColumnSelector(comp); + + setControl(comp); + } + + protected boolean readParsingExpression() { + if(null == wizard.metaFile && !wizard.openFile()) + return false; + + try { + FileReader reader = new FileReader(wizard.metaFile); + + if(!reader.ready()) + 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); + 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); + 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; + } + + protected void copyExisting(IMemento oldMeta, IMemento newMeta) { + IMemento[] children = oldMeta.getChildren(IDataSetParser.XMLColumn); + IMemento child; + for(int j=0; j<children.length; j++) { + child = newMeta.createChild(IDataSetParser.XMLColumn); + child.putString(IDataSetParser.XMLname, children[j].getString(IDataSetParser.XMLname)); + } + children = oldMeta.getChildren(IDataSetParser.XMLSeries); + for(int j=0; j<children.length; j++) { + child = newMeta.createChild(IDataSetParser.XMLSeries); + child.putString(IDataSetParser.XMLparsingExpression, children[j].getString(IDataSetParser.XMLparsingExpression)); + child.putString(IDataSetParser.XMLparsingSpacer, children[j].getString(IDataSetParser.XMLparsingSpacer)); + } + } + + 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; + } + + public void dispose() { + super.dispose(); + } +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/dataset/SelectTableParsingWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/dataset/SelectTableParsingWizardPage.java new file mode 100644 index 0000000000..d2270c2650 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/dataset/SelectTableParsingWizardPage.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * 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.ui.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.systemtap.ui.graphingapi.nonui.datasets.IDataSetParser; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.table.TableDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.table.TableParser; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +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"); + setTitle(Localization.getString("SelectTableParsingWizardPage.SelectTableDataSetParsing")); + } + + 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")); + 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); + } + + protected boolean readParsingExpression() { + if(null == wizard.metaFile && !wizard.openFile()) + return false; + + try { + FileReader reader = new FileReader(wizard.metaFile); + + if(!reader.ready()) + 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(TableDataSet.ID)) + return false; + + IMemento[] children2 = children[i].getChildren(IDataSetParser.XMLColumn); + txtSeries.setText("" + children2.length); + 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); + 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; + } + + protected void copyExisting(IMemento oldMeta, IMemento newMeta) { + IMemento[] children = oldMeta.getChildren(IDataSetParser.XMLColumn); + IMemento child; + for(int j=0; j<children.length; j++) { + child = newMeta.createChild(IDataSetParser.XMLColumn); + child.putString(IDataSetParser.XMLname, children[j].getString(IDataSetParser.XMLname)); + } + children = oldMeta.getChildren(IDataSetParser.XMLSeries); + for(int j=0; j<children.length; j++) { + child = newMeta.createChild(IDataSetParser.XMLSeries); + child.putString(IDataSetParser.XMLparsingExpression, children[j].getString(IDataSetParser.XMLparsingExpression)); + child.putString(IDataSetParser.XMLparsingSpacer, children[j].getString(IDataSetParser.XMLparsingSpacer)); + } + newMeta.createChild(IDataSetParser.XMLDelimiter).putString(IDataSetParser.XMLparsingExpression, oldMeta.getChild(IDataSetParser.XMLDelimiter).getString(IDataSetParser.XMLparsingExpression)); + } + + 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; + } + + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/AggregateFactory.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/AggregateFactory.java new file mode 100644 index 0000000000..687dc2a56e --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/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.ui.graphingapi.ui.wizards.filter; + + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.aggregates.AverageAggregate; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.aggregates.CountAggregate; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.aggregates.IDataAggregate; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.aggregates.MaxAggregate; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.aggregates.MinAggregate; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.aggregates.SumAggregate; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; + + + +public final class AggregateFactory { + private static final String[] aggregateNames = new String[] { + Localization.getString("AggregateFactory.AverageAggregate"), + Localization.getString("AggregateFactory.CountAggregate"), + Localization.getString("AggregateFactory.MaxAggregate"), + Localization.getString("AggregateFactory.MinAggregate"), + Localization.getString("AggregateFactory.SumAggregate") + }; + + private static final String[] aggregateDescriptions = new String[] { + Localization.getString("AggregateFactory.AverageDescription"), + Localization.getString("AggregateFactory.CountDescription"), + Localization.getString("AggregateFactory.MaxDescription"), + Localization.getString("AggregateFactory.MinDescription"), + Localization.getString("AggregateFactory.SumDescription") + }; + + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/AvailableFilterTypes.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/AvailableFilterTypes.java new file mode 100644 index 0000000000..4065aaeadc --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/AvailableFilterTypes.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.wizards.filter; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.filters.IDataSetFilter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.filters.MatchFilter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.filters.RangeFilter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.filters.SortFilter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.filters.UniqueFilter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +import org.eclipse.ui.IMemento; + + + +public final class AvailableFilterTypes { + private static final String[] filterNames = new String[] { + Localization.getString("AvailableFilterTypes.MatchFilter"), + Localization.getString("AvailableFilterTypes.RangeFilter"), + Localization.getString("AvailableFilterTypes.SortFilter"), + Localization.getString("AvailableFilterTypes.UniqueFilter") + }; + + private static final String[] filterDescriptions = new String[] { + Localization.getString("AvailableFilterTypes.MatchFilterDescription"), + Localization.getString("AvailableFilterTypes.RangeFilterDescription"), + Localization.getString("AvailableFilterTypes.SortFilterDescription"), + Localization.getString("AvailableFilterTypes.UniqueFilterDescription") + }; + + 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(); + int style; + + switch(getIndex(id)) { + case 0: + String val = xml.getString("value"); + style = xml.getInteger("style").intValue(); + return new MatchFilter(column, val, style); + case 1: + style = xml.getInteger("style").intValue(); + String l = xml.getString("low"); + String h = xml.getString("high"); + + Number low, high; + if(l.contains(".")) + low = new Double(Double.parseDouble(l)); + else + low = new Long(Long.parseLong(l)); + if(h.contains(".")) + high = new Double(Double.parseDouble(h)); + else + high = new Long(Long.parseLong(h)); + + return new RangeFilter(column, low, high, style); + case 2: + style = xml.getInteger("style").intValue(); + return new SortFilter(column, style); + case 3: + String agg = xml.getString("aggregate"); + style = xml.getInteger("style").intValue(); + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/FilterWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/FilterWizardPage.java new file mode 100644 index 0000000000..0d00d49b75 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/FilterWizardPage.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * 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.ui.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.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"); + setTitle(title); + } + + public void createControl(Composite parent) { + wizard = (SelectFilterWizard)super.getWizard(); + } + + public boolean canFlipToNextPage() { + return false; + } + + abstract void createFilter(); + + public void dispose() { + wizard = null; + super.dispose(); + } + + protected final SelectionListener selectionListener = new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) {} + + public void widgetSelected(SelectionEvent e) { + createFilter(); + wizard.getContainer().updateButtons(); + } + }; + + protected final ModifyListener modifyListener = new ModifyListener() { + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/MatchFilterWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/MatchFilterWizardPage.java new file mode 100644 index 0000000000..c72abf694a --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/MatchFilterWizardPage.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.wizards.filter; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.filters.MatchFilter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +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"); + setTitle(Localization.getString("MatchFilterWizardPage.CreateMatchFilter")); + } + + 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")); + 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")); + 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")); + radKeepMatch.addSelectionListener(selectionListener); + radKeepMatch.setSelection(true); + radRemoveMatch = new Button(cmpFilterOpts, SWT.RADIO); + radRemoveMatch.setText(Localization.getString("MatchFilterWizardPage.RemoveMatching")); + radRemoveMatch.addSelectionListener(selectionListener); + + setControl(comp); + } + + public boolean canFlipToNextPage() { + return false; + } + + 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); + } + } + + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/RangeFilterWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/RangeFilterWizardPage.java new file mode 100644 index 0000000000..7bc9622a0c --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/RangeFilterWizardPage.java @@ -0,0 +1,175 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.wizards.filter; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.filters.RangeFilter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +import org.eclipse.swt.SWT; +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"); + setTitle(Localization.getString("RangeFilterWizardPage.CreateRangeFilter")); + } + + 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")); + 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")); + 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")); + 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")); + radInside.addSelectionListener(selectionListener); + radInside.setSelection(true); + radOutside = new Button(cmpFilterOpts, SWT.RADIO); + radOutside.setText(Localization.getString("RangeFilterWizardPage.OutsideBounds")); + radOutside.addSelectionListener(selectionListener); + + chkInclusive = new Button(cmpFilterOpts, SWT.CHECK); + chkInclusive.setText(Localization.getString("RangeFilterWizardPage.Inclusive")); + + setControl(comp); + } + + public boolean canFlipToNextPage() { + return false; + } + + 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) {} + } + + 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 KeyListener() { + 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(".")) + e.doit = true; + } + + public void keyReleased(KeyEvent e) {} + }; + + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/SelectFilterWizard.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/SelectFilterWizard.java new file mode 100644 index 0000000000..1419731e88 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/SelectFilterWizard.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.wizards.filter; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.filters.IDataSetFilter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +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 = series; + } + + public void init(IWorkbench workbench, IStructuredSelection selection) { + } + + public void addPages() { + setWindowTitle(Localization.getString("SelectFilterWizard.CreateFilter")); + 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]); + } + } + + public boolean canFinish() { + IWizardPage page = this.getContainer().getCurrentPage(); + if((null != filter) && (page instanceof FilterWizardPage)) + return true; + return false; + } + + public boolean performCancel() { + return true; + } + + public boolean performFinish() { + return true; + } + + public IDataSetFilter getFilter() { + return filter; + } + + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/SelectFilterWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/SelectFilterWizardPage.java new file mode 100644 index 0000000000..b2234bedd1 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/SelectFilterWizardPage.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.wizards.filter; + +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +import org.eclipse.swt.SWT; +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.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.forms.widgets.ColumnLayout; + + + +public class SelectFilterWizardPage extends WizardPage { + public SelectFilterWizardPage() { + super("selectFilter"); + setTitle(Localization.getString("SelectFilterWizardPage.SelectFilter")); + filterID = ""; + btnFilters = null; + buttonListener = new ButtonSelectionListener(); + } + + 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); + } + + public IWizardPage getNextPage() { + return AvailableFilterTypes.getFilterWizardPage(filterID); + } + + public boolean canFlipToNextPage() { + return (filterID.length() > 0); + } + + 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 implements SelectionListener { + public void widgetDefaultSelected(SelectionEvent e) {} + + 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" + + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/SortFilterWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/SortFilterWizardPage.java new file mode 100644 index 0000000000..666c7364f1 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/SortFilterWizardPage.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.ui.graphingapi.ui.wizards.filter; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.filters.SortFilter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +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"); + setTitle(Localization.getString("SortFilterWizardPage.CreateSortFilter")); + } + + 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")); + 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")); + radAscending.addSelectionListener(selectionListener); + radAscending.setSelection(true); + radDescending = new Button(cmpFilterOpts, SWT.RADIO); + radDescending.setText(Localization.getString("SortFilterWizardPage.Descending")); + radDescending.addSelectionListener(selectionListener); + + setControl(comp); + } + + public boolean canFlipToNextPage() { + return false; + } + + 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); + } + + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/UniqueFilterWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/UniqueFilterWizardPage.java new file mode 100644 index 0000000000..2fdac8eaf1 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/filter/UniqueFilterWizardPage.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.wizards.filter; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.filters.UniqueFilter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +import org.eclipse.swt.SWT; +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"); + setTitle(Localization.getString("UniqueFilterWizardPage.CreateUniqueFilter")); + aggregateID = ""; + } + + 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")); + 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 lblAggregate = new Label(cmpFilterOpts, SWT.NONE); + lblAggregate.setText(Localization.getString("UniqueFilterWizardPage.Aggregate")); + + 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); + } + + public boolean canFlipToNextPage() { + return false; + } + + 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); + } + } + + 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 SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) {} + + public void widgetSelected(SelectionEvent e) { + if(e.widget instanceof Button) { + Button target = (Button)e.widget; + + for(int i=0; i<btnAggregates.length; i++) { + if(target == btnAggregates[i]) { + lblDesc.setText(AggregateFactory.getAggregateName(btnAggregates[i].getData().toString()) + "\n\n" + + AggregateFactory.getAggregateDescription(btnAggregates[i].getData().toString())); + aggregateID = btnAggregates[i].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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/graph/GraphFactory.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/graph/GraphFactory.java new file mode 100644 index 0000000000..a61836e0ed --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/graph/GraphFactory.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.ui.graphingapi.ui.wizards.graph; + +import java.util.LinkedList; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.adapters.BlockAdapter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.adapters.ScrollAdapter; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IBlockDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IHistoricalDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.GraphData; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.graphs.BarGraph; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.graphs.IGraph; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.graphs.LineGraph; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.graphs.PieChart; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.graphs.ScatterGraph; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.GraphingAPIUIPlugin; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.widgets.GraphComposite; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; + + + +public final class GraphFactory { + private static final String[] graphNames = new String[] { + Localization.getString("GraphFactory.ScatterGraph"), + Localization.getString("GraphFactory.LineGraph"), + Localization.getString("GraphFactory.BarGraph"), + Localization.getString("GraphFactory.PieChart") + }; + + private static final String[] graphDescriptions = new String[] { + Localization.getString("GraphFactory.ScatterDescription"), + Localization.getString("GraphFactory.LineDescription"), + Localization.getString("GraphFactory.BarDescription"), + Localization.getString("GraphFactory.PieDescription") + }; + + private static final Image[] graphImages = new Image[] { + GraphingAPIUIPlugin.getImageDescriptor("icons/graphs/ScatterGraph.gif").createImage(), + GraphingAPIUIPlugin.getImageDescriptor("icons/graphs/LineGraph.gif").createImage(), + GraphingAPIUIPlugin.getImageDescriptor("icons/graphs/BarGraph.gif").createImage(), + GraphingAPIUIPlugin.getImageDescriptor("icons/graphs/PieChart.gif").createImage() + }; + + private static final String[] graphIDs = new String[] { + ScatterGraph.ID, + LineGraph.ID, + BarGraph.ID, + PieChart.ID + }; + + public static String[] getAvailableGraphs(IDataSet data) { + LinkedList<String> ids = new LinkedList<String>(); + if(data instanceof IHistoricalDataSet) { + ids.add(ScatterGraph.ID); + ids.add(LineGraph.ID); + ids.add(BarGraph.ID); + } + if(data instanceof IBlockDataSet) { + if(!ids.contains(BarGraph.ID)) + ids.add(BarGraph.ID); + ids.add(PieChart.ID); + } + + String[] id = new String[0]; + return (String[])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 IGraph createGraph(GraphComposite comp, GraphData gd, IDataSet data) { + IGraph g = null; + switch(getIndex(gd.graphID)) { + case 0: + g = new ScatterGraph(comp, SWT.NONE, gd.title, new ScrollAdapter((IHistoricalDataSet)data, gd.xSeries, gd.ySeries, gd.key)); + break; + case 1: + g = new LineGraph(comp, SWT.NONE, gd.title, new ScrollAdapter((IHistoricalDataSet)data, gd.xSeries, gd.ySeries, gd.key)); + break; + case 2: + if(!(data instanceof IBlockDataSet) || (null != gd.key)) + g = new BarGraph(comp, SWT.NONE, gd.title, new ScrollAdapter((IHistoricalDataSet)data, gd.xSeries, gd.ySeries, gd.key)); + else + g = new BarGraph(comp, SWT.NONE, gd.title, new BlockAdapter((IBlockDataSet)data, gd.xSeries, gd.ySeries)); + break; + case 3: + g = new PieChart(comp, SWT.NONE, gd.title, new BlockAdapter((IBlockDataSet)data, gd.xSeries, gd.ySeries)); + break; + } + return g; + } + + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/graph/GraphModel.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/graph/GraphModel.java new file mode 100644 index 0000000000..2fd002ca39 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/graph/GraphModel.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.wizards.graph; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.GraphData; + +public class GraphModel { + public GraphModel(IDataSet d) { + graph = new GraphData(); + graph.graphID = ""; + graph.title = ""; + 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 = y; + } + + public boolean isGraphSet() { + return ("" != graph.graphID); + } + + public boolean isSeriesSet() { + return ((-1 <= graph.xSeries) && (null != graph.ySeries) && graph.ySeries.length > 0); + } + + public boolean isTitleSet() { + return !("".equals(graph.title)); + } + + private GraphData graph; + private IDataSet data; +} diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/graph/SelectGraphWizard.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/graph/SelectGraphWizard.java new file mode 100644 index 0000000000..c12861f363 --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/graph/SelectGraphWizard.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.wizards.graph; + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.datasets.IDataSet; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.GraphData; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +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); + } + + public void init(IWorkbench workbench, IStructuredSelection selection) { + } + + public void addPages() { + setWindowTitle(Localization.getString("SelectGraphWizard.CreateGraph")); + selectGraphPage = new SelectGraphWizardPage(); + addPage(selectGraphPage); + selectSeriesPage = new SelectSeriesWizardPage(); + addPage(selectSeriesPage); + } + + public boolean canFinish() { + if (this.getContainer().getCurrentPage() == selectSeriesPage && + selectSeriesPage.isPageComplete()) + return true; + return false; + } + + public boolean performCancel() { + model.destroy(); + return true; + } + + public boolean performFinish() { + return true; + } + + public GraphData getGraphData() { + return model.getGraphData(); + } + + 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.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/graph/SelectGraphWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/graph/SelectGraphWizardPage.java new file mode 100644 index 0000000000..c9e314a48b --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/graph/SelectGraphWizardPage.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.wizards.graph; + +import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.Localization; +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.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.ui.forms.widgets.ColumnLayout; + + + + +public class SelectGraphWizardPage extends WizardPage implements Listener { + public SelectGraphWizardPage() { + super("selectGraph"); + setTitle(Localization.getString("SelectGraphWizardPage.SelectGraph")); + btnGraphs = null; + } + + public void createControl(Composite parent) { + wizard = (SelectGraphWizard)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 cmpGraphOpts = new Composite(comp, SWT.NONE); + cmpGraphOpts.setLayoutData(data1); + 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.NONE); + //btnGraphs[i].setText(GraphTypeConstants.getGraphName(graphIDs[i])); + btnGraphs[i].setImage(GraphFactory.getGraphImage(graphIDs[i])); + btnGraphs[i].addListener(SWT.Selection, this); + btnGraphs[i].setData(graphIDs[i]); + } + + FormData data2 = new FormData(); + data2.left = new FormAttachment(cmpGraphOpts); + 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); + } + + 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]) { + lblDesc.setText(GraphFactory.getGraphName(btnGraphs[i].getData().toString()) + "\n\n" + + GraphFactory.getGraphDescription(btnGraphs[i].getData().toString())); + saveDataToModel(btnGraphs[i].getData().toString()); + wizard.getContainer().updateButtons(); + } + } + } + + public IWizardPage getNextPage() { + return wizard.selectSeriesPage; + } + + 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())); + } + + public void dispose() { + super.dispose(); + if(null != btnGraphs) + for(int i=0; i<btnGraphs.length; i++) + btnGraphs[i] = null; + btnGraphs = null; + lblDesc = null; + } + + private Button[] btnGraphs; + private Label lblDesc; + private SelectGraphWizard wizard; +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/graph/SelectSeriesWizardPage.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/graph/SelectSeriesWizardPage.java new file mode 100644 index 0000000000..9664490e8f --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.ui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/ui/wizards/graph/SelectSeriesWizardPage.java @@ -0,0 +1,328 @@ +/******************************************************************************* + * 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.ui.graphingapi.ui.wizards.graph; + +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.linuxtools.systemtap.ui.graphingapi.ui.internal.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"); + setTitle(Localization.getString("SelectSeriesWizardPage.SelectSeries")); + } + + 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")); + txtTitle = new Text(comp, SWT.BORDER); + txtTitle.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + getWizard().getContainer().updateButtons(); + if(txtTitle.getText().length() == 0) { + setErrorMessage(Localization.getString("SelectSeriesWizardPage.TitleNotSet")); + setMessage(null); + } else { + setErrorMessage(null); + setMessage(""); + } + } + }); + 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")); + cboXItem = new Combo(cmpGraphOpts, SWT.DROP_DOWN); + cboXItem.addSelectionListener(new ComboSelectionListener()); + cboXItem.add(Localization.getString("SelectSeriesWizardPage.RowID")); + 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 + ":"); + cboYItems[i] = new Combo(cmpGraphOpts, SWT.DROP_DOWN); + cboYItems[i].addSelectionListener(new ComboSelectionListener()); + + if(i>0) { + cboYItems[i].add(Localization.getString("SelectSeriesWizardPage.NA")); + 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")); + btnKey.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) {} + 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")); + txtKey = new Text(comp, SWT.BORDER); + + if(null != txtKey) { + txtKey.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + getWizard().getContainer().updateButtons(); + if(txtTitle.getText().length() == 0) { + setErrorMessage(Localization.getString("SelectSeriesWizardPage.KeyNotSet")); + 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); + } + + public boolean canFlipToNextPage() { + return false; + } + + 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())) + 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; + } + + 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 { + public void widgetDefaultSelected(SelectionEvent e) {} + + 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")); + setMessage(null); + } else { + setErrorMessage(null); + setMessage(""); + } + if(txtTitle.getText().length() == 0) { + setErrorMessage(Localization.getString("SelectSeriesWizardPage.TitleNotSet")); + 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 |