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
00033 }
00034
00038 public ScopeTreeViewer(Tree tree) {
00039 super(tree, SWT.VIRTUAL);
00040
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
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
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
00112 return this.getTextBasedOnColumnStatus(sTitles, sSeparator, iStartColIndex, 0);
00113 }
00114
00115
00116
00117
00118
00119
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
00140
00141
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
00152 sText[i] = val;
00153 }
00154 }
00155 }
00156 }
00157 if (need_to_refresh) {
00158
00159
00160
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,
00181 boolean bSorted, boolean bDisplayed) {
00182
00183 TreeViewerColumn colMetric = new TreeViewerColumn(this,SWT.RIGHT);
00184 colMetric.setLabelProvider(new MetricLabelProvider(objMetric ) );
00185
00186 TreeColumn col = colMetric.getColumn();
00187 col.setText(objMetric.getDisplayName());
00188 col.setWidth(120);
00189
00190
00191 col.setData(objMetric);
00192 col.setMoveable(true);
00193
00194 int iPosition = this.doGetColumnCount();
00195 ColumnViewerSorter colSorter = new ColumnViewerSorter(this,
00196 col, objMetric,iPosition);
00197 if(bSorted)
00198 colSorter.setSorter(colSorter, ColumnViewerSorter.ASC);
00199
00200 return colMetric;
00201 }
00202
00203
00204
00205
00206
00207
00208
00209 public void refreshElement(Object element, boolean updateLabels)
00210 {
00211 super.internalRefresh(element, updateLabels);
00212 }
00213
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 }