Skip to content

Commit

Permalink
feat: Create wrappers for view initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelsa committed May 25, 2026
1 parent 853f9a9 commit 3d4fc0d
Showing 1 changed file with 80 additions and 11 deletions.
91 changes: 80 additions & 11 deletions src/main/java/edu/ntnu/idi/idatt/view/SceneFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import edu.ntnu.idi.idatt.view.primary.transactions.TransactionModel;
import edu.ntnu.idi.idatt.view.primary.transactions.TransactionView;
import javafx.scene.Parent;
import javafx.util.Pair;

import java.util.ArrayDeque;
import java.util.Deque;
Expand Down Expand Up @@ -114,13 +115,11 @@ public static Parent createStartView() {
}

/**
* Initialization method for Portfolio View.
* Initialization method for all Portfolio views.
*
* @return View's root.
* @return View's root and controller.
*/
public static Parent createPortfolioView() {

mark(() -> createPortfolioView());
private static Pair<Parent, PortfolioController> createDefaultPortfolioView() {

PortfolioModel model = new PortfolioModel();
PortfolioView view = new PortfolioView();
Expand All @@ -129,23 +128,66 @@ public static Parent createPortfolioView() {
view.setModel(model);
view.setController(controller);

return view.getInstance();
return new Pair<Parent, PortfolioController>(view.getInstance(), controller);
}

/**
* Wrapper for Portfolio View initialization method.
*
* <p>
* Initializes a default portfolio.
* </p>
*
* @return View's root.
*/
public static Parent createPortfolioView() {

mark(() -> createPortfolioView());

Pair<Parent, PortfolioController> vc = createDefaultPortfolioView();
return vc.getKey(); // View
}

/**
* Wrapper for Portfolio View initialization method.
*
* <p>
* Initializes a portfolio with a search query.
* </p>
*
* @param initialSearch - Initial search query
* @return View's root
*/
public static Parent createPortfolioView(String initialSearch) {

mark(() -> createPortfolioView(initialSearch));

Pair<Parent, PortfolioController> vc = createDefaultPortfolioView();
Parent view = vc.getKey();

if (initialSearch == null || initialSearch.isEmpty()) {
return view;
}

PortfolioController controller = vc.getValue();
controller.handleSearchQuery(initialSearch);
return view;

}

/**
* Initialization method for Exchange View.
*
* @return View's root.
*/
public static Parent createExchangeView(boolean markValue) {
private static Parent createDefaultExchangeView(boolean clean) {

if (markValue) {
mark(() -> createExchangeView(true));
} else {
if (clean) {
navigation.clear();
mark(() -> createExchangeView(true));
}

mark(() -> createDefaultExchangeView(false));

ExchangeModel model = new ExchangeModel();
ExchangeView view = new ExchangeView();
ExchangeController controller = new ExchangeController(model);
Expand All @@ -157,6 +199,33 @@ public static Parent createExchangeView(boolean markValue) {

}

/**
* Wrapper for Exchange View initialization method.
*
* <p>
* Initializes a default exchange view.
* </p>
*
* @return View's root
*/
public static Parent createExchangeView() {
return createDefaultExchangeView(false);
}

/**
* Wrapper for Exchange View initialization method.
*
* <p>
* Initializes a default exchange view with the clean parameter.
* </p>
*
* @param clean - should it reset the page stack.
* @rteturn View's root
*/
public static Parent createExchangeView(boolean clean) {
return createDefaultExchangeView(clean);
}

/**
* Initialization method for Stock View.
*
Expand Down

0 comments on commit 3d4fc0d

Please sign in to comment.