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