/*****************************************************************************
- * Copyright (c) 2007 Intel Corporation, 2009, 2012 Ericsson.
+ * 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
* Vitaly A. Provodin, Intel - Initial API and implementation
* Alvaro Sanchez-Leon - Updated for TMF
* Patrick Tasse - Refactoring
- *
*****************************************************************************/
+
package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;
import java.util.Iterator;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
+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.Display;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.TableItem;
/**
* Handler for the tool tips in the generic time graph view.
public class TimeGraphTooltipHandler {
private Shell _tipShell;
- private Table _tipTable;
+ private Composite _tipComposite;
private Point _tipPosition;
private final ITimeDataProvider _timeDataProvider;
ITimeGraphPresentationProvider _utilImp = null;
_tipShell.setLayout(gridLayout);
_tipShell.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
- _tipTable = new Table(_tipShell, SWT.NONE);
- new TableColumn(_tipTable, SWT.NONE);
- new TableColumn(_tipTable, SWT.NONE);
- _tipTable.setForeground(display
- .getSystemColor(SWT.COLOR_INFO_FOREGROUND));
- _tipTable.setBackground(display
- .getSystemColor(SWT.COLOR_INFO_BACKGROUND));
- _tipTable.setHeaderVisible(false);
- _tipTable.setLinesVisible(false);
-
- _tipTable.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseDown(MouseEvent e) {
- _tipShell.dispose();
- }
- });
-
- _tipTable.addMouseTrackListener(new MouseTrackAdapter() {
- @Override
- public void mouseExit(MouseEvent e) {
- _tipShell.dispose();
- }
- });
+ _tipComposite = new Composite(_tipShell, SWT.NONE);
+ _tipComposite.setLayout(new GridLayout(3, false));
+ setupControl(_tipComposite);
- _tipTable.addMouseMoveListener(new MouseMoveListener() {
- @Override
- public void mouseMove(MouseEvent e) {
- _tipShell.dispose();
- }
- });
}
/**
}
private void addItem(String name, String value) {
- TableItem line = new TableItem(_tipTable, SWT.NONE);
- line.setText(0, name);
- line.setText(1, value);
+ Label nameLabel = new Label(_tipComposite, SWT.NO_FOCUS);
+ nameLabel.setText(name);
+ setupControl(nameLabel);
+ Label separator = new Label(_tipComposite, SWT.NO_FOCUS | SWT.SEPARATOR | SWT.VERTICAL);
+ GridData gd = new GridData(SWT.CENTER, SWT.CENTER, false, false);
+ gd.heightHint = nameLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
+ separator.setLayoutData(gd);
+ setupControl(separator);
+ Label valueLabel = new Label(_tipComposite, SWT.NO_FOCUS);
+ valueLabel.setText(value);
+ setupControl(valueLabel);
}
private void fillValues(Point pt, TimeGraphControl timeGraphControl, ITimeGraphEntry entry) {
if (currEvent == null || currEvent.getTime() < currPixelTime) {
if (nextEvent != null && nextEvent.getTime() < nextPixelTime) {
currEvent = nextEvent;
+ currPixelTime = nextEvent.getTime();
}
}
// state name
- addItem(_utilImp.getStateTypeName(), entry.getName());
+ String stateTypeName = _utilImp.getStateTypeName(entry);
+ String entryName = entry.getName();
+ if (stateTypeName == null) {
+ stateTypeName = _utilImp.getStateTypeName();
+ }
+
+ if (!entryName.isEmpty()) {
+ addItem(stateTypeName, entry.getName());
+ }
+
if (currEvent == null) {
return;
}
+
// state
String state = _utilImp.getEventName(currEvent);
if (state != null) {
}
// This block receives a list of <String, String> values to be added to the tip table
- Map<String, String> eventAddOns = _utilImp.getEventHoverToolTipInfo(currEvent);
+ Map<String, String> eventAddOns = _utilImp.getEventHoverToolTipInfo(currEvent, currPixelTime);
if (eventAddOns != null) {
for (Iterator<String> iter = eventAddOns.keySet().iterator(); iter.hasNext();) {
String message = iter.next();
}
Resolution res = Resolution.NANOSEC;
- if (_timeDataProvider.isCalendarFormat()) {
+ TimeFormat tf = _timeDataProvider.getTimeFormat();
+ if (tf == TimeFormat.CALENDAR) {
addItem(Messages.TmfTimeTipHandler_TRACE_DATE, eventStartTime > -1 ?
Utils.formatDate(eventStartTime)
: "?"); //$NON-NLS-1$
- if (eventDuration > 0) {
- addItem(Messages.TmfTimeTipHandler_TRACE_START_TIME, eventStartTime > -1 ?
- Utils.formatTime(eventStartTime, TimeFormat.ABSOLUTE, res)
- : "?"); //$NON-NLS-1$
-
- addItem(Messages.TmfTimeTipHandler_TRACE_STOP_TIME, eventEndTime > -1 ?
- Utils.formatTime(eventEndTime, TimeFormat.ABSOLUTE, res)
- : "?"); //$NON-NLS-1$
- } else {
- addItem(Messages.TmfTimeTipHandler_TRACE_EVENT_TIME, eventStartTime > -1 ?
- Utils.formatTime(eventStartTime, TimeFormat.ABSOLUTE, res)
- : "?"); //$NON-NLS-1$
- }
+ }
+ if (eventDuration > 0) {
+ addItem(Messages.TmfTimeTipHandler_TRACE_START_TIME, eventStartTime > -1 ?
+ Utils.formatTime(eventStartTime, tf, res)
+ : "?"); //$NON-NLS-1$
+
+ addItem(Messages.TmfTimeTipHandler_TRACE_STOP_TIME, eventEndTime > -1 ?
+ Utils.formatTime(eventEndTime, tf, res)
+ : "?"); //$NON-NLS-1$
} else {
- if (eventDuration > 0) {
- addItem(Messages.TmfTimeTipHandler_TRACE_START_TIME, eventStartTime > -1 ?
- Utils.formatTime(eventStartTime, TimeFormat.RELATIVE, res)
- : "?"); //$NON-NLS-1$
-
- addItem(Messages.TmfTimeTipHandler_TRACE_STOP_TIME, eventEndTime > -1 ?
- Utils.formatTime(eventEndTime, TimeFormat.RELATIVE, res)
- : "?"); //$NON-NLS-1$
- } else {
- addItem(Messages.TmfTimeTipHandler_TRACE_EVENT_TIME, eventStartTime > -1 ?
- Utils.formatTime(eventStartTime, TimeFormat.RELATIVE, res)
- : "?"); //$NON-NLS-1$
- }
+ addItem(Messages.TmfTimeTipHandler_TRACE_EVENT_TIME, eventStartTime > -1 ?
+ Utils.formatTime(eventStartTime, tf, res)
+ : "?"); //$NON-NLS-1$
}
if (eventDuration > 0) {
// Duration in relative format in any case
+ if (tf == TimeFormat.CALENDAR) {
+ tf = TimeFormat.RELATIVE;
+ }
addItem(Messages.TmfTimeTipHandler_DURATION, eventDuration > -1 ?
- Utils.formatTime(eventDuration, TimeFormat.RELATIVE, res)
+ Utils.formatTime(eventDuration, tf, res)
: "?"); //$NON-NLS-1$
}
}
TimeGraphControl timeGraphControl = (TimeGraphControl) event.widget;
createTooltipShell(timeGraphControl.getShell());
ITimeGraphEntry entry = timeGraphControl.getEntry(pt);
- _tipTable.remove(0, _tipTable.getItemCount() - 1);
+ for (Control child : _tipComposite.getChildren()) {
+ child.dispose();
+ }
fillValues(pt, timeGraphControl, entry);
- if (_tipTable.getItemCount() == 0) {
+ if (_tipComposite.getChildren().length == 0) {
return;
}
- _tipTable.getColumn(0).pack();
- _tipTable.getColumn(1).pack();
_tipShell.pack();
_tipPosition = control.toDisplay(pt);
_tipShell.pack();
shell.setBounds(shellBounds);
}
+ private void setupControl(Control control) {
+ control.setForeground(_tipShell.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
+ control.setBackground(_tipShell.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
+
+ control.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseDown(MouseEvent e) {
+ _tipShell.dispose();
+ }
+ });
+
+ control.addMouseTrackListener(new MouseTrackAdapter() {
+ @Override
+ public void mouseExit(MouseEvent e) {
+ _tipShell.dispose();
+ }
+ });
+
+ control.addMouseMoveListener(new MouseMoveListener() {
+ @Override
+ public void mouseMove(MouseEvent e) {
+ _tipShell.dispose();
+ }
+ });
+ }
}