ExperimentView.java
Go to the documentation of this file.00001 package edu.rice.cs.hpc.viewer.experiment;
00002
00003 import org.eclipse.jface.dialogs.MessageDialog;
00004
00005 import edu.rice.cs.hpc.common.util.ProcedureAliasMap;
00006 import edu.rice.cs.hpc.data.experiment.*;
00007 import edu.rice.cs.hpc.viewer.framework.Activator;
00008 import edu.rice.cs.hpc.viewer.scope.BaseScopeView;
00009 import edu.rice.cs.hpc.viewer.scope.bottomup.CallerScopeView;
00010 import edu.rice.cs.hpc.viewer.scope.flat.FlatScopeView;
00011 import edu.rice.cs.hpc.viewer.scope.topdown.ScopeView;
00012 import edu.rice.cs.hpc.viewer.util.PreferenceConstants;
00013 import edu.rice.cs.hpc.viewer.util.WindowTitle;
00014 import edu.rice.cs.hpc.viewer.window.Database;
00015 import edu.rice.cs.hpc.viewer.window.ViewerWindow;
00016 import edu.rice.cs.hpc.viewer.window.ViewerWindowManager;
00017
00018 import edu.rice.cs.hpc.data.experiment.scope.RootScope;
00019 import edu.rice.cs.hpc.data.experiment.scope.RootScopeType;
00020 import edu.rice.cs.hpc.filter.service.FilterMap;
00021
00022 import org.eclipse.ui.IWorkbenchPage;
00023 import org.eclipse.ui.IWorkbenchWindow;
00024 import org.eclipse.ui.PartInitException;
00025 import org.eclipse.ui.preferences.ScopedPreferenceStore;
00026
00027
00028
00029
00030
00031
00032 public class ExperimentView {
00033
00034 static final private int VIEW_STATE_INIT = -1;
00035
00036 private IWorkbenchPage objPage;
00040 protected BaseScopeView []arrScopeViews;
00041
00046 public ExperimentView(IWorkbenchPage objTarget) {
00047 if(objTarget != null) {
00048 this.objPage = objTarget;
00049
00050 } else {
00051 System.err.println("EV Error: active page is null !");
00052 }
00053 }
00054
00062 public boolean loadExperimentAndProcess(String sFilename, boolean bCallerView) {
00063
00064 Experiment experiment = this.loadExperiment(sFilename, bCallerView);
00065
00066 if(experiment != null) {
00067 try {
00068
00069 FilterMap filter = FilterMap.getInstance();
00070 if (filter.isFilterEnabled()) {
00071 experiment.filter(FilterMap.getInstance());
00072 }
00073 this.generateView(experiment);
00074 } catch (java.lang.OutOfMemoryError e)
00075 {
00076 MessageDialog.openError(this.objPage.getWorkbenchWindow().getShell(), "Out of memory",
00077 "hpcviewer requires more heap memory allocation.\nJava heap size can be increased by modifying \"-Xmx\" parameter in hpcivewer.ini file.");
00078 } catch (java.lang.RuntimeException e)
00079 {
00080 MessageDialog.openError(objPage.getWorkbenchWindow().getShell(), "Critical error",
00081 "XML file is not in correct format: \n"+e.getMessage());
00082 e.printStackTrace();
00083 }
00084 return true;
00085 }
00086 return false;
00087 }
00088
00095 public boolean loadExperimentAndProcess(String sFilename) {
00096 ScopedPreferenceStore objPref = (ScopedPreferenceStore)Activator.getDefault().getPreferenceStore();
00097 boolean bCallerView = objPref.getBoolean(PreferenceConstants.P_CALLER_VIEW);
00098 return this.loadExperimentAndProcess(sFilename, bCallerView);
00099 }
00100
00107 public Experiment loadExperiment(String sFilename, boolean bCallerView) {
00108 Experiment experiment = null;
00109
00110 org.eclipse.swt.widgets.Shell objShell = this.objPage.getWorkbenchWindow().getShell();
00111 try
00112 {
00113 experiment = new Experiment();
00114 experiment.open( new java.io.File(sFilename), new ProcedureAliasMap(), bCallerView );
00115
00116 } catch(java.io.FileNotFoundException fnf)
00117 {
00118 System.err.println("File not found:" + sFilename + "\tException:"+fnf.getMessage());
00119 MessageDialog.openError(objShell, "Error:File not found", "Cannot find the file "+sFilename);
00120 experiment = null;
00121 }
00122 catch(java.io.IOException io)
00123 {
00124 System.err.println("IO error:" + sFilename + "\tIO msg: " + io.getMessage());
00125 MessageDialog.openError(objShell, "Error: Unable to read", "Cannot read the file "+sFilename);
00126 experiment = null;
00127 }
00128 catch(InvalExperimentException ex)
00129 {
00130 String where = sFilename + " " + " " + ex.getLineNumber();
00131 System.err.println("$" + where);
00132 MessageDialog.openError(objShell, "Incorrect Experiment File", "File "+sFilename
00133 + " has incorrect tag at line:"+ex.getLineNumber());
00134 experiment = null;
00135 }
00136 catch(NullPointerException npe)
00137 {
00138 System.err.println("$" + npe.getMessage() + sFilename);
00139 MessageDialog.openError(objShell, "File is invalid", "File has null pointer:"
00140 +sFilename + ":"+npe.getMessage());
00141 experiment = null;
00142 } catch (Exception e) {
00143
00144 e.printStackTrace();
00145 }
00146 return experiment;
00147 }
00148
00153 public BaseScopeView[] getViews() {
00154 return this.arrScopeViews;
00155 }
00156
00157
00158
00159
00160
00161
00162 public void setViews(BaseScopeView[] views) {
00163 arrScopeViews = views;
00164 }
00165
00170 public void generateView(Experiment experiment) {
00171
00172 IWorkbenchWindow window = this.objPage.getWorkbenchWindow();
00173
00174 ViewerWindow vWin = ViewerWindowManager.getViewerWindow(window);
00175 if (vWin == null) {
00176 System.out.printf("ExperimentManager.setExperiment: ViewerWindow class not found\n");
00177 }
00178
00179
00180
00181
00182 Database db = new Database();
00183 db.setExperimentView(this);
00184
00185 if (vWin.addDatabase(db) < 0) {
00186 return;
00187 }
00188
00189 db.setExperiment(experiment);
00190
00191
00192 final String viewIdx = Integer.toString(vWin.reserveDatabaseNumber());
00193
00194
00195 Object []rootChildren = experiment.getRootScopeChildren();
00196 int nbChildren = rootChildren.length;
00197 arrScopeViews = new BaseScopeView[nbChildren];
00198
00199 for(int k=0;nbChildren>k;k++)
00200 {
00201 RootScope child = (RootScope) rootChildren[k];
00202 try {
00203 BaseScopeView objView;
00204 objView = openView(objPage, child, viewIdx, db, VIEW_STATE_INIT);
00205
00206 arrScopeViews[k] = objView;
00207 } catch (PartInitException e) {
00208 e.printStackTrace();
00209 }
00210 }
00211
00212
00213 WindowTitle wt = new WindowTitle();
00214 wt.refreshAllTitles();
00215 }
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 static public BaseScopeView openView(IWorkbenchPage page, RootScope root, String secondaryID,
00233 Database db, int viewState )
00234 throws PartInitException {
00235
00236 BaseScopeView objView = null;
00237
00238 if (root.getType() == RootScopeType.CallingContextTree) {
00239 int state = (viewState<=0? IWorkbenchPage.VIEW_ACTIVATE : viewState);
00240
00241 objView = (BaseScopeView) page.showView(ScopeView.ID , secondaryID, state);
00242
00243 if (viewState == VIEW_STATE_INIT) {
00244 objView.setInput(db, root, false);
00245 }
00246
00247 } else if (root.getType() == RootScopeType.CallerTree) {
00248 if (viewState != VIEW_STATE_INIT) {
00249
00250 objView = (BaseScopeView) page.showView(CallerScopeView.ID , secondaryID, IWorkbenchPage.VIEW_ACTIVATE);
00251 } else {
00252
00253 objView = (BaseScopeView) page.showView(CallerScopeView.ID , secondaryID, IWorkbenchPage.VIEW_VISIBLE);
00254 }
00255
00256
00257 objView.setInput(db, root, false);
00258
00259 } else if (root.getType() == RootScopeType.Flat) {
00260 int state = (viewState<=0? IWorkbenchPage.VIEW_VISIBLE : viewState);
00261 objView = (BaseScopeView) page.showView(FlatScopeView.ID, secondaryID, state);
00262 if (viewState == VIEW_STATE_INIT) {
00263 objView.setInput(db, root, false);
00264 }
00265 }
00266 return objView;
00267 }
00268
00269 }