From 52279c68c5df48abcf593d670ec4509cc812eeb3 Mon Sep 17 00:00:00 2001 From: SeekDaSky Date: Wed, 13 Dec 2017 16:05:02 +0100 Subject: [PATCH] Fix erreur lors de query vide + disable champ de recherche durant la mise a jour de l'affichage --- controller/RootLayout.java | 45 +++++++++++++++++++++----------------- model/NewsListModel.java | 7 ++++++ 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/controller/RootLayout.java b/controller/RootLayout.java index 5bfd996..19e4497 100644 --- a/controller/RootLayout.java +++ b/controller/RootLayout.java @@ -152,34 +152,37 @@ public class RootLayout extends Application implements EventObserver { case "NewsQuerySuccess": System.out.println(NewsListModel.getInstance().getNews().size()+" News ont été trouvé"); - if(NewsListModel.getInstance().getNews().size() != 0) { - this.articles.clearContent(); + this.articles.clearContent(); - TextField tx = new TextField(); - tx.setPromptText("search..."); - tx.setId("mag_searchbar"); - tx.setOnKeyPressed(new EventHandler() { + TextField tx = new TextField(); + tx.setPromptText("search..."); + tx.setId("mag_searchbar"); + tx.setDisable(true); + tx.setOnKeyPressed(new EventHandler() { - @Override - public void handle(KeyEvent arg0) { - if(arg0.getCode() == KeyCode.ENTER) { - NewsListModel.getInstance().query(tx.textProperty().get()); - } - + @Override + public void handle(KeyEvent arg0) { + if(arg0.getCode() == KeyCode.ENTER) { + NewsListModel.getInstance().query(tx.textProperty().get()); } - }); + } - Platform.runLater(new Runnable() { + }); + + Platform.runLater(new Runnable() { - @Override - public void run() { - RootLayout.this.main_container.getChildren().add(tx); - - } + @Override + public void run() { + RootLayout.this.main_container.getChildren().add(tx); - }); + } + + }); + + + if(NewsListModel.getInstance().getNews().size() != 0) { // For each news for( NewsModel news : NewsListModel.getInstance().getNews() ){ @@ -196,6 +199,8 @@ public class RootLayout extends Application implements EventObserver { } } } + + tx.setDisable(false); break; diff --git a/model/NewsListModel.java b/model/NewsListModel.java index 9407e56..1e12e0d 100644 --- a/model/NewsListModel.java +++ b/model/NewsListModel.java @@ -119,6 +119,13 @@ public class NewsListModel implements Observable{ } public void query(String q) { + //si recherche vide + if(q.isEmpty()) { + this.news = new ArrayList(); + NewsListModel.this.notifyObservers(new Event("NewsModel","NewsQuerySuccess")); + return; + } + //si la recherche de source s'est fini avec une erreur, pas la peine de chercher des articles if(this.apiError) { NewsListModel.this.notifyObservers(new Event("NewsModel","NewsQueryFailed"));