-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement barebone TransactionMVC for TransactionArchive
- Loading branch information
Showing
5 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/edu/ntnu/idi/idatt/view/primary/transactions/TransactionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package edu.ntnu.idi.idatt.view.primary.transactions; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| import edu.ntnu.idi.idatt.model.transaction.Transaction; | ||
| import edu.ntnu.idi.idatt.session.UserSession; | ||
| import edu.ntnu.idi.idatt.view.components.AbstractController; | ||
| import edu.ntnu.idi.idatt.view.components.elements.TransactionComponent; | ||
|
|
||
| public class TransactionController extends AbstractController<TransactionModel> { | ||
|
|
||
| private UserSession session = UserSession.getInstance(); | ||
| private final ArrayList<TransactionComponent> loadedTransactionComponents = new ArrayList<>(); | ||
|
|
||
| public TransactionController(TransactionModel model) { | ||
| super(model); | ||
| for (Transaction transaction : session.getPlayer().getTransactionArchive().getTransactions(1)) { | ||
| TransactionComponent transactionComponent = new TransactionComponent(transaction); | ||
| loadedTransactionComponents.add(transactionComponent); | ||
| } | ||
| model.transactionList.addAll(loadedTransactionComponents); | ||
| } | ||
|
|
||
| } |
16 changes: 16 additions & 0 deletions
16
src/main/java/edu/ntnu/idi/idatt/view/primary/transactions/TransactionModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package edu.ntnu.idi.idatt.view.primary.transactions; | ||
|
|
||
| import edu.ntnu.idi.idatt.view.components.Model; | ||
| import edu.ntnu.idi.idatt.view.components.elements.TransactionComponent; | ||
| import javafx.collections.FXCollections; | ||
| import javafx.collections.ObservableList; | ||
|
|
||
| public class TransactionModel implements Model { | ||
|
|
||
| ObservableList<TransactionComponent> transactionList = FXCollections.observableArrayList(); | ||
|
|
||
| public ObservableList<TransactionComponent> getTransactionList() { | ||
| return transactionList; | ||
| } | ||
|
|
||
| } |
73 changes: 73 additions & 0 deletions
73
src/main/java/edu/ntnu/idi/idatt/view/primary/transactions/TransactionView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package edu.ntnu.idi.idatt.view.primary.transactions; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import edu.ntnu.idi.idatt.view.SceneFactory; | ||
| import edu.ntnu.idi.idatt.view.SceneManager; | ||
| import edu.ntnu.idi.idatt.view.components.AbstractViewUI; | ||
| import edu.ntnu.idi.idatt.view.components.ui.UIFactory; | ||
| import javafx.beans.binding.Bindings; | ||
| import javafx.geometry.Insets; | ||
| import javafx.geometry.Pos; | ||
| import javafx.scene.Parent; | ||
| import javafx.scene.control.ScrollPane; | ||
| import javafx.scene.layout.HBox; | ||
| import javafx.scene.layout.Region; | ||
|
|
||
| public class TransactionView extends AbstractViewUI { | ||
|
|
||
| HBox root; | ||
|
|
||
| @Override | ||
| public Parent createContent() { | ||
| root = new HBox(); | ||
| root.getStyleClass().add("primary"); | ||
| root.setMinWidth(Region.USE_PREF_SIZE); | ||
| root.setAlignment(Pos.CENTER); | ||
| root.setSpacing(20.0); | ||
|
|
||
| ScrollPane wrapper = new ScrollPane(); | ||
| wrapper.setContent(root); | ||
| wrapper.setPadding(new Insets(20.0, 0, 20.0, 0)); | ||
| wrapper.setFitToWidth(true); | ||
| wrapper.setFitToHeight(true); | ||
| wrapper.getStyleClass().add("primary"); | ||
|
|
||
| return wrapper; | ||
| } | ||
|
|
||
| @Override | ||
| public Parent createNavigation() { | ||
| return UIFactory.createNavigation("Transactions", List.of()); | ||
| } | ||
|
|
||
| @Override | ||
| public Parent createHeader() { | ||
| return UIFactory.createHeader("Search for transactions...", | ||
| query -> System.out.println(query)); | ||
| } | ||
|
|
||
| @Override | ||
| public Parent createToolbar() { | ||
| return UIFactory.createToolbar(() -> this.toggleMenu(), | ||
| () -> SceneManager.switchTo(SceneFactory.createStartView())); | ||
| } | ||
|
|
||
| @Override | ||
| public Parent createMenu() { | ||
| return UIFactory.createMenu("Account", | ||
| List.of(" • Portfolio", " • Transactions"), | ||
| () -> System.out.println("Portfolio clicked!"), | ||
| () -> System.out.println("Transaction clicked!")); | ||
|
|
||
| } | ||
|
|
||
| public void setModel(TransactionModel model) { | ||
| Bindings.bindContent(root.getChildren(), model.getTransactionList()); | ||
| } | ||
|
|
||
| public void setController(TransactionController controller) { | ||
|
|
||
| } | ||
|
|
||
| } |