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     // chart is used to plot graph or histogram on canvas. each editor has its own chart
00035     private Chart chart;
00036     
00037     // a database of an experiment containing raw metrics to plot
00038     protected ThreadLevelDataManager threadData;
00039 
00040     //@Override
00041     public void doSave(IProgressMonitor monitor) {
00042         // TODO Auto-generated method stub
00043     }
00044 
00045     //@Override
00046     public void doSaveAs() {
00047         // TODO Auto-generated method stub
00048     }
00049 
00050     //@Override
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     //@Override
00064     public boolean isDirty() {
00065         return false;
00066     }
00067 
00068     //@Override
00069     public boolean isSaveAsAllowed() {
00070         // TODO Auto-generated method stub
00071         return false;
00072     }
00073 
00074 
00075     //@Override
00076     public void setFocus() {
00077         // TODO Auto-generated method stub
00078 
00079     }
00080     
00081     /******
00082      * Do finalization of the editor
00083      * 
00084      * Due to SWT Chart bug, we need to adjust the range once the create-part-control
00085      *  finishes its layout.
00086      */
00087     public void finalize() {
00088         IAxisSet axisSet = this.getChart().getAxisSet();
00089         axisSet.adjustRange();
00090 
00091         // set the lower range to be zero so that we can see if there is load imbalance or not
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      * (non-Javadoc)
00101      * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
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         // set the window title with a possible db number
00115         WindowTitle wt = new WindowTitle();
00116         wt.setEditorTitle(this.getEditorSite().getWorkbenchWindow(), this); //, exp, editorName);
00117 
00118         //----------------------------------------------
00119         // chart creation
00120         //----------------------------------------------
00121         chart = new InteractiveChart(parent, SWT.NONE);
00122         chart.getTitle().setText( title );
00123 
00124 
00125         //----------------------------------------------
00126         // formatting axis
00127         //----------------------------------------------
00128         IAxisSet axisSet = chart.getAxisSet();
00129         IAxisTick yTick = axisSet.getYAxis(0).getTick();
00130         yTick.setFormat(new DecimalFormat("0.0##E0##"));
00131 
00132         // turn off the legend
00133         chart.getLegend().setVisible(false);
00134         
00135         //----------------------------------------------
00136         // plot data
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      * (non-Javadoc)
00158      * @see edu.rice.cs.hpc.viewer.editor.IViewerEditor#getExperiment()
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 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1