私は初心者で、Web上に見つかったソリューションを自分のアプリケーション構造に適用することに成功しません。これは私の最初の投稿ですので、寛大にしてください。
データベースに接続するためのFactory/DAO/Singletonテンプレートがありました。
現時点でfind関数を実装してもうまく動作します。モデルからコントローラへのobservableArrayListを処理します
次にMVCパターンを実装したいと思います。
モデルは、例えば "Fichier"という名前のクラスです。このクラスは、 "Fichier"のインスタンスを生成するためにFichierSQLによって使用されました。
ビューは、 "FenFichier"という名前のFXMLファイルによって提供されます。 コントローラーは "FenFichierController"というクラッセです。 別のクラスが異なるビューを管理し、 "LoginManager"という名前になっています。
EDITは:githubのコードのおかげ@Jewelsea約loginsession
それはデータベースクエリがあるFichierSQLでありますように、私はそれがここにobservableArrayListを実装するのに最適な場所であるべきだと思います。
問題はで、このクラスの「getFichierList」メソッドにアクセスできず、コントローラからTableViewにデータを入力できません。
あなたのコメントも管理するウィンドウがたくさんあるので、LoginManagerクラスについて歓迎しています。私は完全な方法でこれを行う方法を知らないので、スニペットが必要な場合は教えてください。
Fichier.class
public class Fichier {
private final IntegerProperty fichierID;
/** nom du fichier de mesure */
private final StringProperty nomFichier;
/** le fichier est-il un essai = 1 ? ou un OF = 0 (default) */
private final BooleanProperty isEssai;
/** date de création du fichier de mesure */
private final ObjectProperty<Date> dateCreation;
/** nom du client */
private final StringProperty client;
private static Date DATE_NULL = new Date(0);
/** création d'un fichier vide */
public Fichier() {
this(0,null,false,DATE_NULL,null);
}
/** création d'un fichier de mesure
* @param fid identification unique du fichier dans la BDD
* @param fichier nom du fichier de mesure
* @param ess essai = 1 ou OF = 0
* @param dtecreation date de création du fichier de mesure
* @param cli nom du client
*/
public Fichier(int fid, String fichier, Boolean ess, Date dtecreation, String cli) {
this.fichierID = new SimpleIntegerProperty(fid);
this.nomFichier = new SimpleStringProperty(fichier);
this.isEssai = new SimpleBooleanProperty(ess);
this.dateCreation = new SimpleObjectProperty<Date>(dtecreation);
this.client = new SimpleStringProperty(cli);
}
/**
* renvoie le numéro unique de fichier
* @return fichierID
*/
public int getFichierID() {
return fichierID.get();
}
public IntegerProperty fichierIDProperty() {
return fichierID;
}
/**
* renvoie le nom du fichier de mesure
* @return nomFichier
*/
public String getNomFichier() {
return nomFichier.get();
}
/**
* modifie le nom du fichier de mesure
* @param newFichier
*/
public void setNomFichier(String newFichier) {
this.nomFichier.set(newFichier);
}
public StringProperty nomFichierProperty() {
return nomFichier;
}
/**
* renvoie si le fichier de mesure est un essai = True ou OF = False
* @return isEssai
*/
public Boolean getIsEssai() {
return isEssai.get();
}
/**
* modifie le type de fichier de mesure en essai = True ou OF = False
* @param newIsEssai
*/
public void setIsEssai(Boolean newIsEssai) {
this.isEssai.set(newIsEssai);
}
public BooleanProperty isEssaiProperty() {
return isEssai;
}
/**
* renvoie la date de creation du fichier de mesure
* @return dateCreation
*/
public Date getDateCreation() {
return dateCreation.get();
}
/**
* modifie la date de creation du fichier de mesure
* @param newDateCreation
*/
public void setDateCreation(Date newDateCreation) {
this.dateCreation.set(newDateCreation);
}
public ObjectProperty<Date> dateCreationProperty() {
return dateCreation;
}
/**
* renvoie le client
* @return client
*/
public String getClient() {
return client.get();
}
/**
* modifie le client
* @param newClient
*/
public void setClient(String newClient) {
this.client.set(newClient);
}
public StringProperty nomClientProperty() {
return client;
}
FichierSQL.class
public class FichierSQL extends DAO<Fichier> {
private ObservableList<Fichier> fichierList = FXCollections.observableArrayList();
public FichierSQL(Connection conn) {
super(conn);
}
public boolean create(Fichier obj) {
return false;
}
public boolean delete(Fichier obj) {
return false;
}
public boolean update(Fichier obj) {
return false;
}
public Fichier find(String nomFichier) {
Fichier fich = new Fichier();
try {
ResultSet result = this.connect
.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)
.executeQuery("SELECT * FROM tb_fichier WHERE fichier LIKE '" + nomFichier + "'");
while (result.next())
fich = new Fichier(
result.getInt("fichierid"),
result.getString("fichier"),
result.getBoolean("isEssai"),
result.getDate("datecreation"),
result.getString("client")
);
fichierList.add(fich);
} catch (SQLException e) {
e.printStackTrace();
}
return fich;
}
public ObservableList<Fichier> getFichierList() {
return fichierList;
}
LoginManager.class
public class LoginManager {
private Scene scene;
private Stage stage;
private BorderPane fenMainLayout;
public LoginManager(Stage stage, Scene scene) {
this.scene = scene;
this.stage = stage;
}
/**
* Callback method invoked to notify that a user has been authenticated.
* Will show the main application screen.
*/
public void authenticated(String sessionID) {
showMainView(sessionID);
}
/**
* Callback method invoked to notify that a user has logged out of the main
* application. Will show the login application screen.
*/
public void logout() {
showLoginScreen();
}
public void showLoginScreen() {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("login.fxml"));
scene.setRoot((Parent) loader.load());
LoginController controller = loader.<LoginController> getController();
controller.initManager(this);
} catch (IOException ex) {
Logger.getLogger(LoginManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void showMainView(String sessionID) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/applicationTelabFX/FenMain.fxml"));
fenMainLayout = (BorderPane) loader.load();
Scene scene = new Scene(fenMainLayout);
stage.setScene(scene);
stage.setWidth(800);
stage.setHeight(600);
FenMainController controller = loader.<FenMainController> getController();
controller.initSessionID(this, sessionID);
stage.setTitle("TestLL");
stage.show();
showFichierView();
} catch (IOException ex) {
Logger.getLogger(LoginManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void showFichierView() {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/applicationTelabFX/FenFichier.fxml"));
AnchorPane fichierView = (AnchorPane) loader.load();
fenMainLayout.setCenter(fichierView);
FenFichierController controller = loader.getController();
} catch (IOException ex) {
Logger.getLogger(LoginManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
FenFichierController。クラス
public class FenFichierController {
@FXML
private TableView<Fichier> fichierTable;
@FXML
private TableColumn<Fichier, Integer> fichierIDCol;
@FXML
private TableColumn<Fichier, String> fichierMesCol;
@FXML
private Label fichierIDLabel;
@FXML
private Label nomFichierLabel;
@FXML
private CheckBox isEssaiCB;
@FXML
private Label dateCreationLabel;
@FXML
private Label clientLabel;
/**
* The constructor.
* The constructor is called before the initialize() method.
*/
public FenFichierController() { }
/**
* Initializes the controller class. This method is automatically called
* after the fxml file has been loaded.
*/
@FXML
private void initialize() {
// Initialize the person table with the two columns.
fichierIDCol.setCellValueFactory(cellData -> cellData.getValue().fichierIDProperty().asObject());
fichierMesCol.setCellValueFactory(cellData -> cellData.getValue().nomFichierProperty());
fichierTable.setItems(getFichierList);
}
public ObservableList<Fichier> fichiersData;
public void creationData(){
fichiersData = FXCollections.observableArrayList();
try{
AbstractDAOFactory adf = AbstractDAOFactory.getFactory(AbstractDAOFactory.SQLSERVER_DAO_FACTORY);
DAO<Fichier> fichierDao = adf.getFichierDAO();
Fichier fich = fichierDao.find("%");
}
catch(Exception e){
e.printStackTrace();
System.out.println("Erreur de création des données");
}
}
}がまだ存在しない場合は
@James_Dを行うことができますので、 getFichierDAO(){return new fichierSQL(conn);}私は何かを誤解していると思います。 DAO にする必要がありますか? –
cosmo
FichierSQL
こと:あなたの代わりにideaはすでに次のような別のクラスに実装されています:public DAO私はそのメソッドの戻り値の型を 'FichierSQL'に変更することを意味しました。したがって、抽象DAOクラスのAPIを変更せずに、既存の 'getFichierList()'メソッドを呼び出すことができます(または、キャストは醜いでしょう)。 –
いくつかの内部クラスは、フィジックスを変更する必要があります。基本オブジェクトは "fichier"のようにユーザーの操作は必要ありませんが、ユーザーにとっては変更が必要です。だから、私は基本的な作業に感謝します。あなたは私に貴重な助けを与える。どうもありがとう。私は警告メッセージを表示する最後のコメント:これはチャット笑ではありません。 Thx – cosmo