2010-07-12 Francois Chouinard <fchouinar@gmail.com> Contributions for Bug319429...
[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.event.TmfEvent;
22 import org.eclipse.linuxtools.tmf.event.TmfEventContent;
23 import org.eclipse.linuxtools.tmf.event.TmfEventReference;
24 import org.eclipse.linuxtools.tmf.event.TmfEventSource;
25 import org.eclipse.linuxtools.tmf.event.TmfEventType;
26 import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
27 import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;
28
29 public class CustomEvent extends TmfEvent {
30
31 protected static final String TIMESTAMP_INPUT_FORMAT_KEY = "CE_TS_I_F";
32 protected static final String NO_MESSAGE = "";
33 public static final byte TIMESTAMP_SCALE = -3;
34
35 protected CustomTraceDefinition fDefinition;
36 protected Map<String, String> fData;
37 private String[] fColumnData;
38
39 public CustomEvent(CustomTraceDefinition definition, TmfEvent other) {
40 super(other);
41 fDefinition = definition;
42 fData = new HashMap<String, String>();
43 }
44
45 public CustomEvent(CustomTraceDefinition definition, TmfTimestamp timestamp, TmfEventSource source, TmfEventType type, TmfEventReference reference) {
46 super(timestamp, source, type, reference);
47 fDefinition = definition;
48 fData = new HashMap<String, String>();
49 }
50
51 public CustomEvent(CustomTraceDefinition definition, TmfTimestamp originalTS, TmfTimestamp effectiveTS, TmfEventSource source, TmfEventType type, TmfEventReference reference) {
52 super(originalTS, effectiveTS, source, type, reference);
53 fDefinition = definition;
54 fData = new HashMap<String, String>();
55 }
56
57 @Override
58 public TmfTimestamp getTimestamp() {
59 if (fData != null) processData();
60 return super.getTimestamp();
61 }
62
63 @Override
64 public TmfTimestamp getOriginalTimestamp() {
65 if (fData != null) processData();
66 return super.getOriginalTimestamp();
67 }
68
69 @Override
70 public TmfEventContent getContent() {
71 if (fData != null) processData();
72 return super.getContent();
73 }
74
75 public String[] extractItemFields() {
76 if (fData != null) processData();
77 return fColumnData;
78 }
79
80 private void processData() {
81 String timeStampString = fData.get(CustomTraceDefinition.TAG_TIMESTAMP);
82 String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
83 Date date = null;
84 if (timeStampInputFormat != null && timeStampString != null) {
85 SimpleDateFormat dateFormat = new SimpleDateFormat(timeStampInputFormat);
86 try {
87 date = dateFormat.parse(timeStampString);
88 fOriginalTimestamp = fEffectiveTimestamp = new TmfTimestamp(date.getTime(), TIMESTAMP_SCALE);
89 } catch (ParseException e) {
90 fOriginalTimestamp = fEffectiveTimestamp = TmfTimestamp.Zero;
91 }
92 } else {
93 fOriginalTimestamp = fEffectiveTimestamp = TmfTimestamp.Zero;
94 }
95
96 int i = 0;
97 fColumnData = new String[fDefinition.outputs.size()];
98 for (OutputColumn outputColumn : fDefinition.outputs) {
99 String value = fData.get(outputColumn.name);
100 if (outputColumn.name.equals(CustomTraceDefinition.TAG_TIMESTAMP) && date != null) {
101 SimpleDateFormat dateFormat = new SimpleDateFormat(fDefinition.timeStampOutputFormat);
102 fColumnData[i++] = dateFormat.format(date);
103 } else {
104 fColumnData[i++] = value;
105 }
106 }
107 String message = fData.get(CustomTraceDefinition.TAG_MESSAGE);;
108 setContent(new TmfEventContent(this, message));
109 fData = null;
110 }
111 }
This page took 0.032388 seconds and 5 git commands to generate.