001 package nl.cwi.sen1.visplugin.csvexport; 002 003 import java.awt.BorderLayout; 004 import java.io.IOException; 005 006 import javax.swing.JLabel; 007 import javax.swing.JPanel; 008 009 import nl.cwi.sen1.relationstores.types.RTuple; 010 import nl.cwi.sen1.visplugin.VisualizationPluginWindow; 011 012 /** 013 * This class represents the window of the CSV Export plugin in the meta environment 014 * @author Antoine Savelkoul 015 * @author Chris Woolderink 016 * @date 14-03-2007 017 */ 018 public class CsvExportVisualizationWindow extends VisualizationPluginWindow { 019 private RTuple m_fact; // used to store the RTuple that has to be exported 020 private JLabel m_message; // used for the message that will be shown after the export is completed 021 022 /** 023 * Returns JPanel including JTable with Data. 024 * @param fact the RStore to be exported 025 * @return the content for the tab that will be shown in the Meta Environment 026 * @author Antoine Savelkoul 027 * @author Chris Woolderink 028 * @date 16-03-2007 029 */ 030 public JPanel render(RTuple fact) { 031 m_fact = fact; 032 033 // Create and return the content for the tab that will be shown in the Meta Environment 034 JPanel controlArea = new JPanel(new BorderLayout()); 035 m_message = new JLabel(); 036 controlArea.add(m_message); 037 return controlArea; 038 } 039 040 /** 041 * Called when the plugin is loaded 042 * @author Raymond Bergen 043 * @date 16-03-2007 044 */ 045 public void executeOnLoad() { 046 exportToCsvClicked(); 047 } 048 049 /** 050 * Exports the loaded RTuple to a CSV file 051 * @param fileName The name of the the CSV output will be written to 052 * @author Antoine Savelkoul 053 * @author Chris Woolderink 054 * @date 16-03-2007 055 */ 056 protected void exportToCsv(String fileName){ 057 String message = ""; 058 try { 059 Exporter.exportToFile( m_fact, fileName, Exporter.ExportSelection.DATA_ONLY); 060 message = "The RStore has been exported successfully. You can close this window."; 061 } 062 catch( IOException e ) { 063 message = "The RStore has not been succesfully exported. Error while writing file. You can close this window. "; 064 } 065 066 m_message.setText(message); 067 } 068 } 069