package GUI;
import Handler.; import Model.; import java.io.; import javax.swing.;
public class ProjectViewer extends javax.swing.JPanel { MainViewer mv; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); ProjectViewerHandler pvh = new ProjectViewerHandler();
public ProjectViewer()
{
try
{
initComponents();
pvh.processProjectList();
displayProjects();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
}
}
public void setMainViewer(MainViewer mv)
{
this.mv = mv;
}
private void displayProjects()throws Exception
{
lblCount.setText("No. of Projects: " + pvh.returnProjectList().length);
tableProjectViewer.setModel(new javax.swing.table.DefaultTableModel(pvh.returnProjectList(),new String [] {"ID", "Project Common Name", "Project Name", "Manager"}));
tableProjectViewer.setDefaultEditor(Object.class, null);
}
private void checkSelectedSearchOption()throws Exception
{
if(rbID.isSelected())
{
try
{
Double.parseDouble(txtSearch.getText());
searchByID();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Please enter a numerical value!", "ERROR", JOptionPane.ERROR_MESSAGE);
}
}
else if(rbCommonName.isSelected())
{
searchByCommonName();
}
else if(rbProjectName.isSelected())
{
searchByProjectName();
}
else if(rbManager.isSelected())
{
searchByManager();
}
else
{
JOptionPane.showMessageDialog(null, "Please select a search category!", "ERROR", JOptionPane.ERROR_MESSAGE);
}
}
private void searchByID()throws Exception
{
pvh.processProjectListByID(txtSearch.getText());
displayProjects();
}
private void searchByCommonName()throws Exception
{
pvh.processProjectListByCommonName(txtSearch.getText());
displayProjects();
}
private void searchByProjectName()throws Exception
{
pvh.processProjectListByProjectName(txtSearch.getText());
displayProjects();
}
private void searchByManager()throws Exception
{
pvh.processProjectListByManager(txtSearch.getText());
displayProjects();
}
/**
* 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">
private void initComponents() {
bgSearchProject = new javax.swing.ButtonGroup();
scrollpaneProjectViewer = new javax.swing.JScrollPane();
tableProjectViewer = new javax.swing.JTable();
panelOptions = new javax.swing.JPanel();
lblSearch = new javax.swing.JLabel();
txtSearch = new javax.swing.JTextField();
rbID = new javax.swing.JRadioButton();
rbCommonName = new javax.swing.JRadioButton();
rbProjectName = new javax.swing.JRadioButton();
rbManager = new javax.swing.JRadioButton();
btnSearch = new javax.swing.JButton();
btnViewAll = new javax.swing.JButton();
lblCount = new javax.swing.JLabel();
panelEdge = new javax.swing.JPanel();
bgSearchProject.add(rbID);
bgSearchProject.add(rbCommonName);
bgSearchProject.add(rbProjectName);
bgSearchProject.add(rbManager);
tableProjectViewer.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{"1", "Project 1", "Group 1", null},
{"2", "Project 2", "Group 2", null},
{"3", "Project 3", "Group 3", null}
},
new String [] {
"ID", "Project Common Name", "Project Name", "Manager"
}
) {
boolean[] canEdit = new boolean [] {
false, false, false, false
};
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
tableProjectViewer.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tableProjectViewerMouseClicked(evt);
}
});
scrollpaneProjectViewer.setViewportView(tableProjectViewer);
panelOptions.setBackground(java.awt.Color.blue);
panelOptions.setPreferredSize(new java.awt.Dimension(100, 74));
lblSearch.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
lblSearch.setForeground(java.awt.Color.white);
lblSearch.setText("Search project:");
txtSearch.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
rbID.setBackground(java.awt.Color.blue);
rbID.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
rbID.setForeground(java.awt.Color.white);
rbID.setSelected(true);
rbID.setText("ID");
rbCommonName.setBackground(java.awt.Color.blue);
rbCommonName.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
rbCommonName.setForeground(java.awt.Color.white);
rbCommonName.setText("Common Name");
rbProjectName.setBackground(java.awt.Color.blue);
rbProjectName.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
rbProjectName.setForeground(java.awt.Color.white);
rbProjectName.setText("Project Name");
rbManager.setBackground(java.awt.Color.blue);
rbManager.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
rbManager.setForeground(java.awt.Color.white);
rbManager.setText("Manager");
btnSearch.setBackground(new java.awt.Color(0, 51, 153));
btnSearch.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N
btnSearch.setForeground(java.awt.Color.white);
btnSearch.setText("SEARCH");
btnSearch.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
btnSearch.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSearchActionPerformed(evt);
}
});
btnViewAll.setBackground(new java.awt.Color(0, 51, 153));
btnViewAll.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N
btnViewAll.setForeground(java.awt.Color.white);
btnViewAll.setText("VIEW ALL");
btnViewAll.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
btnViewAll.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnViewAllActionPerformed(evt);
}
});
lblCount.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
lblCount.setForeground(java.awt.Color.white);
lblCount.setText("No. of Projects: 0");
panelEdge.setBackground(java.awt.Color.white);
javax.swing.GroupLayout panelEdgeLayout = new javax.swing.GroupLayout(panelEdge);
panelEdge.setLayout(panelEdgeLayout);
panelEdgeLayout.setHorizontalGroup(
panelEdgeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
panelEdgeLayout.setVerticalGroup(
panelEdgeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 10, Short.MAX_VALUE)
);
javax.swing.GroupLayout panelOptionsLayout = new javax.swing.GroupLayout(panelOptions);
panelOptions.setLayout(panelOptionsLayout);
panelOptionsLayout.setHorizontalGroup(
panelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelOptionsLayout.createSequentialGroup()
.addContainerGap()
.addComponent(lblSearch)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(34, 34, 34)
.addComponent(rbID)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(rbCommonName)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(rbProjectName)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(rbManager)
.addGap(28, 28, 28)
.addComponent(btnSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(btnViewAll, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(lblCount)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(panelEdge, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
panelOptionsLayout.setVerticalGroup(
panelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelOptionsLayout.createSequentialGroup()
.addContainerGap()
.addGroup(panelOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblSearch)
.addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnSearch)
.addComponent(lblCount)
.addComponent(rbID)
.addComponent(rbCommonName)
.addComponent(rbProjectName)
.addComponent(rbManager)
.addComponent(btnViewAll))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE)
.addComponent(panelEdge, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(scrollpaneProjectViewer, javax.swing.GroupLayout.DEFAULT_SIZE, 930, Short.MAX_VALUE)
.addContainerGap())
.addComponent(panelOptions, javax.swing.GroupLayout.DEFAULT_SIZE, 950, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(panelOptions, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(scrollpaneProjectViewer, javax.swing.GroupLayout.DEFAULT_SIZE, 435, Short.MAX_VALUE)
.addContainerGap())
);
}// </editor-fold>
private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {
if(txtSearch.getText().trim().length() >= 1)
{
try
{
checkSelectedSearchOption();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e.getCause(), "ERROR", JOptionPane.ERROR_MESSAGE);
}
}
else
{
JOptionPane.showMessageDialog(null, "Please enter a search value!", "ERROR", JOptionPane.ERROR_MESSAGE);
}
}
private void btnViewAllActionPerformed(java.awt.event.ActionEvent evt) {
try
{
pvh.processProjectList();
displayProjects();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
}
}
private void tableProjectViewerMouseClicked(java.awt.event.MouseEvent evt) {
if(evt.getClickCount() == 2)
{
Project prj = new Project();
prj.setID(Integer.parseInt(tableProjectViewer.getModel().getValueAt(tableProjectViewer.getSelectedRow(), 0).toString()));
prj.setCommonName(tableProjectViewer.getModel().getValueAt(tableProjectViewer.getSelectedRow(), 1).toString());
prj.setProjectName(tableProjectViewer.getModel().getValueAt(tableProjectViewer.getSelectedRow(), 2).toString());
prj.setManager(tableProjectViewer.getModel().getValueAt(tableProjectViewer.getSelectedRow(), 3).toString());
mv.displayMembers(prj.getID(), prj.getCommonName(), prj.getProjectName(), prj.getManager());
}
}
// Variables declaration - do not modify
private javax.swing.ButtonGroup bgSearchProject;
private javax.swing.JButton btnSearch;
private javax.swing.JButton btnViewAll;
private javax.swing.JLabel lblCount;
private javax.swing.JLabel lblSearch;
private javax.swing.JPanel panelEdge;
private javax.swing.JPanel panelOptions;
private javax.swing.JRadioButton rbCommonName;
private javax.swing.JRadioButton rbID;
private javax.swing.JRadioButton rbManager;
private javax.swing.JRadioButton rbProjectName;
private javax.swing.JScrollPane scrollpaneProjectViewer;
private javax.swing.JTable tableProjectViewer;
private javax.swing.JTextField txtSearch;
// End of variables declaration
}