import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jface.bindings.keys.KeyStroke;
-import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphSelection;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
private static String getTimegraphSelectionName(final SWTBotView view) {
final TimeGraphControl timegraph = view.bot().widget(WidgetOfType.widgetOfType(TimeGraphControl.class));
return UIThreadRunnable.syncExec(() -> {
- ISelection selection = timegraph.getSelectionTrace();
- if (selection instanceof TimeGraphSelection) {
- TimeGraphSelection sel = (TimeGraphSelection) selection;
- ITimeGraphEntry entry = (ITimeGraphEntry) sel.getFirstElement();
+ ITimeGraphEntry entry = timegraph.getSelectedTrace();
+ if (entry != null) {
return entry.getName();
}
return null;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphSelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchActionConstants;
/** Timeout between updates in the build thread in ms */
private static final long BUILD_UPDATE_TIMEOUT = 500;
- // Fraction of a function duration to be added as spacing
- private static final double SPACING_RATIO = 0.01;
-
private static final Image PROCESS_IMAGE = Activator.getDefault().getImageFromPath("icons/obj16/process_obj.gif"); //$NON-NLS-1$
private static final Image THREAD_IMAGE = Activator.getDefault().getImageFromPath("icons/obj16/thread_obj.gif"); //$NON-NLS-1$
private static final Image STACKFRAME_IMAGE = Activator.getDefault().getImageFromPath("icons/obj16/stckframe_obj.gif"); //$NON-NLS-1$
if (entry.getFunctionName().length() > 0) {
long entryTime = entry.getFunctionEntryTime();
long exitTime = entry.getFunctionExitTime();
- long spacingTime = (long) ((exitTime - entryTime) * SPACING_RATIO);
- entryTime -= spacingTime;
- exitTime += spacingTime;
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.fromNanos(entryTime), TmfTimestamp.fromNanos(exitTime));
broadcast(new TmfWindowRangeUpdatedSignal(CallStackView.this, range));
getTimeGraphViewer().setStartFinishTime(entryTime, exitTime);
public void mouseDoubleClick(MouseEvent e) {
TimeGraphControl timeGraphControl = getTimeGraphViewer().getTimeGraphControl();
ISelection selection = timeGraphControl.getSelection();
- if (selection instanceof TimeGraphSelection) {
- Object o = ((TimeGraphSelection) selection).getFirstElement();
- if (o instanceof CallStackEvent) {
- CallStackEvent event = (CallStackEvent) o;
- long startTime = event.getTime();
- long endTime = startTime + event.getDuration();
- long spacingTime = (long) ((endTime - startTime) * SPACING_RATIO);
- startTime -= spacingTime;
- endTime += spacingTime;
- TmfTimeRange range = new TmfTimeRange(TmfTimestamp.fromNanos(startTime), TmfTimestamp.fromNanos(endTime));
- broadcast(new TmfWindowRangeUpdatedSignal(CallStackView.this, range));
- getTimeGraphViewer().setStartFinishTime(startTime, endTime);
- startZoomThread(startTime, endTime);
+ if (selection instanceof IStructuredSelection) {
+ for (Object object : ((IStructuredSelection) selection).toList()) {
+ if (object instanceof CallStackEvent) {
+ CallStackEvent event = (CallStackEvent) object;
+ long startTime = event.getTime();
+ long endTime = startTime + event.getDuration();
+ TmfTimeRange range = new TmfTimeRange(TmfTimestamp.fromNanos(startTime), TmfTimestamp.fromNanos(endTime));
+ broadcast(new TmfWindowRangeUpdatedSignal(CallStackView.this, range));
+ getTimeGraphViewer().setStartFinishTime(startTime, endTime);
+ startZoomThread(startTime, endTime);
+ break;
+ }
}
}
}
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
return super.setFocus();
}
+ /**
+ * Returns the current selection for this time graph. If a time graph entry
+ * is selected, it will be the first element in the selection. If a time
+ * event is selected, it will be the second element in the selection.
+ *
+ * @return the current selection
+ */
@Override
public ISelection getSelection() {
- TimeGraphSelection sel = new TimeGraphSelection();
- ITimeGraphEntry trace = getSelectedTrace();
- if (null != trace && null != fTimeProvider) {
+ ITimeGraphEntry entry = getSelectedTrace();
+ if (null != entry && null != fTimeProvider) {
long selectedTime = fTimeProvider.getSelectionBegin();
- ITimeEvent event = Utils.findEvent(trace, selectedTime, 0);
- sel.add(trace);
- if (event != null) {
- sel.add(event);
+ ITimeEvent event = Utils.findEvent(entry, selectedTime, 0);
+ if (event == null) {
+ return new StructuredSelection(entry);
}
+ return new StructuredSelection(new Object[] { entry, event });
}
- return sel;
+ return StructuredSelection.EMPTY;
}
/**
* @return The selection
*/
public ISelection getSelectionTrace() {
- TimeGraphSelection sel = new TimeGraphSelection();
- ITimeGraphEntry trace = getSelectedTrace();
- if (null != trace) {
- sel.add(trace);
+ ITimeGraphEntry entry = getSelectedTrace();
+ if (null != entry) {
+ return new StructuredSelection(entry);
}
- return sel;
+ return StructuredSelection.EMPTY;
}
/**
@Override
public void setSelection(ISelection selection) {
- if (selection instanceof TimeGraphSelection) {
- TimeGraphSelection sel = (TimeGraphSelection) selection;
- Object ob = sel.getFirstElement();
+ if (selection instanceof IStructuredSelection) {
+ Object ob = ((IStructuredSelection) selection).getFirstElement();
if (ob instanceof ITimeGraphEntry) {
- ITimeGraphEntry trace = (ITimeGraphEntry) ob;
- selectItem(trace, false);
+ selectItem((ITimeGraphEntry) ob, false);
}
}
/*****************************************************************************
- * Copyright (c) 2007, 2014 Intel Corporation, Ericsson
+ * Copyright (c) 2007, 2016 Intel Corporation, Ericsson
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
import java.util.List;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
/**
* Selection object for the time graph scale
* @version 1.0
* @author Alvaro Sanchez-Leon
* @author Patrick Tasse
+ * @deprecated Use {@link StructuredSelection} instead.
*/
+@Deprecated
public class TimeGraphSelection implements IStructuredSelection {
private List<Object> list = new ArrayList<>();