Java tutorial
/* * 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 co.edu.unal.pos.gui; import java.text.NumberFormat; import java.util.Currency; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.TreeMap; import javax.swing.JComboBox; import javax.swing.JTextField; import javax.swing.SwingWorker; import org.apache.commons.lang.StringUtils; import org.springframework.format.number.CurrencyFormatter; import co.edu.unal.pos.common.constants.AggregationLevel; import co.edu.unal.pos.common.constants.IntegerFilterOperator; import co.edu.unal.pos.common.properties.PropertiesProvider; import co.edu.unal.pos.hadoop.JobRunner; import co.edu.unal.pos.hadoop.ReaderClient; import co.edu.unal.pos.model.SaleFact; import co.edu.unal.pos.model.SaleFactFilter; /** * * @author andres.rojas */ public class PosHadoopJFrame extends javax.swing.JFrame { /** * */ private static final long serialVersionUID = 1L; private static final String[] CONFIGURATION_COLUMN_NAMES = { "Property", "Value" }; private static final String[] MAP_REDUCE_RESULTS_COLUMNS_NAMES = { "Year", "Month", "Day", "Quantity", "Price", "Product Id", "Product Description" }; private static final String[] OPERATORS = { "=", "<", ">", "<=", ">=" }; private static final String[] AGGREGATION_LEVELS = { "Year", "Month", "Day" }; javax.swing.table.DefaultTableModel configurationTableDataModel = new javax.swing.table.DefaultTableModel( new Object[][] { { null, null }, { null, null }, { null, null }, { null, null } }, CONFIGURATION_COLUMN_NAMES); private Map<String, String> properties = new TreeMap<String, String>(); private javax.swing.table.DefaultTableModel mapReduceResultsTableDataModel = new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null, null, null, null }, { null, null, null, null, null, null, null }, { null, null, null, null, null, null, null }, { null, null, null, null, null, null, null }, }, MAP_REDUCE_RESULTS_COLUMNS_NAMES); private NumberFormat currencyFormatter = null; /** * Creates new form PosHadoopJFrame */ public PosHadoopJFrame() { initComponents(); this.setTitle("POS Hadoop"); currencyFormatter = NumberFormat.getCurrencyInstance(); } /** * 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() { jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jTabbedPane = new javax.swing.JTabbedPane(); etlJPanel = new javax.swing.JPanel(); etlJProgressBar = new javax.swing.JProgressBar(); startEtlJPanel = new javax.swing.JPanel(); startEtlJButton = new javax.swing.JButton(); mapReduceJPanel = new javax.swing.JPanel(); aggregationLevelJLabel = new javax.swing.JLabel(); aggregationLevelJComboBox = new javax.swing.JComboBox(); filtersJPanel = new javax.swing.JPanel(); productIdLabel = new javax.swing.JLabel(); productIdJTextField = new javax.swing.JTextField(); productDescriptionJLabel = new javax.swing.JLabel(); productDescriptionJTextField = new javax.swing.JTextField(); yearJLabel = new javax.swing.JLabel(); monthJLabel = new javax.swing.JLabel(); dayJLabel = new javax.swing.JLabel(); yearJTextField = new javax.swing.JTextField(); monthJTextField = new javax.swing.JTextField(); dayJTextField = new javax.swing.JTextField(); yearOperatorJComboBox = new javax.swing.JComboBox(); monthOperatorJComboBox = new javax.swing.JComboBox(); dayOperatorJComboBox = new javax.swing.JComboBox(); startMapReduceJPanel = new javax.swing.JPanel(); startMapReduceJButton = new javax.swing.JButton(); mapReduceResultsJPanel = new javax.swing.JPanel(); mapReduceResultsJScrollPane = new javax.swing.JScrollPane(); mapReduceResultsJTable = new javax.swing.JTable(); configurationJPanel = new javax.swing.JPanel(); configurationJScrollPane = new javax.swing.JScrollPane(); configurationJTable = new javax.swing.JTable(); saveConfigurationJButton = new javax.swing.JButton(); jTable1.setModel( new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null } }, new String[] { "Title 1", "Title 2", "Title 3", "Title 4" })); jScrollPane1.setViewportView(jTable1); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); startEtlJButton.setText("Start"); startEtlJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { startEtlJButtonActionPerformed(evt); } }); startEtlJPanel.add(startEtlJButton); javax.swing.GroupLayout etlJPanelLayout = new javax.swing.GroupLayout(etlJPanel); etlJPanel.setLayout(etlJPanelLayout); etlJPanelLayout.setHorizontalGroup(etlJPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(etlJPanelLayout.createSequentialGroup().addContainerGap() .addGroup(etlJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(etlJProgressBar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(startEtlJPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap())); etlJPanelLayout.setVerticalGroup(etlJPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(etlJPanelLayout.createSequentialGroup().addGap(102, 102, 102) .addComponent(etlJProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(startEtlJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(562, Short.MAX_VALUE))); jTabbedPane.addTab("ETL", etlJPanel); aggregationLevelJLabel.setText("Aggregation Level"); aggregationLevelJComboBox.setModel(new javax.swing.DefaultComboBoxModel(AGGREGATION_LEVELS)); filtersJPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Filters")); productIdLabel.setText("Product Id"); productDescriptionJLabel.setText("Product Desc."); yearJLabel.setText("Year"); monthJLabel.setText("Month"); dayJLabel.setText("Day"); yearOperatorJComboBox.setModel(new javax.swing.DefaultComboBoxModel(OPERATORS)); monthOperatorJComboBox.setModel(new javax.swing.DefaultComboBoxModel(OPERATORS)); dayOperatorJComboBox.setModel(new javax.swing.DefaultComboBoxModel(OPERATORS)); javax.swing.GroupLayout filtersJPanelLayout = new javax.swing.GroupLayout(filtersJPanel); filtersJPanel.setLayout(filtersJPanelLayout); filtersJPanelLayout.setHorizontalGroup(filtersJPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(filtersJPanelLayout.createSequentialGroup().addContainerGap().addGroup(filtersJPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(productDescriptionJLabel).addComponent(productIdLabel) .addGroup(filtersJPanelLayout.createSequentialGroup().addComponent(yearJLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(yearOperatorJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(filtersJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(productIdJTextField).addComponent(productDescriptionJTextField) .addGroup(filtersJPanelLayout.createSequentialGroup() .addComponent(yearJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(monthJLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(monthOperatorJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(monthJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(dayJLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(dayJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(dayOperatorJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap())); filtersJPanelLayout.setVerticalGroup(filtersJPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(filtersJPanelLayout.createSequentialGroup().addContainerGap().addGroup(filtersJPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(productIdLabel).addComponent(productIdJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(filtersJPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(productDescriptionJLabel) .addComponent(productDescriptionJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(filtersJPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(yearJLabel).addComponent(monthJLabel).addComponent(dayJLabel) .addComponent(yearJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(monthJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(dayJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(yearOperatorJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(monthOperatorJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(dayOperatorJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(29, Short.MAX_VALUE))); startMapReduceJButton.setText("Start"); startMapReduceJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { startMapReduceJButtonActionPerformed(evt); } }); javax.swing.GroupLayout startMapReduceJPanelLayout = new javax.swing.GroupLayout(startMapReduceJPanel); startMapReduceJPanel.setLayout(startMapReduceJPanelLayout); startMapReduceJPanelLayout.setHorizontalGroup( startMapReduceJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, startMapReduceJPanelLayout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(startMapReduceJButton))); startMapReduceJPanelLayout.setVerticalGroup( startMapReduceJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, startMapReduceJPanelLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(startMapReduceJButton).addContainerGap())); mapReduceResultsJPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Results")); mapReduceResultsJTable.setModel(mapReduceResultsTableDataModel); mapReduceResultsJScrollPane.setViewportView(mapReduceResultsJTable); javax.swing.GroupLayout mapReduceResultsJPanelLayout = new javax.swing.GroupLayout(mapReduceResultsJPanel); mapReduceResultsJPanel.setLayout(mapReduceResultsJPanelLayout); mapReduceResultsJPanelLayout.setHorizontalGroup( mapReduceResultsJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(mapReduceResultsJPanelLayout .createSequentialGroup().addContainerGap().addComponent(mapReduceResultsJScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE) .addContainerGap())); mapReduceResultsJPanelLayout.setVerticalGroup( mapReduceResultsJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(mapReduceResultsJPanelLayout.createSequentialGroup().addContainerGap() .addComponent(mapReduceResultsJScrollPane).addContainerGap())); javax.swing.GroupLayout mapReduceJPanelLayout = new javax.swing.GroupLayout(mapReduceJPanel); mapReduceJPanel.setLayout(mapReduceJPanelLayout); mapReduceJPanelLayout.setHorizontalGroup( mapReduceJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(mapReduceJPanelLayout.createSequentialGroup().addContainerGap() .addGroup(mapReduceJPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(filtersJPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(startMapReduceJPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(mapReduceJPanelLayout.createSequentialGroup() .addComponent(aggregationLevelJLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(aggregationLevelJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE)) .addComponent(mapReduceResultsJPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap())); mapReduceJPanelLayout.setVerticalGroup(mapReduceJPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(mapReduceJPanelLayout.createSequentialGroup().addContainerGap() .addGroup(mapReduceJPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(aggregationLevelJLabel) .addComponent(aggregationLevelJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(filtersJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(startMapReduceJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(mapReduceResultsJPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())); jTabbedPane.addTab("Map Reduce", mapReduceJPanel); configurationJTable.setModel(configurationTableDataModel); configurationJScrollPane.setViewportView(configurationJTable); saveConfigurationJButton.setText("Save"); saveConfigurationJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { saveConfigurationJButtonActionPerformed(evt); } }); javax.swing.GroupLayout configurationJPanelLayout = new javax.swing.GroupLayout(configurationJPanel); configurationJPanel.setLayout(configurationJPanelLayout); configurationJPanelLayout.setHorizontalGroup(configurationJPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(configurationJPanelLayout.createSequentialGroup().addContainerGap() .addGroup(configurationJPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(configurationJScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 533, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, configurationJPanelLayout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent(saveConfigurationJButton))) .addContainerGap())); configurationJPanelLayout.setVerticalGroup( configurationJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(configurationJPanelLayout.createSequentialGroup().addContainerGap() .addComponent(configurationJScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 687, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(saveConfigurationJButton).addContainerGap())); jTabbedPane.addTab("Configuration", configurationJPanel); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( layout.createSequentialGroup().addContainerGap().addComponent(jTabbedPane).addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( layout.createSequentialGroup().addContainerGap().addComponent(jTabbedPane).addContainerGap())); pack(); }// </editor-fold>//GEN-END:initComponents private void startMapReduceJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startMapReduceJButtonActionPerformed SwingWorker<Void, Void> swingWorker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { disableGUI(); String id = StringUtils.trimToNull(productIdJTextField.getText()); String description = StringUtils.trimToNull(productDescriptionJTextField.getText()); Integer year = getIntegerValue(yearJTextField); IntegerFilterOperator yearOperator = getIntegerFilterOperator(yearOperatorJComboBox); Integer month = getIntegerValue(monthJTextField); IntegerFilterOperator monthOperator = getIntegerFilterOperator(monthOperatorJComboBox); Integer day = getIntegerValue(dayJTextField); IntegerFilterOperator dayOperator = getIntegerFilterOperator(dayOperatorJComboBox); SaleFactFilter saleFactFilter = new SaleFactFilter(id, description, year, yearOperator, month, monthOperator, day, dayOperator); JobRunner.getInstance().runJob(getAggregationLevel(), saleFactFilter); List<SaleFact> saleFacts = ReaderClient.getInstance().getSaleFacts(); String[][] mapReduceResults = new String[saleFacts.size()][MAP_REDUCE_RESULTS_COLUMNS_NAMES.length]; for (int i = 0; i < saleFacts.size(); i++) { SaleFact saleFact = saleFacts.get(i); mapReduceResults[i][0] = saleFact.getTimeDimension().getYear() != null ? String.valueOf(saleFact.getTimeDimension().getYear()) : ""; mapReduceResults[i][1] = saleFact.getTimeDimension().getMonth() != null ? String.valueOf(saleFact.getTimeDimension().getMonth()) : ""; mapReduceResults[i][2] = saleFact.getTimeDimension().getDay() != null ? String.valueOf(saleFact.getTimeDimension().getDay()) : ""; mapReduceResults[i][3] = String.valueOf(saleFact.getProductQuantity()); mapReduceResults[i][4] = currencyFormatter.format(saleFact.getPrice()); mapReduceResults[i][5] = saleFact.getProductDimension().getId(); mapReduceResults[i][6] = saleFact.getProductDimension().getDescription(); } mapReduceResultsTableDataModel.setDataVector(mapReduceResults, MAP_REDUCE_RESULTS_COLUMNS_NAMES); enableGUI(); return null; } }; swingWorker.execute(); }//GEN-LAST:event_startMapReduceJButtonActionPerformed private void startEtlJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startEtlJButtonActionPerformed SwingWorker<Void, Void> swingWorker = new co.edu.unal.pos.hadoop.SwingWorker(this); swingWorker.execute(); }//GEN-LAST:event_startEtlJButtonActionPerformed private void saveConfigurationJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configurationJButtonActionPerformed SwingWorker<Void, Void> swingWorker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { disableGUI(); properties.clear(); for (int i = 0; i < configurationTableDataModel.getRowCount(); i++) { properties.put(configurationTableDataModel.getValueAt(i, 0).toString(), configurationTableDataModel.getValueAt(i, 1).toString()); } PropertiesProvider.getInstance().saveProperties(properties); enableGUI(); return null; } }; swingWorker.execute(); }//GEN-LAST:event_configurationJButtonActionPerformed public void setConfigurationTableDataModel(String[][] configurationTableDataModel) { this.configurationTableDataModel.setDataVector(configurationTableDataModel, CONFIGURATION_COLUMN_NAMES); } public void updatePropertiesTableDataModel() { SwingWorker<Void, Void> swingWorker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { disableGUI(); etlJProgressBar.setStringPainted(true); etlJProgressBar.setIndeterminate(true); etlJProgressBar.setString("Loading application..."); Map<String, String> properties = PropertiesProvider.getInstance().getProperties(); String[][] propertiesTableDataModel = new String[properties.size()][2]; int i = 0; for (Map.Entry<String, String> property : properties.entrySet()) { propertiesTableDataModel[i][0] = property.getKey(); propertiesTableDataModel[i][1] = property.getValue(); i++; } setConfigurationTableDataModel(propertiesTableDataModel); etlJProgressBar.setString(""); etlJProgressBar.setIndeterminate(false); enableGUI(); return null; } }; swingWorker.execute(); } public void enableGUI() { this.jTabbedPane.setEnabled(true); this.startEtlJButton.setEnabled(true); this.saveConfigurationJButton.setEnabled(true); this.configurationJTable.setEnabled(true); this.mapReduceResultsJPanel.setEnabled(true); this.aggregationLevelJComboBox.setEnabled(true); this.filtersJPanel.setEnabled(true); this.yearJTextField.setEnabled(true); this.monthJTextField.setEnabled(true); this.dayJTextField.setEnabled(true); this.yearOperatorJComboBox.setEnabled(true); this.monthOperatorJComboBox.setEnabled(true); this.dayOperatorJComboBox.setEnabled(true); this.mapReduceResultsJTable.setEnabled(true); this.productIdJTextField.setEnabled(true); this.productDescriptionJTextField.setEnabled(true); this.startMapReduceJButton.setEnabled(true); } public void disableGUI() { this.jTabbedPane.setEnabled(false); this.startEtlJButton.setEnabled(false); this.saveConfigurationJButton.setEnabled(false); this.configurationJTable.setEnabled(false); this.mapReduceResultsJPanel.setEnabled(false); this.aggregationLevelJComboBox.setEnabled(false); this.filtersJPanel.setEnabled(false); this.yearJTextField.setEnabled(false); this.monthJTextField.setEnabled(false); this.dayJTextField.setEnabled(false); this.yearOperatorJComboBox.setEnabled(false); this.monthOperatorJComboBox.setEnabled(false); this.dayOperatorJComboBox.setEnabled(false); this.mapReduceResultsJTable.setEnabled(false); this.productIdJTextField.setEnabled(false); this.startMapReduceJButton.setEnabled(false); this.productDescriptionJTextField.setEnabled(false); } public AggregationLevel getAggregationLevel() { String aggregationLevel = aggregationLevelJComboBox.getSelectedItem().toString(); return AggregationLevel.valueOf(aggregationLevel.toUpperCase()); } public javax.swing.JProgressBar getEtlJProgressBar() { return etlJProgressBar; } private Integer getIntegerValue(JTextField jTextField) { String stringValue = StringUtils.trimToNull(jTextField.getText()); Integer integerValue = null; if (stringValue != null) { integerValue = Integer.valueOf(stringValue); } return integerValue; } private IntegerFilterOperator getIntegerFilterOperator(JComboBox jComboBox) { String selectedOperator = (String) jComboBox.getSelectedItem(); return IntegerFilterOperator.getFromString(selectedOperator); } /** * @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(PosHadoopJFrameSwap.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(PosHadoopJFrameSwap.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(PosHadoopJFrameSwap.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(PosHadoopJFrameSwap.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new PosHadoopJFrameSwap().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox aggregationLevelJComboBox; private javax.swing.JLabel aggregationLevelJLabel; private javax.swing.JButton saveConfigurationJButton; private javax.swing.JPanel configurationJPanel; private javax.swing.JScrollPane configurationJScrollPane; private javax.swing.JTable configurationJTable; private javax.swing.JLabel dayJLabel; private javax.swing.JTextField dayJTextField; private javax.swing.JComboBox dayOperatorJComboBox; private javax.swing.JPanel etlJPanel; private javax.swing.JProgressBar etlJProgressBar; private javax.swing.JPanel filtersJPanel; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTabbedPane jTabbedPane; private javax.swing.JTable jTable1; private javax.swing.JPanel mapReduceJPanel; private javax.swing.JPanel mapReduceResultsJPanel; private javax.swing.JScrollPane mapReduceResultsJScrollPane; private javax.swing.JTable mapReduceResultsJTable; private javax.swing.JLabel monthJLabel; private javax.swing.JTextField monthJTextField; private javax.swing.JComboBox monthOperatorJComboBox; private javax.swing.JLabel productDescriptionJLabel; private javax.swing.JTextField productDescriptionJTextField; private javax.swing.JTextField productIdJTextField; private javax.swing.JLabel productIdLabel; private javax.swing.JButton startEtlJButton; private javax.swing.JPanel startEtlJPanel; private javax.swing.JButton startMapReduceJButton; private javax.swing.JPanel startMapReduceJPanel; private javax.swing.JLabel yearJLabel; private javax.swing.JTextField yearJTextField; private javax.swing.JComboBox yearOperatorJComboBox; // End of variables declaration//GEN-END:variables }