Commit | Line | Data |
---|---|---|
ff71e543 MK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2014 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Matthew Khouzam - Initial API and implementation | |
11 | * Alexandre Montplaisir - Updated to new Event Table API | |
12 | *******************************************************************************/ | |
13 | ||
14 | package org.eclipse.linuxtools.btf.ui; | |
15 | ||
16 | import org.eclipse.linuxtools.btf.core.event.BtfEvent; | |
17 | import org.eclipse.linuxtools.btf.core.trace.BtfColumnNames; | |
18 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; | |
19 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; | |
20 | import org.eclipse.linuxtools.tmf.core.event.TmfEventField; | |
21 | import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable; | |
22 | import org.eclipse.linuxtools.tmf.ui.widgets.virtualtable.ColumnData; | |
23 | import org.eclipse.swt.SWT; | |
24 | import org.eclipse.swt.widgets.Composite; | |
25 | ||
26 | /** | |
27 | * BTF event viewer | |
28 | * | |
29 | * @author Matthew Khouzam | |
30 | */ | |
31 | public class BtfEventViewer extends TmfEventsTable { | |
32 | ||
33 | private static final TmfEventField NULL_NOTE_FIELD = | |
34 | new TmfEventField(BtfColumnNames.NOTES.toString(), null, null); | |
35 | ||
36 | private static final String[] COLUMN_NAMES = new String[] { | |
37 | BtfColumnNames.TIMESTAMP.toString(), | |
38 | BtfColumnNames.SOURCE.toString(), | |
39 | BtfColumnNames.SOURCE_INSTANCE.toString(), | |
40 | BtfColumnNames.EVENT_TYPE.toString(), | |
41 | BtfColumnNames.TARGET.toString(), | |
42 | BtfColumnNames.TARGET_INSTANCE.toString(), | |
43 | BtfColumnNames.EVENT.toString(), | |
44 | BtfColumnNames.NOTES.toString() | |
45 | }; | |
46 | ||
47 | private static final ColumnData[] COLUMN_DATA = new ColumnData[] { | |
48 | new ColumnData(COLUMN_NAMES[0], 150, SWT.LEFT), | |
49 | new ColumnData(COLUMN_NAMES[1], 120, SWT.LEFT), | |
50 | new ColumnData(COLUMN_NAMES[2], 100, SWT.LEFT), | |
51 | new ColumnData(COLUMN_NAMES[3], 120, SWT.LEFT), | |
52 | new ColumnData(COLUMN_NAMES[4], 90, SWT.LEFT), | |
53 | new ColumnData(COLUMN_NAMES[5], 100, SWT.LEFT), | |
54 | new ColumnData(COLUMN_NAMES[6], 110, SWT.LEFT), | |
55 | new ColumnData(COLUMN_NAMES[7], 100, SWT.LEFT), | |
56 | }; | |
57 | ||
58 | /** | |
59 | * Basic constructor, will use default column data. | |
60 | * | |
61 | * @param parent | |
62 | * The parent composite UI object | |
63 | * @param cacheSize | |
64 | * The size of the event table cache | |
65 | */ | |
66 | public BtfEventViewer(Composite parent, int cacheSize) { | |
67 | super(parent, cacheSize, COLUMN_DATA); | |
68 | fTable.getColumns()[0].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_TIMESTAMP); | |
69 | fTable.getColumns()[1].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_SOURCE); | |
70 | fTable.getColumns()[3].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_TYPE); | |
71 | fTable.getColumns()[4].setData(Key.FIELD_ID, ITmfEvent.EVENT_FIELD_REFERENCE); | |
72 | } | |
73 | ||
74 | @Override | |
75 | public String[] getItemStrings(ITmfEvent event) { | |
76 | if (!(event instanceof BtfEvent)) { | |
77 | return EMPTY_STRING_ARRAY; | |
78 | } | |
79 | final BtfEvent btfEvent = (BtfEvent) event; | |
80 | final ITmfEventField content = btfEvent.getContent(); | |
81 | final ITmfEventField notesField = content.getField(BtfColumnNames.NOTES.toString()); | |
82 | ||
83 | return new String[] { | |
84 | event.getTimestamp().toString(), | |
85 | event.getSource(), | |
86 | content.getField(BtfColumnNames.SOURCE_INSTANCE.toString()).toString(), | |
87 | btfEvent.getType().getName(), | |
88 | event.getReference(), | |
89 | content.getField(BtfColumnNames.TARGET_INSTANCE.toString()).toString(), | |
90 | content.getField(BtfColumnNames.EVENT.toString()).toString(), | |
91 | ((notesField != null) ? notesField : NULL_NOTE_FIELD).toString() | |
92 | }; | |
93 | } | |
94 | } |