tmf: Support auto-expand level in time graph widgets
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / TimeGraphViewer.java
index 5720623fcc9bf0911b8ae42e3d4366911c7d54dd..85f3c78ee3f03695d8c36676cf798f0f16cf75ec 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Copyright (c) 2007, 2008 Intel Corporation, 2009, 2010, 2011, 2012 Ericsson.
+ * Copyright (c) 2007, 2014 Intel Corporation, Ericsson, others
  * 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
  *   Alexander N. Alexeev, Intel - Add monitors statistics support
  *   Alvaro Sanchez-Leon - Adapted for TMF
  *   Patrick Tasse - Refactoring
- *
+ *   Geneviève Bastien - Add event links between entries
  *****************************************************************************/
 
 package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;
 
 import java.util.ArrayList;
+import java.util.List;
 
 import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
 import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.ViewerFilter;
 import org.eclipse.linuxtools.internal.tmf.ui.Activator;
 import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;
 import org.eclipse.linuxtools.internal.tmf.ui.Messages;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs.TimeGraphLegend;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ILinkEvent;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider;
@@ -32,6 +38,7 @@ import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphScale;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphTooltipHandler;
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.ControlAdapter;
 import org.eclipse.swt.events.ControlEvent;
@@ -60,52 +67,69 @@ import org.eclipse.swt.widgets.Slider;
  */
 public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
 
-    /** vars */
-    private long _minTimeInterval;
-    private long _selectedTime;
-    private ITimeGraphEntry _selectedEntry;
-    private long _beginTime;
-    private long _endTime;
-    private long _time0;
-    private long _time1;
-    private long _time0_;
-    private long _time1_;
-    private long _time0_extSynch = 0;
-    private long _time1_extSynch = 0;
-    private boolean _timeRangeFixed;
-    private int _nameWidthPref = 200;
-    private int _minNameWidth = 6;
-    private int _nameWidth;
-    private Composite _dataViewer;
-
-    private TimeGraphControl _stateCtrl;
-    private TimeGraphScale _timeScaleCtrl;
-    private Slider _verticalScrollBar;
-    private TimeGraphTooltipHandler _threadTip;
-    private TimeGraphColorScheme _colors;
+    /** Constant indicating that all levels of the time graph should be expanded
+     * @since 3.1 */
+    public static final int ALL_LEVELS = AbstractTreeViewer.ALL_LEVELS;
+
+    private static final int DEFAULT_NAME_WIDTH = 200;
+    private static final int MIN_NAME_WIDTH = 6;
+    private static final int MAX_NAME_WIDTH = 1000;
+    private static final int DEFAULT_HEIGHT = 22;
+    private static final long RECENTERING_MARGIN_FACTOR = 50;
+    private static final String HIDE_ARROWS_KEY = "hide.arrows"; //$NON-NLS-1$
+
+    private long fMinTimeInterval;
+    private ITimeGraphEntry fSelectedEntry;
+    private long fBeginTime;
+    private long fEndTime;
+    private long fTime0;
+    private long fTime1;
+    private long fSelectionBegin = 0;
+    private long fSelectionEnd = 0;
+    private long fTime0Bound;
+    private long fTime1Bound;
+    private long fTime0ExtSynch = 0;
+    private long fTime1ExtSynch = 0;
+    private boolean fTimeRangeFixed;
+    private int fNameWidthPref = DEFAULT_NAME_WIDTH;
+    private int fMinNameWidth = MIN_NAME_WIDTH;
+    private int fNameWidth;
+    private Composite fDataViewer;
+
+    private TimeGraphControl fTimeGraphCtrl;
+    private TimeGraphScale fTimeScaleCtrl;
+    private Slider fVerticalScrollBar;
+    private TimeGraphColorScheme fColorScheme;
+    private Object fInputElement;
+    private ITimeGraphContentProvider fTimeGraphContentProvider;
     private ITimeGraphPresentationProvider fTimeGraphProvider;
 
-    ArrayList<ITimeGraphSelectionListener> fSelectionListeners = new ArrayList<ITimeGraphSelectionListener>();
-    ArrayList<ITimeGraphTimeListener> fTimeListeners = new ArrayList<ITimeGraphTimeListener>();
-    ArrayList<ITimeGraphRangeListener> fRangeListeners = new ArrayList<ITimeGraphRangeListener>();
-
-    // Calender Time format, using Epoch reference or Relative time
-    // format(default
-    private boolean calendarTimeFormat = false;
-    private int borderWidth = 0;
-    private int timeScaleHeight = 22;
-
-    private Action resetScale;
-    private Action showLegendAction;
-    private Action nextEventAction;
-    private Action prevEventAction;
-    private Action nextItemAction;
-    private Action previousItemAction;
-    private Action zoomInAction;
-    private Action zoomOutAction;
-
-    /**
-     * Standard constructor
+    private List<ITimeGraphSelectionListener> fSelectionListeners = new ArrayList<>();
+    private List<ITimeGraphTimeListener> fTimeListeners = new ArrayList<>();
+    private List<ITimeGraphRangeListener> fRangeListeners = new ArrayList<>();
+
+    // Time format, using Epoch reference, Relative time format(default) or
+    // Number
+    private TimeFormat fTimeFormat = TimeFormat.RELATIVE;
+    private int fBorderWidth = 0;
+    private int fTimeScaleHeight = DEFAULT_HEIGHT;
+
+    private Action fResetScaleAction;
+    private Action fShowLegendAction;
+    private Action fNextEventAction;
+    private Action fPrevEventAction;
+    private Action fNextItemAction;
+    private Action fPreviousItemAction;
+    private Action fZoomInAction;
+    private Action fZoomOutAction;
+    private Action fHideArrowsAction;
+    private Action fFollowArrowFwdAction;
+    private Action fFollowArrowBwdAction;
+
+    /**
+     * Standard constructor.
+     * <p>
+     * The default timegraph content provider accepts an ITimeGraphEntry[] as input element.
      *
      * @param parent
      *            The parent UI composite object
@@ -114,45 +138,109 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      */
     public TimeGraphViewer(Composite parent, int style) {
         createDataViewer(parent, style);
+        fTimeGraphContentProvider = new ITimeGraphContentProvider() {
+            @Override
+            public ITimeGraphEntry[] getElements(Object inputElement) {
+                if (inputElement instanceof ITimeGraphEntry[]) {
+                    return (ITimeGraphEntry[]) inputElement;
+                }
+                return new ITimeGraphEntry[0];
+            }
+        };
+    }
+
+    /**
+     * Sets the timegraph content provider used by this timegraph viewer.
+     *
+     * @param timeGraphContentProvider
+     *            the timegraph content provider
+     *
+     * @since 3.0
+     */
+    public void setTimeGraphContentProvider(ITimeGraphContentProvider timeGraphContentProvider) {
+        fTimeGraphContentProvider = timeGraphContentProvider;
     }
 
     /**
-     * Sets the timegraph provider used by this timegraph viewer.
+     * Gets the timegraph content provider used by this timegraph viewer.
+     *
+     * @return the timegraph content provider
      *
-     * @param timeGraphProvider the timegraph provider
+     * @since 3.0
+     */
+    public ITimeGraphContentProvider getTimeGraphContentProvider() {
+        return fTimeGraphContentProvider;
+    }
+
+    /**
+     * Sets the timegraph presentation provider used by this timegraph viewer.
+     *
+     * @param timeGraphProvider
+     *            the timegraph provider
      */
     public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider) {
         fTimeGraphProvider = timeGraphProvider;
-        _stateCtrl.setTimeGraphProvider(timeGraphProvider);
-        _threadTip = new TimeGraphTooltipHandler(_dataViewer.getShell(), fTimeGraphProvider, this);
-        _threadTip.activateHoverHelp(_stateCtrl);
+        fTimeGraphCtrl.setTimeGraphProvider(timeGraphProvider);
+        TimeGraphTooltipHandler toolTipHandler = new TimeGraphTooltipHandler(fTimeGraphProvider, this);
+        toolTipHandler.activateHoverHelp(fTimeGraphCtrl);
     }
 
     /**
      * Sets or clears the input for this time graph viewer.
-     * The input array should only contain top-level elements.
      *
-     * @param input the input of this time graph viewer, or <code>null</code> if none
+     * @param inputElement
+     *            The input of this time graph viewer, or <code>null</code> if
+     *            none
+     *
+     * @since 3.0
      */
