FlatScopeViewActionsGUI.java

Go to the documentation of this file.
00001 
00004 package edu.rice.cs.hpc.viewer.scope.flat;
00005 
00006 import org.eclipse.swt.SWT;
00007 import org.eclipse.swt.events.SelectionAdapter;
00008 import org.eclipse.swt.events.SelectionEvent;
00009 import org.eclipse.swt.widgets.Composite;
00010 import org.eclipse.swt.widgets.CoolBar;
00011 import org.eclipse.swt.widgets.Shell;
00012 import org.eclipse.swt.widgets.ToolBar;
00013 import org.eclipse.swt.widgets.ToolItem;
00014 import org.eclipse.ui.IWorkbenchWindow;
00015 
00016 import edu.rice.cs.hpc.data.util.OSValidator;
00017 import edu.rice.cs.hpc.data.experiment.scope.Scope;
00018 import edu.rice.cs.hpc.viewer.resources.Icons;
00019 import edu.rice.cs.hpc.viewer.scope.ScopeViewActions;
00020 import edu.rice.cs.hpc.viewer.scope.ScopeViewActionsGUI;
00021 import edu.rice.cs.hpc.viewer.scope.flat.FlatScopeViewActions;
00022 
00030 public class FlatScopeViewActionsGUI extends ScopeViewActionsGUI {
00031 
00032     private ToolItem tiFlatten;     //flatten button
00033     private ToolItem tiUnFlatten ;  // unflatten button
00034     protected FlatScopeViewActions objFlatAction;
00040     public FlatScopeViewActionsGUI(Shell objShell, IWorkbenchWindow window, Composite parent,
00041             ScopeViewActions objActions) {
00042         super(objShell, window, parent, objActions);
00043         this.objFlatAction = (FlatScopeViewActions) objActions;
00044     }
00045 
00051     public Composite buildGUI(Composite parent, CoolBar coolbar) {
00052         // add toobar actions for flatten and unflatten
00053         Composite c =  addTooBarAction(coolbar);
00054         super.finalizeToolBar(parent, coolbar);
00055         return c;
00056     }
00057 
00061     public void resetActions() {
00062         super.resetActions();
00063         this.tiFlatten.setEnabled(false);
00064         this.tiUnFlatten.setEnabled(false);
00065     }
00066     
00070     public void enableActions() {
00071         super.enableActions();
00072         this.checkFlattenButtons();
00073     }
00074 
00080     protected Composite addTooBarAction(CoolBar parent)  {
00081         // prepare the toolbar
00082         ToolBar toolbar = new ToolBar(parent, SWT.FLAT);
00083 
00084         // ------------- prepare the items
00085         // flatten
00086         tiFlatten = new ToolItem(toolbar, SWT.PUSH);
00087         tiFlatten.setToolTipText("Flatten nodes one level");
00088         tiFlatten.setImage(Icons.getImage(Icons.Image_Flatten));
00089         tiFlatten.addSelectionListener(new SelectionAdapter() {
00090             public void widgetSelected(SelectionEvent e) {
00091                 objFlatAction.flatten();
00092             }
00093         });
00094         
00095         // unflatten
00096         tiUnFlatten = new ToolItem(toolbar, SWT.PUSH);
00097         tiUnFlatten.setToolTipText("Unflatten nodes one level");
00098         tiUnFlatten.setImage(Icons.getImage(Icons.Image_Unflatten));
00099         tiUnFlatten.addSelectionListener(new SelectionAdapter(){
00100             public void widgetSelected(SelectionEvent e) {
00101                 objFlatAction.unflatten();
00102             }           
00103         });
00104         
00105         // 2009.04.21: temporary solution for windowz: add space to show unflatten buttons
00106         if (OSValidator.isWindows()) {
00107             new ToolItem(toolbar, SWT.NULL);
00108         }
00109         
00110         this.createCoolItem(parent, toolbar);
00111 
00112         // we need to add the parent's default actions
00113         // Without this statement, the default actions disappear
00114         Composite objComposite = super.addTooBarAction(parent);
00115         
00116         return objComposite;
00117     }
00121     public void checkFlattenButtons() {
00122         tiFlatten.setEnabled( shouldFlattenBeEnabled() );
00123         tiUnFlatten.setEnabled( shouldUnflattenBeEnabled() );
00124     }
00125 
00131     public void updateFlattenView(Scope parentNode) {
00132         //this.displayRootExperiment(); // display the aggregate metrics
00133         insertParentNode(parentNode);
00134         checkFlattenButtons();
00135     }
00136 
00141     public boolean shouldFlattenBeEnabled() {
00142         
00143         //return (objFlatAction.getScopeZoom().canZoomIn( ));
00144         /*
00145         // https://outreach.scidac.gov/tracker/index.php?func=detail&aid=342&group_id=22&atid=169
00146         // BUGS #342: we need to disable flatten buttons when the tree has been zoomed
00147         if ( objFlatAction.getScopeZoom().canZoomOut() )
00148             return false;
00149         */
00150         // DO NOT flatten if we reach to the point where there is no children 
00151         //return this.myRootScope.getTreeNode().getDepth()>this.myRootScope.getFlattenLevel() + 1;
00152         Object o = this.treeViewer.getInput();
00153         if (o instanceof Scope) {
00154             Scope objNode = (Scope) o;
00155             for( int i=0; i<objNode.getChildCount(); i++ ) {
00156                 if (objNode.getChildAt(i).hasChildren())
00157                     return true;
00158             }
00159         }
00160         return false;
00161     }
00162     
00167     public boolean shouldUnflattenBeEnabled() {
00168         
00169         return (objFlatAction.canUnflatten());
00170         
00171         // DO NOT unflatten if we reach to root scope level
00172         //return (objFlatAction.getFlattenLevel()>0);
00173     }
00174 
00175 
00176 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1