tmf.ui: Introduce TmfFileDialogFactory
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.timing.ui / src / org / eclipse / tracecompass / internal / analysis / timing / ui / views / segmentstore / ExportToTsvAction.java
CommitLineData
37b7faba
MK
1/*******************************************************************************
2 * Copyright (c) 2016 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
10package org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore;
11
12import java.io.FileOutputStream;
13import java.io.IOException;
14import java.io.OutputStream;
15
16import org.eclipse.jdt.annotation.Nullable;
17import org.eclipse.jface.action.Action;
18import org.eclipse.swt.widgets.FileDialog;
19import org.eclipse.swt.widgets.Shell;
20import org.eclipse.tracecompass.internal.analysis.timing.ui.Activator;
674c702f 21import org.eclipse.tracecompass.tmf.ui.dialog.TmfFileDialogFactory;
37b7faba
MK
22
23/**
24 * The export to TSV abstract action
25 *
26 * TODO: improve testing when there is a way to test native widgets
27 *
28 * @author Matthew Khouzam
29 */
30public abstract class ExportToTsvAction extends Action {
31
32 private static final String[] EXTENSTIONS = { "*.tsv", "*.*" };//$NON-NLS-1$//$NON-NLS-2$
33
34 /**
35 * Gets the extension of TSV
36 *
37 * @return the extension of TSV
38 */
39 protected String[] getExtension() {
40 return EXTENSTIONS;
41 }
42
43 @Override
44 public String getText() {
45 return String.valueOf(Messages.AbstractSegmentStoreTableView_exportToTsv);
46 }
47
48 @Override
49 public String getToolTipText() {
50 return String.valueOf(Messages.ExportToTsvAction_exportToTsvToolTip);
51 }
52
53 @Override
54 public void run() {
55 Shell shell = getShell();
56 if (shell == null) {
57 return;
58 }
674c702f 59 FileDialog fd = TmfFileDialogFactory.create(shell);
37b7faba
MK
60 fd.setFilterExtensions(getExtension());
61 String fileName = fd.open();
62 if (fileName == null) {
63 return;
64 }
65 try (FileOutputStream fos = new FileOutputStream(fileName)) {
66 exportToTsv(fos);
67 } catch (IOException e) {
68 Activator.getDefault().logError("IO Error " + fileName, e); //$NON-NLS-1$
69 }
70 }
71
72 /**
73 * Get the shell to open the file dialog
74 *
75 * @return the shell
76 */
77 protected abstract @Nullable Shell getShell();
78
79 /**
80 * Export a given items's TSV
81 *
82 * @param stream
83 * an output stream to write the TSV to
84 */
85 protected abstract void exportToTsv(OutputStream stream);
86}
This page took 0.026272 seconds and 5 git commands to generate.