ScopeTreeViewer.java

Go to the documentation of this file.
00001 
00004 package edu.rice.cs.hpc.viewer.scope;
00005 
00006 import org.eclipse.jface.viewers.TreeViewer;
00007 import org.eclipse.jface.viewers.TreeViewerColumn;
00008 import org.eclipse.swt.SWT;
00009 import org.eclipse.swt.graphics.Image;
00010 import org.eclipse.swt.widgets.Composite;
00011 import org.eclipse.swt.widgets.Tree;
00012 import org.eclipse.swt.widgets.TreeColumn;
00013 import org.eclipse.jface.viewers.TreePath;
00014 import org.eclipse.swt.widgets.TreeItem;
00015 
00016 import edu.rice.cs.hpc.data.experiment.metric.BaseMetric;
00017 import edu.rice.cs.hpc.data.experiment.metric.DerivedMetric;
00018 import edu.rice.cs.hpc.data.experiment.scope.RootScope;
00019 import edu.rice.cs.hpc.viewer.metric.MetricLabelProvider;
00020 import edu.rice.cs.hpc.viewer.util.Utilities;
00021 
00025 public class ScopeTreeViewer extends TreeViewer {
00026 
00030     public ScopeTreeViewer(Composite parent) {
00031         super(parent, SWT.VIRTUAL);
00032         // TODO Auto-generated constructor stub
00033     }
00034 
00038     public ScopeTreeViewer(Tree tree) {
00039         super(tree, SWT.VIRTUAL);
00040         // TODO Auto-generated constructor stub
00041     }
00042 
00047     public ScopeTreeViewer(Composite parent, int style) {
00048         super(parent, SWT.VIRTUAL | style);
00049         this.setUseHashlookup(true);
00050 
00051     }
00052 
00053     
00054     
00060     public TreePath getTreePath(TreeItem item) {
00061         return super.getTreePathFromItem(item);
00062     }
00063 
00072     public TreeViewerColumn addTreeColumn(BaseMetric objMetric, boolean bSorted) {
00073         // laks: addendum for column  
00074         TreeViewerColumn colMetric = addTreeColumn(objMetric, bSorted, false);
00075         return colMetric;
00076     }
00077     
00084     public String getTextBasedOnColumnStatus(String []sListOfTexts, String sSeparator, 
00085             int startColIndex, int startTextIndex) {
00086         StringBuffer sBuf = new StringBuffer();
00087         TreeColumn columns[] = this.getTree().getColumns();
00088         for ( int i=startColIndex; i<columns.length; i++ ) {
00089             if ( columns[i].getWidth()>0 ) {
00090                 if (sBuf.length()>0)
00091                     sBuf.append(sSeparator);
00092                 sBuf.append( sListOfTexts[i+startTextIndex] );
00093             }
00094         }
00095         return sBuf.toString();
00096     }
00097     
00104     public String getColumnTitle(int iStartColIndex, String sSeparator) {
00105         // get the column title first
00106         TreeColumn columns[] = this.getTree().getColumns();
00107         String sTitles[] = new String[columns.length];
00108         for ( int i=0; i<columns.length; i++ ) {
00109             sTitles[i] = "\"" + columns[i].getText().trim() + "\"";
00110         }
00111         // then get the string based on the column status
00112         return this.getTextBasedOnColumnStatus(sTitles, sSeparator, iStartColIndex, 0);
00113     }
00114     
00115     /****
00116      * refresh the title of all metric columns.
00117      * <p/>
00118      * warning: this method uses linear search to see if they are metric column or not,
00119      *  so the complexity is O(n). 
00120      * 
00121      */
00122     public void refreshColumnTitle() {
00123         
00124         String []sText = Utilities.getTopRowItems(this);
00125 
00126         TreeColumn columns[] = this.getTree().getColumns();
00127         boolean need_to_refresh = false;
00128         
00129         for( int i=0; i<columns.length; i++ ) {
00130             
00131             TreeColumn column = columns[i]; 
00132             Object obj = column.getData();
00133             
00134             if (obj instanceof BaseMetric) {
00135                 final String title = ((BaseMetric)obj).getDisplayName();
00136                 column.setText(title);
00137                 
00138                 // -----------------------------------------------------------------
00139                 // if the column is a derived metric, we need to refresh the table
00140                 //  even if the derived metric is not modified at all.
00141                 // this solution is not optimal, but it works
00142                 // -----------------------------------------------------------------
00143                 
00144                 need_to_refresh |= (obj instanceof DerivedMetric);
00145                 if (need_to_refresh) {
00146                     Object objInp = getInput();
00147                     if (objInp instanceof RootScope) {
00148                         DerivedMetric dm = (DerivedMetric) obj;
00149                         String val = dm.getMetricTextValue((RootScope) objInp);
00150 
00151                         // change the current value on the top row with the new value
00152                         sText[i] = val;
00153                     }
00154                 }
00155             }
00156         }
00157         if (need_to_refresh) {
00158             // -----------------------------------------------------------------
00159             // refresh the table, and insert the top row back to the table
00160             //  with the new value of the derived metric
00161             // -----------------------------------------------------------------
00162             TreeItem item = getTree().getItem(0);
00163             Image imgItem = item.getImage(0);
00164             
00165             refresh();
00166             
00167             Utilities.insertTopRow(this, imgItem, sText);
00168         }
00169     }
00170     
00180     private TreeViewerColumn addTreeColumn(BaseMetric objMetric, //int iPosition, 
00181             boolean bSorted, boolean bDisplayed) {
00182         
00183         TreeViewerColumn colMetric = new TreeViewerColumn(this,SWT.RIGHT);  // add column
00184         colMetric.setLabelProvider(new MetricLabelProvider(objMetric /*, Utilities.fontMetric*/) );
00185 
00186         TreeColumn col = colMetric.getColumn();
00187         col.setText(objMetric.getDisplayName());    // set the title
00188         col.setWidth(120); //TODO dynamic size
00189         // associate the data of this column to the metric since we
00190         // allowed columns to move (col position is not enough !)
00191         col.setData(objMetric);
00192         col.setMoveable(true);
00193         //this.colMetrics[i].getColumn().pack();            // resize as much as possible
00194         int iPosition = this.doGetColumnCount();
00195         ColumnViewerSorter colSorter = new ColumnViewerSorter(this, 
00196                 col, objMetric,iPosition); // sorting mechanism
00197         if(bSorted)
00198             colSorter.setSorter(colSorter, ColumnViewerSorter.ASC);
00199 
00200         return colMetric;
00201     }
00202     
00203     /****
00204      * Regreshes the viewer starting at the given element
00205      * 
00206      * @param element
00207      * @param updateLabels
00208      */
00209     public void refreshElement(Object element, boolean updateLabels)
00210     {
00211         super.internalRefresh(element, updateLabels);
00212     }
00213     
00225     /*
00226     public ViewerCell getCell(Point point) {
00227         ViewerRow row = getViewerRow(point);
00228         if (row != null) {
00229             return row.getCell(point);
00230         }
00231 
00232         return null;
00233     }*/
00234 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1