+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package habeas;
+
+import java.util.ArrayList;
+import javax.swing.JFileChooser;
+import javax.swing.JOptionPane;
+import javax.swing.JTable;
+import javax.swing.table.DefaultTableModel;
+import javax.swing.table.TableModel;
+
+/**
+ *
+ * @author hari
+ */
+public class NoticesReportViewDialog extends javax.swing.JDialog {
+
+ private String reportTitle;
+ private String[] reportCols;
+ private ArrayList<Object> reportData;
+
+ /**
+ * Creates new form NoticesReportViewDialog
+ */
+ public NoticesReportViewDialog(java.awt.Frame parent, boolean modal) {
+ super(parent, modal);
+ initComponents();
+ }
+
+ /**
+ * This method is called from within the constructor to initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is always
+ * regenerated by the Form Editor.
+ */
+ @SuppressWarnings("unchecked")
+ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ popMenu = new javax.swing.JPopupMenu();
+ menuExportCSV = new javax.swing.JMenuItem();
+ labelReportTitle = new javax.swing.JLabel();
+ jScrollPane2 = new javax.swing.JScrollPane();
+ tableReport = new javax.swing.JTable();
+
+ popMenu.setLabel("Popup");
+
+ menuExportCSV.setMnemonic('C');
+ menuExportCSV.setText("Export as CSV...");
+ menuExportCSV.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ menuExportCSVActionPerformed(evt);
+ }
+ });
+ popMenu.add(menuExportCSV);
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ setTitle("View Report");
+
+ labelReportTitle.setFont(new java.awt.Font("Noto Sans", 1, 15)); // NOI18N
+ labelReportTitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
+ labelReportTitle.setText("REPORT TITLE");
+
+ tableReport.setModel(new javax.swing.table.DefaultTableModel(
+ new Object [][] {
+
+ },
+ new String [] {
+
+ }
+ ));
+ jScrollPane2.setViewportView(tableReport);
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
+ getContentPane().setLayout(layout);
+ layout.setHorizontalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(labelReportTitle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addContainerGap())
+ .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 682, Short.MAX_VALUE)
+ );
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(labelReportTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE))
+ );
+
+ pack();
+ }// </editor-fold>//GEN-END:initComponents
+
+ private void menuExportCSVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuExportCSVActionPerformed
+ // TODO add your handling code here:
+ JFileChooser chooser = new JFileChooser ();
+ int rt = chooser.showSaveDialog(this);
+ if (rt == JFileChooser.APPROVE_OPTION) {
+ String filePath = chooser.getSelectedFile().getAbsolutePath();
+ boolean ret = Utility.saveReportCSV (filePath, reportCols, reportData);
+ if (ret == false)
+ JOptionPane.showMessageDialog(this, ERROR_SAVING_REPORT);
+ else
+ JOptionPane.showMessageDialog(this, REPORT_SAVED_SUCCESSFULLY);
+ }
+ }//GEN-LAST:event_menuExportCSVActionPerformed
+ private static final String REPORT_SAVED_SUCCESSFULLY = "Report saved successfully";
+ private static final String ERROR_SAVING_REPORT = "Error saving report";
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[]) {
+ /* Set the Nimbus look and feel */
+ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
+ /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
+ * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
+ */
+ try {
+ for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
+ if ("Nimbus".equals(info.getName())) {
+ javax.swing.UIManager.setLookAndFeel(info.getClassName());
+ break;
+ }
+ }
+ } catch (ClassNotFoundException ex) {
+ java.util.logging.Logger.getLogger(NoticesReportViewDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (InstantiationException ex) {
+ java.util.logging.Logger.getLogger(NoticesReportViewDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (IllegalAccessException ex) {
+ java.util.logging.Logger.getLogger(NoticesReportViewDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (javax.swing.UnsupportedLookAndFeelException ex) {
+ java.util.logging.Logger.getLogger(NoticesReportViewDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ }
+ //</editor-fold>
+
+ /* Create and display the dialog */
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ public void run() {
+ NoticesReportViewDialog dialog = new NoticesReportViewDialog(new javax.swing.JFrame(), true);
+ dialog.addWindowListener(new java.awt.event.WindowAdapter() {
+ @Override
+ public void windowClosing(java.awt.event.WindowEvent e) {
+ System.exit(0);
+ }
+ });
+ dialog.setVisible(true);
+ }
+ });
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JScrollPane jScrollPane2;
+ private javax.swing.JLabel labelReportTitle;
+ private javax.swing.JMenuItem menuExportCSV;
+ private javax.swing.JPopupMenu popMenu;
+ private javax.swing.JTable tableReport;
+ // End of variables declaration//GEN-END:variables
+
+ public void setupReportTable(String title, String[] columns,
+ ArrayList<Object> data) {
+ reportTitle = title;
+ reportCols = columns;
+ reportData = data;
+ DefaultTableModel mdl = new DefaultTableModel (columns, 0) {
+ @Override
+ public boolean isCellEditable (int row, int col) {
+ return false;
+ }
+ };
+ tableReport.setModel(mdl);
+ tableReport.setComponentPopupMenu(popMenu);
+
+ labelReportTitle.setText(title);
+ for (int i = 0; i < data.size(); i += columns.length) {
+ Object[] row = new Object[columns.length];
+ for (int j = 0; j < columns.length; j ++)
+ row[j] = data.get(i+j);
+ mdl.addRow (row);
+ }
+ }
+}