diff options
author | Jonas Smedegaard <dr@jones.dk> | 2025-04-30 13:40:58 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2025-04-30 13:40:58 +0200 |
commit | 19584cfa12e80bd32e686c8da416aaec9aa063b9 (patch) | |
tree | 9d5a30810eb6fef9a5795308d16290de78dd7f76 /src | |
parent | f31de856243141d6533d53c0065aefd32fa31b4d (diff) |
improve separation of concerns between view and controller
Diffstat (limited to 'src')
-rw-r--r-- | src/com.example.portfolio2/com/example/portfolio2/Controller.java | 20 | ||||
-rw-r--r-- | src/com.example.portfolio2/com/example/portfolio2/Window.java | 41 |
2 files changed, 38 insertions, 23 deletions
diff --git a/src/com.example.portfolio2/com/example/portfolio2/Controller.java b/src/com.example.portfolio2/com/example/portfolio2/Controller.java index 66519ae..3354dcd 100644 --- a/src/com.example.portfolio2/com/example/portfolio2/Controller.java +++ b/src/com.example.portfolio2/com/example/portfolio2/Controller.java @@ -42,23 +42,15 @@ class Controller { /// callback when category has been selected /// + /// @param section section the category is tied to /// @param category selected category - /// @param select activity selection object - /// @param area activity listing object + // TODO: require a UI instead void onCategorySelected( - final String category, - final ComboBox<String> select, - final TextArea area + final GUI.Section section, + final String category ) { - - // clear the activity selection box - select.getItems().clear(); - - // clear text area - area.clear(); - - // fill activity box from data in store - select.getItems().addAll(store.selectProgram(category)); + view.clearSelections(section); + view.setOptions(section,store.selectProgram(category)); } /// callback when activity has been selected diff --git a/src/com.example.portfolio2/com/example/portfolio2/Window.java b/src/com.example.portfolio2/com/example/portfolio2/Window.java index d3e2b06..774b012 100644 --- a/src/com.example.portfolio2/com/example/portfolio2/Window.java +++ b/src/com.example.portfolio2/com/example/portfolio2/Window.java @@ -100,9 +100,8 @@ public final class Window extends Application { "HumTek", "NatBach"); col.categoryCombo.setOnAction(event -> { con.onCategorySelected( - col.categoryCombo.getValue(), - col.activitySelect, - col.area); + col.section, + col.categoryCombo.getValue()); }); } // TODO: use the list for filling the box @@ -118,9 +117,8 @@ public final class Window extends Application { GUI.Section.SUBJECT2.column) .categoryCombo); con.onCategorySelected( - col.categoryCombo.getValue(), - col.activitySelect, - col.area); + col.section, + col.categoryCombo.getValue()); }); } case GUI.Section.SUBJECT2 -> { @@ -136,9 +134,8 @@ public final class Window extends Application { GUI.Section.SUBJECT1.column) .categoryCombo); con.onCategorySelected( - col.categoryCombo.getValue(), - col.activitySelect, - col.area); + col.section, + col.categoryCombo.getValue()); }); } case GUI.Section.ELECTIVE -> { @@ -219,4 +216,30 @@ public final class Window extends Application { ectsLabel); } } + + /// populate activities for a category + /// + /// @param section structural section to operate on + /// @param activities activities to apply as string + public void setOptions( + final GUI.Section section, final List<String> activities + ) { + + // clear the activity selection box + columns.get(section.column).activitySelect + .getItems().clear(); + + // fill activity box from data in store + columns.get(section.column).activitySelect + .getItems().addAll(activities); + } + + /// remove selections from a category + /// + /// @param section structural section to operate on + public void clearSelections(final GUI.Section section) { + + // clear text area + columns.get(section.column).area.clear(); + } } |