aboutsummaryrefslogtreecommitdiffstats
path: root/ddms/libs/ddmuilib
diff options
context:
space:
mode:
authorSiva Velusamy <vsiva@google.com>2011-09-09 15:05:19 -0700
committerSiva Velusamy <vsiva@google.com>2011-09-09 15:05:19 -0700
commit4e987437c86a343fa59d42f739de8c43e2f1cfab (patch)
tree8a4233d5483c1d8de53ff0a06036ef79d5728979 /ddms/libs/ddmuilib
parente4d2033d51cece0359694426f4e677cedb9450a3 (diff)
downloadsdk-4e987437c86a343fa59d42f739de8c43e2f1cfab.zip
sdk-4e987437c86a343fa59d42f739de8c43e2f1cfab.tar.gz
sdk-4e987437c86a343fa59d42f739de8c43e2f1cfab.tar.bz2
Create logcat table with SWT.VIRTUAL.
Without SWT.VIRTUAL, the UI responsiveness goes down significantly when large numbers of logcat messages are received. Unfortunately, enabling it causes SWT to make all rows to be of the same height, thereby clipping any long messages. In such a case, the complete message can be viewed in the tooltip. Change-Id: I78d6701ccac6ad94675e1ed707700eabfe34bce8
Diffstat (limited to 'ddms/libs/ddmuilib')
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatMessageLabelProvider.java157
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java66
2 files changed, 83 insertions, 140 deletions
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatMessageLabelProvider.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatMessageLabelProvider.java
index 3eb5946..7bbc471 100644
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatMessageLabelProvider.java
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatMessageLabelProvider.java
@@ -18,24 +18,17 @@ package com.android.ddmuilib.logcat;
import com.android.ddmlib.Log.LogLevel;
-import org.eclipse.jface.viewers.ITableColorProvider;
-import org.eclipse.jface.viewers.ITableFontProvider;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.swt.events.ControlAdapter;
-import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.graphics.Point;
/**
- * A JFace label provider for the LogCat log messages. It expects elements of type
+ * A JFace Column label provider for the LogCat log messages. It expects elements of type
* {@link LogCatMessage}.
*/
-public final class LogCatMessageLabelProvider extends LabelProvider
- implements ITableLabelProvider, ITableColorProvider, ITableFontProvider {
+public final class LogCatMessageLabelProvider extends ColumnLabelProvider {
private static final int INDEX_LOGLEVEL = 0;
private static final int INDEX_LOGTIME = 1;
private static final int INDEX_PID = 2;
@@ -50,52 +43,18 @@ public final class LogCatMessageLabelProvider extends LabelProvider
private static final Color WARN_MSG_COLOR = new Color(null, 255, 127, 0);
private static final Color VERBOSE_MSG_COLOR = new Color(null, 0, 0, 0);
- /** Default width to assume for the logcat message column when not able to
- * detect it from the table itself. */
- private static final int DEFAULT_TEXT_COL_WIDTH = 1000;
-
private Font mLogFont;
- private Table mTable;
- private int mWrapWidth;
- private int mColWidth = DEFAULT_TEXT_COL_WIDTH;
- private int mFontWidth;
-
/**
- * Construct a label provider that will be used in rendering the given table.
- * The table argument is provided so that the label provider can figure out the width
- * of the columns, and wrap messages if necessary.
+ * Construct a column label provider for the logcat table.
* @param font default font to use
- * @param parentTable table for which labels are provided
- * @param table
*/
- public LogCatMessageLabelProvider(Font font, Table parentTable) {
+ public LogCatMessageLabelProvider(Font font) {
mLogFont = font;
- mTable = parentTable;
-
- addTextColumnWidthChangeListener();
-
- mColWidth = getColumnWidth();
- mFontWidth = getFontWidth();
- updateWrapWidth();
- }
-
- public Image getColumnImage(Object element, int index) {
- return null;
}
- /**
- * Obtain the correct text for the given column index. The index ordering
- * should match the ordering of the columns in the table created in {@link LogCatPanel}.
- * @return text to be used for specific column index
- */
- public String getColumnText(Object element, int index) {
- if (!(element instanceof LogCatMessage)) {
- return null;
- }
-
- LogCatMessage m = (LogCatMessage) element;
- switch (index) {
+ private String getCellText(LogCatMessage m, int columnIndex) {
+ switch (columnIndex) {
case INDEX_LOGLEVEL:
return Character.toString(m.getLogLevel().getPriorityLetter());
case INDEX_LOGTIME:
@@ -107,58 +66,27 @@ public final class LogCatMessageLabelProvider extends LabelProvider
case INDEX_TAG:
return m.getTag();
case INDEX_TEXT:
- String msg = m.getMessage();
- if (msg.length() < mWrapWidth) {
- return msg;
- }
- return wrapMessage(msg);
+ return m.getMessage();
default:
- return null;
+ return "";
}
}
- /**
- * Wrap logcat message into multiple lines if it exceeds the current width of the text column.
- * @param msg message string to line wrap
- * @return line with newline's inserted
- */
- private String wrapMessage(String msg) {
- StringBuffer sb = new StringBuffer();
-
- int offset = 0;
- int len = msg.length();
-
- while (len > 0) {
- if (offset != 0) {
- /* for all lines but the first one, add a newline and
- * two spaces at the beginning. */
- sb.append("\n ");
- }
-
- int copylen = Math.min(mWrapWidth, len);
- sb.append(msg.substring(offset, offset + copylen));
-
- offset += copylen;
- len -= copylen;
+ @Override
+ public void update(ViewerCell cell) {
+ Object element = cell.getElement();
+ if (!(element instanceof LogCatMessage)) {
+ return;
}
+ LogCatMessage m = (LogCatMessage) element;
- return sb.toString();
+ String text = getCellText(m, cell.getColumnIndex());
+ cell.setText(text);
+ cell.setFont(mLogFont);
+ cell.setForeground(getForegroundColor(m));
}
- public Color getBackground(Object element, int index) {
- return null;
- }
-
- /**
- * Get the foreground text color for given table item and column. The color
- * depends only on the log level, and the same color is used in all columns.
- */
- public Color getForeground(Object element, int index) {
- if (!(element instanceof LogCatMessage)) {
- return null;
- }
-
- LogCatMessage m = (LogCatMessage) element;
+ private Color getForegroundColor(LogCatMessage m) {
LogLevel l = m.getLogLevel();
if (l.equals(LogLevel.VERBOSE)) {
@@ -176,51 +104,16 @@ public final class LogCatMessageLabelProvider extends LabelProvider
return null;
}
- public Font getFont(Object element, int index) {
- return mLogFont;
- }
-
public void setFont(Font preferredFont) {
if (mLogFont != null) {
mLogFont.dispose();
}
mLogFont = preferredFont;
- mFontWidth = getFontWidth();
- updateWrapWidth();
- }
-
- private void addTextColumnWidthChangeListener() {
- mTable.getColumn(INDEX_TEXT).addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent arg0) {
- mColWidth = getColumnWidth();
- updateWrapWidth();
- }
- });
- }
-
- /* # of chars in the column = width of column / width of each character in the font used */
- private void updateWrapWidth() {
- mWrapWidth = mColWidth / mFontWidth;
}
- private int getFontWidth() {
- mTable.setFont(mLogFont);
- GC gc = new GC(mTable);
- try {
- return gc.getFontMetrics().getAverageCharWidth();
- } finally {
- gc.dispose();
- }
- }
-
- private int getColumnWidth() {
- int w = mTable.getColumn(INDEX_TEXT).getWidth();
- if (w != 0) {
- return w; /* return new width only if it is valid */
- } else {
- return mColWidth; /* otherwise stick to current width */
- }
+ @Override
+ public String getToolTipText(Object element) {
+ return element.toString();
}
}
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java
index 5d0540d..6150cc0 100644
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java
@@ -29,9 +29,15 @@ import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.ColumnViewer;
+import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.jface.window.ToolTip;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
@@ -50,10 +56,12 @@ import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
@@ -593,9 +601,11 @@ public final class LogCatPanel extends SelectionDependentPanel
}
private void createLogcatViewTable(Composite parent) {
- /* SWT.VIRTUAL style will make the table render faster, but all rows will be
- * of equal heights which causes wrapped messages to just be clipped. */
- final Table table = new Table(parent, SWT.FULL_SELECTION | SWT.MULTI);
+ // The SWT.VIRTUAL bit causes the table to be rendered faster. However it makes all rows
+ // to be of the same height, thereby clipping any rows with multiple lines of text.
+ // In such a case, users can view the full text by hovering over the item and looking at
+ // the tooltip.
+ final Table table = new Table(parent, SWT.FULL_SELECTION | SWT.MULTI | SWT.VIRTUAL);
mViewer = new TableViewer(table);
table.setLayoutData(new GridData(GridData.FILL_BOTH));
@@ -622,26 +632,66 @@ public final class LogCatPanel extends SelectionDependentPanel
" Log Message field should be pretty long by default. As long as possible for correct display on Mac.",
};
+ mLogCatMessageLabelProvider = new LogCatMessageLabelProvider(getFontFromPrefStore());
for (int i = 0; i < properties.length; i++) {
- TableHelper.createTableColumn(mViewer.getTable(),
+ TableColumn tc = TableHelper.createTableColumn(mViewer.getTable(),
properties[i], /* Column title */
SWT.LEFT, /* Column Style */
sampleText[i], /* String to compute default col width */
getColPreferenceKey(properties[i]), /* Preference Store key for this column */
mPrefStore);
+ TableViewerColumn tvc = new TableViewerColumn(mViewer, tc);
+ tvc.setLabelProvider(mLogCatMessageLabelProvider);
}
mViewer.getTable().setLinesVisible(true); /* zebra stripe the table */
mViewer.getTable().setHeaderVisible(true);
-
- mLogCatMessageLabelProvider = new LogCatMessageLabelProvider(getFontFromPrefStore(),
- mViewer.getTable());
- mViewer.setLabelProvider(mLogCatMessageLabelProvider);
mViewer.setContentProvider(new LogCatMessageContentProvider());
+ WrappingToolTipSupport.enableFor(mViewer, ToolTip.NO_RECREATE);
initDoubleClickListener();
}
+ private static class WrappingToolTipSupport extends ColumnViewerToolTipSupport {
+ protected WrappingToolTipSupport(ColumnViewer viewer, int style,
+ boolean manualActivation) {
+ super(viewer, style, manualActivation);
+ }
+
+ @Override
+ protected Composite createViewerToolTipContentArea(Event event, ViewerCell cell,
+ Composite parent) {
+ Composite comp = new Composite(parent, SWT.NONE);
+ GridLayout l = new GridLayout(1, false);
+ l.horizontalSpacing = 0;
+ l.marginWidth = 0;
+ l.marginHeight = 0;
+ l.verticalSpacing = 0;
+ comp.setLayout(l);
+
+ // Use a browser widget since it automatically provides both wrapping text,
+ // and adds a scroll bar if necessary
+ Browser browser = new Browser(comp, SWT.BORDER);
+ browser.setText(getBrowserText(cell.getElement()));
+ browser.setLayoutData(new GridData(500, 150));
+
+ return comp;
+ }
+
+ private String getBrowserText(Object element) {
+ return String.format("<html><body><code>%s</code></body></html>", element.toString());
+ }
+
+ @Override
+ public boolean isHideOnMouseDown() {
+ return false;
+ }
+
+ public static final void enableFor(ColumnViewer viewer, int style) {
+ new WrappingToolTipSupport(viewer, style, false);
+ }
+ }
+
private String getColPreferenceKey(String field) {
return LOGCAT_VIEW_COLSIZE_PREFKEY_PREFIX + field;
}