Fix erreur lors de query vide + disable champ de recherche durant la mise a jour de l'affichage
This commit is contained in:
parent
d3d845f15c
commit
52279c68c5
|
@ -152,34 +152,37 @@ public class RootLayout extends Application implements EventObserver {
|
||||||
|
|
||||||
case "NewsQuerySuccess":
|
case "NewsQuerySuccess":
|
||||||
System.out.println(NewsListModel.getInstance().getNews().size()+" News ont été trouvé");
|
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();
|
TextField tx = new TextField();
|
||||||
tx.setPromptText("search...");
|
tx.setPromptText("search...");
|
||||||
tx.setId("mag_searchbar");
|
tx.setId("mag_searchbar");
|
||||||
tx.setOnKeyPressed(new EventHandler<KeyEvent>() {
|
tx.setDisable(true);
|
||||||
|
tx.setOnKeyPressed(new EventHandler<KeyEvent>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(KeyEvent arg0) {
|
public void handle(KeyEvent arg0) {
|
||||||
if(arg0.getCode() == KeyCode.ENTER) {
|
if(arg0.getCode() == KeyCode.ENTER) {
|
||||||
NewsListModel.getInstance().query(tx.textProperty().get());
|
NewsListModel.getInstance().query(tx.textProperty().get());
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
}
|
||||||
|
|
||||||
Platform.runLater(new Runnable() {
|
});
|
||||||
|
|
||||||
|
Platform.runLater(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
RootLayout.this.main_container.getChildren().add(tx);
|
RootLayout.this.main_container.getChildren().add(tx);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
if(NewsListModel.getInstance().getNews().size() != 0) {
|
||||||
|
|
||||||
// For each news
|
// For each news
|
||||||
for( NewsModel news : NewsListModel.getInstance().getNews() ){
|
for( NewsModel news : NewsListModel.getInstance().getNews() ){
|
||||||
|
@ -196,6 +199,8 @@ public class RootLayout extends Application implements EventObserver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tx.setDisable(false);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,13 @@ public class NewsListModel implements Observable{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void query(String q) {
|
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
|
//si la recherche de source s'est fini avec une erreur, pas la peine de chercher des articles
|
||||||
if(this.apiError) {
|
if(this.apiError) {
|
||||||
NewsListModel.this.notifyObservers(new Event("NewsModel","NewsQueryFailed"));
|
NewsListModel.this.notifyObservers(new Event("NewsModel","NewsQueryFailed"));
|
||||||
|
|
Loading…
Reference in New Issue