DisplayLogpublic class DisplayLog extends EventDisplay
Fields Summary |
---|
private static final String | PREFS_COL_DATE | private static final String | PREFS_COL_PID | private static final String | PREFS_COL_EVENTTAG | private static final String | PREFS_COL_VALUENAME | private static final String | PREFS_COL_VALUE | private static final String | PREFS_COL_TYPE |
Constructors Summary |
---|
public DisplayLog(String name)
super(name);
|
Methods Summary |
---|
private void | addToLog(com.android.ddmlib.log.EventContainer event, com.android.ddmlib.log.EventLogParser logParser)Adds an {@link EventContainer} to the log.
ScrollBar bar = mLogTable.getVerticalBar();
boolean scroll = bar.getMaximum() == bar.getSelection() + bar.getThumb();
// get the date.
Calendar c = Calendar.getInstance();
long msec = (long) event.sec * 1000L;
c.setTimeInMillis(msec);
// convert the time into a string
String date = String.format("%1$tF %1$tT", c);
String eventName = logParser.getTagMap().get(event.mTag);
String pidName = Integer.toString(event.pid);
// get the value description
EventValueDescription[] valueDescription = logParser.getEventInfoMap().get(event.mTag);
if (valueDescription != null) {
for (int i = 0; i < valueDescription.length; i++) {
EventValueDescription description = valueDescription[i];
try {
String value = event.getValueAsString(i);
logValue(date, pidName, eventName, description.getName(), value,
description.getEventValueType(), description.getValueType());
} catch (InvalidTypeException e) {
logValue(date, pidName, eventName, description.getName(), e.getMessage(),
description.getEventValueType(), description.getValueType());
}
}
// scroll if needed, by showing the last item
if (scroll) {
int itemCount = mLogTable.getItemCount();
if (itemCount > 0) {
mLogTable.showItem(mLogTable.getItem(itemCount - 1));
}
}
}
| protected void | addToLog(com.android.ddmlib.log.EventContainer event, com.android.ddmlib.log.EventLogParser logParser, java.util.ArrayList valueDescriptors, java.util.ArrayList occurrenceDescriptors)Adds an {@link EventContainer} to the log. Only add the values/occurrences defined by
the list of descriptors. If an event is configured to be displayed by value and occurrence,
only the values are displayed (as they mark an event occurrence anyway).
This method is only called when at least one of the descriptor list is non empty.
ScrollBar bar = mLogTable.getVerticalBar();
boolean scroll = bar.getMaximum() == bar.getSelection() + bar.getThumb();
// get the date.
Calendar c = Calendar.getInstance();
long msec = (long) event.sec * 1000L;
c.setTimeInMillis(msec);
// convert the time into a string
String date = String.format("%1$tF %1$tT", c);
String eventName = logParser.getTagMap().get(event.mTag);
String pidName = Integer.toString(event.pid);
if (valueDescriptors.size() > 0) {
for (ValueDisplayDescriptor descriptor : valueDescriptors) {
logDescriptor(event, descriptor, date, pidName, eventName, logParser);
}
} else {
// we display the event. Since the StringBuilder contains the header (date, event name,
// pid) at this point, there isn't anything else to display.
}
// scroll if needed, by showing the last item
if (scroll) {
int itemCount = mLogTable.getItemCount();
if (itemCount > 0) {
mLogTable.showItem(mLogTable.getItem(itemCount - 1));
}
}
| org.eclipse.swt.widgets.Control | createComposite(org.eclipse.swt.widgets.Composite parent, com.android.ddmlib.log.EventLogParser logParser, ILogColumnListener listener)Creates the UI for the event display.
return createLogUI(parent, listener);
| private org.eclipse.swt.widgets.Control | createLogUI(org.eclipse.swt.widgets.Composite parent, ILogColumnListener listener)Creates the UI for a log display.
Composite mainComp = new Composite(parent, SWT.NONE);
GridLayout gl;
mainComp.setLayout(gl = new GridLayout(1, false));
gl.marginHeight = gl.marginWidth = 0;
mainComp.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
mLogTable = null;
}
});
Label l = new Label(mainComp, SWT.CENTER);
l.setText(mName);
l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
mLogTable = new Table(mainComp, SWT.MULTI | SWT.FULL_SELECTION | SWT.V_SCROLL |
SWT.BORDER);
mLogTable.setLayoutData(new GridData(GridData.FILL_BOTH));
IPreferenceStore store = DdmUiPreferences.getStore();
TableColumn col = TableHelper.createTableColumn(
mLogTable, "Time",
SWT.LEFT, "0000-00-00 00:00:00", PREFS_COL_DATE, store); //$NON-NLS-1$
col.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
Object source = e.getSource();
if (source instanceof TableColumn) {
listener.columnResized(0, (TableColumn) source);
}
}
});
col = TableHelper.createTableColumn(
mLogTable, "pid",
SWT.LEFT, "0000", PREFS_COL_PID, store); //$NON-NLS-1$
col.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
Object source = e.getSource();
if (source instanceof TableColumn) {
listener.columnResized(1, (TableColumn) source);
}
}
});
col = TableHelper.createTableColumn(
mLogTable, "Event",
SWT.LEFT, "abcdejghijklmno", PREFS_COL_EVENTTAG, store); //$NON-NLS-1$
col.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
Object source = e.getSource();
if (source instanceof TableColumn) {
listener.columnResized(2, (TableColumn) source);
}
}
});
col = TableHelper.createTableColumn(
mLogTable, "Name",
SWT.LEFT, "Process Name", PREFS_COL_VALUENAME, store); //$NON-NLS-1$
col.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
Object source = e.getSource();
if (source instanceof TableColumn) {
listener.columnResized(3, (TableColumn) source);
}
}
});
col = TableHelper.createTableColumn(
mLogTable, "Value",
SWT.LEFT, "0000000", PREFS_COL_VALUE, store); //$NON-NLS-1$
col.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
Object source = e.getSource();
if (source instanceof TableColumn) {
listener.columnResized(4, (TableColumn) source);
}
}
});
col = TableHelper.createTableColumn(
mLogTable, "Type",
SWT.LEFT, "long, seconds", PREFS_COL_TYPE, store); //$NON-NLS-1$
col.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
Object source = e.getSource();
if (source instanceof TableColumn) {
listener.columnResized(5, (TableColumn) source);
}
}
});
mLogTable.setHeaderVisible(true);
mLogTable.setLinesVisible(true);
return mainComp;
| int | getDisplayType()Gets display type
return DISPLAY_TYPE_LOG_ALL;
| private void | logDescriptor(com.android.ddmlib.log.EventContainer event, ValueDisplayDescriptor descriptor, java.lang.String date, java.lang.String pidName, java.lang.String eventName, com.android.ddmlib.log.EventLogParser logParser)Logs a value from an {@link EventContainer} as defined by the {@link ValueDisplayDescriptor}.
String value;
try {
value = event.getValueAsString(descriptor.valueIndex);
} catch (InvalidTypeException e) {
value = e.getMessage();
}
EventValueDescription[] values = logParser.getEventInfoMap().get(event.mTag);
EventValueDescription valueDescription = values[descriptor.valueIndex];
logValue(date, pidName, eventName, descriptor.valueName, value,
valueDescription.getEventValueType(), valueDescription.getValueType());
| private void | logValue(java.lang.String date, java.lang.String pid, java.lang.String event, java.lang.String valueName, java.lang.String value, EventContainer.EventValueType eventValueType, EventValueDescription.ValueType valueType)Logs a value in the ui.
TableItem item = new TableItem(mLogTable, SWT.NONE);
item.setText(0, date);
item.setText(1, pid);
item.setText(2, event);
item.setText(3, valueName);
item.setText(4, value);
String type;
if (valueType != EventValueDescription.ValueType.NOT_APPLICABLE) {
type = String.format("%1$s, %2$s", eventValueType.toString(), valueType.toString());
} else {
type = eventValueType.toString();
}
item.setText(5, type);
| void | newEvent(com.android.ddmlib.log.EventContainer event, com.android.ddmlib.log.EventLogParser logParser)Adds event to the display.
addToLog(event, logParser);
| void | resetUI()Resets the display. //$NON-NLS-1$
mLogTable.removeAll();
| void | resizeColumn(int index, org.eclipse.swt.widgets.TableColumn sourceColumn)Resizes the index -th column of the log {@link Table} (if applicable).
This does nothing if the Table object is null (because the display
type does not use a column) or if the index -th column is in fact the originating
column passed as argument.
if (mLogTable != null) {
TableColumn col = mLogTable.getColumn(index);
if (col != sourceColumn) {
col.setWidth(sourceColumn.getWidth());
}
}
|
|