Skip to content

Commit

Permalink
feat: Add clickable share to go to stock.
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelSapula committed May 25, 2026
1 parent a5166a7 commit 851c6c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package edu.ntnu.idi.idatt.view.components.elements;

import edu.ntnu.idi.idatt.model.portfolio.Share;
import edu.ntnu.idi.idatt.view.components.primitives.ActionEventHandler;
import edu.ntnu.idi.idatt.view.components.ui.UICompositor;
import edu.ntnu.idi.idatt.view.util.CssUtils;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
Expand All @@ -27,6 +29,7 @@ public class ShareComponent extends HBox {

private final Share share;
private Button sellButton;
private HBox shareComponentUI;

/**
* Constructor for ShareComponent.
Expand Down Expand Up @@ -69,7 +72,10 @@ public ShareComponent(Share share) {
.addContent(sellButton)
.build();

this.getChildren().add(shareComponent.makeUI());
shareComponentUI = (HBox) shareComponent.makeUI();
shareComponentUI.setCursor(Cursor.HAND);

this.getChildren().add(shareComponentUI);
}

/**
Expand All @@ -81,4 +87,13 @@ public void onShareSellButton(Consumer<Share> handler) {
sellButton.setOnAction((e) -> handler.accept(share));
}

/**
* Method for handeling share component click.
*
* @param handler - Functional interface with stock symbol reference.
*/
public void onShareClick(Consumer<String> handler) {
shareComponentUI.setOnMouseClicked(e -> handler.accept(share.getStock().getSymbol()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void setShareModel(List<Share> shareList) {
for (Share share : shareList) {
ShareComponent shareComponent = new ShareComponent(share);
shareComponent.onShareSellButton((sellShare) -> holdingSale(sellShare));
shareComponent.onShareClick((stockSymbol) -> SceneManager.switchTo(SceneFactory.createStockView(stockSymbol)));
model.getShareList().add(shareComponent);
}
}
Expand Down

0 comments on commit 851c6c9

Please sign in to comment.