Temp
This commit is contained in:
parent
d086ce3b85
commit
bb7fcee47a
16 changed files with 270 additions and 25 deletions
|
@ -6,24 +6,32 @@ repositories {
|
|||
mavenCentral()
|
||||
}
|
||||
|
||||
// Note that the test dependencies (junit, …) are inferred from the
|
||||
// sourceSet.test of the core subproject
|
||||
dependencies {
|
||||
implementation 'com.jfoenix:jfoenix:8.0.7'
|
||||
implementation 'de.jensd:fontawesomefx:8.9'
|
||||
implementation 'javax.persistence:javax.persistence-api:2.2'
|
||||
implementation 'com.j256.ormlite:ormlite-core:5.1'
|
||||
ext {
|
||||
smackVersion="4.4.0-alpha2-SNAPSHOT"
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
dependencies {
|
||||
|
||||
// Smack
|
||||
compile "org.igniterealtime.smack:smack-java7:$smackVersion"
|
||||
compile "org.igniterealtime.smack:smack-resolver-dnsjava:$smackVersion"
|
||||
compile "org.igniterealtime.smack:smack-tcp:$smackVersion"
|
||||
compile "org.igniterealtime.smack:smack-openpgp:$smackVersion"
|
||||
compile "org.igniterealtime.smack:smack-experimental:$smackVersion"
|
||||
|
||||
// JFX
|
||||
implementation 'com.jfoenix:jfoenix:8.0.7'
|
||||
implementation 'de.jensd:fontawesomefx:8.9'
|
||||
|
||||
// Database
|
||||
implementation 'javax.persistence:javax.persistence-api:2.2'
|
||||
implementation 'com.j256.ormlite:ormlite-core:5.1'
|
||||
implementation 'com.j256.ormlite:ormlite-jdbc:5.1'
|
||||
implementation 'com.h2database:h2:1.4.197'
|
||||
}
|
||||
|
||||
jfx {
|
||||
// minimal requirement for jfxJar-task
|
||||
mainClass = 'de.vanitasvitae.fasel.sample.Main'
|
||||
|
||||
// minimal requirement for jfxNative-task
|
||||
vendor = 'vanitasvitae'
|
||||
}
|
|
@ -20,7 +20,7 @@ public class FaselApplication extends Application {
|
|||
LoginController controller = loader.getController();
|
||||
controller.setApplication(this);
|
||||
Scene scene = new Scene(root, 1200, 741);
|
||||
primaryStage.setTitle("Hello World");
|
||||
primaryStage.setTitle("Fasel - Login");
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package de.vanitasvitae.fasel;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.j256.ormlite.jdbc.JdbcConnectionSource;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
import com.j256.ormlite.table.TableUtils;
|
||||
import de.vanitasvitae.fasel.db.AbstractDatabase;
|
||||
import de.vanitasvitae.fasel.db.entity.Account;
|
||||
|
||||
public class FaselDBTest {
|
||||
|
||||
private AbstractDatabase database;
|
||||
|
||||
public static void main(String[] args) throws SQLException {
|
||||
FaselDBTest db = new FaselDBTest();
|
||||
db.insert();
|
||||
db.get();
|
||||
}
|
||||
|
||||
public FaselDBTest() throws SQLException {
|
||||
database = new AbstractDatabase() {
|
||||
@Override
|
||||
public ConnectionSource getConnectionSource() throws SQLException {
|
||||
ConnectionSource connectionSource =
|
||||
new JdbcConnectionSource("jdbc:h2:~/.local/share/fasel/db/fasel");
|
||||
return connectionSource;
|
||||
}
|
||||
};
|
||||
TableUtils.createTableIfNotExists(database.getConnectionSource(), Account.class);
|
||||
}
|
||||
|
||||
public void insert() throws SQLException {
|
||||
|
||||
String username = "alice@wonderland.lit";
|
||||
String id = "1234";
|
||||
|
||||
String password = "swordfish";
|
||||
|
||||
Account account = new Account(id, username, password);
|
||||
|
||||
database.getAccountsDao().create(account);
|
||||
}
|
||||
|
||||
public void get() throws SQLException {
|
||||
for (Account account : database.getAccountsDao().queryForAll()) {
|
||||
System.out.print(account.getAccountId() + " " + account.getJid() + " " + account.getPassword());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,14 +6,22 @@ import com.j256.ormlite.dao.Dao;
|
|||
import com.j256.ormlite.dao.DaoManager;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
import de.vanitasvitae.fasel.db.entity.Account;
|
||||
import de.vanitasvitae.fasel.db.entity.Contact;
|
||||
import de.vanitasvitae.fasel.db.entity.XmppEntity;
|
||||
|
||||
public abstract class AbstractDatabase {
|
||||
|
||||
public abstract ConnectionSource getConnectionSource();
|
||||
public abstract ConnectionSource getConnectionSource() throws SQLException;
|
||||
|
||||
public Dao<Account, String> getAccountsDao() throws SQLException {
|
||||
return DaoManager.createDao(getConnectionSource(), Account.class);
|
||||
}
|
||||
|
||||
|
||||
public Dao<XmppEntity, String> getXmppEntityDao() throws SQLException {
|
||||
return DaoManager.createDao(getConnectionSource(), XmppEntity.class);
|
||||
}
|
||||
|
||||
public Dao<Contact, String> getContactsDao() throws SQLException {
|
||||
return DaoManager.createDao(getConnectionSource(), Contact.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package de.vanitasvitae.fasel.db.dao;
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import de.vanitasvitae.fasel.db.entity.XmppEntity;
|
||||
|
||||
public interface XmppEntityDao extends Dao<XmppEntity, String> {
|
||||
|
||||
}
|
|
@ -9,7 +9,7 @@ import de.vanitasvitae.fasel.db.entity.Account;
|
|||
|
||||
public class AccountDaoImpl extends BaseDaoImpl<Account, String> implements AccountDao {
|
||||
|
||||
protected AccountDaoImpl(ConnectionSource connectionSource)
|
||||
public AccountDaoImpl(ConnectionSource connectionSource)
|
||||
throws SQLException {
|
||||
super(connectionSource, Account.class);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package de.vanitasvitae.fasel.db.dao.impl;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.j256.ormlite.dao.BaseDaoImpl;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
import de.vanitasvitae.fasel.db.dao.XmppEntityDao;
|
||||
import de.vanitasvitae.fasel.db.entity.XmppEntity;
|
||||
|
||||
public class XmppEntityDaoImpl extends BaseDaoImpl<XmppEntity, String> implements XmppEntityDao {
|
||||
|
||||
protected XmppEntityDaoImpl(ConnectionSource connectionSource) throws SQLException {
|
||||
super(connectionSource, XmppEntity.class);
|
||||
}
|
||||
}
|
|
@ -8,16 +8,48 @@ import de.vanitasvitae.fasel.db.dao.impl.AccountDaoImpl;
|
|||
@DatabaseTable(tableName = "accounts", daoClass = AccountDaoImpl.class)
|
||||
public class Account {
|
||||
|
||||
@DatabaseField(id = true, dataType = DataType.LONG)
|
||||
private String TAG = "fasel_db";
|
||||
|
||||
@DatabaseField(id = true, dataType = DataType.STRING)
|
||||
private String accountId;
|
||||
|
||||
@DatabaseField(canBeNull = false, dataType = DataType.STRING_BYTES)
|
||||
@DatabaseField(canBeNull = false, dataType = DataType.STRING)
|
||||
private String jid;
|
||||
|
||||
@DatabaseField(canBeNull = false, dataType = DataType.STRING_BYTES)
|
||||
private char[] password;
|
||||
@DatabaseField(canBeNull = false, dataType = DataType.STRING)
|
||||
private String password;
|
||||
|
||||
public Account() {
|
||||
|
||||
}
|
||||
|
||||
public Account(String accountId, String jid, String password) {
|
||||
this.accountId = accountId;
|
||||
this.jid = jid;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(String accountId) {
|
||||
this.accountId = accountId;
|
||||
}
|
||||
|
||||
public String getJid() {
|
||||
return jid;
|
||||
}
|
||||
|
||||
public void setJid(String jid) {
|
||||
this.jid = jid;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package de.vanitasvitae.fasel.db.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.j256.ormlite.field.DataType;
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
@DatabaseTable(tableName = "messages")
|
||||
public class BaseMessage {
|
||||
|
||||
public BaseMessage() {
|
||||
|
||||
}
|
||||
|
||||
@DatabaseField(id = true, columnName = "messageId")
|
||||
private String messageId;
|
||||
|
||||
@DatabaseField(columnName = "senderJid", dataType = DataType.STRING)
|
||||
private String senderJid;
|
||||
|
||||
@DatabaseField(columnName = "accountId", foreign = true)
|
||||
private Account account;
|
||||
|
||||
@DatabaseField(columnName = "sendDate", dataType = DataType.DATE)
|
||||
private Date sendDate;
|
||||
|
||||
@DatabaseField(columnName = "receiveDate", dataType = DataType.DATE)
|
||||
private Date receiveDate;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package de.vanitasvitae.fasel.db.entity;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
@DatabaseTable(tableName = "contacts")
|
||||
public class Contact extends XmppEntity {
|
||||
|
||||
@DatabaseField(id = true)
|
||||
private String id;
|
||||
|
||||
@DatabaseField(foreign = true)
|
||||
private XmppEntity baseEntity;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package de.vanitasvitae.fasel.db.entity;
|
||||
|
||||
import com.j256.ormlite.field.DataType;
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
@DatabaseTable(tableName = "textmessages")
|
||||
public class TextMessage extends BaseMessage {
|
||||
|
||||
public TextMessage() {
|
||||
|
||||
}
|
||||
|
||||
@DatabaseField(canBeNull = false, foreign = true, foreignAutoRefresh = true)
|
||||
private BaseMessage baseMessage;
|
||||
|
||||
@DatabaseField(columnName = "body", dataType = DataType.STRING)
|
||||
private String body;
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package de.vanitasvitae.fasel.db.entity;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
import de.vanitasvitae.fasel.db.dao.impl.XmppEntityDaoImpl;
|
||||
|
||||
@DatabaseTable(tableName = "entities", daoClass = XmppEntityDaoImpl.class)
|
||||
public class XmppEntity {
|
||||
|
||||
@DatabaseField(id = true)
|
||||
private String id;
|
||||
|
||||
@DatabaseField
|
||||
private String jid;
|
||||
|
||||
}
|
|
@ -6,6 +6,9 @@ import com.jfoenix.controls.JFXButton;
|
|||
import com.jfoenix.controls.JFXPasswordField;
|
||||
import com.jfoenix.controls.JFXTextField;
|
||||
import de.vanitasvitae.fasel.FaselApplication;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
|
@ -43,13 +46,30 @@ public class LoginFragmentController {
|
|||
});
|
||||
}
|
||||
|
||||
private static void setUsernameValidator(JFXTextField text_username) {
|
||||
text_username.textProperty().addListener(new ChangeListener<String>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends String> observableValue, String oldValue, String newValue) {
|
||||
ObservableList<String> styleClass = text_username.getStyleClass();
|
||||
if (newValue.length() < 5) {
|
||||
if (styleClass.contains("error")) {
|
||||
return;
|
||||
}
|
||||
styleClass.add("error");
|
||||
} else {
|
||||
styleClass.removeAll("error");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void switchToMainScene() throws IOException {
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
loader.setLocation(getClass().getResource("/fxml/container/main_container.fxml"));
|
||||
Parent root = loader.load();
|
||||
|
||||
Scene scene = new Scene(root, 1200, 741);
|
||||
main.getPrimaryStage().setTitle("Hello World");
|
||||
main.getPrimaryStage().setTitle("Fasel");
|
||||
main.getPrimaryStage().setScene(scene);
|
||||
// primaryStage.show();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package de.vanitasvitae.fasel.xmpp;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
||||
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
public class XmppConnectionService {
|
||||
|
||||
private final XMPPTCPConnection connection;
|
||||
|
||||
public XmppConnectionService(String username, String serverAddress, String password)
|
||||
throws XmppStringprepException {
|
||||
connection = new XMPPTCPConnection(username, password, serverAddress);
|
||||
}
|
||||
|
||||
public void login() throws InterruptedException, IOException, SmackException, XMPPException {
|
||||
connection.connect();
|
||||
connection.login();
|
||||
}
|
||||
|
||||
public void attachDatabase() {
|
||||
|
||||
}
|
||||
}
|
|
@ -3,11 +3,7 @@
|
|||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<VBox alignment="CENTER"
|
||||
style="-fx-background-color: lightgrey;"
|
||||
xmlns="http://javafx.com/javafx/8.0.162-ea"
|
||||
xmlns:fx="http://javafx.com/fxml/1"
|
||||
fx:controller="de.vanitasvitae.fasel.ui.container.LoginController">
|
||||
<VBox alignment="CENTER" prefHeight="298.0" prefWidth="475.0" style="-fx-background-color: lightgrey;" xmlns="http://javafx.com/javafx/8.0.162-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.vanitasvitae.fasel.ui.container.LoginController">
|
||||
|
||||
<HBox alignment="CENTER" style="-fx-background-color: transparent;">
|
||||
<fx:include fx:id="loginFragment" source="../fragment/login.fxml" />
|
||||
|
|
BIN
fasel.mv.db
Normal file
BIN
fasel.mv.db
Normal file
Binary file not shown.
Loading…
Reference in a new issue