StyledScopeLabelProvider.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.viewer.scope;
00002 
00003 import org.eclipse.jface.preference.JFacePreferences;
00004 import org.eclipse.jface.viewers.StyledCellLabelProvider;
00005 import org.eclipse.jface.viewers.StyledString;
00006 import org.eclipse.jface.viewers.StyledString.Styler;
00007 import org.eclipse.jface.viewers.ViewerCell;
00008 import org.eclipse.swt.graphics.Image;
00009 import org.eclipse.ui.IWorkbenchWindow;
00010 
00011 import edu.rice.cs.hpc.data.experiment.scope.CallSiteScope;
00012 import edu.rice.cs.hpc.data.experiment.scope.CallSiteScopeCallerView;
00013 import edu.rice.cs.hpc.data.experiment.scope.ProcedureScope;
00014 import edu.rice.cs.hpc.data.experiment.scope.Scope;
00015 import edu.rice.cs.hpc.viewer.util.Utilities;
00016 import edu.rice.cs.hpc.viewer.window.ViewerWindow;
00017 import edu.rice.cs.hpc.viewer.window.ViewerWindowManager;
00018 
00019 
00020 /***
00021  * 
00022  * Class to display label on the tree of views
00023  * 
00024  * A node of the tree contains three objects: [icon] [callsite] node_label
00025  * Every object has colors to indicate if they are clickable or not
00026  * - An object is clickable if they contain further information such as file source code
00027  * - Otherwise it is not clickable
00028  * 
00029  */
00030 public class StyledScopeLabelProvider extends StyledCellLabelProvider {
00031     
00032     final private Styler STYLE_ACTIVE_LINK;
00033     final private ViewerWindow viewerWindow;
00034 
00040     public StyledScopeLabelProvider(IWorkbenchWindow window) {
00041         super();
00042         STYLE_ACTIVE_LINK = StyledString.createColorRegistryStyler(JFacePreferences.ACTIVE_HYPERLINK_COLOR, null); 
00043         viewerWindow = ViewerWindowManager.getViewerWindow(window);
00044     }
00045     
00046     /*
00047      * (non-Javadoc)
00048      * @see org.eclipse.jface.viewers.StyledCellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell)
00049      */
00050     public void update(ViewerCell cell) {
00051         Object element = cell.getElement();
00052         
00053         if (element instanceof Scope) {
00054             Scope node = (Scope) element;
00055             final String text = getText(node);
00056             
00057             StyledString styledString= new StyledString();
00058 
00059             // ----------------------------------------------
00060             // special case for call sites :
00061             // - coloring the object for call site (if exists)
00062             // - show the icon if exists
00063             // ----------------------------------------------
00064             if (element instanceof CallSiteScope) {
00065                 final CallSiteScope cs = (CallSiteScope) element;
00066                 
00067                 // the line number in XML is 0-based, while the editor is 1-based
00068                 int line = 1+cs.getLineScope().getFirstLineNumber();
00069                 boolean isReadable = Utilities.isFileReadable(cs.getLineScope());
00070                 
00071                 // show the line number
00072                 if (line>0) {
00073                     if (isReadable)
00074                         styledString.append(String.valueOf(line)+": ", StyledString.COUNTER_STYLER);
00075                     else 
00076                         styledString.append(String.valueOf(line)+": ", StyledString.DECORATIONS_STYLER);
00077                 }
00078                 
00079                 // show the icon
00080                 final Image image = Utilities.getScopeNavButton(node);
00081                 cell.setImage(image);
00082             }
00083             if(Utilities.isFileReadable(node)) {
00084                 styledString.append( text, STYLE_ACTIVE_LINK );
00085             } else {
00086                 styledString.append( text );
00087             }
00088             cell.setFont(Utilities.fontGeneral);
00089             cell.setText(styledString.toString());
00090             cell.setStyleRanges(styledString.getStyleRanges());
00091         }
00092     }
00093 
00094     
00098     private String getText(Scope node) 
00099     {
00100         String text = "";
00101             
00102         if (viewerWindow.showCCTLabel())  
00103         {
00104             //---------------------------------------------------------------
00105             // label for debugging purpose
00106             //---------------------------------------------------------------
00107             if (node instanceof CallSiteScope)
00108             {
00109                 CallSiteScope caller = (CallSiteScope) node;
00110                 Scope cct = caller.getLineScope();
00111                 if (node instanceof CallSiteScopeCallerView) 
00112                 {
00113                     Object merged[] = ((CallSiteScopeCallerView)caller).getMergedScopes();
00114                     if (merged != null) {
00115                         int mult = merged.length + 1;
00116                         text = mult + "*";
00117                     }
00118                     cct = ((CallSiteScopeCallerView)caller).getScopeCCT();
00119                 }   
00120                 text += "[c:" + caller.getCCTIndex() +"/" + cct.getCCTIndex()  + "] " ;
00121             } else
00122                 text = "[c:" + node.getCCTIndex() + "] ";
00123         } 
00124         if (viewerWindow.showFlatLabel()) {
00125             text += "[f: " + node.getFlatIndex() ;
00126             if (node instanceof CallSiteScope) {
00127                 ProcedureScope proc = ((CallSiteScope)node).getProcedureScope();
00128                 text += "/" + proc.getFlatIndex();
00129             }
00130             text += "] ";
00131         } 
00132         text += node.getName(); 
00133         return text;
00134     }
00135 
00136 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1