HPCTraceView.java
Go to the documentation of this file.00001 package edu.rice.cs.hpc.traceviewer.main;
00002
00003 import java.io.File;
00004 import java.io.FileInputStream;
00005 import java.io.FileOutputStream;
00006 import java.io.IOException;
00007 import java.io.ObjectInputStream;
00008 import java.io.ObjectOutputStream;
00009 import java.util.Map;
00010
00011 import org.eclipse.core.commands.ExecutionEvent;
00012 import org.eclipse.core.commands.ExecutionException;
00013 import org.eclipse.core.commands.IExecutionListener;
00014 import org.eclipse.core.commands.NotHandledException;
00015 import org.eclipse.jface.action.Action;
00016 import org.eclipse.jface.action.IToolBarManager;
00017 import org.eclipse.jface.dialogs.MessageDialog;
00018 import org.eclipse.jface.layout.GridDataFactory;
00019 import org.eclipse.jface.layout.GridLayoutFactory;
00020 import org.eclipse.swt.SWT;
00021 import org.eclipse.swt.layout.GridData;
00022 import org.eclipse.swt.layout.GridLayout;
00023 import org.eclipse.swt.widgets.Composite;
00024 import org.eclipse.swt.widgets.Display;
00025 import org.eclipse.swt.widgets.FileDialog;
00026 import org.eclipse.swt.widgets.MessageBox;
00027 import org.eclipse.ui.ISourceProvider;
00028 import org.eclipse.ui.ISourceProviderListener;
00029 import org.eclipse.ui.commands.ICommandService;
00030 import org.eclipse.ui.part.ViewPart;
00031 import org.eclipse.ui.services.ISourceProviderService;
00032
00033 import edu.rice.cs.hpc.common.util.SleakManager;
00034 import edu.rice.cs.hpc.traceviewer.actions.OptionMidpoint;
00035 import edu.rice.cs.hpc.traceviewer.actions.OptionRecordsDisplay;
00036 import edu.rice.cs.hpc.traceviewer.operation.RefreshOperation;
00037 import edu.rice.cs.hpc.traceviewer.operation.TraceOperation;
00038 import edu.rice.cs.hpc.traceviewer.services.DataService;
00039 import edu.rice.cs.hpc.traceviewer.spaceTimeData.Frame;
00040 import edu.rice.cs.hpc.traceviewer.spaceTimeData.SpaceTimeDataController;
00041
00042
00043
00044
00045
00046
00047 public class HPCTraceView extends ViewPart
00048 implements ITraceViewAction
00049 {
00050
00052 public static final String ID = "hpctraceview.view";
00053
00055 private SpaceTimeDataController stData = null;
00056
00058 SpaceTimeDetailCanvas detailCanvas;
00059
00060
00061
00062
00063 public void createPartControl(Composite master)
00064 {
00065
00066
00067
00068
00069
00070
00071 master.setLayout(new GridLayout());
00072 master.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
00073
00074 createToolbar(master);
00075
00076 GridLayoutFactory.fillDefaults().numColumns(1).generateLayout(detailCanvas);
00077 GridDataFactory.fillDefaults().grab(true, true).applyTo(detailCanvas);
00078
00079 addTraceViewListener();
00080 }
00081
00082
00083
00084
00085
00086 public void updateView(SpaceTimeDataController _stData)
00087 {
00088 this.stData = _stData;
00089 this.detailCanvas.updateView(_stData);
00090
00091 detailCanvas.setVisible(true);
00092 }
00093
00094
00096 public void setFocus()
00097 {
00098 this.detailCanvas.setFocus();
00099 }
00100
00101
00102
00103
00104
00105
00106 private void addTraceViewListener()
00107 {
00108 final ISourceProviderService service = (ISourceProviderService)getSite().getService(ISourceProviderService.class);
00109 final ISourceProvider yourProvider = service.getSourceProvider(DataService.DATA_UPDATE);
00110 yourProvider.addSourceProviderListener( new ISourceProviderListener(){
00111
00112 public void sourceChanged(int sourcePriority, Map sourceValuesByName) { }
00113 public void sourceChanged(int sourcePriority, String sourceName,
00114 Object sourceValue) {
00115
00116
00117 if (sourceName.equals(DataService.DATA_UPDATE)) {
00118 boolean needRefresh = false;
00119 if (sourceValue instanceof Boolean) {
00120 Boolean refresh = (Boolean) sourceValue;
00121 needRefresh = refresh.booleanValue();
00122 }
00123 detailCanvas.refresh(needRefresh);
00124 }
00125 }
00126 });
00127
00128
00129
00130
00131 final ICommandService commandService = (ICommandService) this.getSite().getService(ICommandService.class);
00132 commandService.addExecutionListener( new IExecutionListener(){
00133
00134 public void notHandled(String commandId, NotHandledException exception) {}
00135 public void postExecuteFailure(String commandId, ExecutionException exception) {}
00136 public void preExecute(String commandId, ExecutionEvent event) {}
00137
00138
00139
00140
00141
00142 public void postExecuteSuccess(String commandId, Object returnValue)
00143 {
00144 if (stData == null)
00145 return;
00146
00147
00148 if (commandId.equals(OptionRecordsDisplay.commandId))
00149 {
00150
00151 detailCanvas.refresh(false);
00152 } else if (commandId.equals(OptionMidpoint.commandId))
00153 {
00154
00155
00156 detailCanvas.refresh(true);
00157
00158
00159
00160
00161
00162
00163 }
00164 }
00165 });
00166 }
00167
00168 private void createToolbar(Composite parent) {
00169
00170 final IToolBarManager tbMgr = getViewSite().getActionBars().getToolBarManager();
00171
00172 final TraceCoolBar traceCoolBar = new TraceCoolBar(tbMgr, this, SWT.NONE);
00173
00174
00175
00176
00177 final Composite labelGroup = new Composite(parent, SWT.NONE);
00178
00179
00180
00181
00182
00183 detailCanvas = new SpaceTimeDetailCanvas(getSite().getWorkbenchWindow(), parent);
00184
00185 detailCanvas.setLabels(labelGroup);
00186 GridLayoutFactory.fillDefaults().numColumns(3).generateLayout(labelGroup);
00187 GridDataFactory.fillDefaults().grab(true, false).align(SWT.BEGINNING, SWT.CENTER).applyTo(labelGroup);
00188
00189 detailCanvas.setButtons(new Action[]{traceCoolBar.home, traceCoolBar.open, traceCoolBar.save, null,
00190 null, traceCoolBar.tZoomIn, traceCoolBar.tZoomOut, traceCoolBar.pZoomIn, traceCoolBar.pZoomOut,
00191 traceCoolBar.goEast, traceCoolBar.goNorth, traceCoolBar.goSouth, traceCoolBar.goWest});
00192
00193 detailCanvas.setVisible(false);
00194
00195
00196
00197
00198 final Display display = getSite().getShell().getDisplay();
00199 SleakManager.init(display);
00200 }
00201
00202
00203
00204
00205
00206
00207 public void home() {
00208 detailCanvas.home();
00209 }
00210
00211 public void timeZoomIn() {
00212 detailCanvas.timeZoomIn();
00213 }
00214
00215 public void timeZoomOut() {
00216 detailCanvas.timeZoomOut();
00217 }
00218
00219 public void processZoomIn() {
00220 detailCanvas.processZoomIn();
00221 }
00222
00223 public void processZoomOut() {
00224 detailCanvas.processZoomOut();
00225 }
00226
00227 public void save() {
00228 FileDialog saveDialog;
00229 saveDialog = new FileDialog(this.getViewSite().getShell(), SWT.SAVE);
00230 saveDialog.setText("Save View Configuration");
00231 String fileName = "";
00232 boolean validSaveFileFound = false;
00233 while(!validSaveFileFound)
00234 {
00235 Frame toSave = detailCanvas.save();
00236 saveDialog.setFileName((int)toSave.begTime+"-"+(int)toSave.endTime+", "
00237 +(int)toSave.begProcess+"-"+(int)toSave.endProcess+".bin");
00238 fileName = saveDialog.open();
00239
00240 if (fileName == null)
00241 return;
00242 else
00243 {
00244 if (!new File(fileName).exists())
00245 validSaveFileFound = true;
00246 else
00247 {
00248
00249
00250
00251
00252 MessageBox msg = new MessageBox(this.getViewSite().getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
00253 msg.setText("File Exists");
00254 msg.setMessage("This file path already exists.\nDo you want to overwrite this save file?");
00255 int selectionChoice = msg.open();
00256
00257 validSaveFileFound = (selectionChoice==SWT.YES);
00258 }
00259 }
00260 }
00261
00262 try
00263 {
00264 ObjectOutputStream out = null;
00265 try
00266 {
00267 out = new ObjectOutputStream(new FileOutputStream(fileName));
00268 out.writeObject(detailCanvas.save());
00269 }
00270 finally
00271 {
00272 out.close();
00273 }
00274 }
00275 catch (IOException e)
00276 {
00277 e.printStackTrace();
00278 }
00279
00280 }
00281
00282 public void open() {
00283 FileDialog openDialog;
00284 openDialog = new FileDialog(this.getViewSite().getShell(), SWT.OPEN);
00285 openDialog.setText("Open View Configuration");
00286 String fileName = "";
00287 boolean validFrameFound = false;
00288 while(!validFrameFound)
00289 {
00290 fileName = openDialog.open();
00291
00292 if (fileName == null) return;
00293 File binFile = new File(fileName);
00294
00295 if (binFile.exists())
00296 {
00297 ObjectInputStream in = null;
00298 try
00299 {
00300 in = new ObjectInputStream(new FileInputStream(fileName));
00301 Frame current = (Frame)in.readObject();
00302 detailCanvas.open(current);
00303 validFrameFound = true;
00304 }
00305 catch (IOException e)
00306 {
00307 validFrameFound = false;
00308 MessageDialog.openError(getViewSite().getShell(), "Error reading the file",
00309 "Fail to read the file: " + fileName );
00310 }
00311 catch (ClassNotFoundException e)
00312 {
00313 validFrameFound = false;
00314 MessageDialog.openError(getViewSite().getShell(), "Error reading the file",
00315 "File format is not recognized. Either the file is corrupted or it's an old format");
00316 }
00317 if (in != null) {
00318 try {
00319 in.close();
00320 } catch (IOException e) {
00321 MessageDialog.openWarning(getViewSite().getShell(), "Error closing the file",
00322 "Unable to close the file: " + fileName);
00323 }
00324 }
00325 }
00326 }
00327 }
00328
00329 public void goNorth() {
00330 detailCanvas.goNorth();
00331 }
00332
00333 public void goSouth() {
00334 detailCanvas.goSouth();
00335 }
00336
00337 public void goEast() {
00338 detailCanvas.goEast();
00339 }
00340
00341 public void goWest() {
00342 detailCanvas.goWest();
00343 }
00344 }