GraphEditorBase.java
Go to the documentation of this file.00001 package edu.rice.cs.hpc.viewer.graph;
00002
00003 import java.text.DecimalFormat;
00004
00005 import org.eclipse.core.runtime.IProgressMonitor;
00006 import org.eclipse.swt.SWT;
00007 import org.eclipse.swt.widgets.Composite;
00008 import org.eclipse.ui.IEditorInput;
00009 import org.eclipse.ui.IEditorSite;
00010 import org.eclipse.ui.PartInitException;
00011 import org.eclipse.ui.part.EditorPart;
00012 import org.swtchart.IAxisSet;
00013 import org.swtchart.IAxisTick;
00014 import org.swtchart.Chart;
00015 import org.swtchart.Range;
00016 import org.swtchart.ext.InteractiveChart;
00017
00018 import edu.rice.cs.hpc.data.experiment.Experiment;
00019 import edu.rice.cs.hpc.data.experiment.metric.MetricRaw;
00020 import edu.rice.cs.hpc.data.experiment.scope.Scope;
00021 import edu.rice.cs.hpc.viewer.editor.IViewerEditor;
00022 import edu.rice.cs.hpc.viewer.metric.ThreadLevelDataManager;
00023 import edu.rice.cs.hpc.viewer.util.WindowTitle;
00024
00025
00032 public abstract class GraphEditorBase extends EditorPart implements IViewerEditor {
00033
00034
00035 private Chart chart;
00036
00037
00038 protected ThreadLevelDataManager threadData;
00039
00040
00041 public void doSave(IProgressMonitor monitor) {
00042
00043 }
00044
00045
00046 public void doSaveAs() {
00047
00048 }
00049
00050
00051 public void init(IEditorSite site, IEditorInput input)
00052 throws PartInitException {
00053
00054 this.setSite(site);
00055 this.setInput(input);
00056
00057 if (input instanceof GraphEditorInput) {
00058 final GraphEditorInput editorInput = (GraphEditorInput) input;
00059 threadData = editorInput.getDatabase().getThreadLevelDataManager();
00060 }
00061 }
00062
00063
00064 public boolean isDirty() {
00065 return false;
00066 }
00067
00068
00069 public boolean isSaveAsAllowed() {
00070
00071 return false;
00072 }
00073
00074
00075
00076 public void setFocus() {
00077
00078
00079 }
00080
00081
00082
00083
00084
00085
00086
00087 public void finalize() {
00088 IAxisSet axisSet = this.getChart().getAxisSet();
00089 axisSet.adjustRange();
00090
00091
00092 Range range = axisSet.getAxes()[1].getRange();
00093 if (range.lower > 0) {
00094 range.lower = 0;
00095 axisSet.getAxes()[1].setRange(range);
00096 }
00097 }
00098
00099
00100
00101
00102
00103 public void createPartControl(Composite parent) {
00104
00105 IEditorInput input = this.getEditorInput();
00106 if (input == null || !(input instanceof GraphEditorInput) )
00107 throw new RuntimeException("Invalid input for graph editor");
00108
00109 GraphEditorInput editor_input = (GraphEditorInput) input;
00110 String title = editor_input.getName();
00111
00112 this.setPartName( title );
00113
00114
00115 WindowTitle wt = new WindowTitle();
00116 wt.setEditorTitle(this.getEditorSite().getWorkbenchWindow(), this);
00117
00118
00119
00120
00121 chart = new InteractiveChart(parent, SWT.NONE);
00122 chart.getTitle().setText( title );
00123
00124
00125
00126
00127
00128 IAxisSet axisSet = chart.getAxisSet();
00129 IAxisTick yTick = axisSet.getYAxis(0).getTick();
00130 yTick.setFormat(new DecimalFormat("0.0##E0##"));
00131
00132
00133 chart.getLegend().setVisible(false);
00134
00135
00136
00137
00138 Scope scope = editor_input.getScope();
00139 MetricRaw metric = editor_input.getMetric();
00140
00141 this.plotData(scope, metric);
00142 }
00143
00144
00145 public String getEditorPartName() {
00146 final GraphEditorInput input = (GraphEditorInput) this.getEditorInput();
00147 final String name = input.getName();
00148 return name;
00149 }
00150
00151 public void setEditorPartName(String title) {
00152 this.setPartName(title);
00153 return;
00154 }
00155
00156
00157
00158
00159
00160 public Experiment getExperiment() {
00161 final GraphEditorInput input = (GraphEditorInput) this.getEditorInput();
00162 return input.getDatabase().getExperiment();
00163 }
00164
00165
00166 protected Chart getChart() {
00167 return this.chart;
00168 }
00169
00176 protected abstract void plotData(Scope scope, MetricRaw metric );
00177
00178 }