/** * * Appfrica Labs Uganda Ltd Copyrigth @since 2009 * @version 2 * * Ticketfrm.java * * This allow the operator to view the ticket information and edit some fields like the status, * the answer and the ticketnotes. * * Created on Oct 22, 2009, 1:48:46 PM */ package questionbox; import qbox.model.*; import java.util.*; import javax.swing.JOptionPane; /** * * @author ivank */ public class Ticketfrm extends javax.swing.JFrame { /** * The ticket object that interacts with the form fields. * */ private Ticket ticket; /** Creates new form Ticketfrm * It also setup alot of variable needed at the start. */ public Ticketfrm(Ticket _ticket) { ticket = _ticket; initComponents(); intializeCategory(); intializeStatus(); setResizable(false); this.setLocationRelativeTo(null); lblTicketid.setText("Ticket ID"); lblStarttime.setText("Start Date"); lblEndtime.setText("Closed Date"); lblOperator.setText("Operator"); lblCaller.setText("Caller"); lblAnswer.setText("Answer"); lblQuery.setText("Query"); lblCategory.setText("Category"); tbTicketnotes.setName("Ticket Notes"); btnSave.setText("Save"); btnCancel.setText("Cancel"); btnSearchAgain.setText("Search Again"); LoadTicket(); } /** 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() { lblTicketid = new javax.swing.JLabel(); lblOperator = new javax.swing.JLabel(); lblStarttime = new javax.swing.JLabel(); lblCaller = new javax.swing.JLabel(); lblStarttimeValue = new javax.swing.JLabel(); lblEndtime = new javax.swing.JLabel(); lblEndtimeValue = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); txtQuery = new javax.swing.JTextArea(); lblQuery = new javax.swing.JLabel(); lblAnswer = new javax.swing.JLabel(); jScrollPane2 = new javax.swing.JScrollPane(); txtAnswer = new javax.swing.JTextArea(); jScrollPane3 = new javax.swing.JScrollPane(); tbTicketnotes = new javax.swing.JTable(); cmbCategory = new javax.swing.JComboBox(); lblCategory = new javax.swing.JLabel(); lblStatus = new javax.swing.JLabel(); cmbStatus = new javax.swing.JComboBox(); btnCancel = new javax.swing.JButton(); btnSave = new javax.swing.JButton(); btnAddticketnote = new javax.swing.JButton(); lblTicketid_Value = new javax.swing.JLabel(); lblOperator_Value = new javax.swing.JLabel(); lblCallerValue = new javax.swing.JLabel(); btnSearchAgain = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setName("Form"); // NOI18N addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { formWindowClosing(evt); } }); org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(questionbox.QuestionBoxApp.class).getContext().getResourceMap(Ticketfrm.class); lblTicketid.setText(resourceMap.getString("lblTicketid.text")); // NOI18N lblTicketid.setName("lblTicketid"); // NOI18N lblOperator.setText(resourceMap.getString("lblOperator.text")); // NOI18N lblOperator.setName("lblOperator"); // NOI18N lblStarttime.setText(resourceMap.getString("lblStarttime.text")); // NOI18N lblStarttime.setName("lblStarttime"); // NOI18N lblCaller.setText(resourceMap.getString("lblCaller.text")); // NOI18N lblCaller.setName("lblCaller"); // NOI18N lblStarttimeValue.setFont(resourceMap.getFont("lblTicketid_Value.font")); // NOI18N lblStarttimeValue.setText(resourceMap.getString("lblStarttimeValue.text")); // NOI18N lblStarttimeValue.setName("lblStarttimeValue"); // NOI18N lblEndtime.setText(resourceMap.getString("lblEndtime.text")); // NOI18N lblEndtime.setName("lblEndtime"); // NOI18N lblEndtimeValue.setFont(resourceMap.getFont("lblTicketid_Value.font")); // NOI18N lblEndtimeValue.setText(resourceMap.getString("lblEndtimeValue.text")); // NOI18N lblEndtimeValue.setName("lblEndtimeValue"); // NOI18N jScrollPane1.setName("jScrollPane1"); // NOI18N txtQuery.setColumns(20); txtQuery.setRows(5); txtQuery.setEnabled(false); txtQuery.setName("txtQuery"); // NOI18N jScrollPane1.setViewportView(txtQuery); lblQuery.setText(resourceMap.getString("lblQuery.text")); // NOI18N lblQuery.setName("lblQuery"); // NOI18N lblAnswer.setText(resourceMap.getString("lblAnswer.text")); // NOI18N lblAnswer.setName("lblAnswer"); // NOI18N jScrollPane2.setName("jScrollPane2"); // NOI18N txtAnswer.setColumns(20); txtAnswer.setRows(5); txtAnswer.setName("txtAnswer"); // NOI18N jScrollPane2.setViewportView(txtAnswer); jScrollPane3.setName("jScrollPane3"); // NOI18N tbTicketnotes.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { }, new String [] { "NoteID", "Details", "Date Added" } )); tbTicketnotes.setName("tbTicketnotes"); // NOI18N jScrollPane3.setViewportView(tbTicketnotes); cmbCategory.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); cmbCategory.setName("cmbCategory"); // NOI18N lblCategory.setText(resourceMap.getString("lblCategory.text")); // NOI18N lblCategory.setName("lblCategory"); // NOI18N lblStatus.setText(resourceMap.getString("lblStatus.text")); // NOI18N lblStatus.setName("lblStatus"); // NOI18N cmbStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); cmbStatus.setName("cmbStatus"); // NOI18N btnCancel.setText(resourceMap.getString("btnCancel.text")); // NOI18N btnCancel.setName("btnCancel"); // NOI18N btnCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCancelActionPerformed(evt); } }); btnSave.setText(resourceMap.getString("btnSave.text")); // NOI18N btnSave.setName("btnSave"); // NOI18N btnSave.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSaveActionPerformed(evt); } }); btnAddticketnote.setText(resourceMap.getString("btnAddticketnote.text")); // NOI18N btnAddticketnote.setName("btnAddticketnote"); // NOI18N btnAddticketnote.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAddticketnoteActionPerformed(evt); } }); lblTicketid_Value.setFont(resourceMap.getFont("lblTicketid_Value.font")); // NOI18N lblTicketid_Value.setText(resourceMap.getString("lblTicketid_Value.text")); // NOI18N lblTicketid_Value.setName("lblTicketid_Value"); // NOI18N lblOperator_Value.setFont(resourceMap.getFont("lblTicketid_Value.font")); // NOI18N lblOperator_Value.setText(resourceMap.getString("lblOperator_Value.text")); // NOI18N lblOperator_Value.setName("lblOperator_Value"); // NOI18N lblCallerValue.setFont(resourceMap.getFont("lblTicketid_Value.font")); // NOI18N lblCallerValue.setText(resourceMap.getString("lblCallerValue.text")); // NOI18N lblCallerValue.setName("lblCallerValue"); // NOI18N btnSearchAgain.setText(resourceMap.getString("btnSearchAgain.text")); // NOI18N btnSearchAgain.setName("btnSearchAgain"); // NOI18N btnSearchAgain.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSearchAgainActionPerformed(evt); } }); 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() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(lblTicketid, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE) .addComponent(lblOperator, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(lblOperator_Value, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(cmbCategory, 0, 149, Short.MAX_VALUE) .addComponent(lblTicketid_Value, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(lblCategory)) .addGap(93, 93, 93) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(lblStarttime) .addGap(18, 18, 18) .addComponent(lblStarttimeValue) .addGap(71, 71, 71) .addComponent(lblEndtime) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(lblEndtimeValue)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(lblCaller, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(lblCallerValue) .addGap(215, 215, 215))) .addGroup(layout.createSequentialGroup() .addComponent(lblStatus) .addGap(18, 18, 18) .addComponent(cmbStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(32, 32, 32)) .addGroup(layout.createSequentialGroup() .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 677, Short.MAX_VALUE) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 677, Short.MAX_VALUE) .addComponent(lblAnswer, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 677, Short.MAX_VALUE) .addComponent(lblQuery)))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 82, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnSearchAgain) .addGap(72, 72, 72) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(btnSave) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnCancel) .addGap(239, 239, 239)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(btnAddticketnote) .addGap(339, 339, 339))))) .addGap(112, 112, 112)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lblStarttimeValue) .addComponent(lblStarttime) .addComponent(lblEndtime) .addComponent(lblEndtimeValue)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lblTicketid) .addComponent(lblTicketid_Value, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lblOperator) .addComponent(lblCaller) .addComponent(lblOperator_Value, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblCallerValue)) .addGap(12, 12, 12) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lblCategory) .addComponent(cmbCategory, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblStatus) .addComponent(cmbStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(13, 13, 13) .addComponent(lblQuery) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(1, 1, 1) .addComponent(lblAnswer, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(31, 31, 31) .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnAddticketnote) .addGap(34, 34, 34) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnCancel) .addComponent(btnSave) .addComponent(btnSearchAgain)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// </editor-fold>//GEN-END:initComponents /** * Sets up the status dropdown list with status information. */ private void intializeStatus() { try{ cmbStatus.removeAllItems(); ArrayList<Status> stats = Status.getAllStatuss(); for(Status s : stats) { cmbStatus.addItem(s.getDescr()); } }catch(Exception e) { System.out.println(e.getMessage()); JOptionPane.showMessageDialog(this, "Loading Status Failed!\n","Error",JOptionPane.ERROR_MESSAGE); } } /** * sets up the category dropdown list with all the categories from the database. */ private void intializeCategory() { try { cmbCategory.removeAllItems(); ArrayList<Category> cats = Category.getAllCategorys(); for(Category c:cats) { cmbCategory.addItem(c.getTitle()); } } catch(Exception e) { System.out.println(e.getMessage()); JOptionPane.showMessageDialog(this, "Loading categories Failed!\n","Error",JOptionPane.ERROR_MESSAGE); } } /** * supposed to intialise the ticketnotes this the right information. * At a the moment of this release the ticket notes feature was not implemented. * @param ticketid */ private void addticketNotes(long ticketid) { Vector<Vector<String>> dataRows = new Vector<Vector<String>>(); Vector header = new Vector(); header.add("AnswerID"); header.add("Query"); header.add("Answer"); header.add("Score"); try{ ArrayList<TicketNote> tnotes = TicketNote.getTicketNotes(ticketid); for(TicketNote tn : tnotes) { Vector<String> cells = new Vector<String>(); cells.add(Long.toString(tn.getTicketNoteid())); cells.add(tn.getNote()); cells.add(tn.getDateUpdated().toString()); dataRows.add(cells); } tbTicketnotes.setModel(new javax.swing.table.DefaultTableModel( dataRows,header)); }catch(Exception e) { System.out.println(e.getMessage()); JOptionPane.showMessageDialog(this, "Loading ticket Notes Failed!\n","Error",JOptionPane.ERROR_MESSAGE); } } /** * This function loads all the ticket fields with the information from the ticket object passed * in the constructor. */ private void LoadTicket() { try{ if(ticket != null)//add new ticket. { Answer answer = Answer.getAnswer(ticket.getAnserid()); User operator = User.getUser(ticket.getOperatorid()); User Caller = User.getUser(ticket.getCallerid()); Query qry = Query.getQuery(ticket.getQueryid()); lblStarttimeValue.setText(ticket.getStartTime().toString()); lblEndtimeValue.setText(ticket.getEndTime().toString()); lblTicketid_Value.setText(Long.toString(ticket.getTicketid())); lblOperator_Value.setText(operator.getFname()+ " " + operator.getLname()); lblCallerValue.setText(Caller.getFname() + " " +Caller.getLname() ); cmbCategory.setSelectedItem(Category.getCategory(qry.getCategoryid()).getTitle()); cmbStatus.setSelectedItem(Status.getStatus(ticket.getStatusid()).getDescr()); txtQuery.setText(qry.getDetails()); txtAnswer.setText(answer.getDetails()); addticketNotes(ticket.getTicketid()); } }catch(Exception e) { System.out.println(e.getMessage()); JOptionPane.showMessageDialog(this, "Loading Ticket Failed!\n","Error",JOptionPane.ERROR_MESSAGE); } } /** * Save the ticket information that may have been changed. * Can only change the answer and the status and also add a new ticketnote. * @param evt */ private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed try { ticket.setStatusid(Status.getStatusbyDesc(cmbStatus.getSelectedItem().toString()).getStatusID()); Answer answer = new Answer(); if(ticket.getAnserid() == 0) { //Create an Answer answer.setCategoryid(Category.getCategoryIDByTitle(cmbCategory.getSelectedItem().toString())); answer.setDetails(txtAnswer.getText()); answer.AddAnswer(); ticket.setAnserid(answer.getAnswerid()); } else { //Update and answer. answer = Answer.getAnswer(ticket.getAnserid()); answer.setDetails(txtAnswer.getText()); answer.UpdateAnswer(); } ticket.UpdateTicket(); //update the ticket with the answer and category or status assigned. JOptionPane.showMessageDialog(this, "Ticket Saved Successfully!\n","Saving Ticket",JOptionPane.INFORMATION_MESSAGE); StaticMain.operatorconsole.refresh(); StaticMain.operatorconsole.show(); this.dispose(); }catch(Exception e) { System.out.println(e.getMessage()); JOptionPane.showMessageDialog(this, "Saving Ticket Failed!\n","Error",JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_btnSaveActionPerformed /** * This closes this form and reopens the Operator console. * @param evt */ private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed // TODO add your handling code here: StaticMain.operatorconsole.refresh(); StaticMain.operatorconsole.show(); this.dispose(); }//GEN-LAST:event_btnCancelActionPerformed /** * More functionality to be added in the future about ticketnotes. * @param evt */ private void btnAddticketnoteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddticketnoteActionPerformed // TODO add your handling code here: JOptionPane.showMessageDialog(this, "Feature not implemented yet.\n" + "This feature (when implemented) is meant for documentation about a ticket.\n" + "Anything that an operator may have done to the ticket\n" + "would be saved here.","Ticket notes",JOptionPane.INFORMATION_MESSAGE); }//GEN-LAST:event_btnAddticketnoteActionPerformed /** * Save as cancel button. */ private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing // TODO add your handling code here: StaticMain.operatorconsole.refresh(); StaticMain.operatorconsole.show(); this.dispose(); }//GEN-LAST:event_formWindowClosing /** * This button gives the user a chance to go and search the database or online for answers to this query. * @param evt */ private void btnSearchAgainActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchAgainActionPerformed // TODO add your handling code here: StaticMain.ticket = this.ticket; StaticMain.search = new Search(); StaticMain.search.setQuery(this.txtQuery.getText()); StaticMain.search.show(); this.dispose(); }//GEN-LAST:event_btnSearchAgainActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { Ticketfrm ticketFrm = new Ticketfrm(null); ticketFrm.setResizable(false); ticketFrm.setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnAddticketnote; private javax.swing.JButton btnCancel; private javax.swing.JButton btnSave; private javax.swing.JButton btnSearchAgain; private javax.swing.JComboBox cmbCategory; private javax.swing.JComboBox cmbStatus; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JLabel lblAnswer; private javax.swing.JLabel lblCaller; private javax.swing.JLabel lblCallerValue; private javax.swing.JLabel lblCategory; private javax.swing.JLabel lblEndtime; private javax.swing.JLabel lblEndtimeValue; private javax.swing.JLabel lblOperator; private javax.swing.JLabel lblOperator_Value; private javax.swing.JLabel lblQuery; private javax.swing.JLabel lblStarttime; private javax.swing.JLabel lblStarttimeValue; private javax.swing.JLabel lblStatus; private javax.swing.JLabel lblTicketid; private javax.swing.JLabel lblTicketid_Value; private javax.swing.JTable tbTicketnotes; private javax.swing.JTextArea txtAnswer; private javax.swing.JTextArea txtQuery; // End of variables declaration//GEN-END:variables }