1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Kalray, Ericsson
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
10 * Xavier Raynaud - Initial API and implementation
11 * Bernd Hufmann - Adapted to new events table column API
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.internal
.tmf
.ui
.commands
;
16 import java
.io
.IOException
;
17 import java
.io
.Writer
;
18 import java
.util
.List
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.ITmfFilter
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.request
.ITmfEventRequest
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.request
.TmfEventRequest
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
26 import org
.eclipse
.tracecompass
.tmf
.ui
.viewers
.events
.columns
.TmfEventTableColumn
;
29 * This TMF Requests exports traces to text files.
30 * @author Xavier Raynaud <xavier.raynaud@kalray.eu>
32 public class ExportToTextRequest
extends TmfEventRequest
{
34 private final Writer fWriter
;
35 private final ITmfFilter fFilter
;
36 private final List
<TmfEventTableColumn
> fColumns
;
37 private IOException fIOException
;
42 * a Writer, typically a FileWriter.
44 * a TmfFilter, if we want to filter some events. May be <code>null</code>.
46 * the {@link TmfEventTableColumn} requesting the export (may be <code>null</code>)
48 public ExportToTextRequest(Writer w
, ITmfFilter filter
, List
<TmfEventTableColumn
> columns
) {
49 super(ITmfEvent
.class, TmfTimeRange
.ETERNITY
, 0, ITmfEventRequest
.ALL_DATA
, ExecutionType
.FOREGROUND
);
51 this.fFilter
= filter
;
52 this.fColumns
= columns
;
56 * Gets the IOException thrown by this export request, if any.
57 * @return the fIoException
59 public IOException
getIOException() {
64 public void handleData(final ITmfEvent event
) {
65 super.handleData(event
);
70 if (fFilter
== null || fFilter
.matches(event
)) {
71 if (fColumns
!= null) {
72 boolean needTab
= false;
73 for (TmfEventTableColumn column
: fColumns
) {
77 fWriter
.write(column
.getItemString(event
));
80 } else { // fallback to default formatting
81 fWriter
.write(event
.getTimestamp().toString());
83 fWriter
.write(event
.getName());
85 ITmfEventField content
= event
.getContent();
86 Object value
= content
.getValue();
88 fWriter
.write(value
.toString());
93 } catch (IOException ex
) {