Fix erreur lors de query vide + disable champ de recherche durant la mise a jour de l'affichage

This commit is contained in:
SeekDaSky 2017-12-13 16:05:02 +01:00
parent d3d845f15c
commit 52279c68c5
2 changed files with 32 additions and 20 deletions

View File

@ -152,35 +152,38 @@ public class RootLayout extends Application implements EventObserver {
case "NewsQuerySuccess":
System.out.println(NewsListModel.getInstance().getNews().size()+" News ont été trouvé");
this.articles.clearContent();
TextField tx = new TextField();
tx.setPromptText("search...");
tx.setId("mag_searchbar");
tx.setDisable(true);
tx.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent arg0) {
if(arg0.getCode() == KeyCode.ENTER) {
NewsListModel.getInstance().query(tx.textProperty().get());
}
}
});
Platform.runLater(new Runnable() {
@Override
public void run() {
RootLayout.this.main_container.getChildren().add(tx);
}
});
if(NewsListModel.getInstance().getNews().size() != 0) {
this.articles.clearContent();
TextField tx = new TextField();
tx.setPromptText("search...");
tx.setId("mag_searchbar");
tx.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent arg0) {
if(arg0.getCode() == KeyCode.ENTER) {
NewsListModel.getInstance().query(tx.textProperty().get());
}
}
});
Platform.runLater(new Runnable() {
@Override
public void run() {
RootLayout.this.main_container.getChildren().add(tx);
}
});
// For each news
for( NewsModel news : NewsListModel.getInstance().getNews() ){
@ -197,6 +200,8 @@ public class RootLayout extends Application implements EventObserver {
}
}
tx.setDisable(false);
break;
case "NewsQueryFailed":

View File

@ -119,6 +119,13 @@ public class NewsListModel implements Observable{
}
public void query(String q) {
//si recherche vide
if(q.isEmpty()) {
this.news = new ArrayList<NewsModel>();
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"));