/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* frmRecommendedsite.java
*
* Created on Jan 19, 2010, 10:55:34 AM
*/
package questionbox;
import org.jdesktop.application.Action;
import qbox.model.* ;
import java.util.*;
import javax.swing.JOptionPane;
import javax.swing.*;
/**
*
* @author ivank
*/
public class Recommendedsitefrm extends javax.swing.JFrame {
private Vector<String> header;
private Vector<Vector<String>> dataRows;
/** Creates new form frmRecommendedsite */
public Recommendedsitefrm() {
initComponents();
LoadRecommendedSites();
this.setTitle("View Recommended Sites");
setLocationRelativeTo(null);
}
public void Refresh()
{
LoadRecommendedSites();
}
public void LoadRecommendedSites()
{
try{
header = new Vector();
header.add("SiteID");
header.add("Description");
header.add("URL");
dataRows = new Vector<Vector<String>>(); // Vector of rows
ArrayList<RecommendedSite> sites = RecommendedSite.getRecommendedSites();
for( RecommendedSite site : sites)
{
Vector<String> cells = new Vector<String>();
cells.add(Long.toString(site.getRecommendedsiteid()));
cells.add(site.getName());
cells.add(site.getUrl());
dataRows.add(cells);
}
this.tbRecSite.setModel(new javax.swing.table.DefaultTableModel( dataRows,header));
// tbRecSite.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
tbRecSite.getColumnModel().getColumn(0).setPreferredWidth(8);
tbRecSite.getColumnModel().getColumn(0).setWidth(8);
// tbPendingRecommendedSites.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);
}
}
/** 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() {
jScrollPane1 = new javax.swing.JScrollPane();
tbRecSite = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setName("Form"); // NOI18N
jScrollPane1.setName("jScrollPane1"); // NOI18N
tbRecSite.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"
}
));
tbRecSite.setName("tbRecSite"); // NOI18N
jScrollPane1.setViewportView(tbRecSite);
javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(questionbox.QuestionBoxApp.class).getContext().getActionMap(Recommendedsitefrm.class, this);
jButton1.setAction(actionMap.get("Createnewsite")); // NOI18N
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(questionbox.QuestionBoxApp.class).getContext().getResourceMap(Recommendedsitefrm.class);
jButton1.setText(resourceMap.getString("btnAddnewsite.text")); // NOI18N
jButton1.setName("btnAddnewsite"); // NOI18N
jButton2.setAction(actionMap.get("Editexistingsite")); // NOI18N
jButton2.setText(resourceMap.getString("btnEditsite.text")); // NOI18N
jButton2.setName("btnEditsite"); // NOI18N
jButton3.setAction(actionMap.get("closeform")); // NOI18N
jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
jButton3.setName("jButton3"); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(103, 103, 103)
.addComponent(jButton1)
.addGap(41, 41, 41)
.addComponent(jButton2)
.addGap(69, 69, 69)
.addComponent(jButton3))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 532, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(25, 25, 25)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 353, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jButton3))
.addGap(19, 19, 19))
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Recommendedsitefrm().setVisible(true);
}
});
}
@Action
public void closeform() {
this.dispose();
}
@Action
public void Editexistingsite() {
try
{
if(this.tbRecSite.getSelectedRowCount() == 1 )
{
int Rowid = tbRecSite.getSelectedRow();
long RecSiteid = Long.parseLong(dataRows.get(Rowid).get(0));
EditSitefrm sitefrm = new EditSitefrm(RecSiteid);
sitefrm.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 recommented site windows \n" , "Error", JOptionPane.ERROR_MESSAGE);
}
}
@Action
public void Createnewsite() {
EditSitefrm sitefrm = new EditSitefrm();
sitefrm.show();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable tbRecSite;
// End of variables declaration//GEN-END:variables
}