HPCCallStackView.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.traceviewer.misc;
00002 
00003 import java.util.Map;
00004 
00005 import org.eclipse.swt.SWT;
00006 import org.eclipse.swt.events.SelectionEvent;
00007 import org.eclipse.swt.events.SelectionListener;
00008 import org.eclipse.swt.layout.GridData;
00009 import org.eclipse.swt.layout.GridLayout;
00010 import org.eclipse.swt.widgets.Composite;
00011 import org.eclipse.swt.widgets.Label;
00012 import org.eclipse.swt.widgets.Spinner;
00013 import org.eclipse.ui.ISizeProvider;
00014 import org.eclipse.ui.ISourceProvider;
00015 import org.eclipse.ui.ISourceProviderListener;
00016 import org.eclipse.ui.part.ViewPart;
00017 import org.eclipse.ui.services.ISourceProviderService;
00018 
00019 import edu.rice.cs.hpc.traceviewer.services.DataService;
00020 import edu.rice.cs.hpc.traceviewer.spaceTimeData.SpaceTimeDataController;
00021 
00023 //all the GUI setup for the call path and minimap are here//
00024 public class HPCCallStackView extends ViewPart implements ISizeProvider
00025 {
00026     
00027     public static final String ID = "hpccallstackview.view";
00028     
00029     CallStackViewer csViewer;
00030     
00032     SpaceTimeMiniCanvas miniCanvas;
00033     
00034     Spinner depthEditor;
00035     
00036 
00037     public void createPartControl(Composite master) 
00038     {
00039         setupEverything(master);
00040         setListener();
00041     }
00042     
00043     private void setupEverything(Composite master)
00044     {
00045         /*************************************************************************
00046          * Master Composite
00047          ************************************************************************/
00048         
00049         master.setLayout(new GridLayout());
00050         master.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, true));
00051         
00052         /*************************************************************************
00053          * Depth View Spinner (the thing with the text box and little arrow buttons)
00054          ************************************************************************/
00055         depthEditor = new Spinner(master, SWT.EMBEDDED);
00056         depthEditor.setMinimum(0);
00057         depthEditor.setPageIncrement(1);
00058         depthEditor.setLayout(new GridLayout());
00059         GridData depthData = new GridData(SWT.CENTER, SWT.TOP, true, false);
00060         depthData.widthHint = 140;
00061         depthEditor.setLayoutData(depthData);
00062         depthEditor.setVisible(false);
00063         depthEditor.addSelectionListener(new SelectionListener() {
00064             public void widgetSelected(SelectionEvent e) {
00065                 String string = depthEditor.getText();
00066                 int value;
00067                 if (string.length()<1)
00068                     // be careful: on linux/GTK, any change in the spinner will consists of two steps:
00069                     //  1) empty the string
00070                     //  2) set with the specified value
00071                     // therefore, we consider any empty string to be illegal
00072                     return;
00073                 else
00074                     value = Integer.valueOf(string);
00075                 int maximum = depthEditor.getMaximum();
00076                 int minimum = 0;
00077                 if (value > maximum)
00078                     value = maximum;
00079                 if (value < minimum)
00080                     value = minimum;
00081                 csViewer.setDepth(value);
00082             }
00083 
00084             public void widgetDefaultSelected(SelectionEvent e) {
00085             }
00086         });
00087         
00088         /*************************************************************************
00089          * CallStackViewer
00090          ************************************************************************/
00091         csViewer = new CallStackViewer(master, this);
00092         
00093         /*************************************************************************
00094          * MiniMap
00095          ************************************************************************/
00096         
00097         Label l = new Label(master, SWT.SINGLE);
00098         l.setText("Mini Map");
00099         miniCanvas = new SpaceTimeMiniCanvas(master);
00100         miniCanvas.setLayout(new GridLayout());
00101         GridData miniCanvasData = new GridData(SWT.CENTER, SWT.BOTTOM, true, false);
00102         miniCanvasData.heightHint = 100;
00103         miniCanvasData.widthHint = 140;
00104         miniCanvas.setLayoutData(miniCanvasData);
00105         
00106         miniCanvas.setVisible(false);
00107     }
00108     
00109     private void setListener() {
00110         ISourceProviderService service = (ISourceProviderService)getSite().getService(ISourceProviderService.class);
00111         ISourceProvider serviceProvider = service.getSourceProvider(DataService.DATA_UPDATE);
00112         serviceProvider.addSourceProviderListener( new ISourceProviderListener(){
00113 
00114             public void sourceChanged(int sourcePriority, Map sourceValuesByName) { }
00115             public void sourceChanged(int sourcePriority, String sourceName,
00116                     Object sourceValue) {
00117                 // eclipse bug: even if we set a very specific source provider, eclipse still
00118                 //  gather event from other source. we then require to put a guard to avoid this.
00119                 if (sourceName.equals(DataService.DATA_UPDATE)) {
00120                     if (sourceValue instanceof SpaceTimeDataController) {
00121                         // new color mapping
00122                         csViewer.updateView();
00123                     } else if (sourceValue instanceof Boolean) {
00124                         // operations when every ones need to refresh their data
00125                         //  this event can happen when a filter event occurs
00126                         miniCanvas.updateView();
00127                         
00128                         // for the callstack viewer, we'll rely on BufferRefreshOperation to refresh
00129                         // the content to ensure that the data from the main view is ready to be fetched
00130                         // csViewer.updateView(); // not needed
00131                     }
00132                 }
00133             }
00134         });
00135     }
00136     
00137     
00138     public void updateView(SpaceTimeDataController _stData) 
00139     {
00140         depthEditor.setMaximum(_stData.getMaxDepth());
00141         depthEditor.setSelection(0);
00142         depthEditor.setVisible(true);
00143 
00144         //this.csViewer.updateView();
00145         
00146         // instead of updating the content of the view, we just make the table
00147         // visible, and let other event to trigger the update content.
00148         // at this point, a data may not be ready to be processed
00149         csViewer.getTable().setVisible(true);
00150         
00151         this.miniCanvas.updateView(_stData);
00152         
00153         miniCanvas.setVisible(true);
00154     }
00155 
00156     /*
00157      * (non-Javadoc)
00158      * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
00159      */
00160     public void setFocus() 
00161     {
00162         // by default, make the table to be the center of the focus
00163         this.csViewer.getTable().setFocus();
00164     }
00165 
00166     /*
00167      * (non-Javadoc)
00168      * @see org.eclipse.ui.ISizeProvider#computePreferredSize(boolean, int, int, int)
00169      */
00170     public int computePreferredSize(boolean width, int availableParallel, int availablePerpendicular, int preferredSize) 
00171     {
00172         return preferredSize;
00173     }
00174 
00175     /*
00176      * (non-Javadoc)
00177      * @see org.eclipse.ui.ISizeProvider#getSizeFlags(boolean)
00178      */
00179     public int getSizeFlags(boolean width) 
00180     {
00181         return width ? SWT.MAX : 0;
00182     }
00183 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1