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,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<KeyEvent>() {
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());
}
@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;

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"));