/**
*
* Appfrica Labs Uganda Ltd Copyrigth @since 2009
* @version 2
*
* This class manages the operators. Editing of existing tickets or addition of new tickets is done here.
*
* Created on Oct 19, 2009, 2:07:23 PM
*/
package questionbox;
import javax.swing.JOptionPane;
import qbox.model.*;
import java.util.*;
/**
*
* @author Victor Miclovich
*/
public class OperatorConsole extends javax.swing.JFrame {
private Vector<String> header;
private Vector<Vector<String>> dataRows;
/**
* refresh the list of pending tickets from the database.
*/
public void refresh()
{
LoadPendingTickets();
}
/**
* This function aids loading of pending tickets from an array of tickets.
*/
public void LoadPendingTickets()
{
try{
header = new Vector();
header.add("TicketID");
header.add("StartTime");
header.add("Query");
header.add("Answer");
header.add("Caller");
header.add("Status");
dataRows = new Vector<Vector<String>>(); // Vector of rows
ArrayList<Ticket> tickets = Ticket.getPendingTickets(StaticMain.loggedinuser.getUserid());
for( Ticket ticket : tickets)
{
Vector<String> cells = new Vector<String>();
cells.add(Long.toString(ticket.getTicketid()));
cells.add(ticket.getStartTime().toString());
cells.add(Query.getQuery(ticket.getQueryid()).getDetails());
cells.add(Answer.getAnswer(ticket.getAnserid()).getDetails());
User user = User.getUser(ticket.getCallerid());
cells.add(user.getFname()+ " " + user.getLname());
cells.add(Status.getStatus(ticket.getStatusid()).getDescr());
dataRows.add(cells);
}
tbPendingTickets.setModel(new javax.swing.table.DefaultTableModel( dataRows,header));
// tbPendingTickets.setDefaultRenderer(Object.class, new MultiLineCellRenderer());
} catch (Exception e) {
System.out.println(e.getMessage());
JOptionPane.showMessageDialog(this, "Loading pending users failed!\n", "Error", JOptionPane.ERROR_MESSAGE);
}
}
/** Creates new form OperatorConsole */
public OperatorConsole() {
initComponents();
setLocationRelativeTo(null);
LoadPendingTickets();
}
/** 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() {
jBAddTicket = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
tbPendingTickets = new javax.swing.JTable();
btnEditticket = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(questionbox.QuestionBoxApp.class).getContext().getResourceMap(OperatorConsole.class);
setTitle(resourceMap.getString("Form.title")); // NOI18N
setName("Form"); // NOI18N
jBAddTicket.setText(resourceMap.getString("jBAddTicket.text")); // NOI18N
jBAddTicket.setName("jBAddTicket"); // NOI18N
jBAddTicket.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBAddTicketActionPerformed(evt);
}
});
jScrollPane1.setName("jScrollPane1"); // NOI18N
tbPendingTickets.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"
}
));
tbPendingTickets.setName("tbPendingTickets"); // NOI18N
jScrollPane1.setViewportView(tbPendingTickets);
btnEditticket.setText(resourceMap.getString("btnEditticket.text")); // NOI18N
btnEditticket.setName("btnEditticket"); // NOI18N
btnEditticket.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEditticketActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 707, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(192, 192, 192)
.addComponent(btnEditticket)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 228, Short.MAX_VALUE)
.addComponent(jBAddTicket)
.addGap(133, 133, 133)))
.addGap(27, 27, 27))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnEditticket)
.addComponent(jBAddTicket))
.addGap(26, 26, 26))
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* This function performs the addition of tickets that have been escalated
* @param evt TicketForm
*/
private void jBAddTicketActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAddTicketActionPerformed
// TODO add your handling code here:
StaticMain.ticket = new Ticket();
StaticMain.ticket.setStartTime(Util.Now());
UserForm ticketForm = new UserForm(4);
ticketForm.show();
}//GEN-LAST:event_jBAddTicketActionPerformed
/**
* This function aids the Editing of tickets already created from the database
*
*/
private void btnEditticketActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditticketActionPerformed
// being created.
try
{
if(tbPendingTickets.getSelectedRowCount() == 1 )
{
int Rowid = tbPendingTickets.getSelectedRow();
long Ticketid = Long.parseLong(dataRows.get(Rowid).get(0));
Ticketfrm ticketfrm = new Ticketfrm(Ticket.getTicket(Ticketid));
this.dispose();
ticketfrm.show();
}
else
{
JOptionPane.showMessageDialog(this, "Please select exactly one row.","Error",JOptionPane.ERROR_MESSAGE);
}
} catch (Exception e) {
System.out.println(e.getMessage());
JOptionPane.showMessageDialog(this, "Failed to open ticket windows \n" , "Error", JOptionPane.ERROR_MESSAGE);
}
}//GEN-LAST:event_btnEditticketActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
OperatorConsole operatorConsole = new OperatorConsole();
operatorConsole.setResizable(false);
operatorConsole.setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnEditticket;
private javax.swing.JButton jBAddTicket;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable tbPendingTickets;
// End of variables declaration//GEN-END:variables
}