Integrate the TmfEvent+ITmfTimestamp API
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / parsers / custom / CustomEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2010 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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.parsers.custom;
14
15 import java.text.ParseException;
16 import java.text.SimpleDateFormat;
17 import java.util.Date;
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
22 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
23 import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
24 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
25 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
26 import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;
27
28 public class CustomEvent extends TmfEvent {
29
30 protected static final String TIMESTAMP_INPUT_FORMAT_KEY = "CE_TS_I_F"; //$NON-NLS-1$
31 protected static final String NO_MESSAGE = ""; //$NON-NLS-1$
32 public static final byte TIMESTAMP_SCALE = -3;
33
34 protected CustomTraceDefinition fDefinition;
35 protected Map<String, String> fData;
36 private String[] fColumnData;
37
38 public CustomEvent(CustomTraceDefinition definition) {
39 fDefinition = definition;
40 fData = new HashMap<String, String>();
41 }
42
43 public CustomEvent(CustomTraceDefinition definition, TmfEvent other) {
44 super(other);
45 fDefinition = definition;
46 fData = new HashMap<String, String>();
47 }
48
49 public CustomEvent(CustomTraceDefinition definition, ITmfTrace<?> parentTrace, TmfTimestamp timestamp, String source, TmfEventType type, String reference) {
50 super(parentTrace, timestamp, source, type, reference);
51 fDefinition = definition;
52 fData = new HashMap<String, String>();
53 }
54
55 @Override
56 public ITmfTimestamp getTimestamp() {
57 if (fData != null) processData();
58 return super.getTimestamp();
59 }
60
61 public String[] extractItemFields() {
62 if (fData != null) processData();
63 return fColumnData;
64 }
65
66 private void processData() {
67 String timeStampString = fData.get(CustomTraceDefinition.TAG_TIMESTAMP);
68 String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
69 Date date = null;
70 if (timeStampInputFormat != null && timeStampString != null) {
71 SimpleDateFormat dateFormat = new SimpleDateFormat(timeStampInputFormat);
72 try {
73 date = dateFormat.parse(timeStampString);
74 fTimestamp = new TmfTimestamp(date.getTime(), TIMESTAMP_SCALE);
75 } catch (ParseException e) {
76 fTimestamp = TmfTimestamp.Zero;
77 }
78 } else {
79 fTimestamp = TmfTimestamp.Zero;
80 }
81
82 int i = 0;
83 fColumnData = new String[fDefinition.outputs.size()];
84 for (OutputColumn outputColumn : fDefinition.outputs) {
85 String value = fData.get(outputColumn.name);
86 if (outputColumn.name.equals(CustomTraceDefinition.TAG_TIMESTAMP) && date != null) {
87 SimpleDateFormat dateFormat = new SimpleDateFormat(fDefinition.timeStampOutputFormat);
88 fColumnData[i++] = dateFormat.format(date);
89 } else {
90 fColumnData[i++] = (value != null ? value : ""); //$NON-NLS-1$
91 }
92 }
93 fData = null;
94 }
95 }
This page took 0.033094 seconds and 5 git commands to generate.