Started implementing the UserTableModel.
This commit is contained in:
@@ -38,7 +38,7 @@ public class Main {
|
|||||||
this.dbCon = new SqlConnector();
|
this.dbCon = new SqlConnector();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
MainWindow window = new MainWindow(this);
|
MainWindow window = new MainWindow(this.dbCon);
|
||||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
|
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -55,8 +55,4 @@ public class Main {
|
|||||||
}
|
}
|
||||||
});*/
|
});*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean userSave(String pName, String pSurname) {
|
|
||||||
return this.dbCon.createUser(pName, pSurname);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
25
src/de/katho/kBorrow/data/KUser.java
Normal file
25
src/de/katho/kBorrow/data/KUser.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package de.katho.kBorrow.data;
|
||||||
|
|
||||||
|
public class KUser {
|
||||||
|
private String name;
|
||||||
|
private String surname;
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
public KUser(int pId, String pName, String pSurname){
|
||||||
|
this.name = pName;
|
||||||
|
this.surname = pSurname;
|
||||||
|
this.id = pId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName(){
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSurname(){
|
||||||
|
return this.surname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId(){
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
package de.katho.kBorrow.db;
|
package de.katho.kBorrow.db;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.data.KUser;
|
||||||
|
|
||||||
public interface DbConnector {
|
public interface DbConnector {
|
||||||
|
|
||||||
public boolean createUser(String pName, String pSurname);
|
public boolean createUser(String pName, String pSurname);
|
||||||
|
public ArrayList<KUser> getUserList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package de.katho.kBorrow.db;
|
package de.katho.kBorrow.db;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.data.KUser;
|
||||||
|
|
||||||
public class SqlConnector implements DbConnector{
|
public class SqlConnector implements DbConnector{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -8,4 +12,10 @@ public class SqlConnector implements DbConnector{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArrayList<KUser> getUserList() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,12 @@ import java.sql.DriverManager;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.data.KUser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class sqliteConnector
|
* @class sqliteConnector
|
||||||
* @author Servicepoint
|
* @author Servicepoint
|
||||||
@@ -109,44 +112,38 @@ public class SqliteConnector implements DbConnector {
|
|||||||
private Hashtable<String, String> loadScheme(){
|
private Hashtable<String, String> loadScheme(){
|
||||||
Hashtable<String, String> tScheme= new Hashtable<String, String>();
|
Hashtable<String, String> tScheme= new Hashtable<String, String>();
|
||||||
|
|
||||||
tScheme.put("kborrow",
|
|
||||||
"CREATE TABLE kborrow ("
|
|
||||||
+ "setting_name TEXT,"
|
|
||||||
+ "value INT"
|
|
||||||
+ ")");
|
|
||||||
|
|
||||||
tScheme.put("article",
|
tScheme.put("article",
|
||||||
"CREATE TABLE article ("
|
"CREATE TABLE article ("
|
||||||
+ "id INT PRIMARY KEY,"
|
+ "id INTEGER PRIMARY KEY NOT NULL,"
|
||||||
+ "name TEXT NOT NULL,"
|
+ "name TEXT NOT NULL,"
|
||||||
+ "description TEXT"
|
+ "description TEXT"
|
||||||
+ ")");
|
+ ")");
|
||||||
|
|
||||||
tScheme.put("lender",
|
tScheme.put("lender",
|
||||||
"CREATE TABLE lender ("
|
"CREATE TABLE lender ("
|
||||||
+ "id INT PRIMARY KEY,"
|
+ "id INTEGER PRIMARY KEY NOT NULL,"
|
||||||
+ "name TEXT,"
|
+ "name TEXT,"
|
||||||
+ "surname TEXT,"
|
+ "surname TEXT,"
|
||||||
+ "student_number INT,"
|
+ "student_number INTEGER,"
|
||||||
+ "comment TEXT"
|
+ "comment TEXT"
|
||||||
+ ")");
|
+ ")");
|
||||||
|
|
||||||
tScheme.put("user",
|
tScheme.put("user",
|
||||||
"CREATE TABLE user ("
|
"CREATE TABLE user ("
|
||||||
+ "id INT PRIMARY KEY,"
|
+ "id INTEGER PRIMARY KEY NOT NULL,"
|
||||||
+ "name TEXT,"
|
+ "name TEXT,"
|
||||||
+ "surname TEXT"
|
+ "surname TEXT"
|
||||||
+ ")");
|
+ ")");
|
||||||
|
|
||||||
tScheme.put("lending",
|
tScheme.put("lending",
|
||||||
"CREATE TABLE lending ("
|
"CREATE TABLE lending ("
|
||||||
+ "id INT PRIMARY KEY,"
|
+ "id INTEGER PRIMARY KEY NOT NULL,"
|
||||||
+ "article_id INT,"
|
+ "article_id INTEGER,"
|
||||||
+ "user_id INT,"
|
+ "user_id INTEGER,"
|
||||||
+ "lender_id INT,"
|
+ "lender_id INTEGER,"
|
||||||
+ "start_date DATE DEFAULT CURRENT_DATE,"
|
+ "start_date INTEGER DEFAULT CURRENT_DATE,"
|
||||||
+ "expected_end_date DATE,"
|
+ "expected_end_date INTEGER,"
|
||||||
+ "end_date DATE,"
|
+ "end_date INTEGER,"
|
||||||
+ "comment TEXT"
|
+ "comment TEXT"
|
||||||
+ ")");
|
+ ")");
|
||||||
|
|
||||||
@@ -200,4 +197,24 @@ public class SqliteConnector implements DbConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<KUser> getUserList(){
|
||||||
|
ArrayList<KUser> userArr = new ArrayList<KUser>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Statement st = this.connection.createStatement();
|
||||||
|
String query = "SELECT id, name, surname FROM user";
|
||||||
|
ResultSet rs = st.executeQuery(query);
|
||||||
|
|
||||||
|
while (rs.next()){
|
||||||
|
userArr.add(new KUser(rs.getInt("id"), rs.getString("name"), rs.getString("surname")));
|
||||||
|
}
|
||||||
|
|
||||||
|
return userArr;
|
||||||
|
}
|
||||||
|
catch (SQLException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,16 +7,12 @@ import javax.swing.UnsupportedLookAndFeelException;
|
|||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
|
|
||||||
import javax.swing.BoxLayout;
|
|
||||||
|
|
||||||
|
|
||||||
import javax.swing.border.TitledBorder;
|
import javax.swing.border.TitledBorder;
|
||||||
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
import javax.swing.table.TableModel;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
|
|
||||||
@@ -26,19 +22,17 @@ import java.awt.event.ActionListener;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import de.katho.kBorrow.Main;
|
import de.katho.kBorrow.Main;
|
||||||
|
import de.katho.kBorrow.db.DbConnector;
|
||||||
|
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
import javax.swing.ScrollPaneConstants;
|
|
||||||
import java.awt.GridBagLayout;
|
|
||||||
import java.awt.GridBagConstraints;
|
|
||||||
import java.awt.FlowLayout;
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.GridLayout;
|
|
||||||
|
|
||||||
public class MainWindow implements ActionListener {
|
public class MainWindow implements ActionListener {
|
||||||
|
|
||||||
private Main mainObject;
|
private DbConnector dbCon;
|
||||||
private boolean userModeSave = true;
|
private boolean userModeSave = true;
|
||||||
|
|
||||||
private JFrame frame;
|
private JFrame frame;
|
||||||
@@ -53,9 +47,11 @@ public class MainWindow implements ActionListener {
|
|||||||
private JButton btnUserSave;
|
private JButton btnUserSave;
|
||||||
private JLabel lblUserStatus;
|
private JLabel lblUserStatus;
|
||||||
private JTable userTable;
|
private JTable userTable;
|
||||||
|
private UserTableModel userTableModel;
|
||||||
private JScrollPane scrollUserList;
|
private JScrollPane scrollUserList;
|
||||||
private JPanel panelUserList;
|
private JPanel panelUserList;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the application.
|
* Create the application.
|
||||||
* @throws UnsupportedLookAndFeelException
|
* @throws UnsupportedLookAndFeelException
|
||||||
@@ -63,8 +59,8 @@ public class MainWindow implements ActionListener {
|
|||||||
* @throws InstantiationException
|
* @throws InstantiationException
|
||||||
* @throws ClassNotFoundException
|
* @throws ClassNotFoundException
|
||||||
*/
|
*/
|
||||||
public MainWindow(Main pMainObject) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
|
public MainWindow(DbConnector pDbCon) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
|
||||||
this.mainObject = pMainObject;
|
this.dbCon = pDbCon;
|
||||||
initialize();
|
initialize();
|
||||||
this.frame.setVisible(true);
|
this.frame.setVisible(true);
|
||||||
}
|
}
|
||||||
@@ -107,13 +103,16 @@ public class MainWindow implements ActionListener {
|
|||||||
panelUser.setLayout(null);
|
panelUser.setLayout(null);
|
||||||
|
|
||||||
panelUserList = new JPanel();
|
panelUserList = new JPanel();
|
||||||
panelUserList.setBounds(0, 0, 589, 344);
|
panelUserList.setBounds(0, 0, 589, 320);
|
||||||
panelUserList.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Benutzerliste", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
panelUserList.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Benutzerliste", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||||
panelUser.add(panelUserList);
|
panelUser.add(panelUserList);
|
||||||
panelUserList.setLayout(new BorderLayout(0, 0));
|
panelUserList.setLayout(new BorderLayout(0, 0));
|
||||||
|
|
||||||
userTable = new JTable(new UserTableModel());
|
userTable = new JTable(new UserTableModel(this.dbCon));
|
||||||
userTable.setFillsViewportHeight(true);
|
userTable.setFillsViewportHeight(true);
|
||||||
|
userTableModel = (UserTableModel)userTable.getModel();
|
||||||
|
//userTableModel.
|
||||||
|
|
||||||
|
|
||||||
scrollUserList = new JScrollPane(userTable);
|
scrollUserList = new JScrollPane(userTable);
|
||||||
panelUserList.add(scrollUserList);
|
panelUserList.add(scrollUserList);
|
||||||
@@ -121,7 +120,7 @@ public class MainWindow implements ActionListener {
|
|||||||
|
|
||||||
// User-Edit-Pane
|
// User-Edit-Pane
|
||||||
panelUserEdit = new JPanel();
|
panelUserEdit = new JPanel();
|
||||||
panelUserEdit.setBounds(0, 355, 589, 87);
|
panelUserEdit.setBounds(0, 331, 589, 111);
|
||||||
panelUserEdit.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Benutzer hinzuf\u00FCgen / bearbeiten", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
panelUserEdit.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Benutzer hinzuf\u00FCgen / bearbeiten", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||||
panelUserEdit.setLayout(null);
|
panelUserEdit.setLayout(null);
|
||||||
panelUser.add(this.panelUserEdit);
|
panelUser.add(this.panelUserEdit);
|
||||||
@@ -162,10 +161,11 @@ public class MainWindow implements ActionListener {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if(e.getSource() == this.btnUserSave){
|
if(e.getSource() == this.btnUserSave){
|
||||||
if(this.userModeSave){
|
if(this.userModeSave){
|
||||||
if(this.mainObject.userSave(this.textFieldUserName.getText(), this.textFieldUserSurname.getText())){
|
if(this.dbCon.createUser(this.textFieldUserName.getText(), this.textFieldUserSurname.getText())){
|
||||||
this.lblUserStatus.setText("Benutzer \""+this.textFieldUserName.getText()+" "+this.textFieldUserSurname.getText()+"\" erfolgreich hinzugef<65>gt.");
|
this.lblUserStatus.setText("Benutzer \""+this.textFieldUserName.getText()+" "+this.textFieldUserSurname.getText()+"\" erfolgreich hinzugef<65>gt.");
|
||||||
this.textFieldUserName.setText("");
|
this.textFieldUserName.setText("");
|
||||||
this.textFieldUserSurname.setText("");
|
this.textFieldUserSurname.setText("");
|
||||||
|
this.userTableModel.updateTable();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.lblUserStatus.setText("Benutzer konnte nicht erstellt werden.");
|
this.lblUserStatus.setText("Benutzer konnte nicht erstellt werden.");
|
||||||
|
|||||||
@@ -1,30 +1,50 @@
|
|||||||
package de.katho.kBorrow.gui;
|
package de.katho.kBorrow.gui;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.data.KUser;
|
||||||
|
import de.katho.kBorrow.db.DbConnector;
|
||||||
|
|
||||||
public class UserTableModel extends AbstractTableModel {
|
public class UserTableModel extends AbstractTableModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 435829735305533728L;
|
private static final long serialVersionUID = 435829735305533728L;
|
||||||
|
private DbConnector dbCon;
|
||||||
|
private String[] header = {"Vorname", "Nachname", "Aktion"};
|
||||||
|
private ArrayList<KUser> data;
|
||||||
|
|
||||||
|
public UserTableModel(DbConnector pDbCon){
|
||||||
|
this.dbCon = pDbCon;
|
||||||
|
this.updateTable();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getColumnCount() {
|
public int getColumnCount() {
|
||||||
// TODO Auto-generated method stub
|
return this.header.length;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRowCount() {
|
public int getRowCount() {
|
||||||
// TODO Auto-generated method stub
|
return this.data.size();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getValueAt(int arg0, int arg1) {
|
public String getValueAt(int row, int col) {
|
||||||
// TODO Auto-generated method stub
|
if(col == 0) return this.data.get(row).getName();
|
||||||
return null;
|
else if (col == 1) return this.data.get(row).getSurname();
|
||||||
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getColumnName(int index){
|
||||||
|
return header[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTable(){
|
||||||
|
this.data = this.dbCon.getUserList();
|
||||||
|
this.fireTableDataChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user