Commit 315ff3ca authored by Nils Christian Ehmke's avatar Nils Christian Ehmke

Added the CSV export

parent 32499faf
package kieker.diagnosis.service.export;
public final class CSVData {
private String[] header;
private String[][] values;
public String[] getHeader( ) {
return header;
}
public void setHeader( final String[] aHeader ) {
header = aHeader;
}
public String[][] getValues( ) {
return values;
}
public void setValues( final String[][] aValues ) {
values = aValues;
}
}
package kieker.diagnosis.service.export;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import com.google.inject.Singleton;
import kieker.diagnosis.architecture.exception.BusinessException;
import kieker.diagnosis.architecture.service.ServiceBase;
@Singleton
public class ExportService extends ServiceBase {
public void exportToCSV( final File aFile, final CSVData aCsvData ) throws BusinessException {
try ( final FileWriter fileWriter = new FileWriter( aFile ) ) {
final String[] headers = aCsvData.getHeader( );
final int columnsSize = headers.length;
// The header first
for ( int columnIndex = 0; columnIndex < columnsSize; columnIndex++ ) {
if ( columnIndex != 0 ) {
fileWriter.append( ";" );
}
fileWriter.append( headers[columnIndex] );
}
fileWriter.append( "\n" );
// Now the values
final String[][] values = aCsvData.getValues( );
final int valuesSize = values.length > 0 ? values[0].length : 0;
for ( int rowIndex = 0; rowIndex < valuesSize; rowIndex++ ) {
for ( int columnIndex = 0; columnIndex < columnsSize; columnIndex++ ) {
if ( columnIndex != 0 ) {
fileWriter.append( ";" );
}
fileWriter.append( values[columnIndex][rowIndex] );
}
fileWriter.append( "\n" );
}
} catch ( final IOException ex ) {
throw new BusinessException( ex );
}
}
}
......@@ -10,6 +10,7 @@ import kieker.diagnosis.architecture.ui.ControllerBase;
import kieker.diagnosis.service.aggregatedmethods.AggregatedMethodsFilter;
import kieker.diagnosis.service.aggregatedmethods.AggregatedMethodsService;
import kieker.diagnosis.service.data.AggregatedMethodCall;
import kieker.diagnosis.service.export.CSVData;
import kieker.diagnosis.service.settings.SettingsService;
import kieker.diagnosis.ui.main.MainController;
......@@ -105,4 +106,9 @@ class AggregatedMethodsController extends ControllerBase<AggregatedMethodsViewMo
}
}
public void performExportToCSV( ) {
final CSVData csvData = getViewModel( ).savePresentationAsCSV( );
getController( MainController.class ).performExportToCSV( csvData );
}
}
......@@ -17,6 +17,7 @@ import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import kieker.diagnosis.architecture.ui.EnumStringConverter;
......@@ -541,10 +542,29 @@ public class AggregatedMethodsView extends ViewBase<AggregatedMethodsController>
// Status bar
{
ivStatusLabel = new Label( );
VBox.setMargin( ivStatusLabel, new Insets( 5 ) );
getChildren( ).add( ivStatusLabel );
final HBox hBox = new HBox( );
VBox.setMargin( hBox, new Insets( 5 ) );
{
ivStatusLabel = new Label( );
ivStatusLabel.setMaxWidth( Double.POSITIVE_INFINITY );
HBox.setHgrow( ivStatusLabel, Priority.ALWAYS );
HBox.setMargin( ivStatusLabel, new Insets( 5, 0, 0, 0 ) );
hBox.getChildren( ).add( ivStatusLabel );
}
{
final Hyperlink hyperlink = new Hyperlink( );
hyperlink.setText( getLocalizedString( "exportToCSV" ) );
hyperlink.setOnAction( e -> getController( ).performExportToCSV( ) );
hBox.getChildren( ).add( hyperlink );
}
getChildren( ).add( hBox );
}
}
TextField getFilterHost( ) {
......
......@@ -7,10 +7,14 @@ import java.util.List;
import com.google.inject.Singleton;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import kieker.diagnosis.architecture.exception.BusinessException;
import kieker.diagnosis.architecture.ui.ViewModelBase;
import kieker.diagnosis.service.aggregatedmethods.AggregatedMethodsFilter;
import kieker.diagnosis.service.data.AggregatedMethodCall;
import kieker.diagnosis.service.export.CSVData;
import kieker.diagnosis.service.pattern.PatternService;
@Singleton
......@@ -110,4 +114,30 @@ class AggregatedMethodsViewModel extends ViewModelBase<AggregatedMethodsView> {
return getView( ).getTableView( ).getSelectionModel( ).getSelectedItem( );
}
public CSVData savePresentationAsCSV( ) {
final TableView<AggregatedMethodCall> tableView = getView( ).getTableView( );
final ObservableList<TableColumn<AggregatedMethodCall, ?>> visibleColumns = tableView.getVisibleLeafColumns( );
final int columnSize = visibleColumns.size( );
final int itemsSize = tableView.getItems( ).size( );
final String[] headers = new String[columnSize];
for ( int columnIndex = 0; columnIndex < columnSize; columnIndex++ ) {
headers[columnIndex] = visibleColumns.get( columnIndex ).getText( );
}
final String[][] values = new String[columnSize][itemsSize];
for ( int rowIndex = 0; rowIndex < itemsSize; rowIndex++ ) {
for ( int columnIndex = 0; columnIndex < columnSize; columnIndex++ ) {
final Object cellData = visibleColumns.get( columnIndex ).getCellData( rowIndex );
values[columnIndex][rowIndex] = cellData.toString( );
}
}
final CSVData csvData = new CSVData( );
csvData.setHeader( headers );
csvData.setValues( values );
return csvData;
}
}
......@@ -14,6 +14,7 @@ import javafx.scene.control.ButtonType;
import javafx.scene.control.TextInputDialog;
import javafx.scene.image.Image;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import kieker.diagnosis.architecture.exception.BusinessException;
import kieker.diagnosis.architecture.exception.BusinessRuntimeException;
......@@ -24,6 +25,8 @@ import kieker.diagnosis.architecture.ui.ViewBase;
import kieker.diagnosis.service.data.AggregatedMethodCall;
import kieker.diagnosis.service.data.MethodCall;
import kieker.diagnosis.service.data.MonitoringLogService;
import kieker.diagnosis.service.export.CSVData;
import kieker.diagnosis.service.export.ExportService;
import kieker.diagnosis.ui.main.properties.LastImportPathProperty;
import kieker.diagnosis.ui.methods.MethodsView;
import kieker.diagnosis.ui.progress.ProgressDialog;
......@@ -178,4 +181,19 @@ public class MainController extends ControllerBase<MainViewModel> {
}
}
public void performExportToCSV( final CSVData aCsvData ) {
try {
final FileChooser fileChooser = new FileChooser( );
fileChooser.setTitle( getLocalizedString( "titleExportToCSV" ) );
final File file = fileChooser.showSaveDialog( getViewModel( ).getWindow( ) );
if ( file != null ) {
final ExportService exportService = getService( ExportService.class );
exportService.exportToCSV( file, aCsvData );
}
} catch ( final BusinessException ex ) {
throw new BusinessRuntimeException( ex );
}
}
}
......@@ -9,6 +9,7 @@ import kieker.diagnosis.architecture.exception.BusinessRuntimeException;
import kieker.diagnosis.architecture.ui.ControllerBase;
import kieker.diagnosis.service.data.AggregatedMethodCall;
import kieker.diagnosis.service.data.MethodCall;
import kieker.diagnosis.service.export.CSVData;
import kieker.diagnosis.service.methods.MethodsFilter;
import kieker.diagnosis.service.methods.MethodsService;
import kieker.diagnosis.service.methods.SearchType;
......@@ -126,4 +127,9 @@ class MethodsController extends ControllerBase<MethodsViewModel> {
}
}
public void performExportToCSV( ) {
final CSVData csvData = getViewModel( ).savePresentationAsCSV( );
getController( MainController.class ).performExportToCSV( csvData );
}
}
......@@ -19,6 +19,7 @@ import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import jfxtras.scene.control.CalendarTimeTextField;
......@@ -511,9 +512,27 @@ public class MethodsView extends ViewBase<MethodsController> {
// Status bar
{
ivStatusLabel = new Label( );
VBox.setMargin( ivStatusLabel, new Insets( 5 ) );
getChildren( ).add( ivStatusLabel );
final HBox hBox = new HBox( );
VBox.setMargin( hBox, new Insets( 5 ) );
{
ivStatusLabel = new Label( );
ivStatusLabel.setMaxWidth( Double.POSITIVE_INFINITY );
HBox.setHgrow( ivStatusLabel, Priority.ALWAYS );
HBox.setMargin( ivStatusLabel, new Insets( 5, 0, 0, 0 ) );
hBox.getChildren( ).add( ivStatusLabel );
}
{
final Hyperlink hyperlink = new Hyperlink( );
hyperlink.setText( getLocalizedString( "exportToCSV" ) );
hyperlink.setOnAction( e -> getController( ).performExportToCSV( ) );
hBox.getChildren( ).add( hyperlink );
}
getChildren( ).add( hBox );
}
}
......
......@@ -7,9 +7,13 @@ import java.util.List;
import com.google.inject.Singleton;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import kieker.diagnosis.architecture.exception.BusinessException;
import kieker.diagnosis.architecture.ui.ViewModelBase;
import kieker.diagnosis.service.data.MethodCall;
import kieker.diagnosis.service.export.CSVData;
import kieker.diagnosis.service.methods.MethodsFilter;
import kieker.diagnosis.service.pattern.PatternService;
......@@ -116,4 +120,30 @@ class MethodsViewModel extends ViewModelBase<MethodsView> {
return getView( ).getTableView( ).getSelectionModel( ).getSelectedItem( );
}
public CSVData savePresentationAsCSV( ) {
final TableView<MethodCall> tableView = getView( ).getTableView( );
final ObservableList<TableColumn<MethodCall, ?>> visibleColumns = tableView.getVisibleLeafColumns( );
final int columnSize = visibleColumns.size( );
final int itemsSize = tableView.getItems( ).size( );
final String[] headers = new String[columnSize];
for ( int columnIndex = 0; columnIndex < columnSize; columnIndex++ ) {
headers[columnIndex] = visibleColumns.get( columnIndex ).getText( );
}
final String[][] values = new String[columnSize][itemsSize];
for ( int rowIndex = 0; rowIndex < itemsSize; rowIndex++ ) {
for ( int columnIndex = 0; columnIndex < columnSize; columnIndex++ ) {
final Object cellData = visibleColumns.get( columnIndex ).getCellData( rowIndex );
values[columnIndex][rowIndex] = cellData.toString( );
}
}
final CSVData csvData = new CSVData( );
csvData.setHeader( headers );
csvData.setValues( values );
return csvData;
}
}
......@@ -35,4 +35,5 @@ labelMaxDuration=Maximal Duration:
labelTotalDuration=Total Duration:
jumpToMethods=Jump to method calls
saveAsFavorite=Save as favorite
\ No newline at end of file
saveAsFavorite=Save as favorite
exportToCSV=Export to CSV
\ No newline at end of file
......@@ -35,4 +35,5 @@ labelMaxDuration=Maximale Dauer:
labelTotalDuration=Gesamtdauer:
jumpToMethods=Zu Methodenaufrufen springen
saveAsFavorite=Als Favorit speichern
\ No newline at end of file
saveAsFavorite=Als Favorit speichern
exportToCSV=In CSV exportieren
\ No newline at end of file
titleImportLog=Import monitoring log
titleExportToCSV=Export to CSV
titleReallyClose=Really close?
headerReallyClose=Do you really want to close the application?
......
titleImportLog=Monitoring Log Importieren
titleExportToCSV=In CSV exportieren
titleReallyClose=Wirklich beenden?
headerReallyClose=Wollen Sie die Anwendung wirklich beenden?
......
......@@ -33,4 +33,5 @@ labelTimestamp=Timestamp:
labelTraceId=Trace Id:
saveAsFavorite=Save as favorite
jumpToTrace=Jump to trace
\ No newline at end of file
jumpToTrace=Jump to trace
exportToCSV=Export to CSV
\ No newline at end of file
......@@ -33,4 +33,5 @@ labelTimestamp=Zeitstempel:
labelTraceId=Trace Id:
jumpToTrace=Zum Trace springen
saveAsFavorite=Als Favorit speichern
\ No newline at end of file
saveAsFavorite=Als Favorit speichern
exportToCSV=In CSV exportieren
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment