Skip to content

44 stock tab on UI now automatically updates #47

Merged
merged 2 commits into from
May 26, 2026
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/main/java/View/MainGameScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ public class MainGameScene implements ExchangeObserver {

// References to UI components that need refreshing
private TableView<PortfolioRow> portfolioTable;
private TableView<StockRow> table;
private ListView<Share> holdingsList;
private TableView<HistoryRow> historyTable;
private ComboBox<Integer> weekFilterCombo;
private Runnable loadStocks;

/**
* Constructs the main game scene.
Expand Down Expand Up @@ -159,10 +161,10 @@ private VBox createStocksPanel() {
filter.setItems(FXCollections.observableArrayList("All", "Gainers", "Losers"));
filter.setValue("All");

TableView<StockRow> table = new TableView<>();
table = new TableView<>();
addStockColumns(table);

Runnable loadStocks = () -> {
loadStocks = () -> {
List<Stock> stocks;
String filterVal = filter.getValue();
String searchVal = search.getText().trim();
Expand Down Expand Up @@ -407,6 +409,8 @@ protected void updateItem(Share s, boolean empty) {
}
} catch (NumberFormatException ex) {
alert("Error", "Enter a valid number for quantity");
} catch (IllegalArgumentException ex) {
alert("Error", ex.getMessage());
}
});

Expand Down Expand Up @@ -573,6 +577,9 @@ private void updateStatus() {
}

private void refreshAllUI() {
if (table != null && loadStocks != null) {
loadStocks.run();
}
if (portfolioTable != null) {
updatePortfolio(portfolioTable);
}
Expand Down