-/*****************************************************************************\r
- * Copyright (c) 2007, 2008 Intel Corporation, 2009, 2010, 2011, 2012 Ericsson.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * Intel Corporation - Initial API and implementation\r
- * Ruslan A. Scherbakov, Intel - Initial API and implementation\r
- * Alexander N. Alexeev, Intel - Add monitors statistics support\r
- * Alvaro Sanchez-Leon - Adapted for TMF\r
- * Patrick Tasse - Refactoring\r
- *\r
- *****************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;\r
-\r
-import java.util.ArrayList;\r
-\r
-import org.eclipse.jface.action.Action;\r
-import org.eclipse.jface.viewers.ISelectionProvider;\r
-import org.eclipse.linuxtools.internal.tmf.ui.ITmfImageConstants;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
-import org.eclipse.linuxtools.internal.tmf.ui.TmfUiPlugin;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.dialogs.TimeGraphLegend;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphScale;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphTooltipHandler;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.ControlAdapter;\r
-import org.eclipse.swt.events.ControlEvent;\r
-import org.eclipse.swt.events.KeyAdapter;\r
-import org.eclipse.swt.events.KeyEvent;\r
-import org.eclipse.swt.events.MouseEvent;\r
-import org.eclipse.swt.events.MouseWheelListener;\r
-import org.eclipse.swt.events.SelectionAdapter;\r
-import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.events.SelectionListener;\r
-import org.eclipse.swt.graphics.Rectangle;\r
-import org.eclipse.swt.layout.FillLayout;\r
-import org.eclipse.swt.layout.GridData;\r
-import org.eclipse.swt.layout.GridLayout;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.ScrollBar;\r
-import org.eclipse.swt.widgets.Slider;\r
-\r
-public class TimeGraphViewer implements ITimeDataProvider, SelectionListener {\r
-\r
- /** vars */\r
- private long _minTimeInterval;\r
- private long _selectedTime;\r
- private ITimeGraphEntry _selectedEntry;\r
- private long _beginTime;\r
- private long _endTime;\r
- private long _time0;\r
- private long _time1;\r
- private long _time0_;\r
- private long _time1_;\r
- private long _time0_extSynch = 0;\r
- private long _time1_extSynch = 0;\r
- private boolean _timeRangeFixed;\r
- private int _nameWidthPref = 200;\r
- private int _minNameWidth = 6;\r
- private int _nameWidth;\r
- private Composite _dataViewer;\r
-\r
- private TimeGraphControl _stateCtrl;\r
- private TimeGraphScale _timeScaleCtrl;\r
- private Slider _verticalScrollBar;\r
- private TimeGraphTooltipHandler _threadTip;\r
- private TimeGraphColorScheme _colors;\r
- private ITimeGraphPresentationProvider fTimeGraphProvider;\r
-\r
- ArrayList<ITimeGraphSelectionListener> fSelectionListeners = new ArrayList<ITimeGraphSelectionListener>();\r
- ArrayList<ITimeGraphTimeListener> fTimeListeners = new ArrayList<ITimeGraphTimeListener>();\r
- ArrayList<ITimeGraphRangeListener> fRangeListeners = new ArrayList<ITimeGraphRangeListener>();\r
-\r
- // Calender Time format, using Epoch reference or Relative time\r
- // format(default\r
- private boolean calendarTimeFormat = false;\r
- private int borderWidth = 4;\r
- private int timeScaleHeight = 22;\r
-\r
- private Action resetScale;\r
- private Action showLegendAction;\r
- private Action nextEventAction;\r
- private Action prevEventAction;\r
- private Action nextItemAction;\r
- private Action previousItemAction;\r
- private Action zoomInAction;\r
- private Action zoomOutAction;\r
-\r
- /** ctor */\r
- public TimeGraphViewer(Composite parent, int style) {\r
- createDataViewer(parent, style);\r
- }\r
-\r
- /**\r
- * Sets the timegraph provider used by this timegraph viewer.\r
- * \r
- * @param timeGraphProvider the timegraph provider\r
- */\r
- public void setTimeGraphProvider(ITimeGraphPresentationProvider timeGraphProvider) {\r
- fTimeGraphProvider = timeGraphProvider;\r
- _stateCtrl.setTimeGraphProvider(timeGraphProvider);\r
- _threadTip = new TimeGraphTooltipHandler(_dataViewer.getShell(), fTimeGraphProvider, this);\r
- _threadTip.activateHoverHelp(_stateCtrl);\r
- }\r
-\r
- /**\r
- * Sets or clears the input for this time graph viewer.\r
- * The input array should only contain top-level elements.\r
- *\r
- * @param input the input of this time graph viewer, or <code>null</code> if none\r
- */\r
- public void setInput(ITimeGraphEntry[] input) {\r
- if (null != _stateCtrl) {\r
- if (null == input) {\r
- input = new ITimeGraphEntry[0];\r
- }\r
- setTimeRange(input);\r
- _verticalScrollBar.setEnabled(true);\r
- setTopIndex(0);\r
- _selectedTime = 0;\r
- refreshAllData(input);\r
- }\r
- }\r
-\r
- public void refresh() {\r
- setInput(_stateCtrl.getTraces());\r
- }\r
-\r
- public void controlMoved(ControlEvent e) {\r
- }\r
-\r
- public void controlResized(ControlEvent e) {\r
- resizeControls();\r
- }\r
-\r
- // called from the display order in the API\r
- public void modelUpdate(ITimeGraphEntry[] traces, long start,\r
- long end, boolean updateTimeBounds) {\r
- if (null != _stateCtrl) {\r
- //loadOptions();\r
- updateInternalData(traces, start, end);\r
- if (updateTimeBounds) {\r
- _timeRangeFixed = true;\r
- // set window to match limits\r
- setStartFinishTime(_time0_, _time1_);\r
- } else {\r
- _stateCtrl.redraw();\r
- _timeScaleCtrl.redraw();\r
- }\r
- }\r
- }\r
-\r
- protected String getViewTypeStr() {\r
- return "viewoption.threads"; //$NON-NLS-1$\r
- }\r
-\r
- int getMarginWidth(int idx) {\r
- return 0;\r
- }\r
-\r
- int getMarginHeight(int idx) {\r
- return 0;\r
- }\r
-\r
- void loadOptions() {\r
- _minTimeInterval = 1;\r
- _selectedTime = -1;\r
- _nameWidth = Utils.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$\r
- _nameWidthPref, _minNameWidth, 1000);\r
- }\r
-\r
- void saveOptions() {\r
- Utils.saveIntOption(getPreferenceString("namewidth"), _nameWidth); //$NON-NLS-1$\r
- }\r
-\r
- protected Control createDataViewer(Composite parent, int style) {\r
- loadOptions();\r
- _colors = new TimeGraphColorScheme();\r
- _dataViewer = new Composite(parent, style) {\r
- @Override\r
- public void redraw() {\r
- _stateCtrl.redraw();\r
- super.redraw();\r
- }\r
- };\r
- GridLayout gl = new GridLayout(2, false);\r
- gl.marginHeight = borderWidth;\r
- gl.marginWidth = 0;\r
- gl.verticalSpacing = 0;\r
- gl.horizontalSpacing = 0;\r
- _dataViewer.setLayout(gl);\r
-\r
- _timeScaleCtrl = new TimeGraphScale(_dataViewer, _colors);\r
- _timeScaleCtrl.setTimeProvider(this);\r
- _timeScaleCtrl.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));\r
- _timeScaleCtrl.setHeight(timeScaleHeight);\r
-\r
- _verticalScrollBar = new Slider(_dataViewer, SWT.VERTICAL | SWT.NO_FOCUS);\r
- _verticalScrollBar.setLayoutData(new GridData(SWT.DEFAULT, SWT.FILL, false, true, 1, 2));\r
- _verticalScrollBar.addSelectionListener(new SelectionAdapter() {\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- setTopIndex(_verticalScrollBar.getSelection());\r
- }\r
- });\r
- _verticalScrollBar.setEnabled(false);\r
-\r
- _stateCtrl = createTimeGraphControl();\r
-\r
- _stateCtrl.setTimeProvider(this);\r
- _stateCtrl.addSelectionListener(this);\r
- _stateCtrl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2));\r
- _stateCtrl.addMouseWheelListener(new MouseWheelListener() {\r
- @Override\r
- public void mouseScrolled(MouseEvent e) {\r
- adjustVerticalScrollBar();\r
- }\r
- });\r
- _stateCtrl.addKeyListener(new KeyAdapter() {\r
- @Override\r
- public void keyPressed(KeyEvent e) {\r
- adjustVerticalScrollBar();\r
- }\r
- });\r
-\r
- Composite filler = new Composite(_dataViewer, SWT.NONE);\r
- GridData gd = new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false);\r
- gd.heightHint = _stateCtrl.getHorizontalBar().getSize().y;\r
- filler.setLayoutData(gd);\r
- filler.setLayout(new FillLayout());\r
-\r
- _stateCtrl.addControlListener(new ControlAdapter() {\r
- @Override\r
- public void controlResized(ControlEvent event) {\r
- resizeControls();\r
- }\r
- });\r
- resizeControls();\r
- _dataViewer.update();\r
- adjustVerticalScrollBar();\r
- return _dataViewer;\r
- }\r
-\r
- public void dispose() {\r
- saveOptions();\r
- _stateCtrl.dispose();\r
- _dataViewer.dispose();\r
- _colors.dispose();\r
- }\r
-\r
- protected TimeGraphControl createTimeGraphControl() {\r
- return new TimeGraphControl(_dataViewer, _colors);\r
- }\r
-\r
- public void resizeControls() {\r
- Rectangle r = _dataViewer.getClientArea();\r
- if (r.isEmpty())\r
- return;\r
-\r
- int width = r.width;\r
- if (_nameWidth > width - _minNameWidth)\r
- _nameWidth = width - _minNameWidth;\r
- if (_nameWidth < _minNameWidth)\r
- _nameWidth = _minNameWidth;\r
- adjustVerticalScrollBar();\r
- }\r
-\r
- /** Tries to set most convenient time range for display. */\r
- public void setTimeRange(ITimeGraphEntry traces[]) {\r
- _endTime = 0;\r
- _beginTime = -1;\r
- for (int i = 0; i < traces.length; i++) {\r
- ITimeGraphEntry entry = traces[i];\r
- if (entry.getEndTime() >= entry.getStartTime() && entry.getEndTime() > 0) {\r
- if (_beginTime < 0 || entry.getStartTime() < _beginTime) {\r
- _beginTime = entry.getStartTime();\r
- }\r
- if (entry.getEndTime() > _endTime) {\r
- _endTime = entry.getEndTime();\r
- }\r
- }\r
- }\r
-\r
- if (_beginTime < 0) {\r
- _beginTime = 0;\r
- }\r
- }\r
-\r
- public void setTimeBounds() {\r
- //_time0_ = _beginTime - (long) ((_endTime - _beginTime) * 0.02);\r
- _time0_ = _beginTime;\r
- if (_time0_ < 0)\r
- _time0_ = 0;\r
- // _time1_ = _time0_ + (_endTime - _time0_) * 1.05;\r
- _time1_ = _endTime;\r
- // _time0_ = Math.floor(_time0_);\r
- // _time1_ = Math.ceil(_time1_);\r
- if (!_timeRangeFixed) {\r
- _time0 = _time0_;\r
- _time1 = _time1_;\r
- }\r
- if (_time1 - _time0 < _minTimeInterval) {\r
- _time1 = _time0 + _minTimeInterval;\r
- }\r
- }\r
-\r
- /**\r
- * @param traces\r
- * @param start\r
- * @param end\r
- */\r
- void updateInternalData(ITimeGraphEntry[] traces, long start, long end) {\r
- if (null == traces)\r
- traces = new ITimeGraphEntry[0];\r
- if ((start == 0 && end == 0) || start < 0 || end < 0) {\r
- // Start and end time are unspecified and need to be determined from\r
- // individual processes\r
- setTimeRange(traces);\r
- } else {\r
- _beginTime = start;\r
- _endTime = end;\r
- }\r
-\r
- refreshAllData(traces);\r
- }\r
-\r
- /**\r
- * @param traces\r
- */\r
- private void refreshAllData(ITimeGraphEntry[] traces) {\r
- setTimeBounds();\r
- if (_selectedTime < _beginTime) {\r
- _selectedTime = _beginTime;\r
- } else if (_selectedTime > _endTime) {\r
- _selectedTime = _endTime;\r
- }\r
- _stateCtrl.refreshData(traces);\r
- _timeScaleCtrl.redraw();\r
- adjustVerticalScrollBar();\r
- }\r
-\r
- public void setFocus() {\r
- if (null != _stateCtrl)\r
- _stateCtrl.setFocus();\r
- }\r
-\r
- public boolean isInFocus() {\r
- return _stateCtrl.isInFocus();\r
- }\r
-\r
- public ITimeGraphEntry getSelection() {\r
- return _stateCtrl.getSelectedTrace();\r
- }\r
-\r
- public int getSelectionIndex() {\r
- return _stateCtrl.getSelectedIndex();\r
- }\r
-\r
- @Override\r
- public long getTime0() {\r
- return _time0;\r
- }\r
-\r
- @Override\r
- public long getTime1() {\r
- return _time1;\r
- }\r
-\r
- @Override\r
- public long getMinTimeInterval() {\r
- return _minTimeInterval;\r
- }\r
-\r
- @Override\r
- public int getNameSpace() {\r
- return _nameWidth;\r
- }\r
-\r
- @Override\r
- public void setNameSpace(int width) {\r
- _nameWidth = width;\r
- width = _stateCtrl.getClientArea().width;\r
- if (_nameWidth > width - 6)\r
- _nameWidth = width - 6;\r
- if (_nameWidth < 6)\r
- _nameWidth = 6;\r
- _stateCtrl.adjustScrolls();\r
- _stateCtrl.redraw();\r
- _timeScaleCtrl.redraw();\r
- }\r
-\r
- @Override\r
- public int getTimeSpace() {\r
- int w = _stateCtrl.getClientArea().width;\r
- return w - _nameWidth;\r
- }\r
-\r
- @Override\r
- public long getSelectedTime() {\r
- return _selectedTime;\r
- }\r
-\r
- @Override\r
- public long getBeginTime() {\r
- return _beginTime;\r
- }\r
-\r
- @Override\r
- public long getEndTime() {\r
- return _endTime;\r
- }\r
-\r
- @Override\r
- public long getMaxTime() {\r
- return _time1_;\r
- }\r
-\r
- @Override\r
- public long getMinTime() {\r
- return _time0_;\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see\r
- * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider\r
- * #setStartFinishTimeNotify(long, long)\r
- */\r
- @Override\r
- public void setStartFinishTimeNotify(long time0, long time1) {\r
- setStartFinishTime(time0, time1);\r
- notifyRangeListeners(time0, time1);\r
- }\r
-\r
-\r
- /* (non-Javadoc)\r
- * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider#notifyStartFinishTime()\r
- */\r
- @Override\r
- public void notifyStartFinishTime() {\r
- notifyRangeListeners(_time0, _time1);\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see\r
- * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider\r
- * #setStartFinishTime(long, long)\r
- */\r
- @Override\r
- public void setStartFinishTime(long time0, long time1) {\r
- _time0 = time0;\r
- if (_time0 < _time0_)\r
- _time0 = _time0_;\r
- if (_time0 > _time1_)\r
- _time0 = _time1_;\r
- _time1 = time1;\r
- if (_time1 < _time0_)\r
- _time1 = _time0_;\r
- if (_time1 > _time1_)\r
- _time1 = _time1_;\r
- if (_time1 - _time0 < _minTimeInterval)\r
- _time1 = _time0 + _minTimeInterval;\r
- _timeRangeFixed = true;\r
- _stateCtrl.adjustScrolls();\r
- _stateCtrl.redraw();\r
- _timeScaleCtrl.redraw();\r
- }\r
-\r
- public void setTimeBounds(long beginTime, long endTime) {\r
- _beginTime = beginTime;\r
- _endTime = endTime;\r
- _time0_ = beginTime;\r
- _time1_ = endTime;\r
- _stateCtrl.adjustScrolls();\r
- }\r
-\r
- @Override\r
- public void resetStartFinishTime() {\r
- setStartFinishTimeNotify(_time0_, _time1_);\r
- _timeRangeFixed = false;\r
- }\r
-\r
- @Override\r
- public void setSelectedTimeNotify(long time, boolean ensureVisible) {\r
- setSelectedTimeInt(time, ensureVisible, true);\r
- }\r
- \r
- @Override\r
- public void setSelectedTime(long time, boolean ensureVisible) {\r
- setSelectedTimeInt(time, ensureVisible, false);\r
- }\r
-\r
- private void setSelectedTimeInt(long time, boolean ensureVisible, boolean doNotify) {\r
- long time0 = _time0;\r
- long time1 = _time1;\r
- if (ensureVisible) {\r
- long timeSpace = (long) ((_time1 - _time0) * .02);\r
- long timeMid = (long) ((_time1 - _time0) * .5);\r
- if (time < _time0 + timeSpace) {\r
- long dt = _time0 - time + timeMid;\r
- _time0 -= dt;\r
- _time1 -= dt;\r
- } else if (time > _time1 - timeSpace) {\r
- long dt = time - _time1 + timeMid;\r
- _time0 += dt;\r
- _time1 += dt;\r
- }\r
- if (_time0 < _time0_) {\r
- _time1 = Math.min(_time1_, _time1 + (_time0_ - _time0));\r
- _time0 = _time0_;\r
- } else if (_time1 > _time1_) {\r
- _time0 = Math.max(_time0_, _time0 - (_time1 - _time1_));\r
- _time1 = _time1_;\r
- }\r
- }\r
- if (_time1 - _time0 < _minTimeInterval) {\r
- _time1 = _time0 + _minTimeInterval;\r
- }\r
- _stateCtrl.adjustScrolls();\r
- _stateCtrl.redraw();\r
- _timeScaleCtrl.redraw();\r
- \r
- \r
- boolean notifySelectedTime = (time != _selectedTime);\r
- _selectedTime = time;\r
- \r
- if (doNotify && ((time0 != _time0) || (time1 != _time1))) {\r
- notifyRangeListeners(_time0, _time1);\r
- }\r
- \r
- if (doNotify && notifySelectedTime) {\r
- notifyTimeListeners(_selectedTime);\r
- }\r
- }\r
-\r
- @Override\r
- public void widgetDefaultSelected(SelectionEvent e) {\r
- if (_selectedEntry != getSelection()) {\r
- _selectedEntry = getSelection();\r
- notifySelectionListeners(_selectedEntry);\r
- }\r
- }\r
-\r
- @Override\r
- public void widgetSelected(SelectionEvent e) {\r
- if (_selectedEntry != getSelection()) {\r
- _selectedEntry = getSelection();\r
- notifySelectionListeners(_selectedEntry);\r
- }\r
- }\r
-\r
- public void selectNextEvent() {\r
- _stateCtrl.selectNextEvent();\r
- adjustVerticalScrollBar();\r
- }\r
-\r
- public void selectPrevEvent() {\r
- _stateCtrl.selectPrevEvent();\r
- adjustVerticalScrollBar();\r
- }\r
-\r
- public void selectNextItem() {\r
- _stateCtrl.selectNextTrace();\r
- adjustVerticalScrollBar();\r
- }\r
-\r
- public void selectPrevItem() {\r
- _stateCtrl.selectPrevTrace();\r
- adjustVerticalScrollBar();\r
- }\r
-\r
- public void showLegend() {\r
- if (_dataViewer == null || _dataViewer.isDisposed())\r
- return;\r
-\r
- TimeGraphLegend.open(_dataViewer.getShell(), fTimeGraphProvider);\r
- }\r
-\r
- public void zoomIn() {\r
- _stateCtrl.zoomIn();\r
- }\r
-\r
- public void zoomOut() {\r
- _stateCtrl.zoomOut();\r
- }\r
-\r
- private String getPreferenceString(String string) {\r
- return getViewTypeStr() + "." + string; //$NON-NLS-1$\r
- }\r
-\r
- public void addSelectionListener(ITimeGraphSelectionListener listener) {\r
- fSelectionListeners.add(listener);\r
- }\r
-\r
- public void removeSelectionListener(ITimeGraphSelectionListener listener) {\r
- fSelectionListeners.remove(listener);\r
- }\r
-\r
- private void notifySelectionListeners(ITimeGraphEntry selection) {\r
- TimeGraphSelectionEvent event = new TimeGraphSelectionEvent(this, selection);\r
-\r
- for (ITimeGraphSelectionListener listener : fSelectionListeners) {\r
- listener.selectionChanged(event);\r
- }\r
- }\r
-\r
- public void addTimeListener(ITimeGraphTimeListener listener) {\r
- fTimeListeners.add(listener);\r
- }\r
-\r
- public void removeTimeListener(ITimeGraphTimeListener listener) {\r
- fTimeListeners.remove(listener);\r
- }\r
-\r
- private void notifyTimeListeners(long time) {\r
- TimeGraphTimeEvent event = new TimeGraphTimeEvent(this, time);\r
-\r
- for (ITimeGraphTimeListener listener : fTimeListeners) {\r
- listener.timeSelected(event);\r
- }\r
- }\r
-\r
- public void addRangeListener(ITimeGraphRangeListener listener) {\r
- fRangeListeners.add(listener);\r
- }\r
-\r
- public void removeRangeListener(ITimeGraphRangeListener listener) {\r
- fRangeListeners.remove(listener);\r
- }\r
-\r
- private void notifyRangeListeners(long startTime, long endTime) {\r
- // Check if the time has actually changed from last notification\r
- if (startTime != _time0_extSynch || endTime != _time1_extSynch) {\r
- // Notify Time Scale Selection Listeners\r
- TimeGraphRangeUpdateEvent event = new TimeGraphRangeUpdateEvent(this, startTime, endTime);\r
-\r
- for (ITimeGraphRangeListener listener : fRangeListeners) {\r
- listener.timeRangeUpdated(event);\r
- }\r
-\r
- // update external synch timers\r
- updateExtSynchTimers();\r
- }\r
- }\r
-\r
- public void setSelectedTime(long time, boolean ensureVisible, Object source) {\r
- if (this == source) {\r
- return;\r
- }\r
-\r
- setSelectedTimeNotify(time, ensureVisible);\r
- }\r
-\r
- public void setSelectedEvent(ITimeEvent event, Object source) {\r
- if (event == null || source == this) {\r
- return;\r
- }\r
- _selectedEntry = event.getEntry();\r
- _stateCtrl.selectItem(_selectedEntry, false);\r
-\r
- setSelectedTimeInt(event.getTime(), true, true);\r
- adjustVerticalScrollBar();\r
- }\r
-\r
- public void setSelectedTraceTime(ITimeGraphEntry trace, long time, Object source) {\r
- if (trace == null || source == this) {\r
- return;\r
- }\r
- _selectedEntry = trace;\r
- _stateCtrl.selectItem(trace, false);\r
-\r
- setSelectedTimeInt(time, true, true);\r
- }\r
-\r
- public void setSelection(ITimeGraphEntry trace) {\r
- _selectedEntry = trace;\r
- _stateCtrl.selectItem(trace, false);\r
- adjustVerticalScrollBar();\r
- }\r
-\r
- public void setSelectVisTimeWindow(long time0, long time1, Object source) {\r
- if (source == this) {\r
- return;\r
- }\r
-\r
- setStartFinishTime(time0, time1);\r
-\r
- // update notification time values since we are now in synch with the\r
- // external application\r
- updateExtSynchTimers();\r
- }\r
-\r
- /**\r
- * update the cache timers used to identify the need to send a time window\r
- * update to external registered listeners\r
- */\r
- private void updateExtSynchTimers() {\r
- // last time notification cache\r
- _time0_extSynch = _time0;\r
- _time1_extSynch = _time1;\r
- }\r
-\r
- public void setTimeCalendarFormat(boolean toAbsoluteCaltime) {\r
- calendarTimeFormat = toAbsoluteCaltime;\r
- }\r
-\r
- @Override\r
- public boolean isCalendarFormat() {\r
- return calendarTimeFormat;\r
- }\r
-\r
- public int getBorderWidth() {\r
- return borderWidth;\r
- }\r
-\r
- public void setBorderWidth(int borderWidth) {\r
- if (borderWidth > -1) {\r
- this.borderWidth = borderWidth;\r
- GridLayout gl = (GridLayout)_dataViewer.getLayout();\r
- gl.marginHeight = borderWidth;\r
- }\r
- }\r
-\r
- public int getHeaderHeight() {\r
- return timeScaleHeight;\r
- }\r
-\r
- public void setHeaderHeight(int headerHeight) {\r
- if (headerHeight > -1) {\r
- this.timeScaleHeight = headerHeight;\r
- _timeScaleCtrl.setHeight(headerHeight);\r
- }\r
- }\r
-\r
- public int getItemHeight() {\r
- if (_stateCtrl != null) {\r
- return _stateCtrl.getItemHeight();\r
- }\r
- return 0;\r
- }\r
-\r
- public void setItemHeight(int rowHeight) {\r
- if (_stateCtrl != null) {\r
- _stateCtrl.setItemHeight(rowHeight);\r
- }\r
- }\r
-\r
- public void setMinimumItemWidth(int width) {\r
- if (_stateCtrl != null) {\r
- _stateCtrl.setMinimumItemWidth(width);\r
- }\r
- }\r
-\r
- public void setNameWidthPref(int width) {\r
- _nameWidthPref = width;\r
- if (width == 0) {\r
- _minNameWidth = 0;\r
- _nameWidth = 0;\r
- }\r
- }\r
-\r
- public int getNameWidthPref(int width) {\r
- return _nameWidthPref;\r
- }\r
-\r
- /**\r
- * Returns the primary control associated with this viewer.\r
- *\r
- * @return the SWT control which displays this viewer's content\r
- */\r
- public Control getControl() {\r
- return _dataViewer;\r
- }\r
-\r
- /**\r
- * Returns the time graph control associated with this viewer.\r
- *\r
- * @return the time graph control\r
- */\r
- TimeGraphControl getTimeGraphControl() {\r
- return _stateCtrl;\r
- }\r
-\r
- /**\r
- * Get the selection provider\r
- * \r
- * @return the selection provider\r
- */\r
- public ISelectionProvider getSelectionProvider() {\r
- return _stateCtrl;\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see\r
- * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.ITimeAnalysisViewer\r
- * #waitCursor(boolean)\r
- */\r
- public void waitCursor(boolean waitInd) {\r
- _stateCtrl.waitCursor(waitInd);\r
- }\r
-\r
- public ScrollBar getHorizontalBar() {\r
- return _stateCtrl.getHorizontalBar();\r
- }\r
-\r
- public Slider getVerticalBar() {\r
- return _verticalScrollBar;\r
- }\r
-\r
- public void setTopIndex(int index) {\r
- _stateCtrl.setTopIndex(index);\r
- adjustVerticalScrollBar();\r
- }\r
-\r
- public int getTopIndex() {\r
- return _stateCtrl.getTopIndex();\r
- }\r
-\r
- public void setExpandedState(ITimeGraphEntry entry, boolean expanded) {\r
- _stateCtrl.setExpandedState(entry, expanded);\r
- adjustVerticalScrollBar();\r
- }\r
-\r
- public int getExpandedElementCount() {\r
- return _stateCtrl.getExpandedElementCount();\r
- }\r
-\r
- public ITimeGraphEntry[] getExpandedElements() {\r
- return _stateCtrl.getExpandedElements();\r
- }\r
-\r
- public void addTreeListener(ITimeGraphTreeListener listener) {\r
- _stateCtrl.addTreeListener(listener);\r
- }\r
-\r
- public void removeTreeListener(ITimeGraphTreeListener listener) {\r
- _stateCtrl.removeTreeListener(listener);\r
- }\r
- \r
- public Action getResetScaleAction() {\r
- if (resetScale == null) {\r
- // resetScale\r
- resetScale = new Action() {\r
- @Override\r
- public void run() {\r
- resetStartFinishTime();\r
- }\r
- };\r
- resetScale.setText(Messages.TmfTimeGraphViewer_ResetScaleActionNameText);\r
- resetScale.setToolTipText(Messages.TmfTimeGraphViewer_ResetScaleActionToolTipText);\r
- resetScale.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_HOME_MENU));\r
- } \r
- return resetScale;\r
- }\r
-\r
- public Action getShowLegendAction() {\r
- if (showLegendAction == null) {\r
- // showLegend\r
- showLegendAction = new Action() {\r
- @Override\r
- public void run() {\r
- showLegend();\r
- }\r
- };\r
- showLegendAction.setText(Messages.TmfTimeGraphViewer_LegendActionNameText);\r
- showLegendAction.setToolTipText(Messages.TmfTimeGraphViewer_LegendActionToolTipText);\r
- showLegendAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_SHOW_LEGEND));\r
- }\r
-\r
- return showLegendAction;\r
- }\r
- \r
- public Action getNextEventAction() {\r
- if (nextEventAction == null) {\r
- nextEventAction = new Action() {\r
- @Override\r
- public void run() {\r
- selectNextEvent();\r
- }\r
- };\r
-\r
- nextEventAction.setText(Messages.TmfTimeGraphViewer_NextEventActionNameText);\r
- nextEventAction.setToolTipText(Messages.TmfTimeGraphViewer_NextEventActionToolTipText);\r
- nextEventAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_EVENT));\r
- } \r
-\r
- return nextEventAction;\r
- }\r
-\r
- public Action getPreviousEventAction() {\r
- if (prevEventAction == null) {\r
- prevEventAction = new Action() {\r
- @Override\r
- public void run() {\r
- selectPrevEvent();\r
- }\r
- };\r
-\r
- prevEventAction.setText(Messages.TmfTimeGraphViewer_PreviousEventActionNameText);\r
- prevEventAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousEventActionToolTipText);\r
- prevEventAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_EVENT));\r
- } \r
-\r
- return prevEventAction;\r
- }\r
-\r
- public Action getNextItemAction() {\r
- if (nextItemAction == null) {\r
-\r
- nextItemAction = new Action() {\r
- @Override\r
- public void run() {\r
- selectNextItem();\r
- }\r
- };\r
- nextItemAction.setText(Messages.TmfTimeGraphViewer_NextItemActionNameText);\r
- nextItemAction.setToolTipText(Messages.TmfTimeGraphViewer_NextItemActionToolTipText);\r
- nextItemAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_ITEM));\r
- }\r
- return nextItemAction;\r
- }\r
-\r
- public Action getPreviousItemAction() {\r
- if (previousItemAction == null) {\r
-\r
- previousItemAction = new Action() {\r
- @Override\r
- public void run() {\r
- selectPrevItem();\r
- }\r
- };\r
- previousItemAction.setText(Messages.TmfTimeGraphViewer_PreviousItemActionNameText);\r
- previousItemAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousItemActionToolTipText);\r
- previousItemAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_ITEM));\r
- }\r
- return previousItemAction;\r
- }\r
- \r
- public Action getZoomInAction() {\r
- if (zoomInAction == null) {\r
- zoomInAction = new Action() {\r
- @Override\r
- public void run() {\r
- zoomIn();\r
- }\r
- };\r
- zoomInAction.setText(Messages.TmfTimeGraphViewer_ZoomInActionNameText);\r
- zoomInAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomInActionToolTipText);\r
- zoomInAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_IN_MENU));\r
- }\r
- return zoomInAction;\r
- }\r
-\r
- public Action getZoomOutAction() {\r
- if (zoomOutAction == null) {\r
- zoomOutAction = new Action() {\r
- @Override\r
- public void run() {\r
- zoomOut();\r
- }\r
- };\r
- zoomOutAction.setText(Messages.TmfTimeGraphViewer_ZoomOutActionNameText);\r
- zoomOutAction.setToolTipText(Messages.TmfTimeGraphViewer_ZoomOutActionToolTipText);\r
- zoomOutAction.setImageDescriptor(TmfUiPlugin.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_ZOOM_OUT_MENU));\r
- }\r
- return zoomOutAction;\r
- }\r
- \r
- \r
- private void adjustVerticalScrollBar() {\r
- int topIndex = _stateCtrl.getTopIndex();\r
- int countPerPage = _stateCtrl.countPerPage();\r
- int expandedElementCount = _stateCtrl.getExpandedElementCount();\r
- if (topIndex + countPerPage > expandedElementCount) {\r
- _stateCtrl.setTopIndex(Math.max(0, expandedElementCount - countPerPage));\r
- }\r
-\r
- int selection = _stateCtrl.getTopIndex();\r
- int min = 0;\r
- int max = Math.max(1, expandedElementCount - 1);\r
- int thumb = Math.min(max, Math.max(1, countPerPage - 1));\r
- int increment = 1;\r
- int pageIncrement = Math.max(1, countPerPage);\r
- _verticalScrollBar.setValues(selection, min, max, thumb, increment, pageIncrement);\r
- }\r
- \r
- \r
-\r
-}\r
+/*****************************************************************************
+ * Copyright (c) 2007, 2013 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ * Ruslan A. Scherbakov, Intel - Initial API and implementation
+ * Alexander N. Alexeev, Intel - Add monitors statistics support
+ * Alvaro Sanchez-Leon - Adapted for TMF
+ * Patrick Tasse - Refactoring
+ *****************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph;
+
+import java.util.ArrayList;
+
+import org.eclipse.jface.action.Action;
+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.ITimeEvent;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider;
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme;
+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;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.MenuDetectListener;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseWheelListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.ScrollBar;
+import org.eclipse.swt.widgets.Slider;
+
+/**
+ * Generic time graph viewer implementation
+ *
+ * @version 1.0
+ * @author Patrick Tasse, and others
+ */
+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;
+ private ITimeGraphPresentationProvider fTimeGraphProvider;
+
+ ArrayList<ITimeGraphSelectionListener> fSelectionListeners = new ArrayList<ITimeGraphSelectionListener>();
+ ArrayList<ITimeGraphTimeListener> fTimeListeners = new ArrayList<ITimeGraphTimeListener>();
+ ArrayList<ITimeGraphRangeListener> fRangeListeners = new ArrayList<ITimeGraphRangeListener>();
+
+ // Time format, using Epoch reference, Relative time format(default) or Number
+ private TimeFormat timeFormat = TimeFormat.RELATIVE;
+ 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
+ *
+ * @param parent
+ * The parent UI composite object
+ * @param style
+ * The style to use
+ */
+ public TimeGraphViewer(Composite parent, int style) {
+ createDataViewer(parent, style);
+ }
+
+ /**
+ * Sets the timegraph 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);
+ }
+
+ /**
+ * 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
+ */
+ public void setInput(ITimeGraphEntry[] input) {
+ ITimeGraphEntry[] realInput = input;
+
+ if (_stateCtrl != null) {
+ if (realInput == null) {
+ realInput = new ITimeGraphEntry[0];
+ }
+ setTimeRange(realInput);
+ _verticalScrollBar.setEnabled(true);
+ setTopIndex(0);
+ _selectedTime = 0;
+ _selectedEntry = null;
+ refreshAllData(realInput);
+ }
+ }
+
+ /**
+ * Refresh the view
+ */
+ public void refresh() {
+ setInput(_stateCtrl.getTraces());
+ }
+
+ /**
+ * Callback for when the control is moved
+ *
+ * @param e
+ * The caller event
+ */
+ public void controlMoved(ControlEvent e) {
+ }
+
+ /**
+ * Callback for when the control is resized
+ *
+ * @param e
+ * The caller event
+ */
+ public void controlResized(ControlEvent e) {
+ resizeControls();
+ }
+
+ /**
+ * Handler for when the model is updated. Called from the display order in
+ * the API
+ *
+ * @param traces
+ * The traces in the model
+ * @param start
+ * The start time
+ * @param end
+ * The end time
+ * @param updateTimeBounds
+ * Should we updated the time bounds too
+ */
+ public void modelUpdate(ITimeGraphEntry[] traces, long start,
+ long end, boolean updateTimeBounds) {
+ if (null != _stateCtrl) {
+ //loadOptions();
+ updateInternalData(traces, start, end);
+ if (updateTimeBounds) {
+ _timeRangeFixed = true;
+ // set window to match limits
+ setStartFinishTime(_time0_, _time1_);
+ } else {
+ _stateCtrl.redraw();
+ _timeScaleCtrl.redraw();
+ }
+ }
+ }
+
+ /**
+ * @return The string representing the view type
+ */
+ protected String getViewTypeStr() {
+ return "viewoption.threads"; //$NON-NLS-1$
+ }
+
+ int getMarginWidth() {
+ return 0;
+ }
+
+ int getMarginHeight() {
+ return 0;
+ }
+
+ void loadOptions() {
+ _minTimeInterval = 1;
+ _selectedTime = -1;
+ _nameWidth = Utils.loadIntOption(getPreferenceString("namewidth"), //$NON-NLS-1$
+ _nameWidthPref, _minNameWidth, 1000);
+ }
+
+ void saveOptions() {
+ Utils.saveIntOption(getPreferenceString("namewidth"), _nameWidth); //$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) {
+ @Override
+ public void redraw() {
+ _timeScaleCtrl.redraw();
+ _stateCtrl.redraw();
+ super.redraw();
+ }
+ };
+ GridLayout gl = new GridLayout(2, false);
+ gl.marginHeight = borderWidth;
+ gl.marginWidth = 0;
+ gl.verticalSpacing = 0;
+ gl.horizontalSpacing = 0;
+ _dataViewer.setLayout(gl);
+
+ _timeScaleCtrl = new TimeGraphScale(_dataViewer, _colors);
+ _timeScaleCtrl.setTimeProvider(this);
+ _timeScaleCtrl.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
+ _timeScaleCtrl.setHeight(timeScaleHeight);
+
+ _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() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ setTopIndex(_verticalScrollBar.getSelection());
+ }
+ });
+ _verticalScrollBar.setEnabled(false);
+
+ _stateCtrl = createTimeGraphControl(_dataViewer, _colors);
+
+ _stateCtrl.setTimeProvider(this);
+ _stateCtrl.addSelectionListener(this);
+ _stateCtrl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2));
+ _stateCtrl.addMouseWheelListener(new MouseWheelListener() {
+ @Override
+ public void mouseScrolled(MouseEvent e) {
+ adjustVerticalScrollBar();
+ }
+ });
+ _stateCtrl.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ adjustVerticalScrollBar();
+ }
+ });
+
+ Composite filler = new Composite(_dataViewer, SWT.NONE);
+ GridData gd = new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false);
+ gd.heightHint = _stateCtrl.getHorizontalBar().getSize().y;
+ filler.setLayoutData(gd);
+ filler.setLayout(new FillLayout());
+
+ _stateCtrl.addControlListener(new ControlAdapter() {
+ @Override
+ public void controlResized(ControlEvent event) {
+ resizeControls();
+ }
+ });
+ resizeControls();
+ _dataViewer.update();
+ adjustVerticalScrollBar();
+ return _dataViewer;
+ }
+
+ /**
+ * Dispose the view.
+ */
+ public void dispose() {
+ saveOptions();
+ _stateCtrl.dispose();
+ _dataViewer.dispose();
+ _colors.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) {
+ return new TimeGraphControl(parent, colors);
+ }
+
+ /**
+ * Resize the controls
+ */
+ public void resizeControls() {
+ Rectangle r = _dataViewer.getClientArea();
+ if (r.isEmpty()) {
+ return;
+ }
+
+ int width = r.width;
+ if (_nameWidth > width - _minNameWidth) {
+ _nameWidth = width - _minNameWidth;
+ }
+ if (_nameWidth < _minNameWidth) {
+ _nameWidth = _minNameWidth;
+ }
+ adjustVerticalScrollBar();
+ }
+
+ /**
+ * Try to set most convenient time range for display.
+ *
+ * @param traces
+ * The traces in the model
+ */
+ public void setTimeRange(ITimeGraphEntry traces[]) {
+ _endTime = 0;
+ _beginTime = -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 (entry.getEndTime() > _endTime) {
+ _endTime = entry.getEndTime();
+ }
+ }
+ }
+
+ if (_beginTime < 0) {
+ _beginTime = 0;
+ }
+ }
+
+ /**
+ * Recalculate the time bounds
+ */
+ public void setTimeBounds() {
+ //_time0_ = _beginTime - (long) ((_endTime - _beginTime) * 0.02);
+ _time0_ = _beginTime;
+ if (_time0_ < 0) {
+ _time0_ = 0;
+ }
+ // _time1_ = _time0_ + (_endTime - _time0_) * 1.05;
+ _time1_ = _endTime;
+ // _time0_ = Math.floor(_time0_);
+ // _time1_ = Math.ceil(_time1_);
+ if (!_timeRangeFixed) {
+ _time0 = _time0_;
+ _time1 = _time1_;
+ }
+ if (_time1 - _time0 < _minTimeInterval) {
+ _time1 = Math.min(_time1_, _time0 + _minTimeInterval);
+ }
+ }
+
+ /**
+ * @param traces
+ * @param start
+ * @param end
+ */
+ void updateInternalData(ITimeGraphEntry[] traces, long start, long end) {
+ 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(realTraces);
+ } else {
+ _beginTime = start;
+ _endTime = end;
+ }
+
+ refreshAllData(realTraces);
+ }
+
+ /**
+ * @param traces
+ */
+ private void refreshAllData(ITimeGraphEntry[] traces) {
+ setTimeBounds();
+ if (_selectedTime < _beginTime) {
+ _selectedTime = _beginTime;
+ } else if (_selectedTime > _endTime) {
+ _selectedTime = _endTime;
+ }
+ _stateCtrl.refreshData(traces);
+ _timeScaleCtrl.redraw();
+ adjustVerticalScrollBar();
+ }
+
+ /**
+ * Callback for when this view is focused
+ */
+ public void setFocus() {
+ if (null != _stateCtrl) {
+ _stateCtrl.setFocus();
+ }
+ }
+
+ /**
+ * Get the current focus status of this view.
+ *
+ * @return If the view is currently focused, or not
+ */
+ public boolean isInFocus() {
+ return _stateCtrl.isInFocus();
+ }
+
+ /**
+ * Get the view's current selection
+ *
+ * @return The entry that is selected
+ */
+ public ITimeGraphEntry getSelection() {
+ return _stateCtrl.getSelectedTrace();
+ }
+
+ /**
+ * Get the index of the current selection
+ *
+ * @return The index
+ */
+ public int getSelectionIndex() {
+ return _stateCtrl.getSelectedIndex();
+ }
+
+ @Override
+ public long getTime0() {
+ return _time0;
+ }
+
+ @Override
+ public long getTime1() {
+ return _time1;
+ }
+
+ @Override
+ public long getMinTimeInterval() {
+ return _minTimeInterval;
+ }
+
+ @Override
+ public int getNameSpace() {
+ return _nameWidth;
+ }
+
+ @Override
+ public void setNameSpace(int width) {
+ _nameWidth = width;
+ int w = _stateCtrl.getClientArea().width;
+ if (_nameWidth > w - 6) {
+ _nameWidth = w - 6;
+ }
+ if (_nameWidth < 6) {
+ _nameWidth = 6;
+ }
+ _stateCtrl.adjustScrolls();
+ _stateCtrl.redraw();
+ _timeScaleCtrl.redraw();
+ }
+
+ @Override
+ public int getTimeSpace() {
+ int w = _stateCtrl.getClientArea().width;
+ return w - _nameWidth;
+ }
+
+ @Override
+ public long getSelectedTime() {
+ return _selectedTime;
+ }
+
+ @Override
+ public long getBeginTime() {
+ return _beginTime;
+ }
+
+ @Override
+ public long getEndTime() {
+ return _endTime;
+ }
+
+ @Override
+ public long getMaxTime() {
+ return _time1_;
+ }
+
+ @Override
+ public long getMinTime() {
+ return _time0_;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.widgets.ITimeDataProvider
+ * #setStartFinishTimeNotify(long, long)
+ */
+ @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);
+ }
+
+ /*
+ * (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_;
+ }
+ if (_time0 > _time1_) {
+ _time0 = _time1_;
+ }
+ _time1 = time1;
+ if (_time1 < _time0_) {
+ _time1 = _time0_;
+ }
+ if (_time1 > _time1_) {
+ _time1 = _time1_;
+ }
+ if (_time1 - _time0 < _minTimeInterval) {
+ _time1 = Math.min(_time1_, _time0 + _minTimeInterval);
+ }
+ _timeRangeFixed = true;
+ _stateCtrl.adjustScrolls();
+ _stateCtrl.redraw();
+ _timeScaleCtrl.redraw();
+ }
+
+ /**
+ * Set the time bounds to the provided values
+ *
+ * @param beginTime
+ * The start time of the window
+ * @param endTime
+ * The end time
+ */
+ public void setTimeBounds(long beginTime, long endTime) {
+ _beginTime = beginTime;
+ _endTime = endTime;
+ _time0_ = beginTime;
+ _time1_ = endTime;
+ _stateCtrl.adjustScrolls();
+ }
+
+ @Override
+ public void resetStartFinishTime() {
+ setStartFinishTime(_time0_, _time1_);
+ _timeRangeFixed = false;
+ }
+
+ @Override
+ public void setSelectedTimeNotify(long time, boolean ensureVisible) {
+ setSelectedTimeInt(time, ensureVisible, true);
+ }
+
+ @Override
+ public void setSelectedTime(long time, boolean ensureVisible) {
+ setSelectedTimeInt(time, ensureVisible, false);
+ }
+
+ private void setSelectedTimeInt(long time, boolean ensureVisible, boolean doNotify) {
+ long time0 = _time0;
+ long time1 = _time1;
+ 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;
+ }
+ 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 (_time1 - _time0 < _minTimeInterval) {
+ _time1 = Math.min(_time1_, _time0 + _minTimeInterval);
+ }
+ _stateCtrl.adjustScrolls();
+ _stateCtrl.redraw();
+ _timeScaleCtrl.redraw();
+
+
+ boolean notifySelectedTime = (time != _selectedTime);
+ _selectedTime = time;
+
+ if (doNotify && ((time0 != _time0) || (time1 != _time1))) {
+ notifyRangeListeners(_time0, _time1);
+ }
+
+ if (doNotify && notifySelectedTime) {
+ notifyTimeListeners(_selectedTime);
+ }
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ if (_selectedEntry != getSelection()) {
+ _selectedEntry = getSelection();
+ notifySelectionListeners(_selectedEntry);
+ }
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (_selectedEntry != getSelection()) {
+ _selectedEntry = getSelection();
+ notifySelectionListeners(_selectedEntry);
+ }
+ }
+
+ /**
+ * Callback for when the next event is selected
+ */
+ public void selectNextEvent() {
+ _stateCtrl.selectNextEvent();
+ adjustVerticalScrollBar();
+ }
+
+ /**
+ * Callback for when the previous event is selected
+ */
+ public void selectPrevEvent() {
+ _stateCtrl.selectPrevEvent();
+ adjustVerticalScrollBar();
+ }
+
+ /**
+ * Callback for when the next item is selected
+ */
+ public void selectNextItem() {
+ _stateCtrl.selectNextTrace();
+ adjustVerticalScrollBar();
+ }
+
+ /**
+ * Callback for when the previous item is selected
+ */
+ public void selectPrevItem() {
+ _stateCtrl.selectPrevTrace();
+ adjustVerticalScrollBar();
+ }
+
+ /**
+ * Callback for the show legend action
+ */
+ public void showLegend() {
+ if (_dataViewer == null || _dataViewer.isDisposed()) {
+ return;
+ }
+
+ TimeGraphLegend.open(_dataViewer.getShell(), fTimeGraphProvider);
+ }
+
+ /**
+ * Callback for the Zoom In action
+ */
+ public void zoomIn() {
+ _stateCtrl.zoomIn();
+ }
+
+ /**
+ * Callback for the Zoom Out action
+ */
+ public void zoomOut() {
+ _stateCtrl.zoomOut();
+ }
+
+ private String getPreferenceString(String string) {
+ return getViewTypeStr() + "." + string; //$NON-NLS-1$
+ }
+
+ /**
+ * Add a selection listener
+ *
+ * @param listener
+ * The listener to add
+ */
+ public void addSelectionListener(ITimeGraphSelectionListener listener) {
+ fSelectionListeners.add(listener);
+ }
+
+ /**
+ * Remove a selection listener
+ *
+ * @param listener
+ * The listener to remove
+ */
+ public void removeSelectionListener(ITimeGraphSelectionListener listener) {
+ fSelectionListeners.remove(listener);
+ }
+
+ private void notifySelectionListeners(ITimeGraphEntry selection) {
+ TimeGraphSelectionEvent event = new TimeGraphSelectionEvent(this, selection);
+
+ for (ITimeGraphSelectionListener listener : fSelectionListeners) {
+ listener.selectionChanged(event);
+ }
+ }
+
+ /**
+ * Add a time listener
+ *
+ * @param listener
+ * The listener to add
+ */
+ public void addTimeListener(ITimeGraphTimeListener listener) {
+ fTimeListeners.add(listener);
+ }
+
+ /**
+ * Remove a time listener
+ *
+ * @param listener
+ * The listener to remove
+ */
+ public void removeTimeListener(ITimeGraphTimeListener listener) {
+ fTimeListeners.remove(listener);
+ }
+
+ private void notifyTimeListeners(long time) {
+ TimeGraphTimeEvent event = new TimeGraphTimeEvent(this, time);
+
+ for (ITimeGraphTimeListener listener : fTimeListeners) {
+ listener.timeSelected(event);
+ }
+ }
+
+ /**
+ * Add a range listener
+ *
+ * @param listener
+ * The listener to add
+ */
+ public void addRangeListener(ITimeGraphRangeListener listener) {
+ fRangeListeners.add(listener);
+ }
+
+ /**
+ * Remove a range listener
+ *
+ * @param listener
+ * The listener to remove
+ */
+ public void removeRangeListener(ITimeGraphRangeListener listener) {
+ fRangeListeners.remove(listener);
+ }
+
+ private void notifyRangeListeners(long startTime, long endTime) {
+ // Check if the time has actually changed from last notification
+ if (startTime != _time0_extSynch || endTime != _time1_extSynch) {
+ // Notify Time Scale Selection Listeners
+ TimeGraphRangeUpdateEvent event = new TimeGraphRangeUpdateEvent(this, startTime, endTime);
+
+ for (ITimeGraphRangeListener listener : fRangeListeners) {
+ listener.timeRangeUpdated(event);
+ }
+
+ // update external synch timers
+ updateExtSynchTimers();
+ }
+ }
+
+ /**
+ * Callback to set a selected event in the view
+ *
+ * @param event
+ * The event that was selected
+ * @param source
+ * The source of this selection event
+ */
+ public void setSelectedEvent(ITimeEvent event, Object source) {
+ if (event == null || source == this) {
+ return;
+ }
+ _selectedEntry = event.getEntry();
+ _stateCtrl.selectItem(_selectedEntry, false);
+
+ setSelectedTimeInt(event.getTime(), true, true);
+ adjustVerticalScrollBar();
+ }
+
+ /**
+ * Set the seeked time of a trace
+ *
+ * @param trace
+ * The trace that was seeked
+ * @param time
+ * The target time
+ * @param source
+ * The source of this seek event
+ */
+ public void setSelectedTraceTime(ITimeGraphEntry trace, long time, Object source) {
+ if (trace == null || source == this) {
+ return;
+ }
+ _selectedEntry = trace;
+ _stateCtrl.selectItem(trace, false);
+
+ setSelectedTimeInt(time, true, true);
+ }
+
+ /**
+ * Callback for a trace selection
+ *
+ * @param trace
+ * The trace that was selected
+ */
+ public void setSelection(ITimeGraphEntry trace) {
+ _selectedEntry = trace;
+ _stateCtrl.selectItem(trace, false);
+ adjustVerticalScrollBar();
+ }
+
+ /**
+ * Callback for a time window selection
+ *
+ * @param time0
+ * Start time of the range
+ * @param time1
+ * End time of the range
+ * @param source
+ * Source of the event
+ */
+ public void setSelectVisTimeWindow(long time0, long time1, Object source) {
+ if (source == this) {
+ return;
+ }
+
+ setStartFinishTime(time0, time1);
+
+ // update notification time values since we are now in synch with the
+ // external application
+ updateExtSynchTimers();
+ }
+
+ /**
+ * update the cache timers used to identify the need to send a time window
+ * update to external registered listeners
+ */
+ private void updateExtSynchTimers() {
+ // last time notification cache
+ _time0_extSynch = _time0;
+ _time1_extSynch = _time1;
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public TimeFormat getTimeFormat() {
+ return timeFormat;
+ }
+
+ /**
+ * @param tf the {@link TimeFormat} used to display timestamps
+ * @since 2.0
+ */
+ public void setTimeFormat(TimeFormat tf) {
+ this.timeFormat = tf;
+ }
+
+ /**
+ * Retrieve the border width
+ *
+ * @return The width
+ */
+ public int getBorderWidth() {
+ return borderWidth;
+ }
+
+ /**
+ * Set the border width
+ *
+ * @param borderWidth
+ * The width
+ */
+ public void setBorderWidth(int borderWidth) {
+ if (borderWidth > -1) {
+ this.borderWidth = borderWidth;
+ GridLayout gl = (GridLayout)_dataViewer.getLayout();
+ gl.marginHeight = borderWidth;
+ }
+ }
+
+ /**
+ * Retrieve the height of the header
+ *
+ * @return The height
+ */
+ public int getHeaderHeight() {
+ return timeScaleHeight;
+ }
+
+ /**
+ * Set the height of the header
+ *
+ * @param headerHeight
+ * The height to set
+ */
+ public void setHeaderHeight(int headerHeight) {
+ if (headerHeight > -1) {
+ this.timeScaleHeight = headerHeight;
+ _timeScaleCtrl.setHeight(headerHeight);
+ }
+ }
+
+ /**
+ * Retrieve the height of an item row
+ *
+ * @return The height
+ */
+ public int getItemHeight() {
+ if (_stateCtrl != null) {
+ return _stateCtrl.getItemHeight();
+ }
+ return 0;
+ }
+
+ /**
+ * Set the height of an item row
+ *
+ * @param rowHeight
+ * The height to set
+ */
+ public void setItemHeight(int rowHeight) {
+ if (_stateCtrl != null) {
+ _stateCtrl.setItemHeight(rowHeight);
+ }
+ }
+
+ /**
+ * Set the minimum item width
+ *
+ * @param width
+ * The min width
+ */
+ public void setMinimumItemWidth(int width) {
+ if (_stateCtrl != null) {
+ _stateCtrl.setMinimumItemWidth(width);
+ }
+ }
+
+ /**
+ * Set the width for the name column
+ *
+ * @param width The width
+ */
+ public void setNameWidthPref(int width) {
+ _nameWidthPref = width;
+ if (width == 0) {
+ _minNameWidth = 0;
+ _nameWidth = 0;
+ }
+ }
+
+ /**
+ * Retrieve the configure width for the name column
+ *
+ * @param width
+ * Unused?
+ * @return The width
+ */
+ public int getNameWidthPref(int width) {
+ return _nameWidthPref;
+ }
+
+ /**
+ * Returns the primary control associated with this viewer.
+ *
+ * @return the SWT control which displays this viewer's content
+ */
+ public Control getControl() {
+ return _dataViewer;
+ }
+
+ /**
+ * Returns the time graph control associated with this viewer.
+ *
+ * @return the time graph control
+ */
+ TimeGraphControl getTimeGraphControl() {
+ return _stateCtrl;
+ }
+
+ /**
+ * Returns the time graph scale associated with this viewer.
+ *
+ * @return the time graph scale
+ */
+ TimeGraphScale getTimeGraphScale() {
+ return _timeScaleCtrl;
+ }
+
+ /**
+ * Return the x coordinate corresponding to a time
+ *
+ * @param time the time
+ * @return the x coordinate corresponding to the time
+ *
+ * @since 2.0
+ */
+ public int getXForTime(long time) {
+ return _stateCtrl.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 _stateCtrl.getTimeAtX(x);
+ }
+
+ /**
+ * Get the selection provider
+ *
+ * @return the selection provider
+ */
+ public ISelectionProvider getSelectionProvider() {
+ return _stateCtrl;
+ }
+
+ /**
+ * Wait for the cursor
+ *
+ * @param waitInd
+ * Wait indefinitely?
+ */
+ public void waitCursor(boolean waitInd) {
+ _stateCtrl.waitCursor(waitInd);
+ }
+
+ /**
+ * Get the horizontal scroll bar object
+ *
+ * @return The scroll bar
+ */
+ public ScrollBar getHorizontalBar() {
+ return _stateCtrl.getHorizontalBar();
+ }
+
+ /**
+ * Get the vertical scroll bar object
+ *
+ * @return The scroll bar
+ */
+ public Slider getVerticalBar() {
+ return _verticalScrollBar;
+ }
+
+ /**
+ * Set the given index as the top one
+ *
+ * @param index
+ * The index that will go to the top
+ */
+ public void setTopIndex(int index) {
+ _stateCtrl.setTopIndex(index);
+ adjustVerticalScrollBar();
+ }
+
+ /**
+ * Retrieve the current top index
+ *
+ * @return The top index
+ */
+ public int getTopIndex() {
+ return _stateCtrl.getTopIndex();
+ }
+
+ /**
+ * Set the expanded state of an entry
+ *
+ * @param entry
+ * The entry to expand/collapse
+ * @param expanded
+ * True for expanded, false for collapsed
+ */
+ public void setExpandedState(ITimeGraphEntry entry, boolean expanded) {
+ _stateCtrl.setExpandedState(entry, expanded);
+ adjustVerticalScrollBar();
+ }
+
+ /**
+ * Collapses all nodes of the viewer's tree, starting with the root.
+ *
+ * @since 2.0
+ */
+ public void collapseAll() {
+ _stateCtrl.collapseAll();
+ adjustVerticalScrollBar();
+ }
+
+ /**
+ * Expands all nodes of the viewer's tree, starting with the root.
+ *
+ * @since 2.0
+ */
+ public void expandAll() {
+ _stateCtrl.expandAll();
+ adjustVerticalScrollBar();
+ }
+
+ /**
+ * Get the number of sub-elements when expanded
+ *
+ * @return The element count
+ */
+ public int getExpandedElementCount() {
+ return _stateCtrl.getExpandedElementCount();
+ }
+
+ /**
+ * Get the sub-elements
+ *
+ * @return The array of entries that are below this one
+ */
+ public ITimeGraphEntry[] getExpandedElements() {
+ return _stateCtrl.getExpandedElements();
+ }
+
+ /**
+ * Add a tree listener
+ *
+ * @param listener
+ * The listener to add
+ */
+ public void addTreeListener(ITimeGraphTreeListener listener) {
+ _stateCtrl.addTreeListener(listener);
+ }
+
+ /**
+ * Remove a tree listener
+ *
+ * @param listener
+ * The listener to remove
+ */
+ public void removeTreeListener(ITimeGraphTreeListener listener) {
+ _stateCtrl.removeTreeListener(listener);
+ }
+
+ /**
+ * Get the reset scale action.
+ *
+ * @return The Action object
+ */
+ public Action getResetScaleAction() {
+ if (resetScale == null) {
+ // resetScale
+ resetScale = 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));
+ }
+ return resetScale;
+ }
+
+ /**
+ * Get the show legend action.
+ *
+ * @return The Action object
+ */
+ public Action getShowLegendAction() {
+ if (showLegendAction == null) {
+ // showLegend
+ showLegendAction = 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));
+ }
+
+ return showLegendAction;
+ }
+
+ /**
+ * Get the the next event action.
+ *
+ * @return The action object
+ */
+ public Action getNextEventAction() {
+ if (nextEventAction == null) {
+ nextEventAction = 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));
+ }
+
+ return nextEventAction;
+ }
+
+ /**
+ * Get the previous event action.
+ *
+ * @return The Action object
+ */
+ public Action getPreviousEventAction() {
+ if (prevEventAction == null) {
+ prevEventAction = 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));
+ }
+
+ return prevEventAction;
+ }
+
+ /**
+ * Get the next item action.
+ *
+ * @return The Action object
+ */
+ public Action getNextItemAction() {
+ if (nextItemAction == null) {
+
+ nextItemAction = 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));
+ }
+ return nextItemAction;
+ }
+
+ /**
+ * Get the previous item action.
+ *
+ * @return The Action object
+ */
+ public Action getPreviousItemAction() {
+ if (previousItemAction == null) {
+
+ previousItemAction = 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));
+ }
+ return previousItemAction;
+ }
+
+ /**
+ * Get the zoom in action
+ *
+ * @return The Action object
+ */
+ public Action getZoomInAction() {
+ if (zoomInAction == null) {
+ zoomInAction = 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));
+ }
+ return zoomInAction;
+ }
+
+ /**
+ * Get the zoom out action
+ *
+ * @return The Action object
+ */
+ public Action getZoomOutAction() {
+ if (zoomOutAction == null) {
+ zoomOutAction = 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));
+ }
+ return zoomOutAction;
+ }
+
+
+ private void adjustVerticalScrollBar() {
+ int topIndex = _stateCtrl.getTopIndex();
+ int countPerPage = _stateCtrl.countPerPage();
+ int expandedElementCount = _stateCtrl.getExpandedElementCount();
+ if (topIndex + countPerPage > expandedElementCount) {
+ _stateCtrl.setTopIndex(Math.max(0, expandedElementCount - countPerPage));
+ }
+
+ int selection = _stateCtrl.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);
+ }
+
+ /**
+ * @param listener a {@link MenuDetectListener}
+ * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
+ * @since 1.2
+ */
+ public void addTimeGraphEntryMenuListener(MenuDetectListener listener) {
+ _stateCtrl.addTimeGraphEntryMenuListener(listener);
+ }
+
+ /**
+ * @param listener a {@link MenuDetectListener}
+ * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeGraphEntryMenuListener(org.eclipse.swt.events.MenuDetectListener)
+ * @since 1.2
+ */
+ public void removeTimeGraphEntryMenuListener(MenuDetectListener listener) {
+ _stateCtrl.removeTimeGraphEntryMenuListener(listener);
+ }
+
+ /**
+ * @param listener a {@link MenuDetectListener}
+ * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#addTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
+ * @since 1.2
+ */
+ public void addTimeEventMenuListener(MenuDetectListener listener) {
+ _stateCtrl.addTimeEventMenuListener(listener);
+ }
+
+ /**
+ * @param listener a {@link MenuDetectListener}
+ * @see org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.TimeGraphControl#removeTimeEventMenuListener(org.eclipse.swt.events.MenuDetectListener)
+ * @since 1.2
+ */
+ public void removeTimeEventMenuListener(MenuDetectListener listener) {
+ _stateCtrl.removeTimeEventMenuListener(listener);
+ }
+
+ /**
+ * @param filter The filter object to be attached to the view
+ * @since 2.0
+ */
+ public void addFilter(ViewerFilter filter) {
+ _stateCtrl.addFilter(filter);
+ refresh();
+ }
+
+ /**
+ * @param filter The filter object to be attached to the view
+ * @since 2.0
+ */
+ public void removeFilter(ViewerFilter filter) {
+ _stateCtrl.removeFilter(filter);
+ refresh();
+ }
+
+}