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;
00033 private ToolItem tiUnFlatten ;
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
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
00082 ToolBar toolbar = new ToolBar(parent, SWT.FLAT);
00083
00084
00085
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
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
00106 if (OSValidator.isWindows()) {
00107 new ToolItem(toolbar, SWT.NULL);
00108 }
00109
00110 this.createCoolItem(parent, toolbar);
00111
00112
00113
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
00133 insertParentNode(parentNode);
00134 checkFlattenButtons();
00135 }
00136
00141 public boolean shouldFlattenBeEnabled() {
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
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
00172
00173 }
00174
00175
00176 }