BaseScopeView.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.viewer.scope;
00002 
00003 import org.eclipse.jface.viewers.TreeViewerColumn;
00004 import org.eclipse.swt.widgets.Tree;
00005 import org.eclipse.swt.widgets.TreeColumn;
00006 import org.eclipse.swt.widgets.TreeItem;
00007 
00008 import edu.rice.cs.hpc.data.experiment.Experiment;
00009 import edu.rice.cs.hpc.data.experiment.scope.RootScope;
00010 import edu.rice.cs.hpc.data.experiment.scope.RootScopeType;
00011 import edu.rice.cs.hpc.filter.service.FilterMap;
00012 
00017 abstract public class BaseScopeView  extends AbstractBaseScopeView {
00018     
00019     //======================================================
00020     // ................ ATTRIBUTES..........................
00021     //======================================================
00022 
00023     //======================================================
00024     // ................ METHODS  ..........................
00025     //======================================================
00026     public BaseScopeView()
00027     {
00028         super();
00029     }
00030     
00031     @Override
00032     public void dispose() 
00033     {
00034         //serviceProvider.removeSourceProviderListener(listener);
00035         super.dispose();
00036     }
00040     
00041     /****
00042      * enable/disable filter
00043      * 
00044      * @param isEnabled
00045      */
00046     protected void enableFilter(boolean isEnabled)
00047     {
00048         if (treeViewer.getTree().isDisposed())
00049             return;
00050         
00051         //AbstractContentProvider provider = (AbstractContentProvider) treeViewer.getContentProvider();
00052         //provider.setEnableFilter(isEnabled);
00053         Experiment experiment = getExperiment();
00054         RootScope root         = (RootScope) experiment.getRootScope();
00055         RootScopeType rootType = myRootScope.getType();
00056         
00057         // reassign root scope
00058         // we have 2 roots: one for the original, the other one for the filter roots
00059         // the getRootScope() method will return the correct one depending if the filter mode is on or off
00060         if (rootType == RootScopeType.CallingContextTree) 
00061         {
00062             myRootScope = (RootScope) root.getChildAt(0);
00063             
00064         } else if (rootType == RootScopeType.CallerTree) 
00065         {
00066             myRootScope = (RootScope) root.getChildAt(1);
00067         } else if (rootType == RootScopeType.Flat)
00068         {
00069             myRootScope = (RootScope) root.getChildAt(2);
00070         }
00071         // update the content of the view
00072         updateDisplay();
00073     }
00074     
00075 
00076     
00077     //======================================================
00078     // ................ UPDATE ............................
00079     //======================================================
00080     
00081     /*
00082      * (non-Javadoc)
00083      * @see edu.rice.cs.hpc.viewer.scope.AbstractBaseScopeView#updateDisplay()
00084      */
00085     public void updateDisplay() 
00086     {
00087         // return immediately when there's no database or the view is closed (disposed)
00088         if (database == null || treeViewer == null || treeViewer.getTree().isDisposed())
00089             return;
00090         
00091         // ------------------------------------------------------------
00092         // Tell children to update the content with the new database
00093         // ------------------------------------------------------------
00094         final Experiment myExperiment = database.getExperiment();        
00095         this.updateDatabase(myExperiment);
00096 
00097         // Update root scope
00098         if (myRootScope.getChildCount() > 0) {
00099             treeViewer.setInput(myRootScope);
00100             
00101             this.objViewActions.updateContent(getExperiment(), myRootScope);
00102 
00103             // FIXME: For unknown reason, the updateContent method above does not resize the column automatically,
00104             // so we need to do it here, manually ... sigh
00105             this.objViewActions.resizeColumns();    // resize the column to fit all metrics
00106             
00107             // Laks 2009.03.17: select the first scope
00108             TreeItem objItem = this.treeViewer.getTree().getItem(1);
00109             this.treeViewer.getTree().setSelection(objItem);
00110             // reset the button
00111             this.objViewActions.checkNodeButtons();
00112         } else {
00113             // empty experiment data (it should be a warning instead of an error. The error should be on the profile side).
00114             this.objViewActions.showErrorMessage("Warning: empty database.");
00115         }
00116     }
00117 
00118     /*
00119      * (non-Javadoc)
00120      * @see edu.rice.cs.hpc.viewer.scope.AbstractBaseScopeView#initTableColumns()
00121      */
00122     protected void initTableColumns(boolean keepColumnStatus) {
00123         
00124         if (treeViewer != null) {
00125             Tree tree = treeViewer.getTree();
00126             if (tree != null && !tree.isDisposed())
00127             {
00128                 AbstractContentProvider provider = (AbstractContentProvider) treeViewer.getContentProvider();
00129                 FilterMap filter = FilterMap.getInstance();
00130                 provider.setEnableFilter(filter.isFilterEnabled());
00131                 
00132                 initTableColumns(tree, keepColumnStatus);
00133             }
00134         }
00135     }
00136 
00137     /******
00138      * The same version as {@link BaseScopeView.initTableColumns} but without
00139      *  worrying if the tree has been disposed or not.
00140      * 
00141      * @param tree
00142      * @param keepColumnStatus
00143      */
00144     private void initTableColumns(Tree tree, boolean keepColumnStatus) 
00145     {
00146         final Experiment myExperiment = database.getExperiment();        
00147         int nbMetrics = myExperiment.getMetricCount();
00148         boolean status[] = new boolean[nbMetrics];
00149 
00150         int iColCount = tree.getColumnCount();
00151         if(iColCount>1) {
00152             TreeColumn []columns = tree.getColumns();
00153             
00154             // this is Eclipse Indigo bug: when a column is disposed, the next column will have
00155             //  zero as its width. Somehow they didn't preserve the width of the columns.
00156             // Hence, we have to retrieve the information of column width before the dispose action
00157             for(int i=1;i<iColCount;i++) {              
00158                 // bug fix: for callers view activation, we have to reserve the current status
00159                 if (keepColumnStatus) {
00160                     int width = columns[i].getWidth();
00161                     status[i-1] = (width > 0);
00162                 }
00163             }
00164             
00165             // remove the metric columns blindly
00166             // TODO we need to have a more elegant solution here
00167             for(int i=1;i<iColCount;i++) {
00168                 TreeColumn column = columns[i]; //treeViewer.getTree().getColumn(1);
00169                 column.dispose();
00170             }
00171         }
00172         // prepare the data for the sorter class for tree
00173         sorterTreeColumn.setMetric(myExperiment.getMetric(0));
00174 
00175         // dirty solution to update titles
00176         TreeViewerColumn []colMetrics = new TreeViewerColumn[nbMetrics];
00177         {
00178             // Update metric title labels
00179             String[] titles = new String[nbMetrics+1];
00180             titles[0] = "Scope";    // unused element. Already defined
00181             // add table column for each metric
00182             for (int i=0; i<nbMetrics; i++)
00183             {
00184                 titles[i+1] = myExperiment.getMetric(i).getDisplayName();   // get the title
00185                 colMetrics[i] = this.treeViewer.addTreeColumn(myExperiment.getMetric(i), (i==0));
00186                 
00187                 // bug fix: for view initialization, we need to reset the status of hide/view
00188                 if (!keepColumnStatus) {
00189                     status[i] = myExperiment.getMetric(i).getDisplayed();
00190                 }
00191             }
00192             treeViewer.setColumnProperties(titles); // do we need this ??
00193         }
00194         // update the root scope of the actions !
00195         this.objViewActions.updateContent(myExperiment, (RootScope)this.myRootScope);
00196         this.objViewActions.objActionsGUI.setColumnsStatus(status);
00197 
00198     }
00203     abstract protected void updateDatabase(Experiment new_database);
00204 
00205 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1