Merge remote-tracking branch 'origin/InspectArticle'
This commit is contained in:
@@ -23,4 +23,5 @@ public interface DbConnector {
|
|||||||
public int createNewLender(String pLName, String pLSurname, String pLSN);
|
public int createNewLender(String pLName, String pLSurname, String pLSN);
|
||||||
public ArrayList<KLending> getActiveLendingList();
|
public ArrayList<KLending> getActiveLendingList();
|
||||||
public int returnLending(int lendingId, int artId, String string);
|
public int returnLending(int lendingId, int artId, String string);
|
||||||
|
public ArrayList<KLending> getLendingListForArticle(int pArtId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,4 +99,10 @@ public class SqlConnector implements DbConnector{
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArrayList<KLending> getLendingListForArticle(int pArtId) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -287,6 +287,27 @@ public class SqliteConnector implements DbConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<KLending> getLendingListForArticle(int pArtId){
|
||||||
|
ArrayList<KLending> lendingArr = new ArrayList<KLending>();
|
||||||
|
|
||||||
|
try{
|
||||||
|
Statement st = connection.createStatement();
|
||||||
|
String query = "SELECT id, user_id, lender_id, start_date, expected_end_date, end_date FROM lending WHERE article_id = '"+pArtId+"' ORDER BY id DESC";
|
||||||
|
|
||||||
|
ResultSet rs = st.executeQuery(query);
|
||||||
|
|
||||||
|
while(rs.next()){
|
||||||
|
lendingArr.add(new KLending(rs.getInt("id"), rs.getInt("user_id"), rs.getInt("lender_id"), pArtId, rs.getString("start_date"), rs.getString("expected_end_date"), rs.getString("end_date")));
|
||||||
|
}
|
||||||
|
|
||||||
|
return lendingArr;
|
||||||
|
}
|
||||||
|
catch(SQLException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
return lendingArr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return 0: Benutzer erfolgreich erzeugt
|
* @return 0: Benutzer erfolgreich erzeugt
|
||||||
|
|||||||
93
src/de/katho/kBorrow/gui/ArticleInspectFrame.java
Normal file
93
src/de/katho/kBorrow/gui/ArticleInspectFrame.java
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
package de.katho.kBorrow.gui;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.data.KArticle;
|
||||||
|
import de.katho.kBorrow.db.DbConnector;
|
||||||
|
import de.katho.kBorrow.models.ArticleInspectTableModel;
|
||||||
|
import de.katho.kBorrow.models.ArticleTableModel;
|
||||||
|
|
||||||
|
public class ArticleInspectFrame extends JFrame {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -8993341404926674307L;
|
||||||
|
private JPanel contentPane;
|
||||||
|
private JTable table;
|
||||||
|
private ArticleInspectTableModel artInsModel;
|
||||||
|
private ArticleTableModel articleModel;
|
||||||
|
private KArticle article;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the frame.
|
||||||
|
*/
|
||||||
|
public ArticleInspectFrame(int pRow, final DbConnector dbCon, HashMap<String, Object> pModels) {
|
||||||
|
articleModel = (ArticleTableModel)pModels.get("articletablemodel");
|
||||||
|
article = articleModel.getArticleByRow(pRow);
|
||||||
|
|
||||||
|
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
|
setBounds(150, 150, 660, 541);
|
||||||
|
setTitle("Details: "+article.getName());
|
||||||
|
|
||||||
|
// ContentPane
|
||||||
|
contentPane = new JPanel();
|
||||||
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
|
setContentPane(contentPane);
|
||||||
|
contentPane.setLayout(null);
|
||||||
|
|
||||||
|
// Panel Info
|
||||||
|
JPanel panelInfo = new JPanel();
|
||||||
|
panelInfo.setBounds(0, 0, 644, 134);
|
||||||
|
panelInfo.setBorder(BorderFactory.createTitledBorder("Artikeldetails"));
|
||||||
|
|
||||||
|
panelInfo.setLayout(null);
|
||||||
|
|
||||||
|
JLabel lblNewLabel_1 = new JLabel("Artikelname:");
|
||||||
|
JLabel lblArticleName = new JLabel(article.getName());
|
||||||
|
JLabel lblNewLabel_2 = new JLabel ("Artikelbeschreibung:");
|
||||||
|
JTextArea taArticleDesc = new JTextArea(article.getDescription());
|
||||||
|
taArticleDesc.setRows(5);
|
||||||
|
taArticleDesc.setBorder(BorderFactory.createEtchedBorder());
|
||||||
|
|
||||||
|
lblNewLabel_1.setBounds(10, 21, 100, 20);
|
||||||
|
lblNewLabel_2.setBounds(10, 47, 100, 20);
|
||||||
|
lblArticleName.setBounds(120, 21, 100, 20);
|
||||||
|
taArticleDesc.setBounds(120, 45, 250, 78);
|
||||||
|
taArticleDesc.setEditable(false);
|
||||||
|
|
||||||
|
panelInfo.add(lblNewLabel_1);
|
||||||
|
panelInfo.add(lblNewLabel_2);
|
||||||
|
panelInfo.add(lblArticleName);
|
||||||
|
panelInfo.add(taArticleDesc);
|
||||||
|
|
||||||
|
// Table
|
||||||
|
artInsModel = new ArticleInspectTableModel(pRow, dbCon, pModels);
|
||||||
|
table = new JTable(artInsModel);
|
||||||
|
table.setFillsViewportHeight(true);
|
||||||
|
table.setRowHeight(30);
|
||||||
|
table.getColumnModel().getColumn(0).setMinWidth(30);
|
||||||
|
table.getColumnModel().getColumn(0).setMaxWidth(30);
|
||||||
|
table.getColumnModel().getColumn(0).setPreferredWidth(30);
|
||||||
|
|
||||||
|
JScrollPane scrollPane = new JScrollPane(table);
|
||||||
|
scrollPane.setBounds(0, 131, 644, 371);
|
||||||
|
scrollPane.setBorder(BorderFactory.createTitledBorder("Alle Ausleihen des Artikels \""+article.getName()+"\""));
|
||||||
|
|
||||||
|
// Add components to ContentPane
|
||||||
|
contentPane.add(panelInfo);
|
||||||
|
contentPane.add(scrollPane);
|
||||||
|
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ import de.katho.kBorrow.data.KArticle;
|
|||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.db.DbConnector;
|
||||||
import de.katho.kBorrow.listener.ArticleDeleteTableButton;
|
import de.katho.kBorrow.listener.ArticleDeleteTableButton;
|
||||||
import de.katho.kBorrow.listener.ArticleEditTableButton;
|
import de.katho.kBorrow.listener.ArticleEditTableButton;
|
||||||
|
import de.katho.kBorrow.listener.ArticleInspectTableButton;
|
||||||
import de.katho.kBorrow.models.ArticleTableModel;
|
import de.katho.kBorrow.models.ArticleTableModel;
|
||||||
|
|
||||||
public class ArticlePanel extends JPanel implements ActionListener, KeyListener {
|
public class ArticlePanel extends JPanel implements ActionListener, KeyListener {
|
||||||
@@ -61,10 +62,11 @@ public class ArticlePanel extends JPanel implements ActionListener, KeyListener
|
|||||||
articleTable.setRowHeight(30);
|
articleTable.setRowHeight(30);
|
||||||
ArticleDeleteTableButton articleDeleteTableButton = new ArticleDeleteTableButton("L<EFBFBD>schen", articleTable, this, articleController);
|
ArticleDeleteTableButton articleDeleteTableButton = new ArticleDeleteTableButton("L<EFBFBD>schen", articleTable, this, articleController);
|
||||||
ArticleEditTableButton articleEditTableButton = new ArticleEditTableButton("Bearbeiten", articleTable, this);
|
ArticleEditTableButton articleEditTableButton = new ArticleEditTableButton("Bearbeiten", articleTable, this);
|
||||||
|
ArticleInspectTableButton articleInspectTableButton = new ArticleInspectTableButton("Details", articleTable, dbCon, pModels);
|
||||||
|
|
||||||
for (int i = 3; i <= 4; i++){
|
for (int i = 3; i <= 5; i++){
|
||||||
articleTable.getColumnModel().getColumn(i).setCellEditor(i == 3 ? articleEditTableButton : articleDeleteTableButton);
|
articleTable.getColumnModel().getColumn(i).setCellEditor(i == 3 ? articleInspectTableButton : i == 4 ? articleEditTableButton : articleDeleteTableButton);
|
||||||
articleTable.getColumnModel().getColumn(i).setCellRenderer(i == 3 ? articleEditTableButton : articleDeleteTableButton);
|
articleTable.getColumnModel().getColumn(i).setCellRenderer(i == 3 ? articleInspectTableButton : i == 4 ? articleEditTableButton : articleDeleteTableButton);
|
||||||
|
|
||||||
articleTable.getColumnModel().getColumn(i).setMinWidth(30);
|
articleTable.getColumnModel().getColumn(i).setMinWidth(30);
|
||||||
articleTable.getColumnModel().getColumn(i).setMaxWidth(30);
|
articleTable.getColumnModel().getColumn(i).setMaxWidth(30);
|
||||||
|
|||||||
42
src/de/katho/kBorrow/listener/ArticleInspectTableButton.java
Normal file
42
src/de/katho/kBorrow/listener/ArticleInspectTableButton.java
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package de.katho.kBorrow.listener;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
|
||||||
|
import sun.tools.jar.Main;
|
||||||
|
import de.katho.kBorrow.db.DbConnector;
|
||||||
|
import de.katho.kBorrow.gui.ArticleInspectFrame;
|
||||||
|
|
||||||
|
public class ArticleInspectTableButton extends TableButton {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -2591133864537097893L;
|
||||||
|
|
||||||
|
public ArticleInspectTableButton(String pLabel, final JTable pTable, final DbConnector dbCon, final HashMap<String, Object> pModels) throws IOException {
|
||||||
|
super(pLabel);
|
||||||
|
URL url = Main.class.getResource("/icons/system-search.png");
|
||||||
|
ImageIcon icon = new ImageIcon(url);
|
||||||
|
|
||||||
|
buttonE.setIcon(icon);
|
||||||
|
buttonR.setIcon(icon);
|
||||||
|
|
||||||
|
buttonE.addActionListener(new ActionListener(){
|
||||||
|
public void actionPerformed(ActionEvent e){
|
||||||
|
fireEditingStopped();
|
||||||
|
|
||||||
|
int row = pTable.getSelectedRow();
|
||||||
|
|
||||||
|
new ArticleInspectFrame(row, dbCon, pModels);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
93
src/de/katho/kBorrow/models/ArticleInspectTableModel.java
Normal file
93
src/de/katho/kBorrow/models/ArticleInspectTableModel.java
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
package de.katho.kBorrow.models;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.data.KArticle;
|
||||||
|
import de.katho.kBorrow.data.KLender;
|
||||||
|
import de.katho.kBorrow.data.KLending;
|
||||||
|
import de.katho.kBorrow.data.KUser;
|
||||||
|
import de.katho.kBorrow.db.DbConnector;
|
||||||
|
|
||||||
|
public class ArticleInspectTableModel extends AbstractTableModel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 2293157709447086998L;
|
||||||
|
private String[] header;
|
||||||
|
private ArrayList<KLending> data;
|
||||||
|
private DbConnector dbCon;
|
||||||
|
private KArticle article;
|
||||||
|
private ArticleTableModel articleModel;
|
||||||
|
private UserTableModel userModel;
|
||||||
|
private LenderModel lenderModel;
|
||||||
|
|
||||||
|
|
||||||
|
public ArticleInspectTableModel(int pRow, DbConnector pDbCon, HashMap<String, Object> pModels){
|
||||||
|
header = new String[] {"ID", "Verliehen von:", "Ausgeliehen an:", "Ausleihdatum", "Vor. R<>ckgabe", "R<EFBFBD>ckgabe"};
|
||||||
|
dbCon = pDbCon;
|
||||||
|
articleModel = (ArticleTableModel)pModels.get("articletablemodel");
|
||||||
|
userModel = (UserTableModel)pModels.get("usertablemodel");
|
||||||
|
lenderModel = (LenderModel)pModels.get("lendermodel");
|
||||||
|
|
||||||
|
article = articleModel.getArticleByRow(pRow);
|
||||||
|
|
||||||
|
updateModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateModel() {
|
||||||
|
data = dbCon.getLendingListForArticle(article.getId());
|
||||||
|
fireTableDataChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getColumnCount() {
|
||||||
|
return header.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColumnName(int col){
|
||||||
|
return header[col];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRowCount() {
|
||||||
|
return data.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCellEditable(int pRow, int pCol){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getValueAt(int row, int col) {
|
||||||
|
switch(col){
|
||||||
|
case 0:
|
||||||
|
return data.get(row).getId();
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
int uid = data.get(row).getUserId();
|
||||||
|
KUser user = userModel.getUserById(uid);
|
||||||
|
|
||||||
|
return user.getName()+" "+user.getSurname();
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
int lid = data.get(row).getLenderId();
|
||||||
|
KLender lender = lenderModel.getLenderById(lid);
|
||||||
|
|
||||||
|
return lender.getName()+" "+lender.getSurname()+" ("+lender.getStudentnumber()+")";
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
return data.get(row).getStartDate();
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
return data.get(row).getExpectedEndDate();
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
return data.get(row).getEndDate();
|
||||||
|
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ public class ArticleTableModel extends AbstractTableModel {
|
|||||||
protected ArrayList<KArticle> data = new ArrayList<KArticle>();
|
protected ArrayList<KArticle> data = new ArrayList<KArticle>();
|
||||||
|
|
||||||
public ArticleTableModel(DbConnector pDbCon){
|
public ArticleTableModel(DbConnector pDbCon){
|
||||||
header = new String [] {"ID", "Artikelname", "Artikelbeschreibung", "", ""};
|
header = new String [] {"ID", "Artikelname", "Artikelbeschreibung", "", "", ""};
|
||||||
this.dbCon = pDbCon;
|
this.dbCon = pDbCon;
|
||||||
this.updateModel();
|
this.updateModel();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user