Advertisement
Guest User

NewConsultation

a guest
Oct 23rd, 2014
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.78 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package startpage;
  7.  
  8. import ejb.ConsultationListRemote;
  9. import entities.Consultation;
  10. import java.awt.BorderLayout;
  11. import java.text.DateFormat;
  12. import java.text.SimpleDateFormat;
  13. import java.util.Date;
  14. import java.util.List;
  15. import java.util.logging.Level;
  16. import java.util.logging.Logger;
  17. import javax.naming.Context;
  18. import javax.naming.InitialContext;
  19. import javax.naming.NamingException;
  20. import javax.swing.DefaultListModel;
  21.  
  22. /**
  23.  *
  24.  * @author Edvin
  25.  */
  26. public class NewConsultation extends javax.swing.JPanel {
  27. List<Consultation> consultationList = lookupConsultationListRemote().getConsultationByAccepted(false);
  28. Consultation consultation;
  29. DefaultListModel listModel = new DefaultListModel();
  30.     /**
  31.      * Creates new form NewConsultation
  32.      */
  33.     public NewConsultation() {
  34.         initComponents();
  35.        
  36.        
  37.             for(Consultation con : consultationList) {
  38.                 System.out.println(con.getDescription());
  39.                 DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  40.                 Date d =con.getDate();
  41.                 String datestring = dateFormat.format(d);
  42.                
  43.                
  44.                 listModel.addElement(datestring + ", " + con.getCustomerID().getName() + ", " + con.getTimeInterval() + "/n");
  45.                    
  46.                
  47.             }
  48.             selectConsultationList.setModel(listModel);
  49.            
  50.         //int i = 0;
  51.         //NewConsuationPanel [] ncp = new NewConsuationPanel [100];
  52.        
  53.         /*for(Consultation keso : kes) {
  54.            
  55.             ncp[i]=new NewConsuationPanel();
  56.             ncp[i].setText(keso.getDescription());
  57.             ncp[i].setConsultation(keso);
  58.             //setLayout(new BorderLayout());
  59.             add(ncp[i]);
  60.            
  61.             //ncp[i].setVisible(true);
  62.             i++;
  63.             System.out.println(i);
  64.         }
  65.        
  66.         //this.updateUI();*/
  67.        
  68.     }
  69.    
  70.  
  71.     /**
  72.      * This method is called from within the constructor to initialize the form.
  73.      * WARNING: Do NOT modify this code. The content of this method is always
  74.      * regenerated by the Form Editor.
  75.      */
  76.     @SuppressWarnings("unchecked")
  77.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  78.     private void initComponents() {
  79.  
  80.         goBackButton = new javax.swing.JButton();
  81.         jScrollPane1 = new javax.swing.JScrollPane();
  82.         selectConsultationList = new javax.swing.JList();
  83.         jScrollPane2 = new javax.swing.JScrollPane();
  84.         descripionArea = new javax.swing.JTextArea();
  85.         acceptButton = new javax.swing.JButton();
  86.         dontAcceptButton = new javax.swing.JButton();
  87.  
  88.         setAutoscrolls(true);
  89.         addMouseListener(new java.awt.event.MouseAdapter() {
  90.             public void mouseEntered(java.awt.event.MouseEvent evt) {
  91.                 formMouseEntered(evt);
  92.             }
  93.         });
  94.  
  95.         goBackButton.setText("Tillbaka");
  96.         goBackButton.addActionListener(new java.awt.event.ActionListener() {
  97.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  98.                 goBackButtonActionPerformed(evt);
  99.             }
  100.         });
  101.  
  102.         selectConsultationList.setModel(new javax.swing.AbstractListModel() {
  103.             String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
  104.             public int getSize() { return strings.length; }
  105.             public Object getElementAt(int i) { return strings[i]; }
  106.         });
  107.         selectConsultationList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
  108.             public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
  109.                 selectConsultationListValueChanged(evt);
  110.             }
  111.         });
  112.         jScrollPane1.setViewportView(selectConsultationList);
  113.  
  114.         descripionArea.setColumns(20);
  115.         descripionArea.setRows(5);
  116.         jScrollPane2.setViewportView(descripionArea);
  117.  
  118.         acceptButton.setText("Acceptera");
  119.         acceptButton.addActionListener(new java.awt.event.ActionListener() {
  120.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  121.                 acceptButtonActionPerformed(evt);
  122.             }
  123.         });
  124.  
  125.         dontAcceptButton.setText("Acceptera inte");
  126.         dontAcceptButton.addActionListener(new java.awt.event.ActionListener() {
  127.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  128.                 dontAcceptButtonActionPerformed(evt);
  129.             }
  130.         });
  131.  
  132.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
  133.         this.setLayout(layout);
  134.         layout.setHorizontalGroup(
  135.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  136.             .addGroup(layout.createSequentialGroup()
  137.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  138.                     .addComponent(goBackButton)
  139.                     .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE))
  140.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  141.                 .addComponent(acceptButton, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
  142.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  143.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  144.                     .addComponent(dontAcceptButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  145.                     .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
  146.         );
  147.         layout.setVerticalGroup(
  148.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  149.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  150.                 .addGap(41, 41, 41)
  151.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  152.                     .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE)
  153.                     .addComponent(jScrollPane2))
  154.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  155.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  156.                     .addComponent(goBackButton)
  157.                     .addComponent(acceptButton)
  158.                     .addComponent(dontAcceptButton))
  159.                 .addContainerGap(56, Short.MAX_VALUE))
  160.         );
  161.     }// </editor-fold>                        
  162.  
  163.     private void goBackButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
  164.         Schedule schema = new Schedule();
  165.        
  166.         removeAll();
  167.         setLayout(new BorderLayout());
  168.         add(schema, BorderLayout.CENTER);
  169.        
  170.         validate();
  171.         repaint();// TODO add your handling code here:
  172.     }                                            
  173.  
  174.     private void formMouseEntered(java.awt.event.MouseEvent evt) {                                  
  175.         // TODO add your handling code here:
  176.     }                                
  177.  
  178.     private void acceptButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
  179.         int i=selectConsultationList.getSelectedIndex();
  180.         if(i>=0){
  181.             System.out.println(i);
  182.             consultation=consultationList.get(i);
  183.             listModel.remove(i);
  184.             selectConsultationList.setModel(listModel);
  185.        
  186.             consultation.setAccepted(true);
  187.             lookupConsultationListRemote().updateConsultation(consultation);
  188.             consultationList = lookupConsultationListRemote().getConsultationByAccepted(false);
  189.         }// TODO add your handling code here:
  190.     }                                            
  191.  
  192.     private void dontAcceptButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                
  193.         int i=selectConsultationList.getSelectedIndex();
  194.         if(i>=0){
  195.             consultation=consultationList.get(i);
  196.             listModel.remove(i);
  197.             selectConsultationList.setModel(listModel);
  198.             lookupConsultationListRemote().removeConsultation(consultation);
  199.             consultationList = lookupConsultationListRemote().getConsultationByAccepted(false);
  200.            
  201.         }// TODO add your handling code here:
  202.     }                                                
  203.  
  204.     private void selectConsultationListValueChanged(javax.swing.event.ListSelectionEvent evt) {                                                    
  205.         System.out.println(selectConsultationList.getAnchorSelectionIndex());
  206.         System.out.println(consultationList.get(selectConsultationList.getAnchorSelectionIndex()).getDescription());
  207.         String name = consultationList.get(selectConsultationList.getAnchorSelectionIndex()).getCustomerID().getName();
  208.         String lastname = consultationList.get(selectConsultationList.getAnchorSelectionIndex()).getCustomerID().getLastName();
  209.         String description = consultationList.get(selectConsultationList.getAnchorSelectionIndex()).getDescription();
  210.         String phone = consultationList.get(selectConsultationList.getAnchorSelectionIndex()).getCustomerID().getPhoneNumber();
  211.         String email = consultationList.get(selectConsultationList.getAnchorSelectionIndex()).getCustomerID().getEmail();
  212.         descripionArea.setText(name + " " + lastname + "\n" + phone + "\n" + email + "\n" + "\n" + description);
  213.     }                                                  
  214.  
  215.  
  216.     // Variables declaration - do not modify                    
  217.     private javax.swing.JButton acceptButton;
  218.     private javax.swing.JTextArea descripionArea;
  219.     private javax.swing.JButton dontAcceptButton;
  220.     private javax.swing.JButton goBackButton;
  221.     private javax.swing.JScrollPane jScrollPane1;
  222.     private javax.swing.JScrollPane jScrollPane2;
  223.     private javax.swing.JList selectConsultationList;
  224.     // End of variables declaration                  
  225.  
  226.     private ConsultationListRemote lookupConsultationListRemote() {
  227.         try {
  228.             Context c = new InitialContext();
  229.             return (ConsultationListRemote) c.lookup("java:comp/env/ConsultationList");
  230.         } catch (NamingException ne) {
  231.             Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
  232.             throw new RuntimeException(ne);
  233.         }
  234.     }
  235.  
  236.    
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement