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 UserInterface.AuthorityWorkArea; import Business.Authority.Authority; import Business.Drug.Drug; import Business.Ecosystem; import Business.UserAccount.UserAccount; import Business.WorkRequest.DrugApprovalRequest; import Business.WorkRequest.WorkRequest; import java.awt.CardLayout; import java.awt.Color; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.table.DefaultTableModel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; /** * * @author kshitij */ public class DrugAnalysisJPanel extends javax.swing.JPanel { private JPanel upc; private Ecosystem ecosystem; private Authority authority; private UserAccount ua; /** * Creates new form AuthorityWorkAreaJPanel */ public DrugAnalysisJPanel(JPanel upc, Ecosystem ecosystem, Authority authority, UserAccount ua) { initComponents(); this.upc = upc; this.ecosystem = ecosystem; this.authority = authority; this.ua = ua; populateMedicineApprovalTable(); } private void populateMedicineApprovalTable() { DefaultTableModel model = (DefaultTableModel) medicineAreajTable.getModel(); model.setRowCount(0); Authority authority = ecosystem.getAuthority(); for (WorkRequest wr : authority.getWorkQueue().getWorkRequestList()) { DrugApprovalRequest dar = (DrugApprovalRequest) wr; if (dar instanceof WorkRequest) { for (Drug drug : dar.getDrugDirectory().getDrugList()) { Object[] row = new Object[10]; row[0] = dar.getReqId(); row[1] = drug.getDrugName(); row[2] = drug; row[3] = drug.getDisease().getDiseaseName(); row[4] = dar.getSender() == null ? ("N/A") : dar.getSender().getPerson().getName(); row[5] = dar.getReceiver() == null ? ("N/A") : dar.getReceiver().getPerson().getName(); row[6] = dar; row[7] = dar.getMessage() == null ? ("Evaluation Required") : wr.getMessage(); row[8] = dar.getCompanyName(); row[9] = dar.getCompanyId(); model.addRow(row); } } } } /** * 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() { jLabel1 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); medicineAreajTable = new javax.swing.JTable(); assignMyselfjButton = new javax.swing.JButton(); backjButton = new javax.swing.JButton(); refreshjButton = new javax.swing.JButton(); approvejButton = new javax.swing.JButton(); dissaprovejButton = new javax.swing.JButton(); viewRequestjButton = new javax.swing.JButton(); companiesPerfjButton = new javax.swing.JButton(); setBackground(new java.awt.Color(115, 166, 200)); setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); jLabel1.setFont(new java.awt.Font("Tahoma", 2, 30)); // NOI18N jLabel1.setText("MEDICINE REVIEW"); medicineAreajTable.setFont(new java.awt.Font("Tahoma", 2, 27)); // NOI18N medicineAreajTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { }, new String[] { "Request Id", "Medicine Name", "Medicine Code", "Disease Cure", "Sender", "Receiver", "Status", "Approval Status", "Organization Name", "Organization Id" }) { boolean[] canEdit = new boolean[] { false, false, false, false, false, false, false, false, false, false }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); medicineAreajTable.setRowHeight(26); jScrollPane1.setViewportView(medicineAreajTable); if (medicineAreajTable.getColumnModel().getColumnCount() > 0) { medicineAreajTable.getColumnModel().getColumn(9).setResizable(false); } assignMyselfjButton.setFont(new java.awt.Font("Tahoma", 2, 27)); // NOI18N assignMyselfjButton.setText("Assign Myself"); assignMyselfjButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { assignMyselfjButtonActionPerformed(evt); } }); backjButton.setFont(new java.awt.Font("Tahoma", 2, 27)); // NOI18N backjButton.setText("<<Back"); backjButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { backjButtonActionPerformed(evt); } }); refreshjButton.setFont(new java.awt.Font("Tahoma", 2, 27)); // NOI18N refreshjButton.setText("Refresh"); refreshjButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { refreshjButtonActionPerformed(evt); } }); approvejButton.setFont(new java.awt.Font("Tahoma", 2, 27)); // NOI18N approvejButton.setText("Approve"); approvejButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { approvejButtonActionPerformed(evt); } }); dissaprovejButton.setFont(new java.awt.Font("Tahoma", 2, 27)); // NOI18N dissaprovejButton.setText("Disapprove"); dissaprovejButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { dissaprovejButtonActionPerformed(evt); } }); viewRequestjButton.setFont(new java.awt.Font("Tahoma", 2, 27)); // NOI18N viewRequestjButton.setText("View Request"); viewRequestjButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { viewRequestjButtonActionPerformed(evt); } }); companiesPerfjButton.setFont(new java.awt.Font("Tahoma", 2, 27)); // NOI18N companiesPerfjButton.setText("Pharmacetical Drug Approval Chart"); companiesPerfjButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { companiesPerfjButtonActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1) .addGroup(layout.createSequentialGroup().addGap(792, 792, 792) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGap(0, 54, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(companiesPerfjButton) .addGroup(layout.createSequentialGroup().addComponent(backjButton) .addGap(105, 105, 105).addComponent(assignMyselfjButton) .addGap(107, 107, 107).addComponent(approvejButton) .addGap(107, 107, 107).addComponent(dissaprovejButton) .addGap(93, 93, 93).addComponent(refreshjButton).addGap(78, 78, 78) .addComponent(viewRequestjButton))) .addGap(242, 242, 242))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(10, 10, 10).addComponent(jLabel1).addGap(40, 40, 40) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 304, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(refreshjButton).addComponent(approvejButton) .addComponent(dissaprovejButton).addComponent(viewRequestjButton) .addComponent(assignMyselfjButton).addComponent(backjButton)) .addGap(162, 162, 162).addComponent(companiesPerfjButton) .addContainerGap(480, Short.MAX_VALUE))); }// </editor-fold>//GEN-END:initComponents private void assignMyselfjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_assignMyselfjButtonActionPerformed int selectedRow = medicineAreajTable.getSelectedRow(); if (selectedRow < 0) { JOptionPane.showMessageDialog(null, "Select a row to assign to you"); return; } DrugApprovalRequest dar = (DrugApprovalRequest) medicineAreajTable.getValueAt(selectedRow, 6); if (dar.getMessage().equals("Drug Approved") || dar.getMessage().equals("Drug Disapproved")) { JOptionPane.showMessageDialog(null, "Drug status has already been set"); return; } dar.setReceiver(ua); dar.setStatus("In-Progress"); populateMedicineApprovalTable(); }//GEN-LAST:event_assignMyselfjButtonActionPerformed private void backjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backjButtonActionPerformed upc.remove(this); CardLayout layout = (CardLayout) upc.getLayout(); layout.previous(upc); }//GEN-LAST:event_backjButtonActionPerformed private void refreshjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshjButtonActionPerformed populateMedicineApprovalTable(); }//GEN-LAST:event_refreshjButtonActionPerformed private void approvejButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_approvejButtonActionPerformed DrugApprovalRequest dar; int selectedRow = medicineAreajTable.getSelectedRow(); if (selectedRow < 0) { JOptionPane.showMessageDialog(null, "Please select a row first"); return; } dar = (DrugApprovalRequest) medicineAreajTable.getValueAt(selectedRow, 6); if (dar.getReceiver() == (null)) { JOptionPane.showMessageDialog(null, "Please assign the request to you first"); return; } if (dar.getReceiver().getPerson().getName() != (ua.getPerson().getName())) { JOptionPane.showMessageDialog(null, "Please Approve the request only assigned to you."); return; } if (dar.getMessage().equals("Drug Approved") || (dar.getMessage().equals("Dissaproved"))) { JOptionPane.showMessageDialog(null, "Drug status has already been set. Please do not attempt to change it"); return; } dar.setStatus("Completed"); dar.setMessage("Drug Approved"); populateMedicineApprovalTable(); }//GEN-LAST:event_approvejButtonActionPerformed private void dissaprovejButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dissaprovejButtonActionPerformed DrugApprovalRequest dar; int selectedRow = medicineAreajTable.getSelectedRow(); if (selectedRow < 0) { JOptionPane.showMessageDialog(null, "Please select a row first"); return; } dar = (DrugApprovalRequest) medicineAreajTable.getValueAt(selectedRow, 6); if (dar.getReceiver() == (null)) { JOptionPane.showMessageDialog(null, "Please assign the request to you first"); return; } if (dar.getReceiver().getPerson().getName() != (ua.getPerson().getName())) { JOptionPane.showMessageDialog(null, "Please Disapprove the request only assigned to you"); return; } if (dar.getMessage().equals("Drug Approved") || (dar.getMessage().equals("Dissaproved"))) { JOptionPane.showMessageDialog(null, "Drug status has already been set. Please do not attempt to change it"); return; } dar.setStatus("Completed"); dar.setMessage("Drug Disapproved"); populateMedicineApprovalTable(); }//GEN-LAST:event_dissaprovejButtonActionPerformed private void viewRequestjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewRequestjButtonActionPerformed int selectedRow = medicineAreajTable.getSelectedRow(); if (selectedRow < 0) { JOptionPane.showMessageDialog(null, "Please select a row to view the request"); return; } DrugApprovalRequest dar = (DrugApprovalRequest) medicineAreajTable.getValueAt(selectedRow, 6); Drug drug = (Drug) medicineAreajTable.getValueAt(selectedRow, 2); ViewRequestJPanel panel = new ViewRequestJPanel(upc, dar, drug); upc.add("View Req", panel); CardLayout layout = (CardLayout) upc.getLayout(); layout.next(upc); }//GEN-LAST:event_viewRequestjButtonActionPerformed private void companiesPerfjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_companiesPerfjButtonActionPerformed HashMap<Integer, Integer> hashMap = new HashMap<Integer, Integer>(); int cmpId = 0; int counter = 0; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Authority authority = ecosystem.getAuthority(); for (WorkRequest wr : authority.getWorkQueue().getWorkRequestList()) { DrugApprovalRequest dar = (DrugApprovalRequest) wr; if (dar instanceof WorkRequest) { if (dar.getMessage().equals("Drug Approved")) // { if (!hashMap.containsKey(dar.getCompanyId())) { counter = 0; counter = counter + 1; } else if (hashMap.containsKey(dar.getCompanyId())) { counter = hashMap.get(dar.getCompanyId()) + 1; } hashMap.put(dar.getCompanyId(), counter); } } } Set set = hashMap.entrySet(); Iterator i = set.iterator(); // Display elements Map.Entry me = null; int compID = 0; int counterID = 0; while (i.hasNext()) { me = (Map.Entry) i.next(); compID = (int) me.getKey(); counterID = (int) me.getValue(); DrugApprovalRequest dar1; for (WorkRequest wr : authority.getWorkQueue().getWorkRequestList()) { if (wr instanceof DrugApprovalRequest) { dar1 = (DrugApprovalRequest) wr; if (dar1.getCompanyId() == compID) { String name = dar1.getCompanyName(); dataset.setValue(counterID, "Total Drugs Approved", name); } } } } JFreeChart chart = ChartFactory.createBarChart("Pharmaceutical Performance", "Company Name", "Total Drugs Approved", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.black); ChartFrame frame = new ChartFrame("Product Performance for Companies", chart); frame.setVisible(true); frame.setSize(850, 900); }//GEN-LAST:event_companiesPerfjButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton approvejButton; private javax.swing.JButton assignMyselfjButton; private javax.swing.JButton backjButton; private javax.swing.JButton companiesPerfjButton; private javax.swing.JButton dissaprovejButton; private javax.swing.JLabel jLabel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable medicineAreajTable; private javax.swing.JButton refreshjButton; private javax.swing.JButton viewRequestjButton; // End of variables declaration//GEN-END:variables }