Package: VdmRtLogEditor$2

VdmRtLogEditor$2

nameinstructionbranchcomplexitylinemethod
run()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
{...}
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * RT Trace Viewer Plugin
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.plugins.rttraceviewer.view;
23:
24: import java.io.File;
25: import java.io.FileNotFoundException;
26: import java.io.FileReader;
27: import java.io.InputStreamReader;
28: import java.lang.reflect.InvocationTargetException;
29: import java.util.HashMap;
30: import java.util.Iterator;
31: import java.util.List;
32: import java.util.Vector;
33:
34: import org.eclipse.core.resources.IFile;
35: import org.eclipse.core.runtime.CoreException;
36: import org.eclipse.core.runtime.IPath;
37: import org.eclipse.core.runtime.IProgressMonitor;
38: import org.eclipse.core.runtime.Path;
39: import org.eclipse.core.runtime.Status;
40: import org.eclipse.jface.dialogs.ErrorDialog;
41: import org.eclipse.jface.dialogs.ProgressMonitorDialog;
42: import org.eclipse.jface.operation.IRunnableWithProgress;
43: import org.eclipse.swt.custom.SashForm;
44: import org.eclipse.swt.layout.FillLayout;
45: import org.eclipse.swt.widgets.Composite;
46: import org.eclipse.swt.widgets.Control;
47: import org.eclipse.swt.widgets.Display;
48: import org.eclipse.swt.widgets.FileDialog;
49: import org.eclipse.swt.widgets.Shell;
50: import org.eclipse.swt.widgets.TabFolder;
51: import org.eclipse.ui.IEditorInput;
52: import org.eclipse.ui.IEditorSite;
53: import org.eclipse.ui.IPathEditorInput;
54: import org.eclipse.ui.IViewPart;
55: import org.eclipse.ui.PartInitException;
56: import org.eclipse.ui.PlatformUI;
57: import org.eclipse.ui.part.EditorPart;
58: import org.eclipse.ui.part.FileEditorInput;
59: import org.overture.ide.core.utility.FileUtility;
60: import org.overture.ide.plugins.rttraceviewer.IRealTimeTaceViewer;
61: import org.overture.ide.plugins.rttraceviewer.TracefileViewerPlugin;
62: import org.overture.ide.plugins.rttraceviewer.data.Conjecture;
63: import org.overture.ide.plugins.rttraceviewer.data.Conjecture.ConjectureType;
64: import org.overture.ide.plugins.rttraceviewer.data.ConjectureData;
65: import org.overture.ide.plugins.rttraceviewer.view.GenericTabItem.AllowedOverrunDirection;
66: import org.overture.ide.ui.internal.util.ConsoleWriter;
67:
68: public class VdmRtLogEditor extends EditorPart implements IViewCallback
69: {
70:         static final boolean $assertionsDisabled = false;// !org/overturetool/tracefile/viewer/TracefileViewer.desiredAssertionStatus();
71:         private static final ConsoleWriter cw = new ConsoleWriter("RT Log viewer");
72:
73:         private File selectedFile;
74:         private Display display;
75:
76:         private SashForm form;
77:         private TabFolder folder;
78:         // private ValidationTable theConjectures;
79:         private GenericTabItem theArch;
80:         private GenericTabItem theOverview;
81:         private HashMap<Long, GenericTabItem> cpuTabs; // CPU Id, Tab
82:         private String fileName;
83:         private List<Long> theTimes;
84:         private long currentTime;
85:
86:         private boolean canExportJpg = true;
87:         private boolean canMoveHorizontal = true;
88:         private boolean canOpenValidation = true;
89:
90:         private TraceFileRunner traceRunner;
91:         private TracefileMarker theMarkers;
92:         private ConjectureData conjectureData;
93:
94:         public VdmRtLogEditor()
95:         {
96:                 conjectureData = new ConjectureData();
97:                 // theConjectures = null;
98:                 theArch = null;
99:                 theOverview = null;
100:                 cpuTabs = new HashMap<Long, GenericTabItem>();
101:                 fileName = null;
102:                 theTimes = null;
103:                 currentTime = 0L;
104:                 traceRunner = null;
105:                 theMarkers = null;
106:         }
107:
108:         @Override
109:         public void init(IEditorSite site, IEditorInput input)
110:                         throws PartInitException
111:         {
112:                 setSite(site);
113:                 setInput(input);
114:                 this.display = site.getShell().getDisplay();
115:
116:                 IPath path = ((IPathEditorInput) input).getPath();
117:
118:                 selectedFile = path.toFile();
119:                 fileName = selectedFile.getAbsolutePath();
120:         }
121:
122:         @Override
123:         public void createPartControl(Composite parent)
124:         {
125:                 Control[] childern = parent.getChildren();
126:                 for (Control control : childern)
127:                 {
128:                         control.setVisible(false);
129:                 }
130:                 form = new SashForm(parent, 512);
131:                 form.setLayout(new FillLayout());
132:                 folder = new TabFolder(form, 128);
133:                 // theConjectures = new ValidationTable(form, this);
134:                 // form.setWeights(new int[] { 85, 15 });
135:                 theArch = new GenericTabItem("Architecture overview", folder, AllowedOverrunDirection.Both);
136:                 theOverview = new GenericTabItem("Execution overview", folder, AllowedOverrunDirection.Vertical);
137:                 cw.clear();
138:                 IFile file = null;
139:                 try
140:                 {
141:
142:                         file = ((FileEditorInput) getEditorInput()).getFile();
143:
144:                         FileUtility.deleteMarker(file, null, TracefileViewerPlugin.PLUGIN_ID);
145:
146:                         theMarkers = new TracefileMarker(file);
147:
148:                         if (FileUtility.getContent(file).size() == 0)
149:                         {
150:                                 ErrorDialog.openError(getSite().getShell(), "Editor open", "File is empty", Status.CANCEL_STATUS);
151:                                 return;
152:                         }
153:
154:                 } catch (Exception e)
155:                 {
156:                         TracefileViewerPlugin.log(e);
157:                 } catch (OutOfMemoryError m)
158:                 {
159:                         showMessage("The trace file can not be visualized because the Java Virtual Machine ran out of heap space. Try to allow Overture more heap space using Virtual Machine custom arguments (e.g. -Xms40m -Xmx512m).");
160:                         return;
161:                 }
162:
163:                 try
164:                 {
165:                         parseFile(selectedFile.getAbsolutePath());
166:                 } catch (Exception e)
167:                 {
168:                         TracefileViewerPlugin.log(e);
169:                 }
170:                 openValidationConjectures(file);
171:         }
172:
173:         private void openValidationConjectures(IFile editorInputFile)
174:         {
175:                 IPath p = new Path(editorInputFile.getName());
176:                 p = p.addFileExtension("vtc");
177:                 IFile vtcFile = editorInputFile.getParent().getFile(p);
178:                 if (vtcFile.exists())
179:                 {
180:                         try
181:                         {
182:                                 ValidationConjecturesView v = getValidationConjecturesView();
183:                                 if (v != null)
184:                                 {
185:                                         conjectureData.clear();
186:                                         v.initializeLink(new InputStreamReader(vtcFile.getContents()), this);
187:                                         updateOverviewPage();
188:                                 }
189:                         } catch (PartInitException e)
190:                         {
191:                                 TracefileViewerPlugin.log(e);
192:                         } catch (CoreException e)
193:                         {
194:                                 TracefileViewerPlugin.log(e);
195:                         }
196:
197:                 }
198:
199:         }
200:
201:         private ValidationConjecturesView getValidationConjecturesView()
202:         {
203:                 IViewPart v;
204:                 try
205:                 {
206:                         if (PlatformUI.getWorkbench().isClosing())
207:                         {
208:                                 return null;
209:                         }
210:                         v = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(IRealTimeTaceViewer.CONJECTURE_VIEW_ID);
211:                         if (v instanceof ValidationConjecturesView)
212:                         {
213:                                 return (ValidationConjecturesView) v;
214:                         }
215:                 } catch (CoreException e)
216:                 {
217:                         TracefileViewerPlugin.log(e);
218:                 }
219:                 return null;
220:         }
221:
222:         void openValidationConjectures()
223:         {
224:                 FileDialog fDlg = new FileDialog(getSite().getShell());
225:                 String valFileName = fDlg.open();
226:
227:                 ValidationConjecturesView v = getValidationConjecturesView();
228:                 if (v != null)
229:                 {
230:                         conjectureData.clear();
231:                         try
232:                         {
233:                                 v.initializeLink(new FileReader(valFileName), this);
234:                         } catch (FileNotFoundException e)
235:                         {
236:                                 TracefileViewerPlugin.log(e);
237:                         }
238:                         updateOverviewPage();
239:                 }
240:         }
241:
242:         void diagramExportAction()
243:         {
244:                 theArch.exportJPG(fileName + ".arch");
245:                 theOverview.exportJPG(fileName + ".overview");
246:
247:                 for (GenericTabItem tab : cpuTabs.values())
248:                 {
249:                         tab.exportJPG(fileName + "." + tab.getName());
250:                 }
251:         }
252:
253:         void moveHorizontal()
254:         {
255:                 SelectTimeDialog theDialog = new SelectTimeDialog(folder.getShell(), theTimes, currentTime);
256:                 if (theDialog.open() == 0 && theDialog.selectedTime != currentTime)
257:                 {
258:                         currentTime = theDialog.selectedTime;
259:                         updateOverviewPage();
260:                 }
261:         }
262:
263:         void moveNextHorizontal()
264:         {
265:                 int index = theTimes.indexOf(currentTime);
266:
267:                 if (index + 1 < theTimes.size())
268:                 {
269:                         currentTime = theTimes.get(index + 1);
270:                         updateOverviewPage();
271:                 }
272:         }
273:
274:         void movePreviousHorizontal()
275:         {
276:                 int index = theTimes.indexOf(currentTime);
277:
278:                 if (index - 1 >= 0)
279:                 {
280:                         currentTime = theTimes.get(index - 1);
281:                         updateOverviewPage();
282:                 }
283:         }
284:
285:         void refresh()
286:         {
287:                 updateOverviewPage();
288:         }
289:
290:         /*
291:          * (non-Javadoc)
292:          * @see org.overture.ide.plugins.rttraceviewer.viewer.IViewCallback#panToTime(long, long)
293:          */
294:         public void panToTime(long time, long thrid)
295:         {
296:                 for (Iterator<Long> iter = theTimes.iterator(); iter.hasNext();)
297:                 {
298:                         long theTime = iter.next().longValue();
299:                         if (theTime < time)
300:                                 currentTime = theTime;
301:                 }
302:
303:                 folder.setSelection(theOverview.getTabItem());
304:                 updateOverviewPage();
305:         }
306:
307:         public void addLowerError(Long time, Long threadID, String name)
308:         {
309:                 conjectureData.addConjecture(new Conjecture(time, threadID, name, ConjectureType.SOURCE));
310:         }
311:
312:         public void addUpperError(Long time, Long threadID, String name)
313:         {
314:                 conjectureData.addConjecture(new Conjecture(time, threadID, name, ConjectureType.DESTINATION));
315:         }
316:
317:         private void parseFile(final String fname)
318:         {
319:
320:                 Shell shell = super.getSite().getShell();
321:
322:                 try
323:                 {
324:                         IRunnableWithProgress op = new IRunnableWithProgress()
325:                         {
326:
327:                                 public void run(IProgressMonitor monitor)
328:                                                 throws InvocationTargetException, InterruptedException
329:                                 {
330:                                         doParse(fname, monitor);
331:                                 }
332:
333:                         };
334:                         new ProgressMonitorDialog(shell).run(false, true, op);
335:                 } catch (InvocationTargetException e)
336:                 {
337:                         TracefileViewerPlugin.log(e);
338:
339:                 } catch (InterruptedException e)
340:                 {
341:                         TracefileViewerPlugin.log(e);
342:                 }
343:         }
344:
345:         @SuppressWarnings("deprecation")
346:         private void doParse(final String fname, IProgressMonitor monitor)
347:         {
348:                 TraceFileParser t = new TraceFileParser(fname);
349:                 t.start();
350:
351:                 while (!t.isFinished())
352:                 {
353:                         if (monitor.isCanceled())
354:                         {
355:                                 try
356:                                 {
357:                                         t.stop();
358:                                 } catch (Exception e)
359:                                 {
360:
361:                                 }
362:                         }
363:                 }
364:
365:                 if (t.error != null)
366:                 {
367:                         showMessage("Parser error " + t.error.getMessage());
368:                 } else if (t.data != null)
369:                 {
370:                         traceRunner = new TraceFileRunner(t.data, conjectureData);
371:                         theTimes = t.data.getEventManager().getEventTimes();
372:                         getSite().getShell().getDisplay().asyncExec(new Runnable()
373:                         {
374:                                 public void run()
375:                                 {
376:                                         createTabPages();
377:                                 }
378:                         });
379:
380:                 } else
381:                 {
382:                         showMessage("Unable to display log data. RT Logger is unset");
383:                 }
384:         }
385:
386:         private void createTabPages()
387:         {
388:                 try
389:                 {
390:                         traceRunner.drawArchitecture(theArch);
391:                         traceRunner.drawOverview(theOverview, new Long(currentTime));
392:                         canExportJpg = true;
393:                         canMoveHorizontal = true;
394:                         canOpenValidation = true;
395:                         Vector<Long> theCpus = traceRunner.getCpuIds();
396:
397:                         cpuTabs.clear();
398:
399:                         for (Long cpu : theCpus)
400:                         {
401:                                 String cpuName = traceRunner.getCpuName(cpu);
402:                                 GenericTabItem theDetail = new GenericTabItem(cpuName, folder, AllowedOverrunDirection.Horizontal);
403:                                 traceRunner.drawCpu(theDetail, cpu, new Long(currentTime));
404:                                 cpuTabs.put(cpu, theDetail);
405:                         }
406:                 } catch (Exception e)
407:                 {
408:                         TracefileViewerPlugin.log(e);
409:
410:                 }
411:
412:         }
413:
414:         /*
415:          * (non-Javadoc)
416:          * @see org.overture.ide.plugins.rttraceviewer.viewer.IViewCallback#updateOverviewPage ()
417:          */
418:         public void updateOverviewPage()
419:         {
420:                 try
421:                 {
422:                         theOverview.disposeFigures();
423:                         traceRunner.drawOverview(theOverview, new Long(currentTime));
424:
425:                         for (Long cpu : cpuTabs.keySet())
426:                         {
427:                                 GenericTabItem tab = cpuTabs.get(cpu);
428:                                 tab.disposeFigures();
429:                                 traceRunner.drawCpu(tab, cpu, new Long(currentTime));
430:                         }
431:
432:                 } catch (Exception e)
433:                 {
434:                         TracefileViewerPlugin.log(e);
435:                 }
436:         }
437:
438:         /*
439:          * (non-Javadoc)
440:          * @see org.overture.ide.plugins.rttraceviewer.viewer.IViewCallback#showMessage(java .lang.String)
441:          */
442:         public void showMessage(final String message)
443:         {
444:                 display.asyncExec(new Runnable()
445:                 {
446:
447:                         public void run()
448:                         {
449:
450:                                 cw.println(message);
451:                                 cw.show();
452:                         }
453:                 });
454:         }
455:
456:         @Override
457:         public void setFocus()
458:         {
459:                 folder.setFocus();
460:         }
461:
462:         @Override
463:         public void dispose()
464:         {
465:
466:                 try
467:                 {
468:                         ValidationConjecturesView v = getValidationConjecturesView();
469:                         if (v != null)
470:                         {
471:                                 v.unlink(this);
472:                         }
473:
474:                         theOverview.disposeFigures();
475:                         if (theMarkers != null)
476:                         {
477:                                 theMarkers.dispose();
478:                         }
479:
480:                 } catch (Exception e)
481:                 {
482:                         TracefileViewerPlugin.log(e);
483:                 }
484:         }
485:
486:         @Override
487:         public void doSave(IProgressMonitor monitor)
488:         {
489:         }
490:
491:         @Override
492:         public void doSaveAs()
493:         {
494:         }
495:
496:         @Override
497:         public boolean isSaveAsAllowed()
498:         {
499:                 return false;
500:         }
501:
502:         @Override
503:         public boolean isDirty()
504:         {
505:                 return false;
506:         }
507:
508:         public boolean canExportJpg()
509:         {
510:                 return canExportJpg;
511:         }
512:
513:         public boolean canMoveHorizontal()
514:         {
515:                 return canMoveHorizontal;
516:         }
517:
518:         public boolean canOpenValidation()
519:         {
520:                 return canOpenValidation;
521:         }
522:
523: }