1 /*******************************************************************************
2 * Copyright (c) 2016 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
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.analysis
.timing
.ui
.views
.segmentstore
;
12 import java
.io
.FileOutputStream
;
13 import java
.io
.IOException
;
14 import java
.io
.OutputStream
;
16 import org
.eclipse
.jdt
.annotation
.Nullable
;
17 import org
.eclipse
.jface
.action
.Action
;
18 import org
.eclipse
.swt
.widgets
.FileDialog
;
19 import org
.eclipse
.swt
.widgets
.Shell
;
20 import org
.eclipse
.tracecompass
.internal
.analysis
.timing
.ui
.Activator
;
21 import org
.eclipse
.tracecompass
.tmf
.ui
.dialog
.TmfFileDialogFactory
;
24 * The export to TSV abstract action
26 * TODO: improve testing when there is a way to test native widgets
28 * @author Matthew Khouzam
30 public abstract class ExportToTsvAction
extends Action
{
32 private static final String
[] EXTENSTIONS
= { "*.tsv", "*.*" };//$NON-NLS-1$//$NON-NLS-2$
35 * Gets the extension of TSV
37 * @return the extension of TSV
39 protected String
[] getExtension() {
44 public String
getText() {
45 return String
.valueOf(Messages
.AbstractSegmentStoreTableView_exportToTsv
);
49 public String
getToolTipText() {
50 return String
.valueOf(Messages
.ExportToTsvAction_exportToTsvToolTip
);
55 Shell shell
= getShell();
59 FileDialog fd
= TmfFileDialogFactory
.create(shell
);
60 fd
.setFilterExtensions(getExtension());
61 String fileName
= fd
.open();
62 if (fileName
== null) {
65 try (FileOutputStream fos
= new FileOutputStream(fileName
)) {
67 } catch (IOException e
) {
68 Activator
.getDefault().logError("IO Error " + fileName
, e
); //$NON-NLS-1$
73 * Get the shell to open the file dialog
77 protected abstract @Nullable Shell
getShell();
80 * Export a given items's TSV
83 * an output stream to write the TSV to
85 protected abstract void exportToTsv(OutputStream stream
);