Hi Xavier, I'm a bit confused, is this for the TimeChartView from the framework, or a modified one you use? Because the Time Chart view already does show bookmarks as a little banner above the corresponding events (see the code in TimeChartView$DecorateThread).
It also doesn't have a getExperiment() method? We usually work on generic ITmfTrace which may or may not be an experiment. A view or widget should know which trace(s) it's currently handling. Getting the bookmarks file is a bit tricky because of CTF traces whose resource is a folder (and you can't open a bookmark from a folder resource). There's a bug 409542 which if ever resolved, might make finding the bookmarks file easier... As for the code above, if you have access to the TimeGraphViewer, there's a public helper method now which could help: getXForTime(). Patrick On Fri, Oct 25, 2013 at 11:30 AM, Xavier Raynaud <xavier.rayn...@kalray.eu>wrote: > Hi Alexandre, > > Following our discussions at #linuxcon, please find hereafter the code I > wrote to draw bookmarks on TMF timegraphs. > I just override TimeGraphPresentationProvider.postDrawControl() method. > > However, this I also need to know the current experiment when this method > is called, I've added a field in the TimeGraphPresentation provider. > > Perhaps there is a better way to do that ? Perhaps using > TmfTraceManager.getCurrentTrace() ? > Where is the best place to contribute this code ? Directly in > TimeGraphPresentationProvider ? > > Xavier Raynaud > > ------------------------------ > > public abstract class KTimeGraphProvider extends > TimeGraphPresentationProvider { > > private TimeChartView fTimeChartView; > > public KTimeGraphProvider(TimeChartView tgv) { > super(); > this.fTimeChartView = tgv; > } > > abstract protected void postDrawEventImpl(IModelTimeEvent > currentEvent, Rectangle rect, GC gc); > > private void drawBookmarks(Rectangle bounds, GC gc) { > if (fTimeChartView != null) { > TmfExperiment experiment = fTimeChartView.getExperiment(); > TimeGraphViewer timeGraphViewer = > fTimeChartView.getTimeGraphViewer(); > if (experiment != null && timeGraphViewer != null) { > int nameSpace = timeGraphViewer.getNameSpace(); > long time0 = timeGraphViewer.getTime0(); > long time1 = timeGraphViewer.getTime1(); > try { > for (IMarker bookmark : > experiment.getBookmarksFile().findMarkers(IMarker.BOOKMARK, false, > IResource.DEPTH_ZERO)) { > int location = > bookmark.getAttribute(IMarker.LOCATION, -1); > if (location != -1) { > long rank = location; > ITmfContext context = > experiment.seekEvent(rank); > ITmfEvent ev = experiment.getNext(context); > context.dispose(); > if (ev != null) { > ITmfTimestamp ts = ev.getTimestamp(); > long selectedTime = ts.normalize(0, > -9).getValue(); > double pixelsPerNanoSec = (bounds.width - > nameSpace <= TimeGraphBaseControl.RIGHT_MARGIN) ? 0 > : (double) (bounds.width - > nameSpace - TimeGraphBaseControl.RIGHT_MARGIN) > / (time1 - time0); > int x = bounds.x + nameSpace + (int) > ((selectedTime - time0) * pixelsPerNanoSec); > if (x >= nameSpace && x < bounds.x + > bounds.width) { > > gc.setForeground(PlatformUI.getWorkbench().getDisplay() > > .getSystemColor(SWT.COLOR_BLACK)); > gc.drawLine(x, bounds.y, x, bounds.y + > bounds.height); > } > } > } > } > } catch (CoreException e) { > Activator.getDefault().getLog().log(e.getStatus()); > } > } > } > } > > /* > * (non-Javadoc) > * @see > * > org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider#postDrawControl(org.eclipse.swt > * .graphics.Rectangle, org.eclipse.swt.graphics.GC) > */ > @Override > public void postDrawControl(Rectangle bounds, GC gc) { > super.postDrawControl(bounds, gc); > drawBookmarks(bounds, gc); > } > } > > _______________________________________________ > linuxtools-dev mailing list > linuxtools-dev@eclipse.org > https://dev.eclipse.org/mailman/listinfo/linuxtools-dev > >
_______________________________________________ linuxtools-dev mailing list linuxtools-dev@eclipse.org https://dev.eclipse.org/mailman/listinfo/linuxtools-dev