CallingContextActionsGUI.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.viewer.scope;
00002 
00003 import org.eclipse.jface.action.MenuManager;
00004 import org.eclipse.swt.SWT;
00005 import org.eclipse.swt.graphics.Image;
00006 import org.eclipse.swt.graphics.Point;
00007 import org.eclipse.swt.graphics.Rectangle;
00008 import org.eclipse.swt.widgets.Composite;
00009 import org.eclipse.swt.widgets.CoolBar;
00010 import org.eclipse.swt.widgets.Event;
00011 import org.eclipse.swt.widgets.Listener;
00012 import org.eclipse.swt.widgets.Menu;
00013 import org.eclipse.swt.widgets.Shell;
00014 import org.eclipse.swt.widgets.ToolBar;
00015 import org.eclipse.swt.widgets.ToolItem;
00016 import org.eclipse.ui.IWorkbenchWindow;
00017 import edu.rice.cs.hpc.data.experiment.scope.Scope;
00018 import edu.rice.cs.hpc.viewer.graph.GraphMenu;
00019 import edu.rice.cs.hpc.viewer.metric.ThreadLevelDataManager;
00020 import edu.rice.cs.hpc.viewer.resources.Icons;
00021 
00022 /*****************************************************
00023  * 
00024  * Action GUI for calling context view
00025  * 
00026  * This class will add a graph icon to show metrics graph of a scope
00027  *
00028  *****************************************************/
00029 public class CallingContextActionsGUI extends ScopeViewActionsGUI {
00030     
00031     private GraphMenu graphMenuManager;
00032     
00033     private ToolItem tiGraph;
00034 
00035     public CallingContextActionsGUI(Shell objShell, IWorkbenchWindow window,
00036             Composite parent, CallingContextViewActions objActions) 
00037     {
00038         super(objShell, window, parent, objActions);
00039         
00040         graphMenuManager = new GraphMenu(window);
00041     }
00042 
00048     public Composite buildGUI(Composite parent, CoolBar coolbar) {
00049         Composite newParent = this.addTooBarAction(coolbar);
00050         this.finalizeToolBar(parent, coolbar);
00051 
00052         return newParent;
00053     }
00054 
00055     
00056     /*
00057      * (non-Javadoc)
00058      * @see edu.rice.cs.hpc.viewer.scope.ScopeViewActionsGUI#addTooBarAction(org.eclipse.swt.widgets.CoolBar)
00059      */
00060     protected Composite addTooBarAction(CoolBar parent)  {
00061         
00062         Composite c = super.addTooBarAction(parent);
00063          
00064         // prepare the toolbar
00065         final ToolBar toolbar = new ToolBar(parent, SWT.FLAT);
00066 
00067         final MenuManager mgr = new MenuManager("graph");
00068 
00069         // prepare the icon
00070         Image imgGraph = Icons.getImage(Icons.Image_Graph);
00071         
00072         // add an item into the toolbar
00073         tiGraph = new ToolItem(toolbar, SWT.DROP_DOWN);
00074         tiGraph.setImage(imgGraph);
00075         tiGraph.setToolTipText("Show the graph of metric values of the selected CCT node for all processes/threads");
00076         tiGraph.addListener(SWT.Selection, new Listener() {
00077 
00078             @Override
00079             public void handleEvent(Event event) {
00080                 if (event.detail == SWT.ARROW || event.detail == 0 || event.detail == SWT.PUSH) {
00081                     Rectangle rect = tiGraph.getBounds();
00082                     Point pt = new Point(rect.x, rect.y + rect.height);
00083                     pt = toolbar.toDisplay(pt);
00084 
00085                     mgr.removeAll();
00086                     mgr.createContextMenu(toolbar);
00087                     
00088                     // create the context menu of graphs
00089                     graphMenuManager.createAdditionalContextMenu(mgr, database, getSelectedScope());
00090                     
00091                     // make the context menu appears next to tool item
00092                     final Menu menu = mgr.getMenu();
00093                     menu.setLocation(pt);
00094                     menu.setVisible(true);
00095                 }
00096             }           
00097         });
00098         
00099         // associate the tool bar as a cool item
00100         createCoolItem(parent, toolbar);
00101         
00102         return c;
00103     }
00104     
00105     @Override
00106     /*
00107      * (non-Javadoc)
00108      * @see edu.rice.cs.hpc.viewer.scope.ScopeViewActionsGUI#enableActions()
00109      */
00110     public void enableActions() {
00111         if (database != null) {
00112             ThreadLevelDataManager tld_mgr = database.getThreadLevelDataManager();
00113             if (tld_mgr != null) {
00114                 boolean available = tld_mgr.isDataAvailable();
00115                 tiGraph.setEnabled(available);
00116                 return;
00117             }
00118         }
00119         tiGraph.setEnabled(false);
00120     }
00121     
00122     private Scope getSelectedScope()
00123     {
00124         return objViewActions.getSelectedNode();
00125     }
00126 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1