-    public void setInput(ITimeGraphEntry[] input) {
-        if (null != _stateCtrl) {
-            if (null == input) {
-                input = new ITimeGraphEntry[0];
-            }
+    public void setInput(Object inputElement) {
+        fInputElement = inputElement;
+        ITimeGraphEntry[] input = fTimeGraphContentProvider.getElements(inputElement);
+
+        if (fTimeGraphCtrl != null) {
             setTimeRange(input);
-            _verticalScrollBar.setEnabled(true);
+            fVerticalScrollBar.setEnabled(true);
             setTopIndex(0);
-            _selectedTime = 0;
-            _selectedEntry = null;
+            fSelectionBegin = 0;
+            fSelectionEnd = 0;
+            fSelectedEntry = null;
             refreshAllData(input);
         }
     }
 
+    /**
+     * Gets the input for this time graph viewer.
+     *
+     * @return The input of this time graph viewer, or <code>null</code> if none
+     *
+     * @since 3.0
+     */
+    public Object getInput() {
+        return fInputElement;
+    }
+
+    /**
+     * Sets (or clears if null) the list of links to display on this combo
+     *
+     * @param links
+     *            the links to display in this time graph combo
+     * @since 2.1
+     */
+    public void setLinks(List<ILinkEvent> links) {
+        if (fTimeGraphCtrl != null) {
+            fTimeGraphCtrl.refreshArrows(links);
+        }
+    }
+
     /**
      * Refresh the view
      */
     public void refresh() {
-        setInput(_stateCtrl.getTraces());
+        ITimeGraphEntry[] input = fTimeGraphContentProvider.getElements(fInputElement);
+        setTimeRange(input);
+        fVerticalScrollBar.setEnabled(true);
+        refreshAllData(input);
     }
 
     /**
@@ -189,110 +277,128 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      */
     public void modelUpdate(ITimeGraphEntry[] traces, long start,
             long end, boolean updateTimeBounds) {
-        if (null != _stateCtrl) {
-            //loadOptions();
+        if (null != fTimeGraphCtrl) {
             updateInternalData(traces, start, end);
             if (updateTimeBounds) {
-                _timeRangeFixed = true;
+                fTimeRangeFixed = true;
                 // set window to match limits
-                setStartFinishTime(_time0_, _time1_);
+                setStartFinishTime(fTime0Bound, fTime1Bound);
             } else {
-                _stateCtrl.redraw();
-                _timeScaleCtrl.redraw();
+                fTimeGraphCtrl.redraw();
+                fTimeScaleCtrl.redraw();
             }
         }
     }
 
+    /**
+     * @return The string representing the view type
+     */
     protected String getViewTypeStr() {
         return "viewoption.threads"; //$NON-NLS-1$
     }
 
-    int getMarginWidth(int idx) {
+    int getMarginWidth() {
         return 0;
     }
 
-    int getMarginHeight(int idx) {
+    int getMarginHeight() {
         return 0;
     }
 
     void loadOptions() {
-        _minTimeInterval = 1;
-        _selectedTime = -1;
-        _nameWidth = Utils.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
-                _nameWidthPref, _minNameWidth, 1000);
+        fMinTimeInterval = 1;
+        fSelectionBegin = -1;
+        fSelectionEnd = -1;
+        fNameWidth = Utils.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
+                fNameWidthPref, fMinNameWidth, MAX_NAME_WIDTH);
     }
 
     void saveOptions() {
-        Utils.saveIntOption(getPreferenceString("namewidth"), _nameWidth); //$NON-NLS-1$
+        Utils.saveIntOption(getPreferenceString("namewidth"), fNameWidth); //$NON-NLS-1$
     }
 
+    /**
+     * Create a data viewer.
+     *
+     * @param parent
+     *            Parent composite
+     * @param style
+     *            Style to use
+     * @return The new data viewer
+     */
     protected Control createDataViewer(Composite parent, int style) {
         loadOptions();
-        _colors = new TimeGraphColorScheme();
-        _dataViewer = new Composite(parent, style) {
+        fColorScheme = new TimeGraphColorScheme();
+        fDataViewer = new Composite(parent, style) {
             @Override
             public void redraw() {
-                _timeScaleCtrl.redraw();
-                _stateCtrl.redraw();
+                fTimeScaleCtrl.redraw();
+                fTimeGraphCtrl.redraw();
                 super.redraw();
             }
         };
         GridLayout gl = new GridLayout(2, false);
-        gl.marginHeight = borderWidth;
+        gl.marginHeight = fBorderWidth;
         gl.marginWidth = 0;
         gl.verticalSpacing = 0;
         gl.horizontalSpacing = 0;
-        _dataViewer.setLayout(gl);
+        fDataViewer.setLayout(gl);
 
-        _timeScaleCtrl = new TimeGraphScale(_dataViewer, _colors);
-        _timeScaleCtrl.setTimeProvider(this);
-        _timeScaleCtrl.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
-        _timeScaleCtrl.setHeight(timeScaleHeight);
+        fTimeScaleCtrl = new TimeGraphScale(fDataViewer, fColorScheme);
+        fTimeScaleCtrl.setTimeProvider(this);
+        fTimeScaleCtrl.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
+        fTimeScaleCtrl.setHeight(fTimeScaleHeight);
 
-        _verticalScrollBar = new Slider(_dataViewer, SWT.VERTICAL | SWT.NO_FOCUS);
-        _verticalScrollBar.setLayoutData(new GridData(SWT.DEFAULT, SWT.FILL, false, true, 1, 2));
-        _verticalScrollBar.addSelectionListener(new SelectionAdapter() {
+        fVerticalScrollBar = new Slider(fDataViewer, SWT.VERTICAL | SWT.NO_FOCUS);
+        fVerticalScrollBar.setLayoutData(new GridData(SWT.DEFAULT, SWT.FILL, false, true, 1, 2));
+        fVerticalScrollBar.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                setTopIndex(_verticalScrollBar.getSelection());
+                setTopIndex(fVerticalScrollBar.getSelection());
             }
         });
-        _verticalScrollBar.setEnabled(false);
+        fVerticalScrollBar.setEnabled(false);
 
-        _stateCtrl = createTimeGraphControl(_dataViewer, _colors);
+        fTimeGraphCtrl = createTimeGraphControl(fDataViewer, fColorScheme);
 
-        _stateCtrl.setTimeProvider(this);
-        _stateCtrl.addSelectionListener(this);
-        _stateCtrl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2));
-        _stateCtrl.addMouseWheelListener(new MouseWheelListener() {
+        fTimeGraphCtrl.setTimeProvider(this);
+        fTimeGraphCtrl.setTimeGraphScale(fTimeScaleCtrl);
+        fTimeGraphCtrl.addSelectionListener(this);
+        fTimeGraphCtrl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2));
+        fTimeGraphCtrl.addMouseWheelListener(new MouseWheelListener() {
             @Override
             public void mouseScrolled(MouseEvent e) {
                 adjustVerticalScrollBar();
             }
         });
-        _stateCtrl.addKeyListener(new KeyAdapter() {
+        fTimeGraphCtrl.addKeyListener(new KeyAdapter() {
             @Override
             public void keyPressed(KeyEvent e) {
+                if (e.character == '+') {
+                    zoomIn();
+                } else if (e.character == '-') {
+                    zoomOut();
+                }
                 adjustVerticalScrollBar();
             }
         });
 
-        Composite filler = new Composite(_dataViewer, SWT.NONE);
+        Composite filler = new Composite(fDataViewer, SWT.NONE);
         GridData gd = new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false);
-        gd.heightHint = _stateCtrl.getHorizontalBar().getSize().y;
+        gd.heightHint = fTimeGraphCtrl.getHorizontalBar().getSize().y;
         filler.setLayoutData(gd);
         filler.setLayout(new FillLayout());
 
-        _stateCtrl.addControlListener(new ControlAdapter() {
+        fTimeGraphCtrl.addControlListener(new ControlAdapter() {
             @Override
             public void controlResized(ControlEvent event) {
                 resizeControls();
             }
         });
         resizeControls();
-        _dataViewer.update();
+        fDataViewer.update();
         adjustVerticalScrollBar();
-        return _dataViewer;
+        return fDataViewer;
     }
 
     /**
@@ -300,15 +406,23 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      */
     public void dispose() {
         saveOptions();
-        _stateCtrl.dispose();
-        _dataViewer.dispose();
-        _colors.dispose();
+        fTimeGraphCtrl.dispose();
+        fDataViewer.dispose();
+        fColorScheme.dispose();
     }
 
     /**
+     * Create a new time graph control.
+     *
+     * @param parent
+     *            The parent composite
+     * @param colors
+     *            The color scheme
+     * @return The new TimeGraphControl
      * @since 2.0
      */
-    protected TimeGraphControl createTimeGraphControl(Composite parent, TimeGraphColorScheme colors) {
+    protected TimeGraphControl createTimeGraphControl(Composite parent,
+            TimeGraphColorScheme colors) {
         return new TimeGraphControl(parent, colors);
     }
 
@@ -316,17 +430,17 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * Resize the controls
      */
     public void resizeControls() {
-        Rectangle r = _dataViewer.getClientArea();
+        Rectangle r = fDataViewer.getClientArea();
         if (r.isEmpty()) {
             return;
         }
 
         int width = r.width;
-        if (_nameWidth > width - _minNameWidth) {
-            _nameWidth = width - _minNameWidth;
+        if (fNameWidth > width - fMinNameWidth) {
+            fNameWidth = width - fMinNameWidth;
         }
-        if (_nameWidth < _minNameWidth) {
-            _nameWidth = _minNameWidth;
+        if (fNameWidth < fMinNameWidth) {
+            fNameWidth = fMinNameWidth;
         }
         adjustVerticalScrollBar();
     }
@@ -338,22 +452,22 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      *            The traces in the model
      */
     public void setTimeRange(ITimeGraphEntry traces[]) {
-        _endTime = 0;
-        _beginTime = -1;
+        fEndTime = 0;
+        fBeginTime = -1;
         for (int i = 0; i < traces.length; i++) {
             ITimeGraphEntry entry = traces[i];
             if (entry.getEndTime() >= entry.getStartTime() && entry.getEndTime() > 0) {
-                if (_beginTime < 0 || entry.getStartTime() < _beginTime) {
-                    _beginTime = entry.getStartTime();
+                if (fBeginTime < 0 || entry.getStartTime() < fBeginTime) {
+                    fBeginTime = entry.getStartTime();
                 }
-                if (entry.getEndTime() > _endTime) {
-                    _endTime = entry.getEndTime();
+                if (entry.getEndTime() > fEndTime) {
+                    fEndTime = entry.getEndTime();
                 }
             }
         }
 
-        if (_beginTime < 0) {
-            _beginTime = 0;
+        if (fBeginTime < 0) {
+            fBeginTime = 0;
         }
     }
 
@@ -361,21 +475,19 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * Recalculate the time bounds
      */
     public void setTimeBounds() {
-        //_time0_ = _beginTime - (long) ((_endTime - _beginTime) * 0.02);
-        _time0_ = _beginTime;
-        if (_time0_ < 0) {
-            _time0_ = 0;
+        fTime0Bound = fBeginTime;
+        if (fTime0Bound < 0) {
+            fTime0Bound = 0;
         }
-        // _time1_ = _time0_ + (_endTime - _time0_) * 1.05;
-        _time1_ = _endTime;
-        // _time0_ = Math.floor(_time0_);
-        // _time1_ = Math.ceil(_time1_);
-        if (!_timeRangeFixed) {
-            _time0 = _time0_;
-            _time1 = _time1_;
+        fTime1Bound = fEndTime;
+        if (!fTimeRangeFixed) {
+            fTime0 = fTime0Bound;
+            fTime1 = fTime1Bound;
         }
-        if (_time1 - _time0 < _minTimeInterval) {
-            _time1 = Math.min(_time1_, _time0 + _minTimeInterval);
+        fTime0 = Math.max(fTime0Bound, Math.min(fTime0, fTime1Bound));
+        fTime1 = Math.max(fTime0Bound, Math.min(fTime1, fTime1Bound));
+        if (fTime1 - fTime0 < fMinTimeInterval) {
+            fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval);
         }
     }
 
@@ -385,19 +497,21 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @param end
      */
     void updateInternalData(ITimeGraphEntry[] traces, long start, long end) {
-        if (null == traces) {
-            traces = new ITimeGraphEntry[0];
+        ITimeGraphEntry[] realTraces = traces;
+
+        if (null == realTraces) {
+            realTraces = new ITimeGraphEntry[0];
         }
         if ((start == 0 && end == 0) || start < 0 || end < 0) {
             // Start and end time are unspecified and need to be determined from
             // individual processes
-            setTimeRange(traces);
+            setTimeRange(realTraces);
         } else {
-            _beginTime = start;
-            _endTime = end;
+            fBeginTime = start;
+            fEndTime = end;
         }
 
-        refreshAllData(traces);
+        refreshAllData(realTraces);
     }
 
     /**
@@ -405,13 +519,18 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      */
     private void refreshAllData(ITimeGraphEntry[] traces) {
         setTimeBounds();
-        if (_selectedTime < _beginTime) {
-            _selectedTime = _beginTime;
-        } else if (_selectedTime > _endTime) {
-            _selectedTime = _endTime;
+        if (fSelectionBegin < fBeginTime) {
+            fSelectionBegin = fBeginTime;
+        } else if (fSelectionBegin > fEndTime) {
+            fSelectionBegin = fEndTime;
+        }
+        if (fSelectionEnd < fBeginTime) {
+            fSelectionEnd = fBeginTime;
+        } else if (fSelectionEnd > fEndTime) {
+            fSelectionEnd = fEndTime;
         }
-        _stateCtrl.refreshData(traces);
-        _timeScaleCtrl.redraw();
+        fTimeGraphCtrl.refreshData(traces);
+        fTimeScaleCtrl.redraw();
         adjustVerticalScrollBar();
     }
 
@@ -419,8 +538,8 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * Callback for when this view is focused
      */
     public void setFocus() {
-        if (null != _stateCtrl) {
-            _stateCtrl.setFocus();
+        if (null != fTimeGraphCtrl) {
+            fTimeGraphCtrl.setFocus();
         }
     }
 
@@ -430,7 +549,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return If the view is currently focused, or not
      */
     public boolean isInFocus() {
-        return _stateCtrl.isInFocus();
+        return fTimeGraphCtrl.isInFocus();
     }
 
     /**
@@ -439,7 +558,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The entry that is selected
      */
     public ITimeGraphEntry getSelection() {
-        return _stateCtrl.getSelectedTrace();
+        return fTimeGraphCtrl.getSelectedTrace();
     }
 
     /**
@@ -448,127 +567,120 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The index
      */
     public int getSelectionIndex() {
-        return _stateCtrl.getSelectedIndex();
+        return fTimeGraphCtrl.getSelectedIndex();
     }
 
     @Override
     public long getTime0() {
-        return _time0;
+        return fTime0;
     }
 
     @Override
     public long getTime1() {
-        return _time1;
+        return fTime1;
     }
 
     @Override
     public long getMinTimeInterval() {
-        return _minTimeInterval;
+        return fMinTimeInterval;
     }
 
     @Override
     public int getNameSpace() {
-        return _nameWidth;
+        return fNameWidth;
     }
 
     @Override
     public void setNameSpace(int width) {
-        _nameWidth = width;
-        width = _stateCtrl.getClientArea().width;
-        if (_nameWidth > width - 6) {
-            _nameWidth = width - 6;
+        fNameWidth = width;
+        int w = fTimeGraphCtrl.getClientArea().width;
+        if (fNameWidth > w - MIN_NAME_WIDTH) {
+            fNameWidth = w - MIN_NAME_WIDTH;
         }
-        if (_nameWidth < 6) {
-            _nameWidth = 6;
+        if (fNameWidth < MIN_NAME_WIDTH) {
+            fNameWidth = MIN_NAME_WIDTH;
         }
-        _stateCtrl.adjustScrolls();
-        _stateCtrl.redraw();
-        _timeScaleCtrl.redraw();
+        fTimeGraphCtrl.adjustScrolls();
+        fTimeGraphCtrl.redraw();
+        fTimeScaleCtrl.redraw();
     }
 
     @Override
     public int getTimeSpace() {
-        int w = _stateCtrl.getClientArea().width;
-        return w - _nameWidth;
-    }
-
-    @Override
-    public long getSelectedTime() {
-        return _selectedTime;
+        int w = fTimeGraphCtrl.getClientArea().width;
+        return w - fNameWidth;
     }
 
     @Override
     public long getBeginTime() {
-        return _beginTime;
+        return fBeginTime;
     }
 
     @Override
     public long getEndTime() {
-        return _endTime;
+        return fEndTime;
     }
 
     @Override
     public long getMaxTime() {
-        return _time1_;
+        return fTime1Bound;
     }
 
     @Override
     public long getMinTime() {
-        return _time0_;
+        return fTime0Bound;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
-     * #setStartFinishTimeNotify(long, long)
+    /**
+     * @since 2.1
      */
+    @Override
+    public long getSelectionBegin() {
+        return fSelectionBegin;
+    }
+
+    /**
+     * @since 2.1
+     */
+    @Override
+    public long getSelectionEnd() {
+        return fSelectionEnd;
+    }
+
     @Override
     public void setStartFinishTimeNotify(long time0, long time1) {
         setStartFinishTime(time0, time1);
         notifyRangeListeners(time0, time1);
     }
 
-
-    /* (non-Javadoc)
-     * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider#notifyStartFinishTime()
-     */
     @Override
     public void notifyStartFinishTime() {
-        notifyRangeListeners(_time0, _time1);
+        notifyRangeListeners(fTime0, fTime1);
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
-     * #setStartFinishTime(long, long)
-     */
     @Override
     public void setStartFinishTime(long time0, long time1) {
-        _time0 = time0;
-        if (_time0 < _time0_) {
-            _time0 = _time0_;
+        fTime0 = time0;
+        if (fTime0 < fTime0Bound) {
+            fTime0 = fTime0Bound;
         }
-        if (_time0 > _time1_) {
-            _time0 = _time1_;
+        if (fTime0 > fTime1Bound) {
+            fTime0 = fTime1Bound;
         }
-        _time1 = time1;
-        if (_time1 < _time0_) {
-            _time1 = _time0_;
+        fTime1 = time1;
+        if (fTime1 < fTime0Bound) {
+            fTime1 = fTime0Bound;
         }
-        if (_time1 > _time1_) {
-            _time1 = _time1_;
+        if (fTime1 > fTime1Bound) {
+            fTime1 = fTime1Bound;
         }
-        if (_time1 - _time0 < _minTimeInterval) {
-            _time1 = Math.min(_time1_, _time0 + _minTimeInterval);
+        if (fTime1 - fTime0 < fMinTimeInterval) {
+            fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval);
         }
-        _timeRangeFixed = true;
-        _stateCtrl.adjustScrolls();
-        _stateCtrl.redraw();
-        _timeScaleCtrl.redraw();
+        fTimeRangeFixed = true;
+        fTimeGraphCtrl.adjustScrolls();
+        fTimeGraphCtrl.redraw();
+        fTimeScaleCtrl.redraw();
     }
 
     /**
@@ -580,17 +692,24 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      *            The end time
      */
     public void setTimeBounds(long beginTime, long endTime) {
-        _beginTime = beginTime;
-        _endTime = endTime;
-        _time0_ = beginTime;
-        _time1_ = endTime;
-        _stateCtrl.adjustScrolls();
+        if (endTime >= beginTime) {
+            fBeginTime = beginTime;
+            fEndTime = endTime;
+            fTime0Bound = beginTime;
+            fTime1Bound = endTime;
+        } else {
+            fBeginTime = 0;
+            fEndTime = 0;
+            fTime0Bound = 0;
+            fTime1Bound = 0;
+        }
+        fTimeGraphCtrl.adjustScrolls();
     }
 
     @Override
     public void resetStartFinishTime() {
-        setStartFinishTime(_time0_, _time1_);
-        _timeRangeFixed = false;
+        setStartFinishTime(fTime0Bound, fTime1Bound);
+        fTimeRangeFixed = false;
     }
 
     @Override
@@ -603,62 +722,88 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
         setSelectedTimeInt(time, ensureVisible, false);
     }
 
+    /**
+     * @since 2.1
+     */
+    @Override
+    public void setSelectionRangeNotify(long beginTime, long endTime) {
+        boolean changed = (beginTime != fSelectionBegin || endTime != fSelectionEnd);
+        fSelectionBegin = Math.max(fTime0Bound, Math.min(fTime1Bound, beginTime));
+        fSelectionEnd = Math.max(fTime0Bound, Math.min(fTime1Bound, endTime));
+        fTimeGraphCtrl.redraw();
+        fTimeScaleCtrl.redraw();
+        if (changed) {
+            notifyTimeListeners(fSelectionBegin, fSelectionEnd);
+        }
+    }
+
+    /**
+     * @since 2.1
+     */
+    @Override
+    public void setSelectionRange(long beginTime, long endTime) {
+        fSelectionBegin = Math.max(fTime0Bound, Math.min(fTime1Bound, beginTime));
+        fSelectionEnd = Math.max(fTime0Bound, Math.min(fTime1Bound, endTime));
+        fTimeGraphCtrl.redraw();
+        fTimeScaleCtrl.redraw();
+    }
+
     private void setSelectedTimeInt(long time, boolean ensureVisible, boolean doNotify) {
-        long time0 = _time0;
-        long time1 = _time1;
+        long time0 = fTime0;
+        long time1 = fTime1;
         if (ensureVisible) {
-            long timeSpace = (long) ((_time1 - _time0) * .02);
-            long timeMid = (long) ((_time1 - _time0) * .5);
-            if (time < _time0 + timeSpace) {
-                long dt = _time0 - time + timeMid;
-                _time0 -= dt;
-                _time1 -= dt;
-            } else if (time > _time1 - timeSpace) {
-                long dt = time - _time1 + timeMid;
-                _time0 += dt;
-                _time1 += dt;
+            long timeSpace = (fTime1 - fTime0) / RECENTERING_MARGIN_FACTOR;
+            long timeMid = (fTime1 - fTime0) / 2;
+            if (time < fTime0 + timeSpace) {
+                long dt = fTime0 - time + timeMid;
+                fTime0 -= dt;
+                fTime1 -= dt;
+            } else if (time > fTime1 - timeSpace) {
+                long dt = time - fTime1 + timeMid;
+                fTime0 += dt;
+                fTime1 += dt;
             }
-            if (_time0 < _time0_) {
-                _time1 = Math.min(_time1_, _time1 + (_time0_ - _time0));
-                _time0 = _time0_;
-            } else if (_time1 > _time1_) {
-                _time0 = Math.max(_time0_, _time0 - (_time1 - _time1_));
-                _time1 = _time1_;
+            if (fTime0 < fTime0Bound) {
+                fTime1 = Math.min(fTime1Bound, fTime1 + (fTime0Bound - fTime0));
+                fTime0 = fTime0Bound;
+            } else if (fTime1 > fTime1Bound) {
+                fTime0 = Math.max(fTime0Bound, fTime0 - (fTime1 - fTime1Bound));
+                fTime1 = fTime1Bound;
             }
         }
-        if (_time1 - _time0 < _minTimeInterval) {
-            _time1 = Math.min(_time1_, _time0 + _minTimeInterval);
+        if (fTime1 - fTime0 < fMinTimeInterval) {
+            fTime1 = Math.min(fTime1Bound, fTime0 + fMinTimeInterval);
         }
-        _stateCtrl.adjustScrolls();
-        _stateCtrl.redraw();
-        _timeScaleCtrl.redraw();
+        fTimeGraphCtrl.adjustScrolls();
+        fTimeGraphCtrl.redraw();
+        fTimeScaleCtrl.redraw();
 
+        boolean notifySelectedTime = (time != fSelectionBegin || time != fSelectionEnd);
+        fSelectionBegin = time;
+        fSelectionEnd = time;
 
-        boolean notifySelectedTime = (time != _selectedTime);
-        _selectedTime = time;
-
-        if (doNotify && ((time0 != _time0) || (time1 != _time1))) {
-            notifyRangeListeners(_time0, _time1);
+        if (doNotify && ((time0 != fTime0) || (time1 != fTime1))) {
+            notifyRangeListeners(fTime0, fTime1);
         }
 
         if (doNotify && notifySelectedTime) {
-            notifyTimeListeners(_selectedTime);
+            notifyTimeListeners(fSelectionBegin, fSelectionEnd);
         }
     }
 
     @Override
     public void widgetDefaultSelected(SelectionEvent e) {
-        if (_selectedEntry != getSelection()) {
-            _selectedEntry = getSelection();
-            notifySelectionListeners(_selectedEntry);
+        if (fSelectedEntry != getSelection()) {
+            fSelectedEntry = getSelection();
+            notifySelectionListeners(fSelectedEntry);
         }
     }
 
     @Override
     public void widgetSelected(SelectionEvent e) {
-        if (_selectedEntry != getSelection()) {
-            _selectedEntry = getSelection();
-            notifySelectionListeners(_selectedEntry);
+        if (fSelectedEntry != getSelection()) {
+            fSelectedEntry = getSelection();
+            notifySelectionListeners(fSelectedEntry);
         }
     }
 
@@ -666,7 +811,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * Callback for when the next event is selected
      */
     public void selectNextEvent() {
-        _stateCtrl.selectNextEvent();
+        fTimeGraphCtrl.selectNextEvent();
         adjustVerticalScrollBar();
     }
 
@@ -674,7 +819,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * Callback for when the previous event is selected
      */
     public void selectPrevEvent() {
-        _stateCtrl.selectPrevEvent();
+        fTimeGraphCtrl.selectPrevEvent();
         adjustVerticalScrollBar();
     }
 
@@ -682,7 +827,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * Callback for when the next item is selected
      */
     public void selectNextItem() {
-        _stateCtrl.selectNextTrace();
+        fTimeGraphCtrl.selectNextTrace();
         adjustVerticalScrollBar();
     }
 
@@ -690,7 +835,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * Callback for when the previous item is selected
      */
     public void selectPrevItem() {
-        _stateCtrl.selectPrevTrace();
+        fTimeGraphCtrl.selectPrevTrace();
         adjustVerticalScrollBar();
     }
 
@@ -698,25 +843,25 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * Callback for the show legend action
      */
     public void showLegend() {
-        if (_dataViewer == null || _dataViewer.isDisposed()) {
+        if (fDataViewer == null || fDataViewer.isDisposed()) {
             return;
         }
 
-        TimeGraphLegend.open(_dataViewer.getShell(), fTimeGraphProvider);
+        TimeGraphLegend.open(fDataViewer.getShell(), fTimeGraphProvider);
     }
 
     /**
      * Callback for the Zoom In action
      */
     public void zoomIn() {
-        _stateCtrl.zoomIn();
+        fTimeGraphCtrl.zoomIn();
     }
 
     /**
      * Callback for the Zoom Out action
      */
     public void zoomOut() {
-        _stateCtrl.zoomOut();
+        fTimeGraphCtrl.zoomOut();
     }
 
     private String getPreferenceString(String string) {
@@ -771,8 +916,8 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
         fTimeListeners.remove(listener);
     }
 
-    private void notifyTimeListeners(long time) {
-        TimeGraphTimeEvent event = new TimeGraphTimeEvent(this, time);
+    private void notifyTimeListeners(long startTime, long endTime) {
+        TimeGraphTimeEvent event = new TimeGraphTimeEvent(this, startTime, endTime);
 
         for (ITimeGraphTimeListener listener : fTimeListeners) {
             listener.timeSelected(event);
@@ -801,7 +946,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
 
     private void notifyRangeListeners(long startTime, long endTime) {
         // Check if the time has actually changed from last notification
-        if (startTime != _time0_extSynch || endTime != _time1_extSynch) {
+        if (startTime != fTime0ExtSynch || endTime != fTime1ExtSynch) {
             // Notify Time Scale Selection Listeners
             TimeGraphRangeUpdateEvent event = new TimeGraphRangeUpdateEvent(this, startTime, endTime);
 
@@ -826,8 +971,8 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
         if (event == null || source == this) {
             return;
         }
-        _selectedEntry = event.getEntry();
-        _stateCtrl.selectItem(_selectedEntry, false);
+        fSelectedEntry = event.getEntry();
+        fTimeGraphCtrl.selectItem(fSelectedEntry, false);
 
         setSelectedTimeInt(event.getTime(), true, true);
         adjustVerticalScrollBar();
@@ -847,8 +992,8 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
         if (trace == null || source == this) {
             return;
         }
-        _selectedEntry = trace;
-        _stateCtrl.selectItem(trace, false);
+        fSelectedEntry = trace;
+        fTimeGraphCtrl.selectItem(trace, false);
 
         setSelectedTimeInt(time, true, true);
     }
@@ -860,8 +1005,8 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      *            The trace that was selected
      */
     public void setSelection(ITimeGraphEntry trace) {
-        _selectedEntry = trace;
-        _stateCtrl.selectItem(trace, false);
+        fSelectedEntry = trace;
+        fTimeGraphCtrl.selectItem(trace, false);
         adjustVerticalScrollBar();
     }
 
@@ -893,23 +1038,25 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      */
     private void updateExtSynchTimers() {
         // last time notification cache
-        _time0_extSynch = _time0;
-        _time1_extSynch = _time1;
+        fTime0ExtSynch = fTime0;
+        fTime1ExtSynch = fTime1;
     }
 
     /**
-     * Set the calendar format
-     *
-     * @param toAbsoluteCaltime
-     *            True for absolute time, false for relative
+     * @since 2.0
      */
-    public void setTimeCalendarFormat(boolean toAbsoluteCaltime) {
-        calendarTimeFormat = toAbsoluteCaltime;
+    @Override
+    public TimeFormat getTimeFormat() {
+        return fTimeFormat;
     }
 
-    @Override
-    public boolean isCalendarFormat() {
-        return calendarTimeFormat;
+    /**
+     * @param tf
+     *            the {@link TimeFormat} used to display timestamps
+     * @since 2.0
+     */
+    public void setTimeFormat(TimeFormat tf) {
+        this.fTimeFormat = tf;
     }
 
     /**
@@ -918,7 +1065,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The width
      */
     public int getBorderWidth() {
-        return borderWidth;
+        return fBorderWidth;
     }
 
     /**
@@ -929,8 +1076,8 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      */
     public void setBorderWidth(int borderWidth) {
         if (borderWidth > -1) {
-            this.borderWidth = borderWidth;
-            GridLayout gl = (GridLayout)_dataViewer.getLayout();
+            this.fBorderWidth = borderWidth;
+            GridLayout gl = (GridLayout) fDataViewer.getLayout();
             gl.marginHeight = borderWidth;
         }
     }
@@ -941,7 +1088,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The height
      */
     public int getHeaderHeight() {
-        return timeScaleHeight;
+        return fTimeScaleHeight;
     }
 
     /**
@@ -952,8 +1099,8 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      */
     public void setHeaderHeight(int headerHeight) {
         if (headerHeight > -1) {
-            this.timeScaleHeight = headerHeight;
-            _timeScaleCtrl.setHeight(headerHeight);
+            this.fTimeScaleHeight = headerHeight;
+            fTimeScaleCtrl.setHeight(headerHeight);
         }
     }
 
@@ -963,8 +1110,8 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The height
      */
     public int getItemHeight() {
-        if (_stateCtrl != null) {
-            return _stateCtrl.getItemHeight();
+        if (fTimeGraphCtrl != null) {
+            return fTimeGraphCtrl.getItemHeight();
         }
         return 0;
     }
@@ -976,8 +1123,8 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      *            The height to set
      */
     public void setItemHeight(int rowHeight) {
-        if (_stateCtrl != null) {
-            _stateCtrl.setItemHeight(rowHeight);
+        if (fTimeGraphCtrl != null) {
+            fTimeGraphCtrl.setItemHeight(rowHeight);
         }
     }
 
@@ -988,21 +1135,22 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      *            The min width
      */
     public void setMinimumItemWidth(int width) {
-        if (_stateCtrl != null) {
-            _stateCtrl.setMinimumItemWidth(width);
+        if (fTimeGraphCtrl != null) {
+            fTimeGraphCtrl.setMinimumItemWidth(width);
         }
     }
 
     /**
      * Set the width for the name column
      *
-     * @param width The width
+     * @param width
+     *            The width
      */
     public void setNameWidthPref(int width) {
-        _nameWidthPref = width;
+        fNameWidthPref = width;
         if (width == 0) {
-            _minNameWidth = 0;
-            _nameWidth = 0;
+            fMinNameWidth = 0;
+            fNameWidth = 0;
         }
     }
 
@@ -1014,7 +1162,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The width
      */
     public int getNameWidthPref(int width) {
-        return _nameWidthPref;
+        return fNameWidthPref;
     }
 
     /**
@@ -1023,25 +1171,53 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return the SWT control which displays this viewer's content
      */
     public Control getControl() {
-        return _dataViewer;
+        return fDataViewer;
     }
 
     /**
      * Returns the time graph control associated with this viewer.
      *
      * @return the time graph control
+     * @since 2.0
      */
-    TimeGraphControl getTimeGraphControl() {
-        return _stateCtrl;
+    public TimeGraphControl getTimeGraphControl() {
+        return fTimeGraphCtrl;
     }
 
     /**
      * Returns the time graph scale associated with this viewer.
      *
      * @return the time graph scale
+     * @since 2.0
+     */
+    public TimeGraphScale getTimeGraphScale() {
+        return fTimeScaleCtrl;
+    }
+
+    /**
+     * Return the x coordinate corresponding to a time
+     *
+     * @param time
+     *            the time
+     * @return the x coordinate corresponding to the time
+     *
+     * @since 2.0
      */
-    TimeGraphScale getTimeGraphScale() {
-        return _timeScaleCtrl;
+    public int getXForTime(long time) {
+        return fTimeGraphCtrl.getXForTime(time);
+    }
+
+    /**
+     * Return the time corresponding to an x coordinate
+     *
+     * @param x
+     *            the x coordinate
+     * @return the time corresponding to the x coordinate
+     *
+     * @since 2.0
+     */
+    public long getTimeAtX(int x) {
+        return fTimeGraphCtrl.getTimeAtX(x);
     }
 
     /**
@@ -1050,7 +1226,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return the selection provider
      */
     public ISelectionProvider getSelectionProvider() {
-        return _stateCtrl;
+        return fTimeGraphCtrl;
     }
 
     /**
@@ -1060,7 +1236,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      *            Wait indefinitely?
      */
     public void waitCursor(boolean waitInd) {
-        _stateCtrl.waitCursor(waitInd);
+        fTimeGraphCtrl.waitCursor(waitInd);
     }
 
     /**
@@ -1069,7 +1245,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The scroll bar
      */
     public ScrollBar getHorizontalBar() {
-        return _stateCtrl.getHorizontalBar();
+        return fTimeGraphCtrl.getHorizontalBar();
     }
 
     /**
@@ -1078,7 +1254,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The scroll bar
      */
     public Slider getVerticalBar() {
-        return _verticalScrollBar;
+        return fVerticalScrollBar;
     }
 
     /**
@@ -1088,7 +1264,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      *            The index that will go to the top
      */
     public void setTopIndex(int index) {
-        _stateCtrl.setTopIndex(index);
+        fTimeGraphCtrl.setTopIndex(index);
         adjustVerticalScrollBar();
     }
 
@@ -1098,7 +1274,37 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The top index
      */
     public int getTopIndex() {
-        return _stateCtrl.getTopIndex();
+        return fTimeGraphCtrl.getTopIndex();
+    }
+
+    /**
+     * Sets the auto-expand level to be used when the input of the viewer is set
+     * using {@link #setInput(Object)}. The value 0 means that there is no
+     * auto-expand; 1 means that top-level elements are expanded, but not their
+     * children; 2 means that top-level elements are expanded, and their
+     * children, but not grand-children; and so on.
+     * <p>
+     * The value {@link #ALL_LEVELS} means that all subtrees should be expanded.
+     * </p>
+     * @param level
+     *            non-negative level, or <code>ALL_LEVELS</code> to expand all
+     *            levels of the tree
+     * @since 3.1
+     */
+    public void setAutoExpandLevel(int level) {
+        fTimeGraphCtrl.setAutoExpandLevel(level);
+    }
+
+    /**
+     * Returns the auto-expand level.
+     *
+     * @return non-negative level, or <code>ALL_LEVELS</code> if all levels of
+     *         the tree are expanded automatically
+     * @see #setAutoExpandLevel
+     * @since 3.1
+     */
+    public int getAutoExpandLevel() {
+        return fTimeGraphCtrl.getAutoExpandLevel();
     }
 
     /**
@@ -1110,7 +1316,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      *            True for expanded, false for collapsed
      */
     public void setExpandedState(ITimeGraphEntry entry, boolean expanded) {
-        _stateCtrl.setExpandedState(entry, expanded);
+        fTimeGraphCtrl.setExpandedState(entry, expanded);
         adjustVerticalScrollBar();
     }
 
@@ -1120,7 +1326,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @since 2.0
      */
     public void collapseAll() {
-        _stateCtrl.collapseAll();
+        fTimeGraphCtrl.collapseAll();
         adjustVerticalScrollBar();
     }
 
@@ -1130,7 +1336,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @since 2.0
      */
     public void expandAll() {
-        _stateCtrl.expandAll();
+        fTimeGraphCtrl.expandAll();
         adjustVerticalScrollBar();
     }
 
@@ -1140,7 +1346,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The element count
      */
     public int getExpandedElementCount() {
-        return _stateCtrl.getExpandedElementCount();
+        return fTimeGraphCtrl.getExpandedElementCount();
     }
 
     /**
@@ -1149,7 +1355,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The array of entries that are below this one
      */
     public ITimeGraphEntry[] getExpandedElements() {
-        return _stateCtrl.getExpandedElements();
+        return fTimeGraphCtrl.getExpandedElements();
     }
 
     /**
@@ -1159,7 +1365,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      *            The listener to add
      */
     public void addTreeListener(ITimeGraphTreeListener listener) {
-        _stateCtrl.addTreeListener(listener);
+        fTimeGraphCtrl.addTreeListener(listener);
     }
 
     /**
@@ -1169,7 +1375,7 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      *            The listener to remove
      */
     public void removeTreeListener(ITimeGraphTreeListener listener) {
-        _stateCtrl.removeTreeListener(listener);
+        fTimeGraphCtrl.removeTreeListener(listener);
     }
 
     /**
@@ -1178,19 +1384,20 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The Action object
      */
     public Action getResetScaleAction() {
-        if (resetScale == null) {
+        if (fResetScaleAction == null) {
             // resetScale
-            resetScale = new Action() {
+            fResetScaleAction = new Action() {
                 @Override
                 public void run() {
                     resetStartFinishTime();
+                    notifyStartFinishTime();
                 }
             };
-            resetScale.setText(Messages.TmfTimeGraphViewer_ResetScaleActionNameText);
-            resetScale.setToolTipText(Messages.TmfTimeGraphViewer_ResetScaleActionToolTipText);
-            resetScale.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HOME_MENU));
+            fResetScaleAction.setText(Messages.TmfTimeGraphViewer_ResetScaleActionNameText);
+            fResetScaleAction.setToolTipText(Messages.TmfTimeGraphViewer_ResetScaleActionToolTipText);
+            fResetScaleAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HOME_MENU));
         }
-        return resetScale;
+        return fResetScaleAction;
     }
 
     /**
@@ -1199,20 +1406,20 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The Action object
      */
     public Action getShowLegendAction() {
-        if (showLegendAction == null) {
+        if (fShowLegendAction == null) {
             // showLegend
-            showLegendAction = new Action() {
+            fShowLegendAction = new Action() {
                 @Override
                 public void run() {
                     showLegend();
                 }
             };
-            showLegendAction.setText(Messages.TmfTimeGraphViewer_LegendActionNameText);
-            showLegendAction.setToolTipText(Messages.TmfTimeGraphViewer_LegendActionToolTipText);
-            showLegendAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SHOW_LEGEND));
+            fShowLegendAction.setText(Messages.TmfTimeGraphViewer_LegendActionNameText);
+            fShowLegendAction.setToolTipText(Messages.TmfTimeGraphViewer_LegendActionToolTipText);
+            fShowLegendAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SHOW_LEGEND));
         }
 
-        return showLegendAction;
+        return fShowLegendAction;
     }
 
     /**
@@ -1221,20 +1428,20 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The action object
      */
     public Action getNextEventAction() {
-        if (nextEventAction == null) {
-            nextEventAction = new Action() {
+        if (fNextEventAction == null) {
+            fNextEventAction = new Action() {
                 @Override
                 public void run() {
                     selectNextEvent();
                 }
             };
 
-            nextEventAction.setText(Messages.TmfTimeGraphViewer_NextEventActionNameText);
-            nextEventAction.setToolTipText(Messages.TmfTimeGraphViewer_NextEventActionToolTipText);
-            nextEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_EVENT));
+            fNextEventAction.setText(Messages.TmfTimeGraphViewer_NextEventActionNameText);
+            fNextEventAction.setToolTipText(Messages.TmfTimeGraphViewer_NextEventActionToolTipText);
+            fNextEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_EVENT));
         }
 
-        return nextEventAction;
+        return fNextEventAction;
     }
 
     /**
@@ -1243,20 +1450,20 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The Action object
      */
     public Action getPreviousEventAction() {
-        if (prevEventAction == null) {
-            prevEventAction = new Action() {
+        if (fPrevEventAction == null) {
+            fPrevEventAction = new Action() {
                 @Override
                 public void run() {
                     selectPrevEvent();
                 }
             };
 
-            prevEventAction.setText(Messages.TmfTimeGraphViewer_PreviousEventActionNameText);
-            prevEventAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousEventActionToolTipText);
-            prevEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_EVENT));
+            fPrevEventAction.setText(Messages.TmfTimeGraphViewer_PreviousEventActionNameText);
+            fPrevEventAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousEventActionToolTipText);
+            fPrevEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_EVENT));
         }
 
-        return prevEventAction;
+        return fPrevEventAction;
     }
 
     /**
@@ -1265,19 +1472,19 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The Action object
      */
     public Action getNextItemAction() {
-        if (nextItemAction == null) {
+        if (fNextItemAction == null) {
 
-            nextItemAction = new Action() {
+            fNextItemAction = new Action() {
                 @Override
                 public void run() {
                     selectNextItem();
                 }
             };
-            nextItemAction.setText(Messages.TmfTimeGraphViewer_NextItemActionNameText);
-            nextItemAction.setToolTipText(Messages.TmfTimeGraphViewer_NextItemActionToolTipText);
-            nextItemAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_ITEM));
+            fNextItemAction.setText(Messages.TmfTimeGraphViewer_NextItemActionNameText);
+            fNextItemAction.setToolTipText(Messages.TmfTimeGraphViewer_NextItemActionToolTipText);
+            fNextItemAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_ITEM));
         }
-        return nextItemAction;
+        return fNextItemAction;
     }
 
     /**
@@ -1286,19 +1493,19 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The Action object
      */
     public Action getPreviousItemAction() {
-        if (previousItemAction == null) {
+        if (fPreviousItemAction == null) {
 
-            previousItemAction = new Action() {
+            fPreviousItemAction = new Action() {
                 @Override
                 public void run() {
                     selectPrevItem();
                 }
             };
-            previousItemAction.setText(Messages.TmfTimeGraphViewer_PreviousItemActionNameText);
-            previousItemAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousItemActionToolTipText);
-            previousItemAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_ITEM));
+            fPreviousItemAction.setText(Messages.TmfTimeGraphViewer_PreviousItemActionNameText);
+            fPreviousItemAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousItemActionToolTipText);
+            fPreviousItemAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_ITEM));
         }
-        return previousItemAction;
+        return fPreviousItemAction;
     }
 
     /**
@@ -1307,18 +1514,18 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The Action object
      */
     public Action getZoomInAction() {
-        if (zoomInAction == null) {
-            zoomInAction = new Action() {
+        if (fZoomInAction == null) {
+            fZoomInAction = new Action() {
                 @Override
                 public void run() {
                     zoomIn();
                 }
             };
-            zoomInAction.setText(Messages.TmfTimeGraphViewer_ZoomInActionNameText);
-            zoomInAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomInActionToolTipText);
-            zoomInAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_IN_MENU));
+            fZoomInAction.setText(Messages.TmfTimeGraphViewer_ZoomInActionNameText);
+            fZoomInAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomInActionToolTipText);
+            fZoomInAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_IN_MENU));
         }
-        return zoomInAction;
+        return fZoomInAction;
     }
 
     /**
@@ -1327,74 +1534,194 @@ public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {
      * @return The Action object
      */
     public Action getZoomOutAction() {
-        if (zoomOutAction == null) {
-            zoomOutAction = new Action() {
+        if (fZoomOutAction == null) {
+            fZoomOutAction = new Action() {
                 @Override
                 public void run() {
                     zoomOut();
                 }
             };
-            zoomOutAction.setText(Messages.TmfTimeGraphViewer_ZoomOutActionNameText);
-            zoomOutAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomOutActionToolTipText);
-            zoomOutAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_OUT_MENU));
+            fZoomOutAction.setText(Messages.TmfTimeGraphViewer_ZoomOutActionNameText);
+            fZoomOutAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomOutActionToolTipText);
+            fZoomOutAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_OUT_MENU));
+        }
+        return fZoomOutAction;
+    }
+
+    /**
+     * Get the hide arrows action
+     *
+     * @param dialogSettings
+     *            The dialog settings section where the state should be stored,
+     *            or null
+     *
+     * @return The Action object
+     *
+     * @since 2.1
+     */
+    public Action getHideArrowsAction(final IDialogSettings dialogSettings) {
+        if (fHideArrowsAction == null) {
+            fHideArrowsAction = new Action(Messages.TmfTimeGraphViewer_HideArrowsActionNameText, IAction.AS_CHECK_BOX) {
+                @Override
+                public void run() {
+                    boolean hideArrows = fHideArrowsAction.isChecked();
+                    fTimeGraphCtrl.hideArrows(hideArrows);
+                    refresh();
+                    if (dialogSettings != null) {
+                        dialogSettings.put(HIDE_ARROWS_KEY, hideArrows);
+                    }
+                    if (fFollowArrowFwdAction != null) {
+                        fFollowArrowFwdAction.setEnabled(!hideArrows);
+                    }
+                    if (fFollowArrowBwdAction != null) {
+                        fFollowArrowBwdAction.setEnabled(!hideArrows);
+                    }
+                }
+            };
+            fHideArrowsAction.setToolTipText(Messages.TmfTimeGraphViewer_HideArrowsActionToolTipText);
+            fHideArrowsAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HIDE_ARROWS));
+            if (dialogSettings != null) {
+                boolean hideArrows = dialogSettings.getBoolean(HIDE_ARROWS_KEY);
+                fTimeGraphCtrl.hideArrows(hideArrows);
+                fHideArrowsAction.setChecked(hideArrows);
+                if (fFollowArrowFwdAction != null) {
+                    fFollowArrowFwdAction.setEnabled(!hideArrows);
+                }
+                if (fFollowArrowBwdAction != null) {
+                    fFollowArrowBwdAction.setEnabled(!hideArrows);
+                }
+            }
+        }
+        return fHideArrowsAction;
+    }
+
+    /**
+     * Get the follow arrow forward action.
+     *
+     * @return The Action object
+     *
+     * @since 2.1
+     */
+    public Action getFollowArrowFwdAction() {
+        if (fFollowArrowFwdAction == null) {
+            fFollowArrowFwdAction = new Action() {
+                @Override
+                public void run() {
+                    fTimeGraphCtrl.followArrowFwd();
+                    adjustVerticalScrollBar();
+                }
+            };
+            fFollowArrowFwdAction.setText(Messages.TmfTimeGraphViewer_FollowArrowForwardActionNameText);
+            fFollowArrowFwdAction.setToolTipText(Messages.TmfTimeGraphViewer_FollowArrowForwardActionToolTipText);
+            fFollowArrowFwdAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_FOLLOW_ARROW_FORWARD));
+            if (fHideArrowsAction != null) {
+                fFollowArrowFwdAction.setEnabled(!fHideArrowsAction.isChecked());
+            }
         }
-        return zoomOutAction;
+        return fFollowArrowFwdAction;
     }
 
+    /**
+     * Get the follow arrow backward action.
+     *
+     * @return The Action object
+     *
+     * @since 2.1
+     */
+    public Action getFollowArrowBwdAction() {
+        if (fFollowArrowBwdAction == null) {
+            fFollowArrowBwdAction = new Action() {
+                @Override
+                public void run() {
+                    fTimeGraphCtrl.followArrowBwd();
+                    adjustVerticalScrollBar();
+                }
+            };
+            fFollowArrowBwdAction.setText(Messages.TmfTimeGraphViewer_FollowArrowBackwardActionNameText);
+            fFollowArrowBwdAction.setToolTipText(Messages.TmfTimeGraphViewer_FollowArrowBackwardActionToolTipText);
+            fFollowArrowBwdAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_FOLLOW_ARROW_BACKWARD));
+            if (fHideArrowsAction != null) {
+                fFollowArrowBwdAction.setEnabled(!fHideArrowsAction.isChecked());
+            }
+        }
+        return fFollowArrowBwdAction;
+    }
 
     private void adjustVerticalScrollBar() {
-        int topIndex = _stateCtrl.getTopIndex();
-        int countPerPage = _stateCtrl.countPerPage();
-        int expandedElementCount = _stateCtrl.getExpandedElementCount();
+        int topIndex = fTimeGraphCtrl.getTopIndex();
+        int countPerPage = fTimeGraphCtrl.countPerPage();
+        int expandedElementCount = fTimeGraphCtrl.getExpandedElementCount();
         if (topIndex + countPerPage > expandedElementCount) {
-            _stateCtrl.setTopIndex(Math.max(0, expandedElementCount - countPerPage));
+            fTimeGraphCtrl.setTopIndex(Math.max(0, expandedElementCount - countPerPage));
         }
 
-        int selection = _stateCtrl.getTopIndex();
+        int selection = fTimeGraphCtrl.getTopIndex();
         int min = 0;
         int max = Math.max(1, expandedElementCount - 1);
         int thumb = Math.min(max, Math.max(1, countPerPage - 1));
         int increment = 1;
         int pageIncrement = Math.max(1, countPerPage);
-        _verticalScrollBar.setValues(selection, min, max, thumb, increment, pageIncrement);
+        fVerticalScrollBar.setValues(selection, min, max, thumb, increment, pageIncrement);
     }
 
     /**
-     * @param listener a {@link MenuDetectListener}
+     * @param listener
+     *            a {@link MenuDetectListener}
      * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
-     * @since 2.0
+     * @since 1.2
      */
     public void addTimeGraphEntryMenuListener(MenuDetectListener listener) {
-        _stateCtrl.addTimeGraphEntryMenuListener(listener);
+        fTimeGraphCtrl.addTimeGraphEntryMenuListener(listener);
     }
 
     /**
-     * @param listener a {@link MenuDetectListener}
+     * @param listener
+     *            a {@link MenuDetectListener}
      * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
-     * @since 2.0
+     * @since 1.2
      */
     public void removeTimeGraphEntryMenuListener(MenuDetectListener listener) {
-        _stateCtrl.removeTimeGraphEntryMenuListener(listener);
+        fTimeGraphCtrl.removeTimeGraphEntryMenuListener(listener);
     }
 
     /**
-     * @param listener a {@link MenuDetectListener}
+     * @param listener
+     *            a {@link MenuDetectListener}
      * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
-     * @since 2.0
+     * @since 1.2
      */
     public void addTimeEventMenuListener(MenuDetectListener listener) {
-        _stateCtrl.addTimeEventMenuListener(listener);
+        fTimeGraphCtrl.addTimeEventMenuListener(listener);
     }
 
     /**
-     * @param listener a {@link MenuDetectListener}
+     * @param listener
+     *            a {@link MenuDetectListener}
      * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
-     * @since 2.0
+     * @since 1.2
      */
     public void removeTimeEventMenuListener(MenuDetectListener listener) {
-        _stateCtrl.removeTimeEventMenuListener(listener);
+        fTimeGraphCtrl.removeTimeEventMenuListener(listener);
     }
 
+    /**
+     * @param filter
+     *            The filter object to be attached to the view
+     * @since 2.0
+     */
+    public void addFilter(ViewerFilter filter) {
+        fTimeGraphCtrl.addFilter(filter);
+        refresh();
+    }
 
+    /**
+     * @param filter
+     *            The filter object to be attached to the view
+     * @since 2.0
+     */
+    public void removeFilter(ViewerFilter filter) {
+        fTimeGraphCtrl.removeFilter(filter);
+        refresh();
+    }
 
 }
This page took 0.211786 seconds and 5 git commands to generate.