diff --git a/controller/RootLayout.java b/controller/RootLayout.java index 4e92163..5a8285b 100644 --- a/controller/RootLayout.java +++ b/controller/RootLayout.java @@ -103,6 +103,32 @@ public class RootLayout extends Application implements EventObserver { NewsListModel.getInstance().setSortType(SortTypes.relevancy); DictionaryModel.getInstance().addObserver("MainClass", this); + + VBox subMenuContainer = (VBox) this.root_layout.lookup("#submenu"); + + for(Node n : subMenuContainer.getChildren()) { + FlowPane p = (FlowPane) n; + p.setOnMousePressed(new EventHandler() { + @Override + public void handle(MouseEvent event) { + + // De-active all items before activating current one + for( Node n2 : subMenuContainer.getChildren() ) + n2.getStyleClass().clear(); + + // Change category + NewsListModel.getInstance().setCategory(Category.valueOf(p.getChildren().get(0).getId().toLowerCase())); + + // Active gui category + p.getStyleClass().add("active"); + + // Re-launch request + NewsListModel.getInstance().query(NewsListModel.getInstance().getQuery()); + } + }); + } + + this.handleMainLayoutChange("magazines"); } @@ -160,6 +186,7 @@ public class RootLayout extends Application implements EventObserver { case "NewsQuerySuccess": System.out.println(NewsListModel.getInstance().getNews().size()+" News ont été trouvé"); + this.root_layout.lookup("#submenu").setVisible(true); this.articles.clearContent(); TextField tx = new TextField(); @@ -226,6 +253,8 @@ public class RootLayout extends Application implements EventObserver { this.dico.clearContent(); + this.root_layout.lookup("#submenu").setVisible(false); + TextField tx1 = new TextField(); tx1.setPromptText("search..."); tx1.setId("mag_searchbar"); @@ -296,31 +325,7 @@ public class RootLayout extends Application implements EventObserver { container.getChildren().add(new Text("translator")); break; case "magazines" : - - VBox subMenuContainer = (VBox) this.root_layout.lookup("#submenu"); - - for(Node n : subMenuContainer.getChildren()) { - FlowPane p = (FlowPane) n; - p.setOnMousePressed(new EventHandler() { - @Override - public void handle(MouseEvent event) { - - // De-active all items before activating current one - for( Node n2 : subMenuContainer.getChildren() ) - n2.getStyleClass().clear(); - - // Change category - NewsListModel.getInstance().setCategory(Category.valueOf(p.getChildren().get(0).getId().toLowerCase())); - - // Active gui category - p.getStyleClass().add("active"); - - // Re-launch request - NewsListModel.getInstance().query(NewsListModel.getInstance().getQuery()); - } - }); - } - + NewsListModel.getInstance().query(""); break; }