Einige weitere Arbeiten an den notwendigen Klassen zum Erstellen und
Bearbeiten von Artikeln.
This commit is contained in:
@@ -38,21 +38,11 @@ public class Main {
|
||||
this.dbCon = new SqlConnector();
|
||||
}
|
||||
try {
|
||||
MainWindow window = new MainWindow(this.dbCon);
|
||||
new MainWindow(this.dbCon);
|
||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
/*EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
MainWindow window = new MainWindow((Main)this);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,16 +65,15 @@ public class ArticleTableModel extends AbstractTableModel {
|
||||
}
|
||||
|
||||
public int getArticleId(int row) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
return this.data.get(row).getId();
|
||||
}
|
||||
|
||||
public String getArticleName(int pRow){
|
||||
return "";
|
||||
return this.data.get(pRow).getName();
|
||||
}
|
||||
|
||||
public String getArticleDescription(int pRow){
|
||||
return null;
|
||||
return this.data.get(pRow).getDescription();
|
||||
}
|
||||
|
||||
public void deleteArticle(int id) {
|
||||
@@ -82,4 +81,14 @@ public class ArticleTableModel extends AbstractTableModel {
|
||||
|
||||
}
|
||||
|
||||
public int createArticle(String pName, String pDesc) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int editArticle(int pId, String pName, String pDesc) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ public class MainWindow implements ActionListener {
|
||||
private DbConnector dbCon;
|
||||
private boolean userModeEdit = false;
|
||||
private boolean articleModeEdit = false;
|
||||
private int editId;
|
||||
private int userEditId;
|
||||
private int articleEditId;
|
||||
|
||||
private JFrame frame;
|
||||
private JTabbedPane tabbedPane;
|
||||
@@ -62,7 +63,7 @@ public class MainWindow implements ActionListener {
|
||||
private JButton btnArticleSave;
|
||||
private JButton btnArticleCancel;
|
||||
private JTextArea textAreaArticleDescription;
|
||||
|
||||
private JLabel lblArticleStatus;
|
||||
|
||||
|
||||
/**
|
||||
@@ -147,7 +148,7 @@ public class MainWindow implements ActionListener {
|
||||
this.textAreaArticleDescription = new JTextArea(5, 30);
|
||||
this.textAreaArticleDescription.setFont(new Font("Tahoma", Font.PLAIN, 11));
|
||||
this.textAreaArticleDescription.setLineWrap(true);
|
||||
this.textAreaArticleDescription.setBounds(90, 59, 250, 100);
|
||||
this.textAreaArticleDescription.setBounds(90, 59, 250, 80);
|
||||
this.textAreaArticleDescription.setBorder(BorderFactory.createEtchedBorder());
|
||||
panelArticleEdit.add(this.textAreaArticleDescription);
|
||||
|
||||
@@ -161,6 +162,10 @@ public class MainWindow implements ActionListener {
|
||||
this.btnArticleCancel.setBounds(490, 102, 89, 23);
|
||||
panelArticleEdit.add(this.btnArticleCancel);
|
||||
|
||||
this.lblArticleStatus = new JLabel("");
|
||||
lblArticleStatus.setBounds(90, 145, 46, 14);
|
||||
panelArticleEdit.add(lblArticleStatus);
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -232,20 +237,31 @@ public class MainWindow implements ActionListener {
|
||||
|
||||
public void setModeEditUser(int pId, String pName, String pSurname){
|
||||
this.userModeEdit = true;
|
||||
this.editId = pId;
|
||||
this.userEditId = pId;
|
||||
this.textFieldUserName.setText(pName);
|
||||
this.textFieldUserSurname.setText(pSurname);
|
||||
}
|
||||
|
||||
public void setModeEditArticle(int articleId, String articleName, String articleDescription) {
|
||||
this.articleModeEdit = true;
|
||||
this.articleEditId = articleId;
|
||||
this.textFieldArticleName.setText(articleName);
|
||||
this.textAreaArticleDescription.setText(articleDescription);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
/**
|
||||
* Aktionen f<>r den Button "Benutzer speichern"
|
||||
*/
|
||||
if(e.getSource() == this.btnUserSave){
|
||||
if(this.userModeEdit){
|
||||
int re = this.userTableModel.editUser(this.editId, this.textFieldUserName.getText(), this.textFieldUserSurname.getText());
|
||||
int re = this.userTableModel.editUser(this.userEditId, this.textFieldUserName.getText(), this.textFieldUserSurname.getText());
|
||||
|
||||
switch(re){
|
||||
case 0:
|
||||
this.lblUserStatus.setText("Benutzer-ID \""+this.editId+"\" erfolgreich bearbeitet.");
|
||||
this.lblUserStatus.setText("Benutzer-ID \""+this.userEditId+"\" erfolgreich bearbeitet.");
|
||||
this.textFieldUserName.setText("");
|
||||
this.textFieldUserSurname.setText("");
|
||||
break;
|
||||
@@ -263,7 +279,7 @@ public class MainWindow implements ActionListener {
|
||||
}
|
||||
|
||||
this.userModeEdit = false;
|
||||
this.editId = 0;
|
||||
this.userEditId = -1;
|
||||
}
|
||||
else {
|
||||
int re = this.userTableModel.createUser(this.textFieldUserName.getText(), this.textFieldUserSurname.getText());
|
||||
@@ -287,22 +303,76 @@ public class MainWindow implements ActionListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktionen f<>r den Button "Artikel speichern"
|
||||
*/
|
||||
if(e.getSource() == this.btnArticleSave){
|
||||
if(this.userModeEdit){
|
||||
int re = this.articleTableModel.editArticle(this.articleEditId, this.textFieldArticleName.getText(), this.textAreaArticleDescription.getText());
|
||||
|
||||
switch(re){
|
||||
case 0:
|
||||
this.lblArticleStatus.setText("Artikel-ID \""+this.articleEditId+"\" erfolgreich bearbeitet.");
|
||||
this.textFieldArticleName.setText("");
|
||||
this.textAreaArticleDescription.setText("");
|
||||
break;
|
||||
|
||||
case 1:
|
||||
this.lblArticleStatus.setText("SQL-Fehler. Artikel konnte nicht bearbeitet werden.");
|
||||
this.textFieldArticleName.setText("");
|
||||
this.textAreaArticleDescription.setText("");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
this.lblArticleStatus.setText("Artikelname muss ausgef<65>llt sein.");
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
this.articleModeEdit = false;
|
||||
this.articleEditId = -1;
|
||||
}
|
||||
|
||||
else {
|
||||
int re = this.articleTableModel.createArticle(this.textFieldArticleName.getText(), this.textAreaArticleDescription.getText());
|
||||
|
||||
switch(re){
|
||||
case 0:
|
||||
this.lblArticleStatus.setText("Artikel \""+this.textFieldArticleName.getText()+"\" erfolgreich hinzugef<65>gt.");
|
||||
this.textFieldArticleName.setText("");
|
||||
this.textAreaArticleDescription.setText("");
|
||||
break;
|
||||
|
||||
case 1:
|
||||
this.lblArticleStatus.setText("SQL-Fehler. Artikel konnte nicht erstellt werden.");
|
||||
this.textFieldArticleName.setText("");
|
||||
this.textAreaArticleDescription.setText("");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
this.lblArticleStatus.setText("Es muss ein Artikelname vergeben werden");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktionen f<>r den Button "Benutzer abbrechen"
|
||||
*/
|
||||
if(e.getSource() == this.btnUserCancel){
|
||||
this.userModeEdit = false;
|
||||
this.textFieldUserName.setText("");
|
||||
this.textFieldUserSurname.setText("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktionen f<>r den Button "Artikel abbrechen"
|
||||
*/
|
||||
if(e.getSource() == this.btnArticleCancel){
|
||||
this.articleModeEdit = false;
|
||||
this.textFieldArticleName.setText("");
|
||||
this.textAreaArticleDescription.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
public void setModeEditArticle(int articleId, String articleName,
|
||||
String articleDescription) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,13 +14,10 @@ public class ArticleEditTableButton extends TableButton {
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -5902626427691636902L;
|
||||
private MainWindow mainwindow;
|
||||
|
||||
public ArticleEditTableButton(String pLabel, JTable pTable, MainWindow pMainwindow) {
|
||||
public ArticleEditTableButton(String pLabel, JTable pTable, final MainWindow pMainWindow) {
|
||||
super(pLabel, pTable);
|
||||
|
||||
this.mainwindow = pMainwindow;
|
||||
|
||||
this.buttonE.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
fireEditingStopped();
|
||||
@@ -28,7 +25,7 @@ public class ArticleEditTableButton extends TableButton {
|
||||
ArticleTableModel model = (ArticleTableModel) table.getModel();
|
||||
int row = table.getSelectedRow();
|
||||
|
||||
mainwindow.setModeEditArticle(model.getArticleId(row), model.getArticleName(row), model.getArticleDescription(row));
|
||||
pMainWindow.setModeEditArticle(model.getArticleId(row), model.getArticleName(row), model.getArticleDescription(row));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -14,14 +14,10 @@ public class UserEditTableButton extends TableButton {
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -886584066497429394L;
|
||||
|
||||
private MainWindow mainwindow;
|
||||
|
||||
public UserEditTableButton(String pLabel, JTable pTable, MainWindow pMainWindow){
|
||||
public UserEditTableButton(String pLabel, JTable pTable, final MainWindow pMainWindow){
|
||||
super(pLabel, pTable);
|
||||
|
||||
this.mainwindow = pMainWindow;
|
||||
|
||||
|
||||
this.buttonE.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
fireEditingStopped();
|
||||
@@ -29,7 +25,7 @@ public class UserEditTableButton extends TableButton {
|
||||
UserTableModel model = (UserTableModel) table.getModel();
|
||||
int row = table.getSelectedRow();
|
||||
|
||||
mainwindow.setModeEditUser(model.getUserId(row), model.getUserName(row), model.getUserSurname(row));
|
||||
pMainWindow.setModeEditUser(model.getUserId(row), model.getUserName(row), model.getUserSurname(row));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user