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
;
23 * The export to TSV abstract action
25 * TODO: improve testing when there is a way to test native widgets
27 * @author Matthew Khouzam
29 public abstract class ExportToTsvAction
extends Action
{
31 private static final String
[] EXTENSTIONS
= { "*.tsv", "*.*" };//$NON-NLS-1$//$NON-NLS-2$
34 * Gets the extension of TSV
36 * @return the extension of TSV
38 protected String
[] getExtension() {
43 public String
getText() {
44 return String
.valueOf(Messages
.AbstractSegmentStoreTableView_exportToTsv
);
48 public String
getToolTipText() {
49 return String
.valueOf(Messages
.ExportToTsvAction_exportToTsvToolTip
);
54 Shell shell
= getShell();
58 FileDialog fd
= new FileDialog(shell
);
59 fd
.setFilterExtensions(getExtension());
60 String fileName
= fd
.open();
61 if (fileName
== null) {
64 try (FileOutputStream fos
= new FileOutputStream(fileName
)) {
66 } catch (IOException e
) {
67 Activator
.getDefault().logError("IO Error " + fileName
, e
); //$NON-NLS-1$
72 * Get the shell to open the file dialog
76 protected abstract @Nullable Shell
getShell();
79 * Export a given items's TSV
82 * an output stream to write the TSV to
84 protected abstract void exportToTsv(OutputStream stream
);