use of org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl in project tracecompass by tracecompass.
the class ResourcesViewTest method testMarkerAxis.
/**
* Test the marker axis
*/
@Test
public void testMarkerAxis() {
SWTBotView viewBot = getViewBot();
/* center window range of first lost event range */
ITmfTimestamp startTime = LOST_EVENT_TIME1.normalize(-10000000L, ITmfTimestamp.NANOSECOND_SCALE);
ITmfTimestamp endTime = LOST_EVENT_END1.normalize(10000000L, ITmfTimestamp.NANOSECOND_SCALE);
TmfTimeRange range = new TmfTimeRange(startTime, endTime);
TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, range));
fBot.waitUntil(ConditionHelpers.windowRange(range));
/* set selection to window start time */
TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, startTime));
timeGraphIsReadyCondition(new TmfTimeRange(startTime, startTime), startTime);
/* get marker axis size with one category */
final TimeGraphMarkerAxis markerAxis = viewBot.bot().widget(WidgetOfType.widgetOfType(TimeGraphMarkerAxis.class));
final Point size1 = getSize(markerAxis);
/* add bookmark at window start time */
viewBot.toolbarButton(ADD_BOOKMARK).click();
SWTBot dialogBot = fBot.shell(ADD_BOOKMARK_DIALOG).bot();
dialogBot.text().setText("B");
dialogBot.button(OK).click();
/* get marker axis size with two categories */
final Point size2 = getSize(markerAxis);
final int rowHeight = size2.y - size1.y;
/*
* get the state area bounds, since we don't know the name space width
*/
final TimeGraphControl timeGraph = viewBot.bot().widget(WidgetOfType.widgetOfType(TimeGraphControl.class));
int x0 = getXForTime(timeGraph, startTime.toNanos());
int x1 = getXForTime(timeGraph, endTime.toNanos());
/*
* click at the center of the marker axis width and first row height, it
* should be within the lost event range
*/
final SWTBotCanvas markerAxisCanvas = new SWTBotCanvas(markerAxis);
markerAxisCanvas.click((x0 + x1) / 2, TOP_MARGIN + rowHeight / 2);
fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(LOST_EVENT_TIME1, LOST_EVENT_END1)));
/*
* click near the left of the marker axis width and center of second row
* height, it should be on the bookmark label
*/
markerAxisCanvas.click(x0 + 2, TOP_MARGIN + rowHeight + rowHeight / 2);
fBot.waitUntil(ConditionHelpers.selectionRange(new TmfTimeRange(startTime, startTime)));
/* click "Remove Bookmark" */
viewBot.toolbarButton(REMOVE_BOOKMARK).click();
assertEquals(size1, getSize(markerAxis));
/* click the 'expanded' icon to collapse */
markerAxisCanvas.click(TOGGLE_SIZE.x / 2, TOGGLE_SIZE.y / 2);
assertEquals(TOGGLE_SIZE.y, getSize(markerAxis).y);
/* click the 'collapsed' icon to expand */
markerAxisCanvas.click(TOGGLE_SIZE.x / 2, TOGGLE_SIZE.y / 2);
assertEquals(size1, getSize(markerAxis));
/* click on the 'X' icon to hide the 'Lost Events' marker category */
markerAxisCanvas.click(TOGGLE_SIZE.x + HIDE_SIZE.x / 2, TOP_MARGIN + HIDE_SIZE.y / 2);
assertEquals(0, getSize(markerAxis).y);
/* show Lost Events markers */
viewBot.viewMenu(LOST_EVENTS).click();
SWTBotUtils.waitUntil(ma -> size1.equals(getSize(ma)), markerAxis, "Lost Events did not reappear");
}
use of org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl in project tracecompass by tracecompass.
the class AbstractTimeGraphView method getVisibleItems.
/**
* Get the set of items that are currently visible in the view, according to
* the visible area height, the vertical scroll position and the expanded
* state of the items. A buffer of items above and below can be included.
*
* @param buffer
* number of items above and below the current visible area that
* should be included
* @return a set of visible items in the view with buffer above and below
* @since 4.2
*/
@NonNull
protected Set<@NonNull TimeGraphEntry> getVisibleItems(int buffer) {
TimeGraphControl timeGraphControl = fTimeGraphViewer.getTimeGraphControl();
if (timeGraphControl.isDisposed()) {
return Collections.emptySet();
}
int start = Integer.max(0, fTimeGraphViewer.getTopIndex() - buffer);
int end = Integer.min(fTimeGraphViewer.getExpandedElementCount() - 1, fTimeGraphViewer.getTopIndex() + timeGraphControl.countPerPage() + buffer);
Set<@NonNull TimeGraphEntry> visible = new HashSet<>(end - start + 1);
for (int i = start; i <= end; i++) {
/*
* Use the getExpandedElement by index to avoid creating a copy of all the the
* elements.
*/
TimeGraphEntry element = (TimeGraphEntry) timeGraphControl.getExpandedElement(i);
if (element != null) {
visible.add(element);
}
}
return visible;
}
use of org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl in project tracecompass by tracecompass.
the class AbstractTimeGraphView method createPartControl.
// ------------------------------------------------------------------------
// ViewPart
// ------------------------------------------------------------------------
@Override
public void createPartControl(Composite parent) {
super.createPartControl(parent);
TimeGraphViewer timeGraphViewer = new TimeGraphViewer(parent, SWT.NONE);
fTimeGraphViewer = timeGraphViewer;
if (fLabelProvider != null) {
timeGraphViewer.setTimeGraphLabelProvider(fLabelProvider);
}
if (fLegendProvider != null) {
timeGraphViewer.setLegendProvider(fLegendProvider);
}
if (fColumns != null) {
timeGraphViewer.setColumns(fColumns);
if (fColumnComparators != null) {
createColumnSelectionListener(timeGraphViewer.getTree());
}
}
timeGraphViewer.setTimeGraphContentProvider(fTimeGraphContentProvider);
timeGraphViewer.setFilterContentProvider(fFilterContentProvider != null ? fFilterContentProvider : fTimeGraphContentProvider);
timeGraphViewer.setFilterLabelProvider(fFilterLabelProvider);
timeGraphViewer.setFilterColumns(fFilterColumns);
timeGraphViewer.addSelectionListener(fMetadataSelectionListener);
ITimeGraphPresentationProvider presentationProvider = getPresentationProvider();
timeGraphViewer.setTimeGraphProvider(presentationProvider);
presentationProvider.addColorListener(stateItems -> TimeGraphStyleUtil.loadValues(getPresentationProvider()));
presentationProvider.refresh();
timeGraphViewer.setAutoExpandLevel(fAutoExpandLevel);
timeGraphViewer.setWeights(fWeight);
TimeGraphControl timeGraphControl = timeGraphViewer.getTimeGraphControl();
Action timeEventFilterAction = new Action() {
@Override
public void run() {
int xCoord = timeGraphControl.toControl(timeGraphControl.getDisplay().getCursorLocation()).x;
if ((timeGraphViewer.getNameSpace() < xCoord) && (xCoord < timeGraphControl.getSize().x)) {
if (fTimeEventFilterDialog != null) {
fTimeEventFilterDialog.close();
fTimeEventFilterDialog = null;
}
fTimeEventFilterDialog = new TimeEventFilterDialog(timeGraphControl.getShell(), AbstractTimeGraphView.this, getTimeGraphViewer().getTimeGraphControl());
fTimeEventFilterDialog.open();
}
}
};
fTimeEventFilterAction = timeEventFilterAction;
timeGraphViewer.addRangeListener(event -> {
final long startTime = event.getStartTime();
final long endTime = event.getEndTime();
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.fromNanos(startTime), TmfTimestamp.fromNanos(endTime));
broadcast(new TmfWindowRangeUpdatedSignal(AbstractTimeGraphView.this, range, fTrace));
startZoomThread(startTime, endTime);
});
timeGraphViewer.addTimeListener(event -> {
ITmfTimestamp startTime = TmfTimestamp.fromNanos(event.getBeginTime());
ITmfTimestamp endTime = TmfTimestamp.fromNanos(event.getEndTime());
broadcast(new TmfSelectionRangeUpdatedSignal(AbstractTimeGraphView.this, startTime, endTime, fTrace));
});
timeGraphViewer.addBookmarkListener(new ITimeGraphBookmarkListener() {
@Override
public void bookmarkAdded(final TimeGraphBookmarkEvent event) {
try {
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
IMarkerEvent bookmark = event.getBookmark();
IFile editorFile = fEditorFile;
if (editorFile == null) {
return;
}
IMarker marker = editorFile.createMarker(IMarker.BOOKMARK);
marker.setAttribute(IMarker.MESSAGE, bookmark.getLabel());
marker.setAttribute(ITmfMarker.MARKER_TIME, Long.toString(bookmark.getTime()));
if (bookmark.getDuration() > 0) {
marker.setAttribute(ITmfMarker.MARKER_DURATION, Long.toString(bookmark.getDuration()));
marker.setAttribute(IMarker.LOCATION, NLS.bind(org.eclipse.tracecompass.internal.tmf.ui.Messages.TmfMarker_LocationTimeRange, TmfTimestamp.fromNanos(bookmark.getTime()), TmfTimestamp.fromNanos(bookmark.getTime() + bookmark.getDuration())));
} else {
marker.setAttribute(IMarker.LOCATION, NLS.bind(org.eclipse.tracecompass.internal.tmf.ui.Messages.TmfMarker_LocationTime, TmfTimestamp.fromNanos(bookmark.getTime())));
}
marker.setAttribute(ITmfMarker.MARKER_COLOR, bookmark.getColor().toString());
}
}, null);
} catch (CoreException e) {
Activator.getDefault().logError(e.getMessage());
}
}
@Override
public void bookmarkRemoved(TimeGraphBookmarkEvent event) {
try {
IMarkerEvent bookmark = event.getBookmark();
IFile editorFile = fEditorFile;
if (editorFile == null) {
return;
}
IMarker[] markers = editorFile.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO);
for (IMarker marker : markers) {
if (bookmark.getLabel().equals(marker.getAttribute(IMarker.MESSAGE)) && Long.toString(bookmark.getTime()).equals(marker.getAttribute(ITmfMarker.MARKER_TIME, (String) null)) && Long.toString(bookmark.getDuration()).equals(marker.getAttribute(ITmfMarker.MARKER_DURATION, Long.toString(0))) && bookmark.getColor().toString().equals(marker.getAttribute(ITmfMarker.MARKER_COLOR))) {
marker.delete();
break;
}
}
} catch (CoreException e) {
Activator.getDefault().logError(e.getMessage());
}
}
});
fTimeGraphViewer.addMarkerListener(() -> restartZoomThread());
timeGraphControl.addPaintListener(new PaintListener() {
/**
* This paint control allows the virtual time graph refresh to occur on paint
* events instead of just scrolling the time axis or zooming. To avoid
* refreshing the model on every paint event, we use a TmfUiRefreshHandler to
* coalesce requests and only execute the last one, we also check if the entries
* have changed to avoid useless model refresh.
*
* @param e
* paint event on the visible area
*/
@Override
public void paintControl(PaintEvent e) {
TmfUiRefreshHandler.getInstance().queueUpdate(this, () -> {
if (timeGraphControl.isDisposed()) {
return;
}
int timeSpace = getTimeGraphViewer().getTimeSpace();
Set<@NonNull TimeGraphEntry> newSet = getVisibleItems(DEFAULT_BUFFER_SIZE);
if (fPrevTimeSpace != timeSpace || !fVisibleEntries.equals(newSet)) {
/*
* Start a zoom thread if the set of visible entries has changed. We do not use
* lists as the order is not important. We cannot use the start index / size of
* the visible entries as we can collapse / reorder events.
*/
fVisibleEntries = newSet;
fPrevTimeSpace = timeSpace;
startZoomThread(getTimeGraphViewer().getTime0(), getTimeGraphViewer().getTime1());
}
});
}
});
IStatusLineManager statusLineManager = getViewSite().getActionBars().getStatusLineManager();
timeGraphControl.setStatusLineManager(statusLineManager);
// View Action Handling
makeActions();
contributeToActionBars();
ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
if (trace != null) {
traceSelected(new TmfTraceSelectedSignal(this, trace));
}
// make selection available to other views
IWorkbenchPartSite site = getSite();
site.setSelectionProvider(timeGraphViewer.getSelectionProvider());
ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
createContextMenu();
fPartListener = new TimeGraphPartListener();
site.getPage().addPartListener(fPartListener);
fPartListener2 = new TimeGraphPartListener2();
site.getPage().addPartListener(fPartListener2);
fOriginalTabLabel = getPartName();
fContextService = site.getWorkbenchWindow().getService(IContextService.class);
if (timeGraphControl.isInFocus()) {
activateContextService();
}
timeGraphControl.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
deactivateContextService();
}
@Override
public void focusGained(FocusEvent e) {
activateContextService();
}
});
updateTimeFormat();
}
use of org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl in project tracecompass by tracecompass.
the class BaseDataProviderTimeGraphView method createTimeEventContextMenu.
private void createTimeEventContextMenu() {
MenuManager eventMenuManager = new MenuManager();
eventMenuManager.setRemoveAllWhenShown(true);
TimeGraphControl timeGraphControl = getTimeGraphViewer().getTimeGraphControl();
final Menu timeEventMenu = eventMenuManager.createContextMenu(timeGraphControl);
timeGraphControl.addTimeEventMenuListener(event -> {
Menu menu = timeEventMenu;
if (event.data instanceof TimeEvent) {
timeGraphControl.setMenu(menu);
return;
}
timeGraphControl.setMenu(null);
event.doit = false;
});
eventMenuManager.addMenuListener(manager -> {
fillTimeEventContextMenu(eventMenuManager);
eventMenuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
});
getSite().registerContextMenu(eventMenuManager, getTimeGraphViewer().getSelectionProvider());
}
use of org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl in project tracecompass by tracecompass.
the class FlameGraphView method createPartControl.
@Override
public void createPartControl(Composite parent) {
super.createPartControl(parent);
fTimeGraphViewer = new TimeGraphViewer(parent, SWT.NONE);
FlameGraphContentProvider timeGraphContentProvider = new FlameGraphContentProvider();
fTimeGraphContentProvider = timeGraphContentProvider;
fTimeGraphViewer.setTimeGraphContentProvider(timeGraphContentProvider);
fTimeGraphViewer.setTimeGraphProvider(new FlameGraphPresentationProvider());
ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
if (trace != null) {
traceSelected(new TmfTraceSelectedSignal(this, trace));
}
contributeToActionBars();
loadSortOption();
loadContentPresentationOption();
TmfSignalManager.register(this);
getSite().setSelectionProvider(fTimeGraphViewer.getSelectionProvider());
IMenuManager menuManager = getViewSite().getActionBars().getMenuManager();
MenuManager item = new MenuManager(Messages.FlameGraphView_ContentPresentation);
item.setRemoveAllWhenShown(true);
item.addMenuListener(manager -> {
item.add(VIEW_BY_THREAD);
item.add(VIEW_AGGREGATE);
});
menuManager.add(item);
createTimeEventContextMenu();
fTimeGraphViewer.getTimeGraphControl().addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
TimeGraphControl timeGraphControl = getTimeGraphViewer().getTimeGraphControl();
ISelection selection = timeGraphControl.getSelection();
if (selection instanceof IStructuredSelection) {
for (Object object : ((IStructuredSelection) selection).toList()) {
if (object instanceof FlamegraphEvent) {
FlamegraphEvent event = (FlamegraphEvent) object;
long startTime = event.getTime();
long endTime = startTime + event.getDuration();
getTimeGraphViewer().setStartFinishTimeNotify(startTime, endTime);
break;
}
}
}
}
});
}
Aggregations