import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.resource.FontDescriptor;
+import org.eclipse.jface.resource.FontRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.OpenStrategy;
+import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.util.SafeRunnable;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.tracecompass.tmf.core.signal.TmfEventSearchAppliedSignal;
import org.eclipse.tracecompass.tmf.core.signal.TmfEventSelectedSignal;
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
-import org.eclipse.tracecompass.tmf.core.signal.TmfTimeSynchSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceUpdatedSignal;
import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.ide.IGotoMarker;
import org.eclipse.ui.themes.ColorUtil;
+import org.eclipse.ui.themes.IThemeManager;
import com.google.common.base.Joiner;
import com.google.common.collect.HashMultimap;
* @author Francois Chouinard
* @author Patrick Tasse
*/
-public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorSettingsListener, ISelectionProvider {
+public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorSettingsListener, ISelectionProvider, IPropertyChangeListener {
/**
* Empty string array, used by {@link #getItemStrings}.
*/
protected static final @NonNull String EMPTY_STRING = ""; //$NON-NLS-1$
- private static final @NonNull String DOT_STAR_PREFIX = "^\\.\\*"; //$NON-NLS-1$
- private static final @NonNull String DOT_STAR_SUFFIX = "\\.\\*$"; //$NON-NLS-1$
-
private static final boolean IS_LINUX = System.getProperty("os.name").contains("Linux") ? true : false; //$NON-NLS-1$ //$NON-NLS-2$
+ private static final String FONT_DEFINITION_ID = "org.eclipse.tracecompass.tmf.ui.font.eventtable"; //$NON-NLS-1$
+
private static final Image BOOKMARK_IMAGE = Activator.getDefault().getImageFromPath(
"icons/elcl16/bookmark_obj.gif"); //$NON-NLS-1$
private static final Image SEARCH_IMAGE = Activator.getDefault().getImageFromPath("icons/elcl16/search.gif"); //$NON-NLS-1$
private LocalResourceManager fResourceManager = new LocalResourceManager(JFaceResources.getResources());
private Color fGrayColor;
private Color fGreenColor;
+ private Font fFont;
private Font fBoldFont;
private final List<TmfEventTableColumn> fColumns = new LinkedList<>();
ITmfTimestamp selectedBeginTimestamp = fSelectedBeginTimestamp;
if (selectedBeginTimestamp != null) {
if (selectedBeginTimestamp.compareTo(ts) <= 0) {
- broadcast(new TmfTimeSynchSignal(TmfEventsTable.this, selectedBeginTimestamp, ts));
+ broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable.this, selectedBeginTimestamp, ts));
if (fTable.getSelectionIndices().length == 2) {
updateStatusLine(ts.getDelta(selectedBeginTimestamp));
}
} else {
- broadcast(new TmfTimeSynchSignal(TmfEventsTable.this, checkNotNull(ts), checkNotNull(fSelectedBeginTimestamp)));
+ broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable.this, checkNotNull(ts), checkNotNull(fSelectedBeginTimestamp)));
updateStatusLine(fSelectedBeginTimestamp.getDelta(ts));
}
}
* paint it or otherwise we would override the platform theme
* (e.g. alternating colors).
*/
- if (styleRanges != null || !background.equals(item.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND))) {
+ if (styleRanges != null || !background.equals(item.getParent().getBackground())) {
// we will paint the table item's background
event.detail &= ~SWT.BACKGROUND;
/*
* The image bounds don't match the default image position.
*/
- gc.drawImage(image, imageBounds.x, imageBounds.y + 1);
+ if (IS_LINUX) {
+ gc.drawImage(image, imageBounds.x + 1, imageBounds.y + 3);
+ } else {
+ gc.drawImage(image, imageBounds.x, imageBounds.y + 1);
+ }
}
gc.setForeground(item.getForeground(event.index));
gc.setFont(item.getFont(event.index));
/*
* The text bounds don't match the default text position.
*/
- gc.drawText(text, textBounds.x - 1, textBounds.y + 2, true);
+ if (IS_LINUX) {
+ gc.drawText(text, textBounds.x + 1, textBounds.y + 3, true);
+ } else {
+ gc.drawText(text, textBounds.x - 1, textBounds.y + 2, true);
+ }
}
});
// Create resources
createResources();
+ initializeFonts();
+ PlatformUI.getWorkbench().getThemeManager().addPropertyChangeListener(this);
+
ColorSettingsManager.addColorSettingsListener(this);
fTable.setItemCount(1); // +1 for header row
TableItem item = fTable.getSelection()[0];
final TmfTimestamp ts = (TmfTimestamp) item.getData(Key.TIMESTAMP);
if (ts != null) {
- broadcast(new TmfTimeSynchSignal(TmfEventsTable.this, ts));
+ broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable.this, ts));
}
if (item.getData() instanceof ITmfEvent) {
broadcast(new TmfEventSelectedSignal(TmfEventsTable.this, (ITmfEvent) item.getData()));
public void dispose() {
stopSearchThread();
stopFilterThread();
+ PlatformUI.getWorkbench().getThemeManager().removePropertyChangeListener(this);
ColorSettingsManager.removeColorSettingsListener(this);
fComposite.dispose();
if ((fTrace != null) && fDisposeOnClose) {
item.setForeground(colorSetting.getForegroundColor());
item.setBackground(colorSetting.getBackgroundColor());
}
- /*
- * Make sure the default system color is used. If the background is set
- * to the default system color's value instead of null, it overrides the
- * platform theme (e.g. alternating colors).
- */
- if (item.getBackground().equals(item.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND))) {
- item.setBackground(null);
- }
+ item.setFont(fFont);
if (searchMatch) {
if (!markerIds.isEmpty()) {
regex = (String) column.getData(Key.SEARCH_TXT);
}
if (regex != null) {
- // remove '.*' at beginning and end of regex
- regex = regex.replaceAll(DOT_STAR_PREFIX, EMPTY_STRING).replaceAll(DOT_STAR_SUFFIX, EMPTY_STRING);
String text = item.getText(index);
try {
Pattern pattern = Pattern.compile(regex);
item.setText(i, FILTER_HINT);
}
item.setForeground(i, fGrayColor);
- item.setFont(i, fTable.getFont());
+ item.setFont(i, fFont);
} else {
item.setText(i, filter);
item.setForeground(i, fGreenColor);
item.setData(Key.STYLE_RANGES, null);
item.setForeground(null);
item.setBackground(null);
+ item.setFont(fFont);
}
/**
/*
* returns true is value was changed
*/
- private boolean updateHeader(final String text) {
+ private boolean updateHeader(final String regex) {
String objKey = null;
String txtKey = null;
if (fHeaderState == HeaderState.SEARCH) {
objKey = Key.FILTER_OBJ;
txtKey = Key.FILTER_TXT;
}
- if (text.trim().length() > 0) {
+ if (regex.length() > 0) {
try {
- final String regex = TmfFilterMatchesNode.regexFix(text);
Pattern.compile(regex);
if (regex.equals(column.getData(txtKey))) {
tableEditor.getEditor().dispose();
fSelectedRank = foundRank;
fRawViewer.selectAndReveal(fSelectedRank);
if (foundTimestamp != null) {
- broadcast(new TmfTimeSynchSignal(TmfEventsTable.this, foundTimestamp));
+ broadcast(new TmfSelectionRangeUpdatedSignal(TmfEventsTable.this, foundTimestamp));
}
fireSelectionChanged(new SelectionChangedEvent(TmfEventsTable.this, getSelection()));
synchronized (fSearchSyncObj) {
fGrayColor = fResourceManager.createColor(ColorUtil.blend(fTable.getBackground().getRGB(), fTable
.getForeground().getRGB()));
fGreenColor = fTable.getDisplay().getSystemColor(SWT.COLOR_DARK_GREEN);
- fBoldFont = fResourceManager.createFont(FontDescriptor.createFrom(fTable.getFont()).setStyle(SWT.BOLD));
+ }
+
+ /**
+ * Initialize the fonts.
+ * @since 1.0
+ */
+ protected void initializeFonts() {
+ FontRegistry fontRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getFontRegistry();
+ fFont = fontRegistry.get(FONT_DEFINITION_ID);
+ fBoldFont = fontRegistry.getBold(FONT_DEFINITION_ID);
+ fTable.setFont(fFont);
+ /* Column header font cannot be set. See Bug 63038 */
+ }
+
+ /**
+ * @since 1.0
+ */
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ if ((IThemeManager.CHANGE_CURRENT_THEME.equals(event.getProperty())) ||
+ (FONT_DEFINITION_ID.equals(event.getProperty()))) {
+ initializeFonts();
+ fTable.refresh();
+ }
}
/**
}
/**
- * Handler for the time synch signal.
+ * Handler for the selection range signal.
*
* @param signal
* The incoming signal
+ * @since 1.0
*/
@TmfSignalHandler
- public void currentTimeUpdated(final TmfTimeSynchSignal signal) {
+ public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal) {
if ((signal.getSource() != this) && (fTrace != null) && (!fTable.isDisposed())) {
// Create a request for one event that will be queued after other ongoing requests. When this request is completed