package org.pasif.gui;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import org.jdesktop.application.Action;
import org.jdesktop.application.Application;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle;
import org.pas.database.DbHelper;
import org.pas.log.LogHandler;
import org.pasif.utils.ColumnTable;
public class DbTablesView extends javax.swing.JInternalFrame {
public DbTablesView(LogHandler log, DbHelper dbHelper) {
initComponents();
this.log = log;
this.dbHelper = dbHelper;
jComboBox2.setModel(new DefaultComboBoxModel(new Vector<Object>(dbHelper.getTables())));
jTable1.setDefaultRenderer(javax.swing.JCheckBox.class, new TableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
return new JCheckBox("选择");
}
});
jTable1.setModel(new ColumnTable(dbHelper.getColumn(jComboBox2.getSelectedItem().toString())));
}
@Action
public void exit() {
dispose();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane2 = new JScrollPane();
jTable1 = new JTable();
jComboBox2 = new JComboBox();
jLabel2 = new JLabel();
jButton3 = new JButton();
jButton4 = new JButton();
setClosable(true);
setIconifiable(true);
setMaximizable(true);
setResizable(true);
ResourceMap resourceMap = Application.getInstance(Client.class).getContext().getResourceMap(DbTablesView.class);
setTitle(resourceMap.getString("Form.title")); // NOI18N
setName("Form"); // NOI18N
addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
formPropertyChange(evt);
}
});
jScrollPane2.setName("jScrollPane2"); // NOI18N
jTable1.setModel(new DefaultTableModel(
new Object [][] {
{"1", null, null},
{"2", null, null},
{"3", null, null},
{"4", null, null}
},
new String [] {
"ID", "选择", "列名"
}
));
jTable1.setName("jTable1"); // NOI18N
jScrollPane2.setViewportView(jTable1);
jComboBox2.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jComboBox2.setMinimumSize(new Dimension(20, 21));
jComboBox2.setName("jComboBox2"); // NOI18N
jComboBox2.setPreferredSize(new Dimension(20, 21));
jComboBox2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jComboBox2ActionPerformed(evt);
}
});
jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
jLabel2.setName("jLabel2"); // NOI18N
jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
jButton3.setName("jButton3"); // NOI18N
jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
jButton4.setName("jButton4"); // NOI18N
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(GroupLayout.LEADING)
.add(GroupLayout.TRAILING, layout.createSequentialGroup()
.add(jButton3)
.addPreferredGap(LayoutStyle.RELATED)
.add(jButton4))
.add(jScrollPane2, GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)
.add(GroupLayout.TRAILING, layout.createSequentialGroup()
.add(jLabel2)
.addPreferredGap(LayoutStyle.RELATED)
.add(jComboBox2, GroupLayout.PREFERRED_SIZE, 113, GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(GroupLayout.BASELINE)
.add(jComboBox2, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
.add(jLabel2, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.RELATED)
.add(jScrollPane2, GroupLayout.DEFAULT_SIZE, 309, Short.MAX_VALUE)
.addPreferredGap(LayoutStyle.RELATED)
.add(layout.createParallelGroup(GroupLayout.BASELINE)
.add(jButton4)
.add(jButton3))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jComboBox2ActionPerformed(ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed
System.out.println("good" + evt.getActionCommand());
}//GEN-LAST:event_jComboBox2ActionPerformed
private void formPropertyChange(PropertyChangeEvent evt) {//GEN-FIRST:event_formPropertyChange
if (evt.getPropertyName().equals("icon") && evt.getOldValue().equals(Boolean.FALSE) && evt.getNewValue().equals(Boolean.TRUE)) {
JInternalFrame j = (JInternalFrame) evt.getSource();
j.setVisible(true);
j.moveToFront();
}
}//GEN-LAST:event_formPropertyChange
// Variables declaration - do not modify//GEN-BEGIN:variables
private JButton jButton3;
private JButton jButton4;
private JComboBox jComboBox2;
private JLabel jLabel2;
private JScrollPane jScrollPane2;
private JTable jTable1;
// End of variables declaration//GEN-END:variables
private LogHandler log;
private DbHelper dbHelper;
}