Compare commits
9 Commits
issue#5
...
#14_datamo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c94643638 | ||
|
|
c5638e697f | ||
|
|
401d68cf47 | ||
|
|
ecb496f35b | ||
|
|
102a46428b | ||
|
|
831d3bda09 | ||
|
|
428806c5b9 | ||
|
|
6dae70df05 | ||
|
|
0d02edec31 |
@@ -6,5 +6,6 @@
|
|||||||
<classpathentry kind="lib" path="lib/mysql-connector-java-5.1.32-bin.jar"/>
|
<classpathentry kind="lib" path="lib/mysql-connector-java-5.1.32-bin.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/sqlite-jdbc-3.7.2.jar"/>
|
<classpathentry kind="lib" path="lib/sqlite-jdbc-3.7.2.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/swingx-all-1.6.4.jar"/>
|
<classpathentry kind="lib" path="lib/swingx-all-1.6.4.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/pdfbox-app-1.8.7.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
@@ -13,3 +13,6 @@ This software uses the Oracle MySQL Java Connector (http://dev.mysql.com/downloa
|
|||||||
### Tango Desktop Project
|
### Tango Desktop Project
|
||||||
This software also uses icons provided by the Tango Desktop Project (http://tango.freedesktop.org/).
|
This software also uses icons provided by the Tango Desktop Project (http://tango.freedesktop.org/).
|
||||||
License will follow!
|
License will follow!
|
||||||
|
|
||||||
|
### Apache PDFBox
|
||||||
|
This software uses the Apache PDFBox (https://pdfbox.apache.org/) package which is published under Apache License v2.0 (http://www.apache.org/licenses/LICENSE-2.0);
|
||||||
174
kBorrow.ucls
174
kBorrow.ucls
@@ -10,8 +10,8 @@
|
|||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
</display>
|
</display>
|
||||||
</class>
|
</class>
|
||||||
<interface id="2" language="java" name="de.katho.kBorrow.db.DbConnector" project="kBorrow"
|
<interface id="2" language="java" name="de.katho.kBorrow.interfaces.DbConnector" project="kBorrow"
|
||||||
file="/kBorrow/src/de/katho/kBorrow/db/DbConnector.java" binary="false" corner="BOTTOM_RIGHT">
|
file="/kBorrow/src/de/katho/kBorrow/interfaces/DbConnector.java" binary="false" corner="BOTTOM_RIGHT">
|
||||||
<position height="225" width="217" x="1048" y="1066"/>
|
<position height="225" width="217" x="1048" y="1066"/>
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
sort-features="false" accessors="true" visibility="true">
|
sort-features="false" accessors="true" visibility="true">
|
||||||
@@ -19,8 +19,8 @@
|
|||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
</display>
|
</display>
|
||||||
</interface>
|
</interface>
|
||||||
<class id="3" language="java" name="de.katho.kBorrow.data.KUser" project="kBorrow"
|
<class id="3" language="java" name="de.katho.kBorrow.data.objects.KUser" project="kBorrow"
|
||||||
file="/kBorrow/src/de/katho/kBorrow/data/KUser.java" binary="false" corner="BOTTOM_RIGHT">
|
file="/kBorrow/src/de/katho/kBorrow/data/objects/KUser.java" binary="false" corner="BOTTOM_RIGHT">
|
||||||
<position height="225" width="143" x="724" y="1066"/>
|
<position height="225" width="143" x="724" y="1066"/>
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
sort-features="false" accessors="true" visibility="true">
|
sort-features="false" accessors="true" visibility="true">
|
||||||
@@ -163,8 +163,8 @@
|
|||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
</display>
|
</display>
|
||||||
</class>
|
</class>
|
||||||
<class id="19" language="java" name="de.katho.kBorrow.data.KArticle" project="kBorrow"
|
<class id="19" language="java" name="de.katho.kBorrow.data.objects.KArticle" project="kBorrow"
|
||||||
file="/kBorrow/src/de/katho/kBorrow/data/KArticle.java" binary="false" corner="BOTTOM_RIGHT">
|
file="/kBorrow/src/de/katho/kBorrow/data/objects/KArticle.java" binary="false" corner="BOTTOM_RIGHT">
|
||||||
<position height="225" width="154" x="2701" y="1066"/>
|
<position height="225" width="154" x="2701" y="1066"/>
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
sort-features="false" accessors="true" visibility="true">
|
sort-features="false" accessors="true" visibility="true">
|
||||||
@@ -181,126 +181,114 @@
|
|||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
</display>
|
</display>
|
||||||
</class>
|
</class>
|
||||||
<association id="21">
|
<realization id="21">
|
||||||
<end type="SOURCE" refId="17" navigable="false">
|
|
||||||
<attribute id="22" name="set">
|
|
||||||
<position height="0" width="0" x="0" y="0"/>
|
|
||||||
</attribute>
|
|
||||||
<multiplicity id="23" minimum="0" maximum="1">
|
|
||||||
<position height="0" width="0" x="0" y="0"/>
|
|
||||||
</multiplicity>
|
|
||||||
</end>
|
|
||||||
<end type="TARGET" refId="1" navigable="true"/>
|
|
||||||
<display labels="true" multiplicity="true"/>
|
|
||||||
</association>
|
|
||||||
<association id="24">
|
|
||||||
<bendpoint x="1017" y="639"/>
|
|
||||||
<end type="SOURCE" refId="4" navigable="false">
|
|
||||||
<attribute id="25" name="dbCon">
|
|
||||||
<position height="0" width="0" x="0" y="0"/>
|
|
||||||
</attribute>
|
|
||||||
<multiplicity id="26" minimum="0" maximum="1">
|
|
||||||
<position height="0" width="0" x="0" y="0"/>
|
|
||||||
</multiplicity>
|
|
||||||
</end>
|
|
||||||
<end type="TARGET" refId="2" navigable="true"/>
|
|
||||||
<display labels="true" multiplicity="true"/>
|
|
||||||
</association>
|
|
||||||
<association id="27">
|
|
||||||
<bendpoint x="2798" y="639"/>
|
|
||||||
<end type="SOURCE" refId="10" navigable="false">
|
|
||||||
<attribute id="28" name="dbCon">
|
|
||||||
<position height="0" width="0" x="0" y="0"/>
|
|
||||||
</attribute>
|
|
||||||
<multiplicity id="29" minimum="0" maximum="1">
|
|
||||||
<position height="0" width="0" x="0" y="0"/>
|
|
||||||
</multiplicity>
|
|
||||||
</end>
|
|
||||||
<end type="TARGET" refId="2" navigable="true"/>
|
|
||||||
<display labels="true" multiplicity="true"/>
|
|
||||||
</association>
|
|
||||||
<generalization id="30">
|
|
||||||
<end type="SOURCE" refId="13"/>
|
|
||||||
<end type="TARGET" refId="12"/>
|
|
||||||
</generalization>
|
|
||||||
<realization id="31">
|
|
||||||
<end type="SOURCE" refId="18"/>
|
|
||||||
<end type="TARGET" refId="2"/>
|
|
||||||
</realization>
|
|
||||||
<realization id="32">
|
|
||||||
<end type="SOURCE" refId="9"/>
|
<end type="SOURCE" refId="9"/>
|
||||||
<end type="TARGET" refId="2"/>
|
<end type="TARGET" refId="2"/>
|
||||||
</realization>
|
</realization>
|
||||||
<association id="33">
|
<generalization id="22">
|
||||||
<end type="SOURCE" refId="5" navigable="false">
|
<end type="SOURCE" refId="6"/>
|
||||||
<attribute id="34" name="data">
|
<end type="TARGET" refId="12"/>
|
||||||
|
</generalization>
|
||||||
|
<association id="23">
|
||||||
|
<bendpoint x="2798" y="639"/>
|
||||||
|
<end type="SOURCE" refId="10" navigable="false">
|
||||||
|
<attribute id="24" name="dbCon">
|
||||||
<position height="0" width="0" x="0" y="0"/>
|
<position height="0" width="0" x="0" y="0"/>
|
||||||
</attribute>
|
</attribute>
|
||||||
<multiplicity id="35" minimum="0" maximum="2147483647">
|
<multiplicity id="25" minimum="0" maximum="1">
|
||||||
|
<position height="0" width="0" x="0" y="0"/>
|
||||||
|
</multiplicity>
|
||||||
|
</end>
|
||||||
|
<end type="TARGET" refId="2" navigable="true"/>
|
||||||
|
<display labels="true" multiplicity="true"/>
|
||||||
|
</association>
|
||||||
|
<realization id="26">
|
||||||
|
<end type="SOURCE" refId="18"/>
|
||||||
|
<end type="TARGET" refId="2"/>
|
||||||
|
</realization>
|
||||||
|
<association id="27">
|
||||||
|
<end type="SOURCE" refId="5" navigable="false">
|
||||||
|
<attribute id="28" name="data">
|
||||||
|
<position height="0" width="0" x="0" y="0"/>
|
||||||
|
</attribute>
|
||||||
|
<multiplicity id="29" minimum="0" maximum="2147483647">
|
||||||
<position height="0" width="0" x="0" y="0"/>
|
<position height="0" width="0" x="0" y="0"/>
|
||||||
</multiplicity>
|
</multiplicity>
|
||||||
</end>
|
</end>
|
||||||
<end type="TARGET" refId="19" navigable="true"/>
|
<end type="TARGET" refId="19" navigable="true"/>
|
||||||
<display labels="true" multiplicity="true"/>
|
<display labels="true" multiplicity="true"/>
|
||||||
</association>
|
</association>
|
||||||
<generalization id="36">
|
<association id="30">
|
||||||
<end type="SOURCE" refId="6"/>
|
<bendpoint x="1017" y="639"/>
|
||||||
<end type="TARGET" refId="12"/>
|
<end type="SOURCE" refId="4" navigable="false">
|
||||||
</generalization>
|
<attribute id="31" name="dbCon">
|
||||||
<association id="37">
|
|
||||||
<end type="SOURCE" refId="14" navigable="false">
|
|
||||||
<attribute id="38" name="dbCon">
|
|
||||||
<position height="0" width="0" x="0" y="0"/>
|
<position height="0" width="0" x="0" y="0"/>
|
||||||
</attribute>
|
</attribute>
|
||||||
<multiplicity id="39" minimum="0" maximum="1">
|
<multiplicity id="32" minimum="0" maximum="1">
|
||||||
<position height="0" width="0" x="0" y="0"/>
|
<position height="0" width="0" x="0" y="0"/>
|
||||||
</multiplicity>
|
</multiplicity>
|
||||||
</end>
|
</end>
|
||||||
<end type="TARGET" refId="2" navigable="true"/>
|
<end type="TARGET" refId="2" navigable="true"/>
|
||||||
<display labels="true" multiplicity="true"/>
|
<display labels="true" multiplicity="true"/>
|
||||||
</association>
|
</association>
|
||||||
<association id="40">
|
<generalization id="33">
|
||||||
<end type="SOURCE" refId="14" navigable="false">
|
<end type="SOURCE" refId="13"/>
|
||||||
<attribute id="41" name="data">
|
<end type="TARGET" refId="12"/>
|
||||||
|
</generalization>
|
||||||
|
<generalization id="34">
|
||||||
|
<end type="SOURCE" refId="8"/>
|
||||||
|
<end type="TARGET" refId="12"/>
|
||||||
|
</generalization>
|
||||||
|
<association id="35">
|
||||||
|
<end type="SOURCE" refId="5" navigable="false">
|
||||||
|
<attribute id="36" name="dbCon">
|
||||||
<position height="0" width="0" x="0" y="0"/>
|
<position height="0" width="0" x="0" y="0"/>
|
||||||
</attribute>
|
</attribute>
|
||||||
<multiplicity id="42" minimum="0" maximum="2147483647">
|
<multiplicity id="37" minimum="0" maximum="1">
|
||||||
|
<position height="0" width="0" x="0" y="0"/>
|
||||||
|
</multiplicity>
|
||||||
|
</end>
|
||||||
|
<end type="TARGET" refId="2" navigable="true"/>
|
||||||
|
<display labels="true" multiplicity="true"/>
|
||||||
|
</association>
|
||||||
|
<generalization id="38">
|
||||||
|
<end type="SOURCE" refId="7"/>
|
||||||
|
<end type="TARGET" refId="12"/>
|
||||||
|
</generalization>
|
||||||
|
<association id="39">
|
||||||
|
<end type="SOURCE" refId="17" navigable="false">
|
||||||
|
<attribute id="40" name="set">
|
||||||
|
<position height="0" width="0" x="0" y="0"/>
|
||||||
|
</attribute>
|
||||||
|
<multiplicity id="41" minimum="0" maximum="1">
|
||||||
|
<position height="0" width="0" x="0" y="0"/>
|
||||||
|
</multiplicity>
|
||||||
|
</end>
|
||||||
|
<end type="TARGET" refId="1" navigable="true"/>
|
||||||
|
<display labels="true" multiplicity="true"/>
|
||||||
|
</association>
|
||||||
|
<association id="42">
|
||||||
|
<end type="SOURCE" refId="14" navigable="false">
|
||||||
|
<attribute id="43" name="data">
|
||||||
|
<position height="0" width="0" x="0" y="0"/>
|
||||||
|
</attribute>
|
||||||
|
<multiplicity id="44" minimum="0" maximum="2147483647">
|
||||||
<position height="0" width="0" x="0" y="0"/>
|
<position height="0" width="0" x="0" y="0"/>
|
||||||
</multiplicity>
|
</multiplicity>
|
||||||
</end>
|
</end>
|
||||||
<end type="TARGET" refId="3" navigable="true"/>
|
<end type="TARGET" refId="3" navigable="true"/>
|
||||||
<display labels="true" multiplicity="true"/>
|
<display labels="true" multiplicity="true"/>
|
||||||
</association>
|
</association>
|
||||||
<generalization id="43">
|
<generalization id="45">
|
||||||
<end type="SOURCE" refId="7"/>
|
|
||||||
<end type="TARGET" refId="12"/>
|
|
||||||
</generalization>
|
|
||||||
<association id="44">
|
|
||||||
<end type="SOURCE" refId="5" navigable="false">
|
|
||||||
<attribute id="45" name="dbCon">
|
|
||||||
<position height="0" width="0" x="0" y="0"/>
|
|
||||||
</attribute>
|
|
||||||
<multiplicity id="46" minimum="0" maximum="1">
|
|
||||||
<position height="0" width="0" x="0" y="0"/>
|
|
||||||
</multiplicity>
|
|
||||||
</end>
|
|
||||||
<end type="TARGET" refId="2" navigable="true"/>
|
|
||||||
<display labels="true" multiplicity="true"/>
|
|
||||||
</association>
|
|
||||||
<generalization id="47">
|
|
||||||
<end type="SOURCE" refId="16"/>
|
<end type="SOURCE" refId="16"/>
|
||||||
<end type="TARGET" refId="12"/>
|
<end type="TARGET" refId="12"/>
|
||||||
</generalization>
|
</generalization>
|
||||||
<generalization id="48">
|
<association id="46">
|
||||||
<end type="SOURCE" refId="8"/>
|
|
||||||
<end type="TARGET" refId="12"/>
|
|
||||||
</generalization>
|
|
||||||
<association id="49">
|
|
||||||
<end type="SOURCE" refId="17" navigable="false">
|
<end type="SOURCE" refId="17" navigable="false">
|
||||||
<attribute id="50" name="dbCon">
|
<attribute id="47" name="dbCon">
|
||||||
<position height="0" width="0" x="0" y="0"/>
|
<position height="0" width="0" x="0" y="0"/>
|
||||||
</attribute>
|
</attribute>
|
||||||
<multiplicity id="51" minimum="0" maximum="1">
|
<multiplicity id="48" minimum="0" maximum="1">
|
||||||
<position height="0" width="0" x="0" y="0"/>
|
<position height="0" width="0" x="0" y="0"/>
|
||||||
</multiplicity>
|
</multiplicity>
|
||||||
</end>
|
</end>
|
||||||
|
|||||||
BIN
lib/pdfbox-app-1.8.7.jar
Normal file
BIN
lib/pdfbox-app-1.8.7.jar
Normal file
Binary file not shown.
49
src/de/katho/kBorrow/KLogger.java
Normal file
49
src/de/katho/kBorrow/KLogger.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package de.katho.kBorrow;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.logging.FileHandler;
|
||||||
|
import java.util.logging.Formatter;
|
||||||
|
import java.util.logging.Handler;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import java.util.logging.SimpleFormatter;
|
||||||
|
|
||||||
|
public class KLogger {
|
||||||
|
private static Logger logger;
|
||||||
|
private Handler fileHandler;
|
||||||
|
private Formatter plainText;
|
||||||
|
|
||||||
|
|
||||||
|
private KLogger() throws IOException {
|
||||||
|
logger = Logger.getLogger(Util.class.getName());
|
||||||
|
String fDir = System.getProperty("user.home")+"/kBorrow";
|
||||||
|
String fName = "kBorrow.log";
|
||||||
|
File dir = new File(fDir);
|
||||||
|
File file = new File(fDir+"/"+fName);
|
||||||
|
|
||||||
|
if(!dir.isDirectory()) dir.mkdir();
|
||||||
|
if(!file.isFile()) file.createNewFile();
|
||||||
|
|
||||||
|
fileHandler = new FileHandler(fDir+"/"+fName, true);
|
||||||
|
plainText = new SimpleFormatter();
|
||||||
|
fileHandler.setFormatter(plainText);
|
||||||
|
logger.addHandler(fileHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Logger getLogger(){
|
||||||
|
if(logger == null){
|
||||||
|
try{
|
||||||
|
new KLogger();
|
||||||
|
} catch(IOException e){
|
||||||
|
Util.showError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void log(Level pLevel, String pMsg, Exception e){
|
||||||
|
getLogger().log(pLevel, pMsg, e);
|
||||||
|
System.out.println(pMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,13 +15,13 @@ public class Settings {
|
|||||||
private String filePath;
|
private String filePath;
|
||||||
private String fileName;
|
private String fileName;
|
||||||
|
|
||||||
public Settings() {
|
public Settings() throws Exception {
|
||||||
this.properties = new Properties();
|
properties = new Properties();
|
||||||
this.filePath = System.getProperty("user.home")+"/kBorrow";
|
filePath = System.getProperty("user.home")+"/kBorrow";
|
||||||
this.fileName = "Settings.cfg";
|
fileName = "Settings.cfg";
|
||||||
|
|
||||||
if(!this.filePathHasValidConfig()){
|
if(!filePathHasValidConfig()){
|
||||||
this.createDefaultConfig();
|
createDefaultConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,14 +31,14 @@ public class Settings {
|
|||||||
*/
|
*/
|
||||||
private boolean filePathHasValidConfig(){
|
private boolean filePathHasValidConfig(){
|
||||||
try {
|
try {
|
||||||
InputStream in = new FileInputStream(this.filePath+"/"+this.fileName);
|
InputStream in = new FileInputStream(filePath+"/"+fileName);
|
||||||
this.properties = new Properties();
|
properties = new Properties();
|
||||||
|
|
||||||
this.properties.load(in);
|
properties.load(in);
|
||||||
|
|
||||||
// Check if the properties file holds certain keys and values.
|
// Check if the properties file holds certain keys and values.
|
||||||
if( (this.properties.containsKey("dBType") && this.properties.containsValue("sqlite") && this.properties.containsKey("sqlitePath")) ||
|
if( (properties.containsKey("dBType") && properties.containsValue("sqlite") && properties.containsKey("sqlitePath")) ||
|
||||||
(this.properties.contains("dbType") && this.properties.containsValue("mysql") && this.properties.containsKey("mysqlDB") && this.properties.containsKey("mysqlHost") && this.properties.containsKey("mysqlUser") && this.properties.containsKey("mysqlPass"))) {
|
(properties.contains("dbType") && properties.containsValue("mysql") && properties.containsKey("mysqlDB") && properties.containsKey("mysqlHost") && properties.containsKey("mysqlUser") && properties.containsKey("mysqlPass"))) {
|
||||||
in.close();
|
in.close();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -49,21 +49,23 @@ public class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
|
Util.showWarning(new Exception("Kann die Settingsdatei nicht finden. Versuche, eine neue zu erzeugen.", e));
|
||||||
return false;
|
return false;
|
||||||
} catch (IOException e){
|
} catch (IOException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a default config to the config file.
|
* Writes a default config to the config file.
|
||||||
|
* @throws Exception
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private void createDefaultConfig() {
|
private void createDefaultConfig() throws Exception {
|
||||||
try {
|
try {
|
||||||
File dir = new File(this.filePath);
|
File dir = new File(filePath);
|
||||||
File file = new File(this.filePath+"/"+this.fileName);
|
File file = new File(filePath+"/"+fileName);
|
||||||
if(!dir.isDirectory()) dir.mkdir();
|
if(!dir.isDirectory()) dir.mkdir();
|
||||||
if(!file.isFile()) file.createNewFile();
|
if(!file.isFile()) file.createNewFile();
|
||||||
else {
|
else {
|
||||||
@@ -73,39 +75,40 @@ public class Settings {
|
|||||||
|
|
||||||
OutputStream os = new FileOutputStream(this.filePath+"/"+this.fileName);
|
OutputStream os = new FileOutputStream(this.filePath+"/"+this.fileName);
|
||||||
|
|
||||||
this.properties.put("dBType", "sqlite");
|
properties.put("dBType", "sqlite");
|
||||||
this.properties.put("sqlitePath",System.getProperty("user.home").replace("\\", "/")+"/kBorrow/kBorrow.db" );
|
properties.put("sqlitePath",System.getProperty("user.home").replace("\\", "/")+"/kBorrow/kBorrow.db" );
|
||||||
this.properties.store(os, null);
|
properties.store(os, null);
|
||||||
|
|
||||||
os.close();
|
os.close();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
System.out.println("I couldn't find the specified properties file while trying to create a default config.");
|
throw new Exception("I couldn't find the specified properties file while trying to create a default config.", e);
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("I had problems, writing to the properties file while trying to create a default config.");
|
throw new Exception("I had problems writing to the properties file while trying to create a default config.", e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProperty(String pKey){
|
public String getProperty(String pKey){
|
||||||
return this.properties.getProperty(pKey);
|
if(properties.containsKey(pKey)) return properties.getProperty(pKey);
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProperty(String pKey, String pValue){
|
public void setProperty(String pKey, String pValue) throws IOException{
|
||||||
this.properties.put(pKey, pValue);
|
properties.put(pKey, pValue);
|
||||||
|
|
||||||
OutputStream os;
|
OutputStream os;
|
||||||
try {
|
try {
|
||||||
os = new FileOutputStream(this.filePath+"/"+this.fileName);
|
os = new FileOutputStream(this.filePath+"/"+this.fileName);
|
||||||
this.properties.store(os, null);
|
properties.store(os, null);
|
||||||
|
|
||||||
os.close();
|
os.close();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
System.out.println("I couldn't find the specified properties file while trying to write the config.");
|
throw new FileNotFoundException("I couldn't find the specified properties file while trying to write the config.");
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("I had problems, writing to the properties file while saving a setting.");
|
throw new IOException("I had problems, writing to the properties file while saving a setting.");
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSettingsDir(){
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,52 @@
|
|||||||
package de.katho.kBorrow;
|
package de.katho.kBorrow;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
|
import org.jdesktop.swingx.JXErrorPane;
|
||||||
|
import org.jdesktop.swingx.error.ErrorInfo;
|
||||||
|
|
||||||
|
public final class Util {
|
||||||
|
private static JFrame mainwindow;
|
||||||
|
|
||||||
public class Util {
|
|
||||||
public static String getCurrentDate(){
|
public static String getCurrentDate(){
|
||||||
DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
|
DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
|
|
||||||
return dateFormat.format(date);
|
return dateFormat.format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String generateRandomString(int length) {
|
||||||
|
char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
Random random = new Random();
|
||||||
|
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
char c = chars[random.nextInt(chars.length)];
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showWarning(Exception e){
|
||||||
|
KLogger.log(Level.WARNING, e.getMessage(), e);
|
||||||
|
ErrorInfo info = new ErrorInfo("Warnung", e.getMessage(), null, null, e, Level.WARNING, null);
|
||||||
|
JXErrorPane.showDialog(mainwindow, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showError(Exception e){
|
||||||
|
KLogger.log(Level.SEVERE, e.getMessage(), e);
|
||||||
|
ErrorInfo info = new ErrorInfo("Fehler", e.getMessage(), null, null, e, Level.SEVERE, null);
|
||||||
|
JXErrorPane.showDialog(mainwindow, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setMainWindow(JFrame p){
|
||||||
|
mainwindow = p;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,19 +2,18 @@ package de.katho.kBorrow.controller;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.data.KArticleModel;
|
||||||
import de.katho.kBorrow.models.ArticleTableModel;
|
import de.katho.kBorrow.data.objects.KArticle;
|
||||||
import de.katho.kBorrow.models.FreeArticleTableModel;
|
import de.katho.kBorrow.interfaces.DbConnector;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
|
|
||||||
public class ArticleController {
|
public class ArticleController {
|
||||||
private DbConnector dbCon;
|
private DbConnector dbCon;
|
||||||
private ArticleTableModel articleTableModel;
|
private KArticleModel kArticleModel;
|
||||||
private FreeArticleTableModel freeArticleTableModel;
|
|
||||||
|
|
||||||
public ArticleController(DbConnector pDbCon, HashMap<String, Object> pModels){
|
public ArticleController(DbConnector pDbCon, HashMap<String, KDataModel> models){
|
||||||
dbCon = pDbCon;
|
dbCon = pDbCon;
|
||||||
articleTableModel = (ArticleTableModel)pModels.get("articletablemodel");
|
kArticleModel = (KArticleModel)models.get("karticlemodel");
|
||||||
freeArticleTableModel = (FreeArticleTableModel)pModels.get("freearticletablemodel");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,8 +28,7 @@ public class ArticleController {
|
|||||||
public int createArticle(String pName, String pDesc) {
|
public int createArticle(String pName, String pDesc) {
|
||||||
int status = dbCon.createArticle(pName, pDesc);
|
int status = dbCon.createArticle(pName, pDesc);
|
||||||
|
|
||||||
articleTableModel.updateModel();
|
kArticleModel.updateModel();
|
||||||
freeArticleTableModel.updateModel();
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -49,8 +47,7 @@ public class ArticleController {
|
|||||||
int status = this.dbCon.editArticle(pId, pName, pDesc);
|
int status = this.dbCon.editArticle(pId, pName, pDesc);
|
||||||
|
|
||||||
if(status == 0){
|
if(status == 0){
|
||||||
articleTableModel.updateModel();
|
kArticleModel.updateModel();
|
||||||
freeArticleTableModel.updateModel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@@ -59,21 +56,19 @@ public class ArticleController {
|
|||||||
/**
|
/**
|
||||||
* L<>scht den Artikel mit der gegebenen ID in der Datenbank und aktualisiert die Tabelle.
|
* L<>scht den Artikel mit der gegebenen ID in der Datenbank und aktualisiert die Tabelle.
|
||||||
*
|
*
|
||||||
* @param pRow Row des Artikels, der gel<65>scht werden soll.
|
* @param pId ID des Artikels, der gel<65>scht werden soll.
|
||||||
* @return 0: Artikel konnte erfolgreich gel<65>scht werden
|
* @return 0: Artikel konnte erfolgreich gel<65>scht werden
|
||||||
* 1: Artikel konnte nicht gel<65>scht werden, unbekannter Fehler (SQL-Fehler)
|
* 1: Artikel konnte nicht gel<65>scht werden, unbekannter Fehler (SQL-Fehler)
|
||||||
* 2: Artikel konnte nicht gel<65>scht werden, weil er im Moment verliehen ist.
|
* 2: Artikel konnte nicht gel<65>scht werden, weil er im Moment verliehen ist.
|
||||||
*/
|
*/
|
||||||
public int deleteArticle(int pRow) {
|
public int deleteArticle(int pId) {
|
||||||
|
|
||||||
if(!articleTableModel.getArticleByRow(pRow).getIsFree()) return 2;
|
if(!((KArticle)kArticleModel.getElement(pId)).getIsFree()) return 2;
|
||||||
|
|
||||||
int id = articleTableModel.getArticleByRow(pRow).getId();
|
int returnCode = dbCon.deleteArticle(pId);
|
||||||
int returnCode = dbCon.deleteArticle(id);
|
|
||||||
|
|
||||||
if(returnCode == 0){
|
if(returnCode == 0){
|
||||||
articleTableModel.updateModel();
|
kArticleModel.updateModel();
|
||||||
freeArticleTableModel.updateModel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnCode;
|
return returnCode;
|
||||||
|
|||||||
@@ -3,38 +3,34 @@ package de.katho.kBorrow.controller;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import de.katho.kBorrow.Util;
|
import de.katho.kBorrow.Util;
|
||||||
import de.katho.kBorrow.data.KLending;
|
import de.katho.kBorrow.data.KArticleModel;
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.data.KLendingModel;
|
||||||
import de.katho.kBorrow.models.ArticleTableModel;
|
import de.katho.kBorrow.data.objects.KLending;
|
||||||
import de.katho.kBorrow.models.FreeArticleTableModel;
|
import de.katho.kBorrow.interfaces.DbConnector;
|
||||||
import de.katho.kBorrow.models.LendingTableModel;
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
|
|
||||||
public class ManageLendingsController {
|
public class ManageLendingsController {
|
||||||
|
|
||||||
private DbConnector dbCon;
|
private DbConnector dbCon;
|
||||||
private FreeArticleTableModel freeArticleTableModel;
|
private KArticleModel articleModel;
|
||||||
private ArticleTableModel articleTableModel;
|
private KLendingModel lendingModel;
|
||||||
private LendingTableModel lendingTableModel;
|
|
||||||
|
|
||||||
public ManageLendingsController(DbConnector pDbCon, HashMap<String, Object> pModels){
|
public ManageLendingsController(DbConnector pDbCon, HashMap<String, KDataModel> models){
|
||||||
dbCon = pDbCon;
|
dbCon = pDbCon;
|
||||||
|
|
||||||
freeArticleTableModel = (FreeArticleTableModel)pModels.get("freearticletablemodel");
|
articleModel = (KArticleModel)models.get("karticlemodel");
|
||||||
articleTableModel = (ArticleTableModel)pModels.get("articletablemodel");
|
lendingModel = (KLendingModel)models.get("klendingmodel");
|
||||||
lendingTableModel = (LendingTableModel)pModels.get("lendingtablemodel");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void returnLending(int pRow) {
|
public void returnLending(int pId) {
|
||||||
KLending lending = lendingTableModel.getLendingByRow(pRow);
|
KLending lending = lendingModel.getElement(pId);
|
||||||
|
|
||||||
int artId = lending.getArticleId();
|
int artId = lending.getArticleId();
|
||||||
int lendingId = lending.getId();
|
|
||||||
|
|
||||||
dbCon.returnLending(lendingId, artId, Util.getCurrentDate());
|
dbCon.returnLending(pId, artId, Util.getCurrentDate());
|
||||||
|
|
||||||
freeArticleTableModel.updateModel();
|
articleModel.updateModel();
|
||||||
articleTableModel.updateModel();
|
lendingModel.updateModel();
|
||||||
lendingTableModel.updateModel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,50 @@
|
|||||||
package de.katho.kBorrow.controller;
|
package de.katho.kBorrow.controller;
|
||||||
|
|
||||||
|
import org.apache.pdfbox.exceptions.COSVisitorException;
|
||||||
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
|
import org.apache.pdfbox.pdmodel.PDPage;
|
||||||
|
import org.apache.pdfbox.pdmodel.common.PDRectangle;
|
||||||
|
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
|
||||||
|
import org.apache.pdfbox.pdmodel.font.PDFont;
|
||||||
|
import org.apache.pdfbox.pdmodel.font.PDType1Font;
|
||||||
|
|
||||||
|
import java.awt.Desktop;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import de.katho.kBorrow.data.KLender;
|
import de.katho.kBorrow.Settings;
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.Util;
|
||||||
import de.katho.kBorrow.models.ArticleTableModel;
|
import de.katho.kBorrow.data.KArticleModel;
|
||||||
import de.katho.kBorrow.models.FreeArticleTableModel;
|
import de.katho.kBorrow.data.KLenderModel;
|
||||||
import de.katho.kBorrow.models.LenderModel;
|
import de.katho.kBorrow.data.KLendingModel;
|
||||||
import de.katho.kBorrow.models.LendingTableModel;
|
import de.katho.kBorrow.data.KUserModel;
|
||||||
import de.katho.kBorrow.models.UserListModel;
|
import de.katho.kBorrow.data.objects.KArticle;
|
||||||
|
import de.katho.kBorrow.data.objects.KLender;
|
||||||
|
import de.katho.kBorrow.data.objects.KLending;
|
||||||
|
import de.katho.kBorrow.data.objects.KUser;
|
||||||
|
import de.katho.kBorrow.interfaces.DbConnector;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
|
|
||||||
public class NewLendingController {
|
public class NewLendingController {
|
||||||
private DbConnector dbCon;
|
private DbConnector dbCon;
|
||||||
private UserListModel userListModel;
|
private KUserModel kUserModel;
|
||||||
private LenderModel lenderModel;
|
private KLenderModel kLenderModel;
|
||||||
private FreeArticleTableModel freeArticleModel;
|
private KArticleModel kArticleModel;
|
||||||
private LendingTableModel lendingTableModel;
|
private KLendingModel kLendingModel;
|
||||||
private ArticleTableModel articleTableModel;
|
private Settings settings;
|
||||||
|
|
||||||
public NewLendingController(DbConnector pDbCon, HashMap<String, Object> pModels){
|
public NewLendingController(DbConnector pDbCon, HashMap<String, KDataModel> models, final Settings pSettings){
|
||||||
dbCon = pDbCon;
|
dbCon = pDbCon;
|
||||||
userListModel = (UserListModel)pModels.get("userlistmodel");
|
kUserModel = (KUserModel)models.get("kusermodel");
|
||||||
lenderModel = (LenderModel)pModels.get("lendermodel");
|
kLenderModel = (KLenderModel)models.get("klendermodel");
|
||||||
freeArticleModel = (FreeArticleTableModel)pModels.get("freearticletablemodel");
|
kArticleModel = (KArticleModel)models.get("karticlemodel");
|
||||||
articleTableModel = (ArticleTableModel)pModels.get("articletablemodel");
|
kLendingModel = (KLendingModel)models.get("klendingmodel");
|
||||||
lendingTableModel = (LendingTableModel)pModels.get("lendingtablemodel");
|
settings = pSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,18 +57,19 @@ public class NewLendingController {
|
|||||||
* 4: Die gegebene Kombination aus Lender-Name, -Surname und -Studentnumber
|
* 4: Die gegebene Kombination aus Lender-Name, -Surname und -Studentnumber
|
||||||
* existiert mehrmals in der Datenbank. Das darf nicht sein und wirft daher einen Fehler!
|
* existiert mehrmals in der Datenbank. Das darf nicht sein und wirft daher einen Fehler!
|
||||||
* 5: Matrikelnummer muss eine Zahl sein!
|
* 5: Matrikelnummer muss eine Zahl sein!
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public int newLending(int pArtId, String pLName, String pLSurname, String pLSN, String pStartDate, Date pEstEndDate, String pUsername){
|
public int newLending(int pArtId, String pLName, String pLSurname, String pLSN, String pStartDate, Date pEstEndDate, String pUsername) throws Exception{
|
||||||
if(pArtId == -1 || pStartDate.isEmpty() || pEstEndDate == null || pLName.isEmpty() || pLSurname.isEmpty() || pUsername.isEmpty()) return 2;
|
if(pArtId == -1 || pStartDate.isEmpty() || pEstEndDate == null || pLName.isEmpty() || pLSurname.isEmpty() || pUsername.isEmpty()) return 2;
|
||||||
if(pEstEndDate.before(new Date())) return 3;
|
if(pEstEndDate.before(new Date())) return 3;
|
||||||
if(!pLSN.matches("[0-9]+")) return 5;
|
if(!pLSN.matches("[0-9]+")) return 5;
|
||||||
|
|
||||||
ArrayList<KLender> lenders = lenderModel.getLenders(pLName, pLSurname, pLSN);
|
ArrayList<KLender> lenders = kLenderModel.getLenders(pLName, pLSurname, pLSN);
|
||||||
if(lenders.size() == 0) {
|
if(lenders.size() == 0) {
|
||||||
int result = dbCon.createNewLender(pLName, pLSurname, pLSN);
|
int result = dbCon.createNewLender(pLName, pLSurname, pLSN);
|
||||||
|
|
||||||
if(result == 0){
|
if(result == 0){
|
||||||
lenderModel.updateModel();
|
kLenderModel.updateModel();
|
||||||
|
|
||||||
return newLending(pArtId, pLName, pLSurname, pLSN, pStartDate, pEstEndDate, pUsername);
|
return newLending(pArtId, pLName, pLSurname, pLSN, pStartDate, pEstEndDate, pUsername);
|
||||||
}
|
}
|
||||||
@@ -60,18 +77,115 @@ public class NewLendingController {
|
|||||||
}
|
}
|
||||||
else if(lenders.size() == 1){
|
else if(lenders.size() == 1){
|
||||||
KLender lender = lenders.get(0);
|
KLender lender = lenders.get(0);
|
||||||
int uId = userListModel.getIdByFullname(pUsername);
|
int uId = kUserModel.getIdByFullname(pUsername);
|
||||||
DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
|
DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
|
||||||
int result = dbCon.createNewLending(pArtId, uId, lender.getId(), pStartDate, dateFormat.format(pEstEndDate));
|
|
||||||
|
|
||||||
if(result == 0){
|
int[] result = dbCon.createNewLending(pArtId, uId, lender.getId(), pStartDate, dateFormat.format(pEstEndDate));
|
||||||
freeArticleModel.updateModel();
|
|
||||||
articleTableModel.updateModel();
|
if(result[0] == 0){
|
||||||
lendingTableModel.updateModel();
|
kArticleModel.updateModel();
|
||||||
return result;
|
kLendingModel.updateModel();
|
||||||
|
createPdfFile(result[1]);
|
||||||
|
|
||||||
|
return result[0];
|
||||||
}
|
}
|
||||||
else return result;
|
else return result[0];
|
||||||
}
|
}
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void createPdfFile(int pLendingId) throws Exception {
|
||||||
|
KLending lending = kLendingModel.getElement(pLendingId);
|
||||||
|
KArticle article = kArticleModel.getElement(lending.getArticleId());
|
||||||
|
KUser user = kUserModel.getElement(lending.getUserId());
|
||||||
|
KLender lender = kLenderModel.getElement(lending.getLenderId());
|
||||||
|
|
||||||
|
PDDocument doc = new PDDocument();
|
||||||
|
PDPage page = new PDPage(PDPage.PAGE_SIZE_A4);
|
||||||
|
PDRectangle rect = page.getMediaBox();
|
||||||
|
doc.addPage(page);
|
||||||
|
|
||||||
|
PDFont fontNormal = PDType1Font.HELVETICA;
|
||||||
|
PDFont fontBold = PDType1Font.HELVETICA_BOLD;
|
||||||
|
|
||||||
|
String[] text = {
|
||||||
|
"Artikel: ",
|
||||||
|
"Verliehen von: ",
|
||||||
|
"Ausgeliehen an: ",
|
||||||
|
"Start der Ausleihe: ",
|
||||||
|
"Voraussichtliche R<>ckgabe: "
|
||||||
|
};
|
||||||
|
String[] vars = {
|
||||||
|
article.getName(),
|
||||||
|
user.getName()+" "+user.getSurname(),
|
||||||
|
lender.getName()+" "+lender.getSurname()+" ("+lender.getStudentnumber()+")",
|
||||||
|
lending.getStartDate(),
|
||||||
|
lending.getExpectedEndDate()
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
File file = createRandomFile();
|
||||||
|
|
||||||
|
PDPageContentStream cos = new PDPageContentStream(doc, page);
|
||||||
|
|
||||||
|
cos.beginText();
|
||||||
|
cos.moveTextPositionByAmount(100, rect.getHeight() - 100);
|
||||||
|
cos.setFont(fontBold, 16);
|
||||||
|
cos.drawString("Ausleihe #"+lending.getId());
|
||||||
|
cos.endText();
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
while (i < text.length){
|
||||||
|
cos.beginText();
|
||||||
|
cos.moveTextPositionByAmount(100, rect.getHeight() - 25*(i+2) - 100 );
|
||||||
|
cos.setFont(fontBold, 12);
|
||||||
|
cos.drawString(text[i]);
|
||||||
|
cos.moveTextPositionByAmount(rect.getWidth() / 2 - 100, 0);
|
||||||
|
cos.setFont(fontNormal, 12);
|
||||||
|
cos.drawString(vars[i]);
|
||||||
|
cos.endText();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
i = i+2;
|
||||||
|
cos.setLineWidth(1);
|
||||||
|
cos.addLine(100, rect.getHeight() - 25*(i+2) - 100, 300, rect.getHeight() - 25*(i+2) - 100);
|
||||||
|
cos.closeAndStroke();
|
||||||
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
cos.beginText();
|
||||||
|
cos.moveTextPositionByAmount(100, rect.getHeight() - 25*(i+2) - 100);
|
||||||
|
cos.setFont(fontNormal, 12);
|
||||||
|
cos.drawString("Unterschrift "+lender.getName()+" "+lender.getSurname());
|
||||||
|
cos.endText();
|
||||||
|
|
||||||
|
cos.close();
|
||||||
|
doc.save(file);
|
||||||
|
doc.close();
|
||||||
|
|
||||||
|
if(Desktop.isDesktopSupported()){
|
||||||
|
Desktop desktop = Desktop.getDesktop();
|
||||||
|
if(desktop.isSupported(Desktop.Action.OPEN)){
|
||||||
|
desktop.open(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException | COSVisitorException e) {
|
||||||
|
throw new Exception("Problem bei der Erstellung der PDF-Datei.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private File createRandomFile() throws IOException{
|
||||||
|
File dir = new File(settings.getSettingsDir()+"/tmp");
|
||||||
|
File file = new File(settings.getSettingsDir()+"/tmp/"+Util.generateRandomString(8)+".pdf");
|
||||||
|
if(!dir.isDirectory()) dir.mkdir();
|
||||||
|
if(!file.isFile()) file.createNewFile();
|
||||||
|
else {
|
||||||
|
file.delete();
|
||||||
|
file.createNewFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package de.katho.kBorrow.controller;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.interfaces.DbConnector;
|
||||||
|
|
||||||
|
public class RewriteToNewUserController {
|
||||||
|
|
||||||
|
private DbConnector dbCon;
|
||||||
|
|
||||||
|
public RewriteToNewUserController(DbConnector pDbCon){
|
||||||
|
dbCon = pDbCon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean rewriteToNewUser(int pOldId, int pNewId){
|
||||||
|
return dbCon.rewriteToNewUser(pOldId, pNewId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,28 +1,32 @@
|
|||||||
package de.katho.kBorrow.controller;
|
package de.katho.kBorrow.controller;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.KLogger;
|
||||||
import de.katho.kBorrow.models.UserTableModel;
|
import de.katho.kBorrow.data.KLendingModel;
|
||||||
import de.katho.kBorrow.models.UserListModel;
|
import de.katho.kBorrow.data.objects.KLending;
|
||||||
|
import de.katho.kBorrow.gui.RewriteToNewUserDialog;
|
||||||
|
import de.katho.kBorrow.interfaces.DbConnector;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
|
|
||||||
public class UserController {
|
public class UserController {
|
||||||
|
|
||||||
private DbConnector dbCon;
|
private DbConnector dbCon;
|
||||||
private UserTableModel userTableModel;
|
private KDataModel userModel;
|
||||||
private UserListModel userListModel;
|
private KDataModel lendingModel;
|
||||||
|
|
||||||
public UserController(DbConnector pDbCon, HashMap<String, Object> pModels) {
|
public UserController(DbConnector pDbCon, HashMap<String, KDataModel> models) {
|
||||||
dbCon = pDbCon;
|
dbCon = pDbCon;
|
||||||
userTableModel = (UserTableModel)pModels.get("usertablemodel");
|
userModel = models.get("kusermodel");
|
||||||
userListModel = (UserListModel)pModels.get("userlistmodel");
|
lendingModel = models.get("klendingmodel");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int createUser(String pName, String pSurname){
|
public int createUser(String pName, String pSurname){
|
||||||
int status = dbCon.createUser(pName, pSurname);
|
int status = dbCon.createUser(pName, pSurname);
|
||||||
|
|
||||||
userTableModel.updateModel();
|
userModel.updateModel();
|
||||||
userListModel.updateModel();
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -31,23 +35,47 @@ public class UserController {
|
|||||||
int status = dbCon.editUser(pId, pName, pSurname);
|
int status = dbCon.editUser(pId, pName, pSurname);
|
||||||
|
|
||||||
if(status == 0){
|
if(status == 0){
|
||||||
userTableModel.updateModel();
|
userModel.updateModel();
|
||||||
userListModel.updateModel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean deleteUser(int pRow){
|
public boolean deleteUser(int pId) {
|
||||||
int id = userTableModel.getUserByRow(pRow).getId();
|
if(!(lendingModel instanceof KLendingModel)) {
|
||||||
|
KLogger.log(Level.SEVERE, "UserController: lendingModel type error!", new Exception("UserController: lendingModel type error!"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if(dbCon.deleteUser(id)){
|
boolean isOccupied = false;
|
||||||
userTableModel.updateModel();
|
|
||||||
userListModel.updateModel();
|
ArrayList<KLending> lendingList = ((KLendingModel)lendingModel).getData();
|
||||||
|
for(KLending elem : lendingList){
|
||||||
|
if(elem.getUserId() == pId){
|
||||||
|
isOccupied = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isOccupied){
|
||||||
|
RewriteToNewUserDialog dialog = new RewriteToNewUserDialog(pId, dbCon, userModel);
|
||||||
|
if(dialog.getResult() == 0){
|
||||||
|
lendingModel.updateModel();
|
||||||
|
userModel.updateModel();
|
||||||
|
|
||||||
|
return deleteUser(pId);
|
||||||
|
}
|
||||||
|
else return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(dbCon.deleteUser(pId)){
|
||||||
|
userModel.updateModel();
|
||||||
|
lendingModel.updateModel();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package de.katho.kBorrow.converter;
|
|||||||
|
|
||||||
import org.jdesktop.swingx.autocomplete.ObjectToStringConverter;
|
import org.jdesktop.swingx.autocomplete.ObjectToStringConverter;
|
||||||
|
|
||||||
import de.katho.kBorrow.data.KLender;
|
import de.katho.kBorrow.data.objects.KLender;
|
||||||
|
|
||||||
public class LenderNameConverter extends ObjectToStringConverter {
|
public class LenderNameConverter extends ObjectToStringConverter {
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package de.katho.kBorrow.converter;
|
|||||||
|
|
||||||
import org.jdesktop.swingx.autocomplete.ObjectToStringConverter;
|
import org.jdesktop.swingx.autocomplete.ObjectToStringConverter;
|
||||||
|
|
||||||
import de.katho.kBorrow.data.KLender;
|
import de.katho.kBorrow.data.objects.KLender;
|
||||||
|
|
||||||
public class LenderStudentnumberConverter extends ObjectToStringConverter {
|
public class LenderStudentnumberConverter extends ObjectToStringConverter {
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package de.katho.kBorrow.converter;
|
|||||||
|
|
||||||
import org.jdesktop.swingx.autocomplete.ObjectToStringConverter;
|
import org.jdesktop.swingx.autocomplete.ObjectToStringConverter;
|
||||||
|
|
||||||
import de.katho.kBorrow.data.KLender;
|
import de.katho.kBorrow.data.objects.KLender;
|
||||||
|
|
||||||
public class LenderSurnameConverter extends ObjectToStringConverter {
|
public class LenderSurnameConverter extends ObjectToStringConverter {
|
||||||
|
|
||||||
|
|||||||
47
src/de/katho/kBorrow/data/KArticleModel.java
Normal file
47
src/de/katho/kBorrow/data/KArticleModel.java
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package de.katho.kBorrow.data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.data.objects.KArticle;
|
||||||
|
import de.katho.kBorrow.interfaces.DbConnector;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
|
import de.katho.kBorrow.interfaces.KGuiModel;
|
||||||
|
|
||||||
|
public class KArticleModel implements KDataModel {
|
||||||
|
|
||||||
|
private ArrayList<KGuiModel> models = new ArrayList<KGuiModel>();
|
||||||
|
private ArrayList<KArticle> data = new ArrayList<KArticle>();
|
||||||
|
private DbConnector dbCon;
|
||||||
|
|
||||||
|
public KArticleModel(DbConnector pDbCon) {
|
||||||
|
dbCon = pDbCon;
|
||||||
|
updateModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register(KGuiModel pModel) {
|
||||||
|
if(!models.contains(pModel)){
|
||||||
|
pModel.fetchData(this);
|
||||||
|
models.add(pModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateModel() {
|
||||||
|
data = dbCon.getArticleList();
|
||||||
|
|
||||||
|
for(KGuiModel model : models){
|
||||||
|
model.fetchData(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<KArticle> getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public KArticle getElement(int id) {
|
||||||
|
for (KArticle elem : data){
|
||||||
|
if(elem.getId() == id) return elem;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,27 +1,50 @@
|
|||||||
package de.katho.kBorrow.models;
|
package de.katho.kBorrow.data;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import de.katho.kBorrow.data.KLender;
|
import de.katho.kBorrow.data.objects.KLender;
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.interfaces.DbConnector;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
|
import de.katho.kBorrow.interfaces.KGuiModel;
|
||||||
|
|
||||||
public class LenderModel {
|
public class KLenderModel implements KDataModel {
|
||||||
private ArrayList<KLender> data;
|
|
||||||
|
private ArrayList<KGuiModel> models = new ArrayList<KGuiModel>();
|
||||||
|
private ArrayList<KLender> data = new ArrayList<KLender>();
|
||||||
private DbConnector dbCon;
|
private DbConnector dbCon;
|
||||||
|
|
||||||
public LenderModel(DbConnector pDbCon){
|
public KLenderModel(DbConnector pDbCon) {
|
||||||
dbCon = pDbCon;
|
dbCon = pDbCon;
|
||||||
updateModel();
|
updateModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateModel(){
|
public void register(KGuiModel pModel) {
|
||||||
data = dbCon.getLenderList();
|
if(!models.contains(pModel)){
|
||||||
|
pModel.fetchData(this);
|
||||||
|
models.add(pModel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<KLender> getList(){
|
public void updateModel() {
|
||||||
|
data = dbCon.getLenderList();
|
||||||
|
|
||||||
|
for(KGuiModel model : models){
|
||||||
|
model.fetchData(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<KLender> getData() {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public KLender getElement(int id) {
|
||||||
|
for(KLender elem : data){
|
||||||
|
if(elem.getId() == id) return elem;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public ArrayList<KLender> getLenders(String pName, String pSurname, String pSN){
|
public ArrayList<KLender> getLenders(String pName, String pSurname, String pSN){
|
||||||
boolean nameEmpty = pName.isEmpty();
|
boolean nameEmpty = pName.isEmpty();
|
||||||
boolean surnameEmpty = pSurname.isEmpty();
|
boolean surnameEmpty = pSurname.isEmpty();
|
||||||
@@ -105,14 +128,4 @@ public class LenderModel {
|
|||||||
return elems;
|
return elems;
|
||||||
}
|
}
|
||||||
|
|
||||||
public KLender getLenderById(int pId){
|
|
||||||
for(KLender elem : data){
|
|
||||||
if(elem.getId() == pId) return elem;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public KLender getLenderByRow(int pRow){
|
|
||||||
return data.get(pRow);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
48
src/de/katho/kBorrow/data/KLendingModel.java
Normal file
48
src/de/katho/kBorrow/data/KLendingModel.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package de.katho.kBorrow.data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.data.objects.KLending;
|
||||||
|
import de.katho.kBorrow.interfaces.DbConnector;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
|
import de.katho.kBorrow.interfaces.KGuiModel;
|
||||||
|
|
||||||
|
public class KLendingModel implements KDataModel {
|
||||||
|
|
||||||
|
private ArrayList<KGuiModel> models = new ArrayList<KGuiModel>();
|
||||||
|
private ArrayList<KLending> data = new ArrayList<KLending>();
|
||||||
|
private DbConnector dbCon;
|
||||||
|
|
||||||
|
public KLendingModel(DbConnector pDbCon) {
|
||||||
|
dbCon = pDbCon;
|
||||||
|
updateModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register(KGuiModel pModel) {
|
||||||
|
if(!models.contains(pModel)){
|
||||||
|
pModel.fetchData(this);
|
||||||
|
models.add(pModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateModel() {
|
||||||
|
data = dbCon.getLendingList();
|
||||||
|
|
||||||
|
for(KGuiModel model : models){
|
||||||
|
model.fetchData(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<KLending> getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public KLending getElement(int id) {
|
||||||
|
for(KLending elem : data){
|
||||||
|
if(elem.getId() == id) return elem;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
54
src/de/katho/kBorrow/data/KUserModel.java
Normal file
54
src/de/katho/kBorrow/data/KUserModel.java
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
package de.katho.kBorrow.data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.data.objects.KUser;
|
||||||
|
import de.katho.kBorrow.interfaces.DbConnector;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
|
import de.katho.kBorrow.interfaces.KGuiModel;
|
||||||
|
|
||||||
|
public class KUserModel implements KDataModel {
|
||||||
|
|
||||||
|
private ArrayList<KGuiModel> models = new ArrayList<KGuiModel>();
|
||||||
|
private ArrayList<KUser> data = new ArrayList<KUser>();
|
||||||
|
private DbConnector dbCon;
|
||||||
|
|
||||||
|
public KUserModel(DbConnector pDbCon){
|
||||||
|
dbCon = pDbCon;
|
||||||
|
updateModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateModel(){
|
||||||
|
data = dbCon.getUserList();
|
||||||
|
|
||||||
|
for(KGuiModel model : models){
|
||||||
|
model.fetchData(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register(KGuiModel pModel) {
|
||||||
|
if(!models.contains(pModel)) {
|
||||||
|
pModel.fetchData(this);
|
||||||
|
models.add(pModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<KUser> getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public KUser getElement(int id) {
|
||||||
|
for(KUser elem : data){
|
||||||
|
if(elem.getId() == id) return elem;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIdByFullname(String pName){
|
||||||
|
for (KUser elem : data){
|
||||||
|
if(pName.equals(elem.getName()+" "+elem.getSurname())) return elem.getId();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.katho.kBorrow.data;
|
package de.katho.kBorrow.data.objects;
|
||||||
|
|
||||||
public class KArticle {
|
public class KArticle {
|
||||||
private int id;
|
private int id;
|
||||||
@@ -7,22 +7,22 @@ public class KArticle {
|
|||||||
private boolean isFree;
|
private boolean isFree;
|
||||||
|
|
||||||
public KArticle(int pId, String pName, boolean pFree, String pDesc) {
|
public KArticle(int pId, String pName, boolean pFree, String pDesc) {
|
||||||
this.id = pId;
|
id = pId;
|
||||||
this.name = pName;
|
name = pName;
|
||||||
this.description = pDesc;
|
description = pDesc;
|
||||||
isFree = pFree;
|
isFree = pFree;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return this.id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return this.description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getIsFree(){
|
public boolean getIsFree(){
|
||||||
@@ -30,11 +30,11 @@ public class KArticle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String pName){
|
public void setName(String pName){
|
||||||
this.name = pName;
|
name = pName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescription(String pDesc){
|
public void setDescription(String pDesc){
|
||||||
this.description = pDesc;
|
description = pDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIsFree(boolean pFree){
|
public void setIsFree(boolean pFree){
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.katho.kBorrow.data;
|
package de.katho.kBorrow.data.objects;
|
||||||
|
|
||||||
public class KLender {
|
public class KLender {
|
||||||
private String name;
|
private String name;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.katho.kBorrow.data;
|
package de.katho.kBorrow.data.objects;
|
||||||
|
|
||||||
public class KLending {
|
public class KLending {
|
||||||
private int id;
|
private int id;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.katho.kBorrow.data;
|
package de.katho.kBorrow.data.objects;
|
||||||
|
|
||||||
public class KUser {
|
public class KUser {
|
||||||
private String name;
|
private String name;
|
||||||
@@ -2,10 +2,11 @@ package de.katho.kBorrow.db;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import de.katho.kBorrow.data.KArticle;
|
import de.katho.kBorrow.data.objects.KArticle;
|
||||||
import de.katho.kBorrow.data.KLender;
|
import de.katho.kBorrow.data.objects.KLender;
|
||||||
import de.katho.kBorrow.data.KLending;
|
import de.katho.kBorrow.data.objects.KLending;
|
||||||
import de.katho.kBorrow.data.KUser;
|
import de.katho.kBorrow.data.objects.KUser;
|
||||||
|
import de.katho.kBorrow.interfaces.DbConnector;
|
||||||
|
|
||||||
public class SqlConnector implements DbConnector{
|
public class SqlConnector implements DbConnector{
|
||||||
|
|
||||||
@@ -75,10 +76,10 @@ public class SqlConnector implements DbConnector{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int createNewLending(int pArtId, int pUId, int pLId,
|
public int[] createNewLending(int pArtId, int pUId, int pLId,
|
||||||
String pStartDate, String pEstEndDate) {
|
String pStartDate, String pEstEndDate) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return 0;
|
return new int[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -105,4 +106,22 @@ public class SqlConnector implements DbConnector{
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArrayList<KUser> getRewriteUserList(int id) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean rewriteToNewUser(int pOldId, int pNewId) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArrayList<KLending> getLendingList() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,12 @@ 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.KArticle;
|
import de.katho.kBorrow.Util;
|
||||||
import de.katho.kBorrow.data.KLender;
|
import de.katho.kBorrow.data.objects.KArticle;
|
||||||
import de.katho.kBorrow.data.KLending;
|
import de.katho.kBorrow.data.objects.KLender;
|
||||||
import de.katho.kBorrow.data.KUser;
|
import de.katho.kBorrow.data.objects.KLending;
|
||||||
|
import de.katho.kBorrow.data.objects.KUser;
|
||||||
|
import de.katho.kBorrow.interfaces.DbConnector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class sqliteConnector
|
* @class sqliteConnector
|
||||||
@@ -92,7 +94,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,7 +110,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (SQLException e){
|
catch (SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,7 +203,27 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return userArr;
|
return userArr;
|
||||||
}
|
}
|
||||||
catch (SQLException e){
|
catch (SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<KUser> getRewriteUserList(int id) {
|
||||||
|
ArrayList<KUser> userArr = new ArrayList<KUser>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Statement st = this.connection.createStatement();
|
||||||
|
String query = "SELECT id, name, surname FROM user WHERE id != "+id;
|
||||||
|
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){
|
||||||
|
Util.showWarning(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,7 +243,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return artArr;
|
return artArr;
|
||||||
}
|
}
|
||||||
catch (SQLException ex){
|
catch (SQLException ex){
|
||||||
ex.printStackTrace();
|
Util.showWarning(ex);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -241,7 +263,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return artArr;
|
return artArr;
|
||||||
}
|
}
|
||||||
catch(SQLException ex){
|
catch(SQLException ex){
|
||||||
ex.printStackTrace();
|
Util.showWarning(ex);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,11 +283,30 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return lendArr;
|
return lendArr;
|
||||||
}
|
}
|
||||||
catch(SQLException ex){
|
catch(SQLException ex){
|
||||||
ex.printStackTrace();
|
Util.showWarning(ex);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<KLending> getLendingList(){
|
||||||
|
ArrayList<KLending> lendingArr = new ArrayList<KLending>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Statement st = connection.createStatement();
|
||||||
|
String query = "SELECT id, user_id, lender_id, article_id, start_date, expected_end_date, end_date FROM lending";
|
||||||
|
|
||||||
|
ResultSet rs = st.executeQuery(query);
|
||||||
|
|
||||||
|
while (rs.next()){
|
||||||
|
lendingArr.add(new KLending(rs.getInt("id"), rs.getInt("user_id"), rs.getInt("lender_id"), rs.getInt("article_id"), rs.getString("start_date"), rs.getString("expected_end_date"), rs.getString("end_date")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(SQLException e){
|
||||||
|
Util.showWarning(e);
|
||||||
|
}
|
||||||
|
return lendingArr;
|
||||||
|
}
|
||||||
|
|
||||||
public ArrayList<KLending> getActiveLendingList() {
|
public ArrayList<KLending> getActiveLendingList() {
|
||||||
ArrayList<KLending> lendingArr = new ArrayList<KLending>();
|
ArrayList<KLending> lendingArr = new ArrayList<KLending>();
|
||||||
|
|
||||||
@@ -282,7 +323,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return lendingArr;
|
return lendingArr;
|
||||||
}
|
}
|
||||||
catch(SQLException e){
|
catch(SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return lendingArr;
|
return lendingArr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -303,7 +344,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return lendingArr;
|
return lendingArr;
|
||||||
}
|
}
|
||||||
catch(SQLException e){
|
catch(SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return lendingArr;
|
return lendingArr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -325,7 +366,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -341,7 +382,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch(SQLException e){
|
catch(SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -357,7 +398,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (SQLException e){
|
catch (SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -373,7 +414,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -388,7 +429,7 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch (SQLException e){
|
catch (SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -404,18 +445,26 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch(SQLException e){
|
catch(SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Erstellt eine neue Ausleihe.
|
||||||
*
|
*
|
||||||
* @return Status-Code:
|
*
|
||||||
* 0: Erfolg
|
* @return R<>ckgabewert ist ein Array mit zwei Werten.
|
||||||
* 1: SQL-Fehler
|
*
|
||||||
|
* Index 0: Enth<74>lt den R<>ckgabestatus:
|
||||||
|
* - Status 0: Alles in Ordnung
|
||||||
|
* - Status 1: SQL-Fehler
|
||||||
|
*
|
||||||
|
* Index 1: Enth<74>lt die ID der gerade erzeugten Tabellenzeile
|
||||||
*/
|
*/
|
||||||
public int createNewLending(int pArtId, int pUId, int pLId, String pStartDate, String pEstEndDate) {
|
public int[] createNewLending(int pArtId, int pUId, int pLId, String pStartDate, String pEstEndDate) {
|
||||||
|
int[] result = new int[2];
|
||||||
|
|
||||||
try{
|
try{
|
||||||
Statement st = connection.createStatement();
|
Statement st = connection.createStatement();
|
||||||
String query = "INSERT INTO lending (article_id, user_id, lender_id, start_date, expected_end_date ) "
|
String query = "INSERT INTO lending (article_id, user_id, lender_id, start_date, expected_end_date ) "
|
||||||
@@ -424,27 +473,33 @@ public class SqliteConnector implements DbConnector {
|
|||||||
|
|
||||||
st.executeUpdate(query);
|
st.executeUpdate(query);
|
||||||
|
|
||||||
return 0;
|
query = "SELECT id FROM lending ORDER BY id DESC LIMIT 1;";
|
||||||
|
|
||||||
|
ResultSet rs = st.executeQuery(query);
|
||||||
|
|
||||||
|
result[1] = rs.getInt("id");
|
||||||
|
result[0] = 0;
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
catch(SQLException e){
|
catch(SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return 1;
|
return new int[]{1,0};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int createNewLender(String pLName, String pLSurname, String pLSN) {
|
public boolean rewriteToNewUser(int pOldId, int pNewId) {
|
||||||
try {
|
try {
|
||||||
Statement st = connection.createStatement();
|
Statement st = connection.createStatement();
|
||||||
String query = "INSERT into lender (name, surname, student_number) "
|
String query = "UPDATE lending SET user_id = '"+pNewId+"' WHERE user_id = '"+pOldId+"'";
|
||||||
+ "VALUES ('"+pLName+"', '"+pLSurname+"', '"+pLSN+"')";
|
|
||||||
|
|
||||||
st.executeUpdate(query);
|
st.executeUpdate(query);
|
||||||
|
|
||||||
return 0;
|
return true;
|
||||||
}
|
}
|
||||||
catch(SQLException e){
|
catch(SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return 1;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -459,10 +514,26 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch(SQLException e){
|
catch(SQLException e){
|
||||||
e.printStackTrace();
|
Util.showWarning(e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int createNewLender(String pLName, String pLSurname, String pLSN) {
|
||||||
|
try{
|
||||||
|
Statement st = connection.createStatement();
|
||||||
|
String query = "INSERT into lender (name, surname, student_number) "
|
||||||
|
+ "VALUES ('"+pLName+"', '"+pLSurname+"', '"+pLSN+"')";
|
||||||
|
|
||||||
|
st.executeUpdate(query);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch(SQLException e){
|
||||||
|
Util.showWarning(e);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ import javax.swing.JLabel;
|
|||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
|
|
||||||
import de.katho.kBorrow.data.KArticle;
|
import de.katho.kBorrow.data.KArticleModel;
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.data.objects.KArticle;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
import de.katho.kBorrow.models.ArticleInspectTableModel;
|
import de.katho.kBorrow.models.ArticleInspectTableModel;
|
||||||
import de.katho.kBorrow.models.ArticleTableModel;
|
|
||||||
|
|
||||||
public class ArticleInspectFrame extends JFrame {
|
public class ArticleInspectFrame extends JFrame {
|
||||||
|
|
||||||
@@ -24,16 +24,15 @@ public class ArticleInspectFrame extends JFrame {
|
|||||||
private static final long serialVersionUID = -8993341404926674307L;
|
private static final long serialVersionUID = -8993341404926674307L;
|
||||||
private JPanel contentPane;
|
private JPanel contentPane;
|
||||||
private JTable table;
|
private JTable table;
|
||||||
private ArticleInspectTableModel artInsModel;
|
private KArticleModel articleModel;
|
||||||
private ArticleTableModel articleModel;
|
|
||||||
private KArticle article;
|
private KArticle article;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the frame.
|
* Create the frame.
|
||||||
*/
|
*/
|
||||||
public ArticleInspectFrame(int pRow, final DbConnector dbCon, HashMap<String, Object> pModels) {
|
public ArticleInspectFrame(int pId, HashMap<String, KDataModel> models) {
|
||||||
articleModel = (ArticleTableModel)pModels.get("articletablemodel");
|
articleModel = (KArticleModel)models.get("karticlemodel");
|
||||||
article = articleModel.getArticleByRow(pRow);
|
article = articleModel.getElement(pId);
|
||||||
|
|
||||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||||
setBounds(150, 150, 660, 541);
|
setBounds(150, 150, 660, 541);
|
||||||
@@ -61,7 +60,7 @@ public class ArticleInspectFrame extends JFrame {
|
|||||||
|
|
||||||
lblNewLabel_1.setBounds(10, 21, 100, 20);
|
lblNewLabel_1.setBounds(10, 21, 100, 20);
|
||||||
lblNewLabel_2.setBounds(10, 47, 100, 20);
|
lblNewLabel_2.setBounds(10, 47, 100, 20);
|
||||||
lblArticleName.setBounds(120, 21, 100, 20);
|
lblArticleName.setBounds(120, 21, 250, 20);
|
||||||
taArticleDesc.setBounds(120, 45, 250, 78);
|
taArticleDesc.setBounds(120, 45, 250, 78);
|
||||||
taArticleDesc.setEditable(false);
|
taArticleDesc.setEditable(false);
|
||||||
|
|
||||||
@@ -71,8 +70,7 @@ public class ArticleInspectFrame extends JFrame {
|
|||||||
panelInfo.add(taArticleDesc);
|
panelInfo.add(taArticleDesc);
|
||||||
|
|
||||||
// Table
|
// Table
|
||||||
artInsModel = new ArticleInspectTableModel(pRow, dbCon, pModels);
|
table = new JTable(new ArticleInspectTableModel(pId, models));
|
||||||
table = new JTable(artInsModel);
|
|
||||||
table.setFillsViewportHeight(true);
|
table.setFillsViewportHeight(true);
|
||||||
table.setRowHeight(30);
|
table.setRowHeight(30);
|
||||||
table.getColumnModel().getColumn(0).setMinWidth(30);
|
table.getColumnModel().getColumn(0).setMinWidth(30);
|
||||||
|
|||||||
@@ -24,8 +24,10 @@ import javax.swing.UIManager;
|
|||||||
import javax.swing.border.TitledBorder;
|
import javax.swing.border.TitledBorder;
|
||||||
|
|
||||||
import de.katho.kBorrow.controller.ArticleController;
|
import de.katho.kBorrow.controller.ArticleController;
|
||||||
import de.katho.kBorrow.data.KArticle;
|
import de.katho.kBorrow.data.KArticleModel;
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.data.objects.KArticle;
|
||||||
|
import de.katho.kBorrow.interfaces.DbConnector;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
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.listener.ArticleInspectTableButton;
|
||||||
@@ -42,27 +44,27 @@ public class ArticlePanel extends JPanel implements ActionListener, KeyListener
|
|||||||
private JLabel lblArticleStatus;
|
private JLabel lblArticleStatus;
|
||||||
private boolean articleModeEdit;
|
private boolean articleModeEdit;
|
||||||
private int articleEditId;
|
private int articleEditId;
|
||||||
private ArticleTableModel articleTableModel;
|
private KArticleModel articleModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the panel.
|
* Create the panel.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public ArticlePanel(final DbConnector dbCon, HashMap<String, Object> pModels) throws IOException {
|
public ArticlePanel(final DbConnector dbCon, HashMap<String, KDataModel> models) throws IOException {
|
||||||
super();
|
super();
|
||||||
this.setLayout(null);
|
this.setLayout(null);
|
||||||
articleTableModel = (ArticleTableModel)pModels.get("articletablemodel");
|
articleModel = (KArticleModel)models.get("karticlemodel");
|
||||||
articleController = new ArticleController(dbCon, pModels);
|
articleController = new ArticleController(dbCon, models);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tabelle und drumherum
|
* Tabelle und drumherum
|
||||||
*/
|
*/
|
||||||
|
|
||||||
JTable articleTable = new JTable(articleTableModel);
|
JTable articleTable = new JTable(new ArticleTableModel(articleModel));
|
||||||
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);
|
ArticleInspectTableButton articleInspectTableButton = new ArticleInspectTableButton("Details", articleTable, models);
|
||||||
|
|
||||||
for (int i = 3; i <= 5; i++){
|
for (int i = 3; i <= 5; i++){
|
||||||
articleTable.getColumnModel().getColumn(i).setCellEditor(i == 3 ? articleInspectTableButton : i == 4 ? articleEditTableButton : articleDeleteTableButton);
|
articleTable.getColumnModel().getColumn(i).setCellEditor(i == 3 ? articleInspectTableButton : i == 4 ? articleEditTableButton : articleDeleteTableButton);
|
||||||
@@ -173,8 +175,8 @@ public class ArticlePanel extends JPanel implements ActionListener, KeyListener
|
|||||||
this.textAreaArticleDescription.setText("");
|
this.textAreaArticleDescription.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setModeEditArticle(int pRow) {
|
public void setModeEditArticle(int pId) {
|
||||||
KArticle art = articleTableModel.getArticleByRow(pRow);
|
KArticle art = articleModel.getElement(pId);
|
||||||
|
|
||||||
this.articleModeEdit = true;
|
this.articleModeEdit = true;
|
||||||
this.articleEditId = art.getId();
|
this.articleEditId = art.getId();
|
||||||
|
|||||||
@@ -5,26 +5,21 @@ import javax.swing.JTabbedPane;
|
|||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.UnsupportedLookAndFeelException;
|
import javax.swing.UnsupportedLookAndFeelException;
|
||||||
|
|
||||||
import org.jdesktop.swingx.JXErrorPane;
|
|
||||||
import org.jdesktop.swingx.error.ErrorInfo;
|
|
||||||
|
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import de.katho.kBorrow.Settings;
|
import de.katho.kBorrow.Settings;
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.Util;
|
||||||
|
import de.katho.kBorrow.data.KArticleModel;
|
||||||
|
import de.katho.kBorrow.data.KLenderModel;
|
||||||
|
import de.katho.kBorrow.data.KLendingModel;
|
||||||
|
import de.katho.kBorrow.data.KUserModel;
|
||||||
import de.katho.kBorrow.db.SqlConnector;
|
import de.katho.kBorrow.db.SqlConnector;
|
||||||
import de.katho.kBorrow.db.SqliteConnector;
|
import de.katho.kBorrow.db.SqliteConnector;
|
||||||
import de.katho.kBorrow.models.ArticleTableModel;
|
import de.katho.kBorrow.interfaces.DbConnector;
|
||||||
import de.katho.kBorrow.models.FreeArticleTableModel;
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
import de.katho.kBorrow.models.LenderModel;
|
|
||||||
import de.katho.kBorrow.models.LendingTableModel;
|
|
||||||
import de.katho.kBorrow.models.UserTableModel;
|
|
||||||
import de.katho.kBorrow.models.UserListModel;
|
|
||||||
|
|
||||||
|
|
||||||
public class MainWindow {
|
public class MainWindow {
|
||||||
|
|
||||||
@@ -36,7 +31,7 @@ public class MainWindow {
|
|||||||
|
|
||||||
|
|
||||||
private Settings set;
|
private Settings set;
|
||||||
private HashMap<String, Object> models;
|
private HashMap<String, KDataModel> models;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the application.
|
* Create the application.
|
||||||
@@ -46,14 +41,25 @@ public class MainWindow {
|
|||||||
* @throws ClassNotFoundException
|
* @throws ClassNotFoundException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public MainWindow() throws IOException {
|
public MainWindow() {
|
||||||
set = new Settings();
|
// Delete all files in tmp-dir
|
||||||
|
Runtime.getRuntime().addShutdownHook(new Thread(){
|
||||||
|
public void run(){
|
||||||
|
File dir = new File(set.getSettingsDir()+"/tmp/");
|
||||||
|
if(dir.isDirectory()){
|
||||||
|
for(File file : dir.listFiles()) file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
frame = new JFrame();
|
frame = new JFrame();
|
||||||
frame.setResizable(false);
|
frame.setResizable(false);
|
||||||
frame.setBounds(100, 100, 600, 500);
|
frame.setBounds(100, 100, 600, 500);
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
Util.setMainWindow(frame);
|
||||||
|
set = new Settings();
|
||||||
|
|
||||||
try {
|
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
|
|
||||||
if(set.getProperty("dBType").equals("sqlite")){
|
if(set.getProperty("dBType").equals("sqlite")){
|
||||||
@@ -63,32 +69,29 @@ public class MainWindow {
|
|||||||
dbCon = new SqlConnector();
|
dbCon = new SqlConnector();
|
||||||
}
|
}
|
||||||
|
|
||||||
models = new HashMap<String, Object>();
|
models = new HashMap<String, KDataModel>();
|
||||||
models.put("usertablemodel", new UserTableModel(dbCon));
|
models.put("karticlemodel", new KArticleModel(dbCon));
|
||||||
models.put("userlistmodel", new UserListModel(dbCon));
|
models.put("klendermodel", new KLenderModel(dbCon));
|
||||||
models.put("articletablemodel", new ArticleTableModel(dbCon));
|
models.put("klendingmodel", new KLendingModel(dbCon));
|
||||||
models.put("freearticletablemodel", new FreeArticleTableModel(dbCon));
|
models.put("kusermodel", new KUserModel(dbCon));
|
||||||
models.put("lendermodel", new LenderModel(dbCon));
|
|
||||||
models.put("lendingtablemodel", new LendingTableModel(dbCon, models));
|
|
||||||
|
|
||||||
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||||
frame.getContentPane().add(this.tabbedPane, BorderLayout.CENTER);
|
frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
|
||||||
tabbedPane.addTab("Neue Ausleihe", new NewLendingPanel(this.dbCon, models));
|
tabbedPane.addTab("Neue Ausleihe", new NewLendingPanel(this.dbCon, models, set));
|
||||||
tabbedPane.addTab("Ausleihen verwalten", new ManageLendingsPanel(this.dbCon, models));
|
tabbedPane.addTab("Ausleihen verwalten", new ManageLendingsPanel(this.dbCon, models));
|
||||||
tabbedPane.addTab("Artikel verwalten", new ArticlePanel(this.dbCon, models));
|
tabbedPane.addTab("Artikel verwalten", new ArticlePanel(this.dbCon, models));
|
||||||
tabbedPane.addTab("Benutzer verwalten", new UserPanel(this.dbCon, models));
|
tabbedPane.addTab("Benutzer verwalten", new UserPanel(this.dbCon, models));
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(ClassNotFoundException | InstantiationException | IllegalAccessException | IOException | UnsupportedLookAndFeelException | SQLException e) {
|
catch(Exception e) {
|
||||||
ErrorInfo info = new ErrorInfo("Exception", e.getMessage(), null, null, e, null, null);
|
Util.showError(e);
|
||||||
JXErrorPane.showDialog(frame, info);
|
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException{
|
public static void main(String[] args) {
|
||||||
new MainWindow();
|
new MainWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,9 @@ import java.util.HashMap;
|
|||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
import de.katho.kBorrow.controller.ManageLendingsController;
|
import de.katho.kBorrow.controller.ManageLendingsController;
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import de.katho.kBorrow.interfaces.DbConnector;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
import de.katho.kBorrow.listener.LendingReturnTableButton;
|
import de.katho.kBorrow.listener.LendingReturnTableButton;
|
||||||
import de.katho.kBorrow.models.LendingTableModel;
|
import de.katho.kBorrow.models.LendingTableModel;
|
||||||
|
|
||||||
@@ -26,16 +25,14 @@ public class ManageLendingsPanel extends JPanel {
|
|||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 925691137664223491L;
|
private static final long serialVersionUID = 925691137664223491L;
|
||||||
|
|
||||||
private LendingTableModel lendingTableModel;
|
|
||||||
private ManageLendingsController manageLendingsController;
|
private ManageLendingsController manageLendingsController;
|
||||||
|
|
||||||
public ManageLendingsPanel(DbConnector dbCon, HashMap<String, Object> models) throws IOException {
|
public ManageLendingsPanel(DbConnector dbCon, HashMap<String, KDataModel> models) throws IOException {
|
||||||
|
|
||||||
lendingTableModel = (LendingTableModel)models.get("lendingtablemodel");
|
|
||||||
manageLendingsController = new ManageLendingsController(dbCon, models);
|
manageLendingsController = new ManageLendingsController(dbCon, models);
|
||||||
|
|
||||||
// Lending-Table
|
// Lending-Table
|
||||||
JTable lendingTable = new JTable(lendingTableModel);
|
JTable lendingTable = new JTable(new LendingTableModel(models));
|
||||||
LendingReturnTableButton lrtb = new LendingReturnTableButton("Ausleihe beenden", lendingTable, manageLendingsController);
|
LendingReturnTableButton lrtb = new LendingReturnTableButton("Ausleihe beenden", lendingTable, manageLendingsController);
|
||||||
lendingTable.getColumnModel().getColumn(0).setMinWidth(30);
|
lendingTable.getColumnModel().getColumn(0).setMinWidth(30);
|
||||||
lendingTable.getColumnModel().getColumn(0).setMaxWidth(30);
|
lendingTable.getColumnModel().getColumn(0).setMaxWidth(30);
|
||||||
|
|||||||
@@ -28,17 +28,21 @@ import javax.swing.border.TitledBorder;
|
|||||||
import org.jdesktop.swingx.JXDatePicker;
|
import org.jdesktop.swingx.JXDatePicker;
|
||||||
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
|
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.Settings;
|
||||||
import de.katho.kBorrow.Util;
|
import de.katho.kBorrow.Util;
|
||||||
import de.katho.kBorrow.controller.NewLendingController;
|
import de.katho.kBorrow.controller.NewLendingController;
|
||||||
import de.katho.kBorrow.converter.LenderNameConverter;
|
import de.katho.kBorrow.converter.LenderNameConverter;
|
||||||
import de.katho.kBorrow.converter.LenderStudentnumberConverter;
|
import de.katho.kBorrow.converter.LenderStudentnumberConverter;
|
||||||
import de.katho.kBorrow.converter.LenderSurnameConverter;
|
import de.katho.kBorrow.converter.LenderSurnameConverter;
|
||||||
import de.katho.kBorrow.data.KArticle;
|
import de.katho.kBorrow.data.KArticleModel;
|
||||||
import de.katho.kBorrow.data.KLender;
|
import de.katho.kBorrow.data.KLenderModel;
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.data.KUserModel;
|
||||||
|
import de.katho.kBorrow.data.objects.KArticle;
|
||||||
|
import de.katho.kBorrow.data.objects.KLender;
|
||||||
|
import de.katho.kBorrow.interfaces.DbConnector;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
import de.katho.kBorrow.listener.NewLendingTableButton;
|
import de.katho.kBorrow.listener.NewLendingTableButton;
|
||||||
import de.katho.kBorrow.models.FreeArticleTableModel;
|
import de.katho.kBorrow.models.FreeArticleTableModel;
|
||||||
import de.katho.kBorrow.models.LenderModel;
|
|
||||||
import de.katho.kBorrow.models.UserListModel;
|
import de.katho.kBorrow.models.UserListModel;
|
||||||
|
|
||||||
import java.awt.event.FocusEvent;
|
import java.awt.event.FocusEvent;
|
||||||
@@ -49,15 +53,12 @@ public class NewLendingPanel extends JPanel implements ActionListener, FocusList
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -7346953418572781322L;
|
private static final long serialVersionUID = -7346953418572781322L;
|
||||||
private FreeArticleTableModel freeArticleTableModel;
|
|
||||||
private JTextField tfName;
|
private JTextField tfName;
|
||||||
private JTextField tfSurname;
|
private JTextField tfSurname;
|
||||||
private JTextField tfStudentNumber;
|
private JTextField tfStudentNumber;
|
||||||
private UserListModel userListModel;
|
|
||||||
private JLabel lblStartDate;
|
private JLabel lblStartDate;
|
||||||
private JLabel lblArticleName;
|
private JLabel lblArticleName;
|
||||||
private int articleId;
|
private int articleId;
|
||||||
private LenderModel lenderModel;
|
|
||||||
private JButton btnCancel;
|
private JButton btnCancel;
|
||||||
private JButton btnSave;
|
private JButton btnSave;
|
||||||
private NewLendingController newLendingController;
|
private NewLendingController newLendingController;
|
||||||
@@ -65,20 +66,31 @@ public class NewLendingPanel extends JPanel implements ActionListener, FocusList
|
|||||||
private JXDatePicker dpEstEndDate;
|
private JXDatePicker dpEstEndDate;
|
||||||
private JLabel lblStatus;
|
private JLabel lblStatus;
|
||||||
|
|
||||||
|
private KArticleModel kArticleModel;
|
||||||
|
private KUserModel kUserModel;
|
||||||
|
private KLenderModel kLenderModel;
|
||||||
|
|
||||||
|
private UserListModel userListModel;
|
||||||
|
private FreeArticleTableModel freeArticleTableModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the panel.
|
* Create the panel.
|
||||||
* @param dbCon
|
* @param dbCon
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public NewLendingPanel(final DbConnector dbCon, HashMap<String, Object> pModel) throws IOException {
|
public NewLendingPanel(final DbConnector dbCon, HashMap<String, KDataModel> models, final Settings pSettings) throws IOException {
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
articleId = -1;
|
articleId = -1;
|
||||||
|
|
||||||
|
kArticleModel = (KArticleModel)models.get("karticlemodel");
|
||||||
|
kUserModel = (KUserModel)models.get("kusermodel");
|
||||||
|
kLenderModel = (KLenderModel)models.get("klendermodel");
|
||||||
|
|
||||||
|
userListModel = new UserListModel(kUserModel);
|
||||||
|
freeArticleTableModel = new FreeArticleTableModel(kArticleModel);
|
||||||
|
|
||||||
// FreeArticleTable
|
// FreeArticleTable
|
||||||
freeArticleTableModel = (FreeArticleTableModel)pModel.get("freearticletablemodel");
|
newLendingController = new NewLendingController(dbCon, models, pSettings);
|
||||||
userListModel = (UserListModel)pModel.get("userlistmodel");
|
|
||||||
lenderModel = (LenderModel)pModel.get("lendermodel");
|
|
||||||
newLendingController = new NewLendingController(dbCon, pModel);
|
|
||||||
|
|
||||||
JTable freeArticleTable = new JTable(freeArticleTableModel);
|
JTable freeArticleTable = new JTable(freeArticleTableModel);
|
||||||
freeArticleTable.setRowHeight(30);
|
freeArticleTable.setRowHeight(30);
|
||||||
@@ -155,9 +167,9 @@ public class NewLendingPanel extends JPanel implements ActionListener, FocusList
|
|||||||
tfName.addKeyListener(this);
|
tfName.addKeyListener(this);
|
||||||
tfSurname.addKeyListener(this);
|
tfSurname.addKeyListener(this);
|
||||||
tfStudentNumber.addKeyListener(this);
|
tfStudentNumber.addKeyListener(this);
|
||||||
AutoCompleteDecorator.decorate(tfName, lenderModel.getList(), false, new LenderNameConverter() );
|
AutoCompleteDecorator.decorate(tfName, kLenderModel.getData(), false, new LenderNameConverter() );
|
||||||
AutoCompleteDecorator.decorate(tfSurname, lenderModel.getList(), false, new LenderSurnameConverter());
|
AutoCompleteDecorator.decorate(tfSurname, kLenderModel.getData(), false, new LenderSurnameConverter());
|
||||||
AutoCompleteDecorator.decorate(tfStudentNumber, lenderModel.getList(), false, new LenderStudentnumberConverter());
|
AutoCompleteDecorator.decorate(tfStudentNumber, kLenderModel.getData(), false, new LenderStudentnumberConverter());
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
btnCancel = new JButton("Abbrechen");
|
btnCancel = new JButton("Abbrechen");
|
||||||
@@ -217,7 +229,7 @@ public class NewLendingPanel extends JPanel implements ActionListener, FocusList
|
|||||||
tfStudentNumber.setText("");
|
tfStudentNumber.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveButtonPressed(){
|
private void saveButtonPressed() throws Exception {
|
||||||
String pLName = tfName.getText();
|
String pLName = tfName.getText();
|
||||||
String pLSurname = tfSurname.getText();
|
String pLSurname = tfSurname.getText();
|
||||||
String startDate = lblStartDate.getText();
|
String startDate = lblStartDate.getText();
|
||||||
@@ -251,8 +263,8 @@ public class NewLendingPanel extends JPanel implements ActionListener, FocusList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setModeNewLending(int pRow) {
|
public void setModeNewLending(int id) {
|
||||||
KArticle art = freeArticleTableModel.getArticleByRow(pRow);
|
KArticle art = kArticleModel.getElement(id);
|
||||||
|
|
||||||
lblStartDate.setText(Util.getCurrentDate());
|
lblStartDate.setText(Util.getCurrentDate());
|
||||||
lblArticleName.setText(art.getName());
|
lblArticleName.setText(art.getName());
|
||||||
@@ -266,7 +278,11 @@ public class NewLendingPanel extends JPanel implements ActionListener, FocusList
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(pEvent.getSource() == btnSave){
|
if(pEvent.getSource() == btnSave){
|
||||||
|
try {
|
||||||
saveButtonPressed();
|
saveButtonPressed();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.showError(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -277,7 +293,7 @@ public class NewLendingPanel extends JPanel implements ActionListener, FocusList
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void focusLost(FocusEvent pEvent) {
|
public void focusLost(FocusEvent pEvent) {
|
||||||
ArrayList<KLender> result = lenderModel.getLenders(tfName.getText(), tfSurname.getText(), tfStudentNumber.getText());
|
ArrayList<KLender> result = kLenderModel.getLenders(tfName.getText(), tfSurname.getText(), tfStudentNumber.getText());
|
||||||
|
|
||||||
if(result.size() == 1){
|
if(result.size() == 1){
|
||||||
tfName.setText(result.get(0).getName());
|
tfName.setText(result.get(0).getName());
|
||||||
@@ -287,7 +303,12 @@ public class NewLendingPanel extends JPanel implements ActionListener, FocusList
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void keyPressed(KeyEvent pKeyPress) {
|
public void keyPressed(KeyEvent pKeyPress) {
|
||||||
if(pKeyPress.getKeyCode() == KeyEvent.VK_ENTER) saveButtonPressed();
|
if(pKeyPress.getKeyCode() == KeyEvent.VK_ENTER)
|
||||||
|
try {
|
||||||
|
saveButtonPressed();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Util.showError(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
107
src/de/katho/kBorrow/gui/RewriteToNewUserDialog.java
Normal file
107
src/de/katho/kBorrow/gui/RewriteToNewUserDialog.java
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
package de.katho.kBorrow.gui;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.controller.RewriteToNewUserController;
|
||||||
|
import de.katho.kBorrow.interfaces.DbConnector;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
|
import de.katho.kBorrow.models.RewriteUserModel;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
|
||||||
|
public class RewriteToNewUserDialog extends JDialog implements ActionListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -6002073589194176368L;
|
||||||
|
private final JPanel contentPanel = new JPanel();
|
||||||
|
|
||||||
|
private JButton okButton;
|
||||||
|
private JButton cancelButton;
|
||||||
|
private RewriteUserModel rwusermodel;
|
||||||
|
private RewriteToNewUserController rwcontroller;
|
||||||
|
|
||||||
|
private int result = 1;
|
||||||
|
private int oldId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the dialog.
|
||||||
|
*/
|
||||||
|
public RewriteToNewUserDialog(int pOldId, DbConnector pDbCon, KDataModel userModel) {
|
||||||
|
setTitle("Ausleihe umschreiben");
|
||||||
|
setModal(true);
|
||||||
|
setModalityType(ModalityType.APPLICATION_MODAL);
|
||||||
|
setResizable(false);
|
||||||
|
setBounds(100, 100, 229, 156);
|
||||||
|
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||||
|
JPanel contentPane = new JPanel();
|
||||||
|
setContentPane(contentPane);
|
||||||
|
contentPane.setLayout(new BorderLayout());
|
||||||
|
oldId = pOldId;
|
||||||
|
rwusermodel = new RewriteUserModel(userModel, oldId);
|
||||||
|
rwcontroller = new RewriteToNewUserController(pDbCon);
|
||||||
|
|
||||||
|
// Content Panel
|
||||||
|
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
|
contentPanel.setLayout(null);
|
||||||
|
|
||||||
|
JComboBox<String> comboBox = new JComboBox<String>(rwusermodel);
|
||||||
|
comboBox.setBounds(11, 52, 200, 30);
|
||||||
|
|
||||||
|
contentPanel.add(comboBox);
|
||||||
|
|
||||||
|
// Button Panel
|
||||||
|
JPanel buttonPane = new JPanel();
|
||||||
|
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||||
|
|
||||||
|
okButton = new JButton("OK");
|
||||||
|
cancelButton = new JButton("Cancel");
|
||||||
|
okButton.addActionListener(this);
|
||||||
|
cancelButton.addActionListener(this);
|
||||||
|
|
||||||
|
buttonPane.add(okButton);
|
||||||
|
buttonPane.add(cancelButton);
|
||||||
|
|
||||||
|
contentPane.add(buttonPane, BorderLayout.SOUTH);
|
||||||
|
contentPane.add(contentPanel, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
JLabel lblBenutzerAuswhlenAuf = new JLabel("<html>Benutzer ausw\u00E4hlen, auf den <br /> Ausleihen umgeschrieben werden sollen.</html>");
|
||||||
|
lblBenutzerAuswhlenAuf.setBounds(11, 11, 200, 30);
|
||||||
|
contentPanel.add(lblBenutzerAuswhlenAuf);
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
|
// OK Button pressed
|
||||||
|
if(e.getSource() == okButton ) {
|
||||||
|
int newId = rwusermodel.getIdByFullname(rwusermodel.getSelectedItem());
|
||||||
|
|
||||||
|
if(rwcontroller.rewriteToNewUser(oldId, newId)){
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel Button pressed
|
||||||
|
if(e.getSource() == cancelButton ) {
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getResult(){
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -20,8 +20,10 @@ import javax.swing.UIManager;
|
|||||||
import javax.swing.border.TitledBorder;
|
import javax.swing.border.TitledBorder;
|
||||||
|
|
||||||
import de.katho.kBorrow.controller.UserController;
|
import de.katho.kBorrow.controller.UserController;
|
||||||
import de.katho.kBorrow.data.KUser;
|
import de.katho.kBorrow.data.KUserModel;
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.data.objects.KUser;
|
||||||
|
import de.katho.kBorrow.interfaces.DbConnector;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
import de.katho.kBorrow.listener.UserDeleteTableButton;
|
import de.katho.kBorrow.listener.UserDeleteTableButton;
|
||||||
import de.katho.kBorrow.listener.UserEditTableButton;
|
import de.katho.kBorrow.listener.UserEditTableButton;
|
||||||
import de.katho.kBorrow.models.UserTableModel;
|
import de.katho.kBorrow.models.UserTableModel;
|
||||||
@@ -36,17 +38,17 @@ public class UserPanel extends JPanel implements ActionListener, KeyListener {
|
|||||||
private JButton btnUserCancel;
|
private JButton btnUserCancel;
|
||||||
private boolean userModeEdit;
|
private boolean userModeEdit;
|
||||||
private int userEditId;
|
private int userEditId;
|
||||||
private UserTableModel userTableModel;
|
private KUserModel kUserModel;
|
||||||
private UserController userController;
|
private UserController userController;
|
||||||
|
|
||||||
public UserPanel(final DbConnector dbCon, HashMap<String, Object> pModels) throws IOException{
|
public UserPanel(final DbConnector dbCon, HashMap<String, KDataModel> models) throws IOException{
|
||||||
super();
|
super();
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
userTableModel = (UserTableModel)pModels.get("usertablemodel");
|
kUserModel = (KUserModel)models.get("kusermodel");
|
||||||
userController = new UserController(dbCon, pModels);
|
userController = new UserController(dbCon, models);
|
||||||
|
|
||||||
//Tabelle und drumherum
|
//Tabelle und drumherum
|
||||||
JTable userTable = new JTable(userTableModel);
|
JTable userTable = new JTable(new UserTableModel(kUserModel));
|
||||||
userTable.setRowHeight(30);
|
userTable.setRowHeight(30);
|
||||||
UserDeleteTableButton userDeleteTableButton = new UserDeleteTableButton("L<EFBFBD>schen", userTable, this, userController);
|
UserDeleteTableButton userDeleteTableButton = new UserDeleteTableButton("L<EFBFBD>schen", userTable, this, userController);
|
||||||
UserEditTableButton userEditTableButton = new UserEditTableButton("Bearbeiten", userTable, this);
|
UserEditTableButton userEditTableButton = new UserEditTableButton("Bearbeiten", userTable, this);
|
||||||
@@ -147,8 +149,8 @@ public class UserPanel extends JPanel implements ActionListener, KeyListener {
|
|||||||
this.textFieldUserSurname.setText("");
|
this.textFieldUserSurname.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setModeEditUser(int pRow){
|
public void setModeEditUser(int pId){
|
||||||
KUser user = userTableModel.getUserByRow(pRow);
|
KUser user = kUserModel.getElement(pId);
|
||||||
|
|
||||||
this.userModeEdit = true;
|
this.userModeEdit = true;
|
||||||
this.userEditId = user.getId();
|
this.userEditId = user.getId();
|
||||||
@@ -205,6 +207,10 @@ public class UserPanel extends JPanel implements ActionListener, KeyListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setStatusLabel(String pText){
|
||||||
|
lblUserStatus.setText(pText);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent pKeyPress) {
|
public void keyPressed(KeyEvent pKeyPress) {
|
||||||
if(pKeyPress.getKeyCode() == KeyEvent.VK_ENTER) saveButtonPressed();
|
if(pKeyPress.getKeyCode() == KeyEvent.VK_ENTER) saveButtonPressed();
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package de.katho.kBorrow.db;
|
package de.katho.kBorrow.interfaces;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import de.katho.kBorrow.data.KArticle;
|
import de.katho.kBorrow.data.objects.KArticle;
|
||||||
import de.katho.kBorrow.data.KLender;
|
import de.katho.kBorrow.data.objects.KLender;
|
||||||
import de.katho.kBorrow.data.KLending;
|
import de.katho.kBorrow.data.objects.KLending;
|
||||||
import de.katho.kBorrow.data.KUser;
|
import de.katho.kBorrow.data.objects.KUser;
|
||||||
|
|
||||||
public interface DbConnector {
|
public interface DbConnector {
|
||||||
|
|
||||||
@@ -19,9 +19,12 @@ public interface DbConnector {
|
|||||||
public int editArticle(int pId, String pName, String pDesc);
|
public int editArticle(int pId, String pName, String pDesc);
|
||||||
public ArrayList<KArticle> getFreeArticleList();
|
public ArrayList<KArticle> getFreeArticleList();
|
||||||
public ArrayList<KLender> getLenderList();
|
public ArrayList<KLender> getLenderList();
|
||||||
public int createNewLending(int pArtId, int pUId, int pLId, String pStartDate, String pEstEndDate);
|
public int[] createNewLending(int pArtId, int pUId, int pLId, String pStartDate, String pEstEndDate);
|
||||||
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> getLendingList();
|
||||||
public ArrayList<KLending> getLendingListForArticle(int pArtId);
|
public ArrayList<KLending> getLendingListForArticle(int pArtId);
|
||||||
|
public ArrayList<KUser> getRewriteUserList(int id);
|
||||||
|
public boolean rewriteToNewUser(int pOldId, int pNewId);
|
||||||
}
|
}
|
||||||
10
src/de/katho/kBorrow/interfaces/KDataModel.java
Normal file
10
src/de/katho/kBorrow/interfaces/KDataModel.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package de.katho.kBorrow.interfaces;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public interface KDataModel {
|
||||||
|
public void register(KGuiModel pModel);
|
||||||
|
public void updateModel();
|
||||||
|
public ArrayList<?> getData();
|
||||||
|
public Object getElement(int id);
|
||||||
|
}
|
||||||
6
src/de/katho/kBorrow/interfaces/KGuiModel.java
Normal file
6
src/de/katho/kBorrow/interfaces/KGuiModel.java
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package de.katho.kBorrow.interfaces;
|
||||||
|
|
||||||
|
|
||||||
|
public interface KGuiModel {
|
||||||
|
public void fetchData(KDataModel pModel);
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import javax.swing.JTable;
|
|||||||
import sun.tools.jar.Main;
|
import sun.tools.jar.Main;
|
||||||
import de.katho.kBorrow.controller.ArticleController;
|
import de.katho.kBorrow.controller.ArticleController;
|
||||||
import de.katho.kBorrow.gui.ArticlePanel;
|
import de.katho.kBorrow.gui.ArticlePanel;
|
||||||
|
import de.katho.kBorrow.models.ArticleTableModel;
|
||||||
|
|
||||||
public class ArticleDeleteTableButton extends TableButton {
|
public class ArticleDeleteTableButton extends TableButton {
|
||||||
|
|
||||||
@@ -24,16 +25,17 @@ public class ArticleDeleteTableButton extends TableButton {
|
|||||||
URL url = Main.class.getResource("/icons/edit-delete.png");
|
URL url = Main.class.getResource("/icons/edit-delete.png");
|
||||||
ImageIcon icon = new ImageIcon(url);
|
ImageIcon icon = new ImageIcon(url);
|
||||||
|
|
||||||
this.buttonE.setIcon(icon);
|
buttonE.setIcon(icon);
|
||||||
this.buttonR.setIcon(icon);
|
buttonR.setIcon(icon);
|
||||||
|
|
||||||
this.buttonE.addActionListener(new ActionListener(){
|
buttonE.addActionListener(new ActionListener(){
|
||||||
public void actionPerformed(ActionEvent e){
|
public void actionPerformed(ActionEvent e){
|
||||||
fireEditingStopped();
|
fireEditingStopped();
|
||||||
|
|
||||||
int row = pTable.getSelectedRow();
|
int row = pTable.getSelectedRow();
|
||||||
|
int id = ((ArticleTableModel)pTable.getModel()).getIdFromRow(row);
|
||||||
|
|
||||||
pPanel.setDeleteStatusLabel(pController.deleteArticle(row));
|
pPanel.setDeleteStatusLabel(pController.deleteArticle(id));
|
||||||
pPanel.resetModeEditArticle();
|
pPanel.resetModeEditArticle();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import javax.swing.JTable;
|
|||||||
|
|
||||||
import sun.tools.jar.Main;
|
import sun.tools.jar.Main;
|
||||||
import de.katho.kBorrow.gui.ArticlePanel;
|
import de.katho.kBorrow.gui.ArticlePanel;
|
||||||
|
import de.katho.kBorrow.models.ArticleTableModel;
|
||||||
|
|
||||||
public class ArticleEditTableButton extends TableButton {
|
public class ArticleEditTableButton extends TableButton {
|
||||||
|
|
||||||
@@ -31,8 +32,9 @@ public class ArticleEditTableButton extends TableButton {
|
|||||||
fireEditingStopped();
|
fireEditingStopped();
|
||||||
|
|
||||||
int row = pTable.getSelectedRow();
|
int row = pTable.getSelectedRow();
|
||||||
|
int id = ((ArticleTableModel)pTable.getModel()).getIdFromRow(row);
|
||||||
|
|
||||||
articleTab.setModeEditArticle(row);
|
articleTab.setModeEditArticle(id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,9 @@ import javax.swing.ImageIcon;
|
|||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
|
|
||||||
import sun.tools.jar.Main;
|
import sun.tools.jar.Main;
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
|
||||||
import de.katho.kBorrow.gui.ArticleInspectFrame;
|
import de.katho.kBorrow.gui.ArticleInspectFrame;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
|
import de.katho.kBorrow.models.ArticleTableModel;
|
||||||
|
|
||||||
public class ArticleInspectTableButton extends TableButton {
|
public class ArticleInspectTableButton extends TableButton {
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ public class ArticleInspectTableButton extends TableButton {
|
|||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -2591133864537097893L;
|
private static final long serialVersionUID = -2591133864537097893L;
|
||||||
|
|
||||||
public ArticleInspectTableButton(String pLabel, final JTable pTable, final DbConnector dbCon, final HashMap<String, Object> pModels) throws IOException {
|
public ArticleInspectTableButton(String pLabel, final JTable pTable, final HashMap<String, KDataModel> models) throws IOException {
|
||||||
super(pLabel);
|
super(pLabel);
|
||||||
URL url = Main.class.getResource("/icons/system-search.png");
|
URL url = Main.class.getResource("/icons/system-search.png");
|
||||||
ImageIcon icon = new ImageIcon(url);
|
ImageIcon icon = new ImageIcon(url);
|
||||||
@@ -33,8 +34,9 @@ public class ArticleInspectTableButton extends TableButton {
|
|||||||
fireEditingStopped();
|
fireEditingStopped();
|
||||||
|
|
||||||
int row = pTable.getSelectedRow();
|
int row = pTable.getSelectedRow();
|
||||||
|
int id = ((ArticleTableModel)pTable.getModel()).getIdFromRow(row);
|
||||||
|
|
||||||
new ArticleInspectFrame(row, dbCon, pModels);
|
new ArticleInspectFrame(id, models);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import javax.swing.JTable;
|
|||||||
|
|
||||||
import sun.tools.jar.Main;
|
import sun.tools.jar.Main;
|
||||||
import de.katho.kBorrow.controller.ManageLendingsController;
|
import de.katho.kBorrow.controller.ManageLendingsController;
|
||||||
|
import de.katho.kBorrow.models.LendingTableModel;
|
||||||
|
|
||||||
public class LendingReturnTableButton extends TableButton {
|
public class LendingReturnTableButton extends TableButton {
|
||||||
|
|
||||||
@@ -31,8 +32,9 @@ public class LendingReturnTableButton extends TableButton {
|
|||||||
fireEditingStopped();
|
fireEditingStopped();
|
||||||
|
|
||||||
int row = pTable.getSelectedRow();
|
int row = pTable.getSelectedRow();
|
||||||
|
int id = ((LendingTableModel)pTable.getModel()).getIdFromRow(row);
|
||||||
|
|
||||||
pController.returnLending(row);
|
pController.returnLending(id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import javax.swing.JTable;
|
|||||||
|
|
||||||
import sun.tools.jar.Main;
|
import sun.tools.jar.Main;
|
||||||
import de.katho.kBorrow.gui.NewLendingPanel;
|
import de.katho.kBorrow.gui.NewLendingPanel;
|
||||||
|
import de.katho.kBorrow.models.FreeArticleTableModel;
|
||||||
|
|
||||||
public class NewLendingTableButton extends TableButton {
|
public class NewLendingTableButton extends TableButton {
|
||||||
|
|
||||||
@@ -31,8 +32,9 @@ public class NewLendingTableButton extends TableButton {
|
|||||||
fireEditingStopped();
|
fireEditingStopped();
|
||||||
|
|
||||||
int row = pTable.getSelectedRow();
|
int row = pTable.getSelectedRow();
|
||||||
|
int id = ((FreeArticleTableModel)pTable.getModel()).getIdFromRow(row);
|
||||||
|
|
||||||
pPanel.setModeNewLending(row);
|
pPanel.setModeNewLending(id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import javax.swing.JTable;
|
|||||||
import sun.tools.jar.Main;
|
import sun.tools.jar.Main;
|
||||||
import de.katho.kBorrow.controller.UserController;
|
import de.katho.kBorrow.controller.UserController;
|
||||||
import de.katho.kBorrow.gui.UserPanel;
|
import de.katho.kBorrow.gui.UserPanel;
|
||||||
|
import de.katho.kBorrow.models.UserTableModel;
|
||||||
|
|
||||||
public class UserDeleteTableButton extends TableButton {
|
public class UserDeleteTableButton extends TableButton {
|
||||||
|
|
||||||
@@ -29,8 +30,11 @@ public class UserDeleteTableButton extends TableButton {
|
|||||||
fireEditingStopped();
|
fireEditingStopped();
|
||||||
|
|
||||||
int row = pTable.getSelectedRow();
|
int row = pTable.getSelectedRow();
|
||||||
|
int id = ((UserTableModel)pTable.getModel()).getIdFromRow(row);
|
||||||
|
|
||||||
|
if(pController.deleteUser(id)) pPanel.setStatusLabel("Benutzer erfolgreich gel<65>scht.");
|
||||||
|
else pPanel.setStatusLabel("Beuntzer konnte nicht gel<65>scht werden.");
|
||||||
|
|
||||||
pController.deleteUser(row);
|
|
||||||
pPanel.resetModeEditUser();
|
pPanel.resetModeEditUser();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import javax.swing.JTable;
|
|||||||
|
|
||||||
import sun.tools.jar.Main;
|
import sun.tools.jar.Main;
|
||||||
import de.katho.kBorrow.gui.UserPanel;
|
import de.katho.kBorrow.gui.UserPanel;
|
||||||
|
import de.katho.kBorrow.models.UserTableModel;
|
||||||
|
|
||||||
public class UserEditTableButton extends TableButton {
|
public class UserEditTableButton extends TableButton {
|
||||||
|
|
||||||
@@ -31,8 +32,9 @@ public class UserEditTableButton extends TableButton {
|
|||||||
fireEditingStopped();
|
fireEditingStopped();
|
||||||
|
|
||||||
int row = pTable.getSelectedRow();
|
int row = pTable.getSelectedRow();
|
||||||
|
int id = ((UserTableModel)pTable.getModel()).getIdFromRow(row);
|
||||||
|
|
||||||
pPanel.setModeEditUser(row);
|
pPanel.setModeEditUser(id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,42 +5,35 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
|
||||||
import de.katho.kBorrow.data.KArticle;
|
import de.katho.kBorrow.data.KLenderModel;
|
||||||
import de.katho.kBorrow.data.KLender;
|
import de.katho.kBorrow.data.KLendingModel;
|
||||||
import de.katho.kBorrow.data.KLending;
|
import de.katho.kBorrow.data.KUserModel;
|
||||||
import de.katho.kBorrow.data.KUser;
|
import de.katho.kBorrow.data.objects.KLender;
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.data.objects.KLending;
|
||||||
|
import de.katho.kBorrow.data.objects.KUser;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
|
import de.katho.kBorrow.interfaces.KGuiModel;
|
||||||
|
|
||||||
public class ArticleInspectTableModel extends AbstractTableModel {
|
public class ArticleInspectTableModel extends AbstractTableModel implements KGuiModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 2293157709447086998L;
|
private static final long serialVersionUID = 2293157709447086998L;
|
||||||
private String[] header;
|
private String[] header;
|
||||||
|
private int articleId;
|
||||||
private ArrayList<KLending> data;
|
private ArrayList<KLending> data;
|
||||||
private DbConnector dbCon;
|
private KUserModel userModel;
|
||||||
private KArticle article;
|
private KLenderModel lenderModel;
|
||||||
private ArticleTableModel articleModel;
|
|
||||||
private UserTableModel userModel;
|
|
||||||
private LenderModel lenderModel;
|
|
||||||
|
|
||||||
|
|
||||||
public ArticleInspectTableModel(int pRow, DbConnector pDbCon, HashMap<String, Object> pModels){
|
public ArticleInspectTableModel(int pId, HashMap<String, KDataModel> models){
|
||||||
header = new String[] {"ID", "Verliehen von:", "Ausgeliehen an:", "Ausleihdatum", "Vor. R<>ckgabe", "R<EFBFBD>ckgabe"};
|
header = new String[] {"ID", "Verliehen von:", "Ausgeliehen an:", "Ausleihdatum", "Vor. R<>ckgabe", "R<EFBFBD>ckgabe"};
|
||||||
dbCon = pDbCon;
|
articleId = pId;
|
||||||
articleModel = (ArticleTableModel)pModels.get("articletablemodel");
|
userModel = (KUserModel)models.get("kusermodel");
|
||||||
userModel = (UserTableModel)pModels.get("usertablemodel");
|
lenderModel = (KLenderModel)models.get("klendermodel");
|
||||||
lenderModel = (LenderModel)pModels.get("lendermodel");
|
|
||||||
|
|
||||||
article = articleModel.getArticleByRow(pRow);
|
fetchData(((KLendingModel)models.get("klendingmodel")));
|
||||||
|
|
||||||
updateModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateModel() {
|
|
||||||
data = dbCon.getLendingListForArticle(article.getId());
|
|
||||||
fireTableDataChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColumnCount() {
|
public int getColumnCount() {
|
||||||
@@ -66,13 +59,13 @@ public class ArticleInspectTableModel extends AbstractTableModel {
|
|||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
int uid = data.get(row).getUserId();
|
int uid = data.get(row).getUserId();
|
||||||
KUser user = userModel.getUserById(uid);
|
KUser user = userModel.getElement(uid);
|
||||||
|
|
||||||
return user.getName()+" "+user.getSurname();
|
return user.getName()+" "+user.getSurname();
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
int lid = data.get(row).getLenderId();
|
int lid = data.get(row).getLenderId();
|
||||||
KLender lender = lenderModel.getLenderById(lid);
|
KLender lender = lenderModel.getElement(lid);
|
||||||
|
|
||||||
return lender.getName()+" "+lender.getSurname()+" ("+lender.getStudentnumber()+")";
|
return lender.getName()+" "+lender.getSurname()+" ("+lender.getStudentnumber()+")";
|
||||||
|
|
||||||
@@ -90,4 +83,16 @@ public class ArticleInspectTableModel extends AbstractTableModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void fetchData(KDataModel pModel) {
|
||||||
|
if(pModel instanceof KLendingModel){
|
||||||
|
data = new ArrayList<KLending>();
|
||||||
|
|
||||||
|
for(KLending elem : ((KLendingModel)pModel).getData()){
|
||||||
|
if(elem.getArticleId() == articleId) data.add(elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
fireTableDataChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,13 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
|
||||||
import de.katho.kBorrow.data.KArticle;
|
import de.katho.kBorrow.data.KArticleModel;
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.data.objects.KArticle;
|
||||||
|
import de.katho.kBorrow.interfaces.DbConnector;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
|
import de.katho.kBorrow.interfaces.KGuiModel;
|
||||||
|
|
||||||
public class ArticleTableModel extends AbstractTableModel {
|
public class ArticleTableModel extends AbstractTableModel implements KGuiModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -17,21 +20,15 @@ public class ArticleTableModel extends AbstractTableModel {
|
|||||||
protected DbConnector dbCon;
|
protected DbConnector dbCon;
|
||||||
protected ArrayList<KArticle> data = new ArrayList<KArticle>();
|
protected ArrayList<KArticle> data = new ArrayList<KArticle>();
|
||||||
|
|
||||||
public ArticleTableModel(DbConnector pDbCon){
|
public ArticleTableModel(KDataModel pModel){
|
||||||
header = new String [] {"ID", "Artikelname", "Artikelbeschreibung", "", "", ""};
|
header = new String [] {"ID", "Artikelname", "Artikelbeschreibung", "", "", ""};
|
||||||
this.dbCon = pDbCon;
|
pModel.register(this);
|
||||||
this.updateModel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getColumnName(int index){
|
public String getColumnName(int index){
|
||||||
return header[index];
|
return header[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateModel() {
|
|
||||||
this.data = this.dbCon.getArticleList();
|
|
||||||
this.fireTableDataChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getColumnCount() {
|
public int getColumnCount() {
|
||||||
return header.length;
|
return header.length;
|
||||||
}
|
}
|
||||||
@@ -63,40 +60,17 @@ public class ArticleTableModel extends AbstractTableModel {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public int getIdFromRow(int pRow){
|
||||||
* Gibt die entsprechende Zeile in der Tabelle f<>r ein Objekt mit der gegebenen ID zur<75>ck.
|
return data.get(pRow).getId();
|
||||||
*
|
|
||||||
* @param id ID, f<>r die die Tabellenzeile herausgesucht werden soll
|
|
||||||
* @return Zeile in der Tabelle. -1, wenn die ID nicht vorhanden ist.
|
|
||||||
*/
|
|
||||||
public int getRowFromId(int id) {
|
|
||||||
for (KArticle elem : this.data){
|
|
||||||
if(elem.getId() == id) return data.indexOf(elem);
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void fetchData(KDataModel pModel) {
|
||||||
* Gibt das Article-Objekt der <20>bergebenen Zeile zur<75>ck.
|
if(pModel instanceof KArticleModel){
|
||||||
*
|
data = ((KArticleModel)pModel).getData();
|
||||||
* @param pRow Zeile, deren Article-Objekt zur<75>ckgegeben werden soll.
|
|
||||||
* @return KArticle-Objekt
|
fireTableDataChanged();
|
||||||
*/
|
}
|
||||||
public KArticle getArticleByRow(int pRow){
|
|
||||||
return data.get(pRow);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gibt das Article-Objekt mit der entsprechendne ID zur<75>ck.
|
|
||||||
*
|
|
||||||
* @param pId Id, deren Objekt zur<75>ckgegeben werden soll.
|
|
||||||
* @return KArticle-Objekt
|
|
||||||
*/
|
|
||||||
public KArticle getArticleById(int pId){
|
|
||||||
for(KArticle elem : data){
|
|
||||||
if(elem.getId() == pId) return elem;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
package de.katho.kBorrow.models;
|
package de.katho.kBorrow.models;
|
||||||
|
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import java.util.ArrayList;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class FreeArticleTableModel extends ArticleTableModel {
|
import de.katho.kBorrow.KLogger;
|
||||||
|
import de.katho.kBorrow.data.KArticleModel;
|
||||||
|
import de.katho.kBorrow.data.objects.KArticle;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
|
import de.katho.kBorrow.interfaces.KGuiModel;
|
||||||
|
|
||||||
|
public class FreeArticleTableModel extends ArticleTableModel implements KGuiModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -10,19 +17,29 @@ public class FreeArticleTableModel extends ArticleTableModel {
|
|||||||
private static final long serialVersionUID = 1908669541941834593L;
|
private static final long serialVersionUID = 1908669541941834593L;
|
||||||
private String[] header;
|
private String[] header;
|
||||||
|
|
||||||
public FreeArticleTableModel(DbConnector pDbCon) {
|
public FreeArticleTableModel(KDataModel pModel) {
|
||||||
super(pDbCon);
|
super(pModel);
|
||||||
this.header = new String[] {"ID", "Artikelname", "Artikelbeschreibung", ""};
|
header = new String[] {"ID", "Artikelname", "Artikelbeschreibung", ""};
|
||||||
|
pModel.register(this);
|
||||||
updateModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateModel(){
|
|
||||||
data = dbCon.getFreeArticleList();
|
|
||||||
fireTableDataChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColumnCount(){
|
public int getColumnCount(){
|
||||||
return header.length;
|
return header.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void fetchData(KDataModel pModel) {
|
||||||
|
if(pModel instanceof KArticleModel){
|
||||||
|
data = new ArrayList<KArticle>();
|
||||||
|
|
||||||
|
for(KArticle elem : ((KArticleModel)pModel).getData()){
|
||||||
|
if (elem.getIsFree()) data.add(elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
fireTableDataChanged();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
KLogger.log(Level.SEVERE, "FreeArticleModel: Typecast error!", new Exception("FreeArticleModel: Typecast error!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,32 +5,34 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
|
||||||
import de.katho.kBorrow.data.KArticle;
|
import de.katho.kBorrow.data.KLendingModel;
|
||||||
import de.katho.kBorrow.data.KLender;
|
import de.katho.kBorrow.data.objects.KArticle;
|
||||||
import de.katho.kBorrow.data.KLending;
|
import de.katho.kBorrow.data.objects.KLender;
|
||||||
import de.katho.kBorrow.data.KUser;
|
import de.katho.kBorrow.data.objects.KLending;
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.data.objects.KUser;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
|
import de.katho.kBorrow.interfaces.KGuiModel;
|
||||||
|
|
||||||
public class LendingTableModel extends AbstractTableModel {
|
public class LendingTableModel extends AbstractTableModel implements KGuiModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 1375465648631587292L;
|
private static final long serialVersionUID = 1375465648631587292L;
|
||||||
private DbConnector dbCon;
|
|
||||||
private String[] header = {"ID", "Artikel", "Verliehen von:", "Ausgeliehen an:", "Ausleihdatum", "Vor. R<>ckgabe", ""};
|
private String[] header = {"ID", "Artikel", "Verliehen von:", "Ausgeliehen an:", "Ausleihdatum", "Vor. R<>ckgabe", ""};
|
||||||
private ArrayList<KLending> data = new ArrayList<KLending>();
|
private ArrayList<KLending> data;
|
||||||
private ArticleTableModel articleModel;
|
private KDataModel articleModel;
|
||||||
private LenderModel lenderModel;
|
private KDataModel lenderModel;
|
||||||
private UserTableModel userTableModel;
|
private KDataModel userModel;
|
||||||
|
private KDataModel lendingModel;
|
||||||
|
|
||||||
public LendingTableModel(DbConnector pDbCon, HashMap<String, Object> pModels ) {
|
public LendingTableModel(HashMap<String, KDataModel> pModels ) {
|
||||||
dbCon = pDbCon;
|
articleModel = pModels.get("karticlemodel");
|
||||||
articleModel = (ArticleTableModel)pModels.get("articletablemodel");
|
lenderModel = pModels.get("klendermodel");
|
||||||
lenderModel = (LenderModel)pModels.get("lendermodel");
|
userModel = pModels.get("kusermodel");
|
||||||
userTableModel = (UserTableModel)pModels.get("usertablemodel");
|
lendingModel = pModels.get("klendingmodel");
|
||||||
|
|
||||||
updateModel();
|
lendingModel.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColumnCount() {
|
public int getColumnCount() {
|
||||||
@@ -52,19 +54,19 @@ public class LendingTableModel extends AbstractTableModel {
|
|||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
int artId = data.get(row).getArticleId();
|
int artId = data.get(row).getArticleId();
|
||||||
KArticle art = articleModel.getArticleById(artId);
|
KArticle art = (KArticle) articleModel.getElement(artId);
|
||||||
|
|
||||||
return art.getName();
|
return art.getName();
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
int uId = data.get(row).getUserId();
|
int uId = data.get(row).getUserId();
|
||||||
KUser user = userTableModel.getUserById(uId);
|
KUser user = (KUser) userModel.getElement(uId);
|
||||||
|
|
||||||
return user.getName()+" "+user.getSurname();
|
return user.getName()+" "+user.getSurname();
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
int lenderId = data.get(row).getLenderId();
|
int lenderId = data.get(row).getLenderId();
|
||||||
KLender lender = lenderModel.getLenderById(lenderId);
|
KLender lender = (KLender) lenderModel.getElement(lenderId);
|
||||||
|
|
||||||
return lender.getName()+" "+lender.getSurname()+" ("+lender.getStudentnumber()+")";
|
return lender.getName()+" "+lender.getSurname()+" ("+lender.getStudentnumber()+")";
|
||||||
|
|
||||||
@@ -79,26 +81,24 @@ public class LendingTableModel extends AbstractTableModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Die Funktion muss differenzierter werden
|
|
||||||
public boolean isCellEditable(int row, int col){
|
public boolean isCellEditable(int row, int col){
|
||||||
if (col > 4) return true;
|
if (col > 4) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateModel(){
|
public void fetchData(KDataModel pModel) {
|
||||||
data = dbCon.getActiveLendingList();
|
data = new ArrayList<KLending>();
|
||||||
|
|
||||||
|
if(pModel instanceof KLendingModel){
|
||||||
|
for(KLending elem : ((KLendingModel)pModel).getData()){
|
||||||
|
if(elem.getEndDate() == null || elem.getEndDate().equals("")) data.add(elem);
|
||||||
|
}
|
||||||
fireTableDataChanged();
|
fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public KLending getLendingByRow(int row) {
|
|
||||||
return data.get(row);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public KLending getLendingById(int id){
|
public int getIdFromRow(int pRow){
|
||||||
for(KLending elem : data){
|
return data.get(pRow).getId();
|
||||||
if(elem.getId() == id) return elem;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
48
src/de/katho/kBorrow/models/RewriteUserModel.java
Normal file
48
src/de/katho/kBorrow/models/RewriteUserModel.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package de.katho.kBorrow.models;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.KLogger;
|
||||||
|
import de.katho.kBorrow.data.KUserModel;
|
||||||
|
import de.katho.kBorrow.data.objects.KUser;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
|
|
||||||
|
public class RewriteUserModel extends UserListModel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -78927566018961799L;
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
public RewriteUserModel(KDataModel pModel, int pId) {
|
||||||
|
super(pModel);
|
||||||
|
id = pId;
|
||||||
|
pModel.register(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIdByFullname(String pName){
|
||||||
|
for (KUser elem : data){
|
||||||
|
if(pName.equals(elem.getName()+" "+elem.getSurname())) return elem.getId();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fetchData(KDataModel pModel){
|
||||||
|
if(pModel instanceof KUserModel){
|
||||||
|
data = new ArrayList<KUser>();
|
||||||
|
|
||||||
|
for(KUser elem : ((KUserModel)pModel).getData()){
|
||||||
|
if(elem.getId() != id) data.add(elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data.size() > 0) setSelectedItem(data.get(0).getName()+" "+data.get(0).getSurname());
|
||||||
|
|
||||||
|
fireIntervalAdded(this, 0, data.size()-1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
KLogger.log(Level.SEVERE, "RewriteUserModel: Typecast error!", new Exception("RewriteUserModel: Typecast error!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,32 +5,23 @@ import java.util.ArrayList;
|
|||||||
import javax.swing.AbstractListModel;
|
import javax.swing.AbstractListModel;
|
||||||
import javax.swing.ComboBoxModel;
|
import javax.swing.ComboBoxModel;
|
||||||
|
|
||||||
import de.katho.kBorrow.data.KUser;
|
import de.katho.kBorrow.data.KUserModel;
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.data.objects.KUser;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
|
import de.katho.kBorrow.interfaces.KGuiModel;
|
||||||
|
|
||||||
public class UserListModel extends AbstractListModel<String> implements ComboBoxModel<String> {
|
public class UserListModel extends AbstractListModel<String> implements ComboBoxModel<String>, KGuiModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -8653066929273274524L;
|
private static final long serialVersionUID = -8653066929273274524L;
|
||||||
private DbConnector dbCon;
|
protected ArrayList<KUser> data;
|
||||||
private ArrayList<KUser> data;
|
protected String selectedItem = null;
|
||||||
private String selectedItem = null;
|
|
||||||
|
|
||||||
public UserListModel(DbConnector pDbCon){
|
public UserListModel(KDataModel pUserModel){
|
||||||
super();
|
super();
|
||||||
dbCon = pDbCon;
|
pUserModel.register(this);
|
||||||
updateModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void updateModel() {
|
|
||||||
data = dbCon.getUserList();
|
|
||||||
|
|
||||||
if(data.size() > 0) setSelectedItem(data.get(0).getName()+" "+data.get(0).getSurname());
|
|
||||||
|
|
||||||
fireIntervalAdded(this, 0, data.size()-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelectedItem(Object object) {
|
public void setSelectedItem(Object object) {
|
||||||
@@ -65,11 +56,14 @@ public class UserListModel extends AbstractListModel<String> implements ComboBox
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getIdByFullname(String pName){
|
public void fetchData(KDataModel pModel) {
|
||||||
for (KUser elem : data){
|
if(pModel instanceof KUserModel){
|
||||||
if(pName.equals(elem.getName()+" "+elem.getSurname())) return elem.getId();
|
data = ((KUserModel)pModel).getData();
|
||||||
}
|
}
|
||||||
return -1;
|
|
||||||
|
if(data.size() > 0) setSelectedItem(data.get(0).getName()+" "+data.get(0).getSurname());
|
||||||
|
|
||||||
|
fireIntervalAdded(this, 0, data.size()-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,30 +4,30 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
|
||||||
import de.katho.kBorrow.data.KUser;
|
import de.katho.kBorrow.data.KUserModel;
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.data.objects.KUser;
|
||||||
|
import de.katho.kBorrow.interfaces.KDataModel;
|
||||||
|
import de.katho.kBorrow.interfaces.KGuiModel;
|
||||||
|
|
||||||
public class UserTableModel extends AbstractTableModel {
|
public class UserTableModel extends AbstractTableModel implements KGuiModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 435829735305533728L;
|
private static final long serialVersionUID = 435829735305533728L;
|
||||||
private DbConnector dbCon;
|
|
||||||
private String[] header = {"ID", "Vorname", "Nachname", "", ""};
|
private String[] header = {"ID", "Vorname", "Nachname", "", ""};
|
||||||
private ArrayList<KUser> data = new ArrayList<KUser>();
|
private ArrayList<KUser> data;
|
||||||
|
|
||||||
public UserTableModel(DbConnector pDbCon){
|
public UserTableModel(KDataModel pModel){
|
||||||
dbCon = pDbCon;
|
pModel.register(this);
|
||||||
updateModel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColumnCount() {
|
public int getColumnCount() {
|
||||||
return this.header.length;
|
return header.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRowCount() {
|
public int getRowCount() {
|
||||||
return this.data.size();
|
return data.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValueAt(int row, int col) {
|
public String getValueAt(int row, int col) {
|
||||||
@@ -50,37 +50,22 @@ public class UserTableModel extends AbstractTableModel {
|
|||||||
return header[index];
|
return header[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateModel(){
|
|
||||||
data = dbCon.getUserList();
|
|
||||||
fireTableDataChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Die Funktion muss differenzierter werden
|
// Die Funktion muss differenzierter werden
|
||||||
public boolean isCellEditable(int row, int col){
|
public boolean isCellEditable(int row, int col){
|
||||||
if (col > 2) return true;
|
if (col > 2) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public int getIdFromRow(int pRow){
|
||||||
*
|
return data.get(pRow).getId();
|
||||||
* @param pId
|
|
||||||
* @return Returns -1 if there is no row for the given id.
|
|
||||||
*/
|
|
||||||
public int getRowFromId(int pId){
|
|
||||||
for(KUser elem : this.data){
|
|
||||||
if(elem.getId() == pId) return data.indexOf(elem);
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public KUser getUserByRow(int pRow){
|
public void fetchData(KDataModel pModel) {
|
||||||
return this.data.get(pRow);
|
if(pModel instanceof KUserModel){
|
||||||
|
data = ((KUserModel)pModel).getData();
|
||||||
|
|
||||||
|
fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public KUser getUserById(int pId){
|
|
||||||
for(KUser elem : this.data){
|
|
||||||
if(elem.getId() == pId) return elem;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user