Need ur Help!
This may be more of design choice and i thought "why to reinvent the wheel". Someone might have required this already.
My question: (i don't want to go for any third party framework since mine is a small project. i am using Adam Bein's afterburner.fx already) I am implementing a standalone application in javafx. I am very much interested in following MVC/MVP/MVVM. Since javafx allows me to separate the UI using fxml, i achieved most of my UI design through fxml. But there i stuck with some problems.
My Structure
TradeView.fxml (all my UI design goes here) TradeController.java (all my UI event handling (also some business logic) goes here) Trade.java (entity class)
Now i have a javafx TableView in my fxml. All TableCoulumns are defined in the fxml itself. The values which i want to bind to my columns are achieved through "PropertyValueFactory" if it is a direct property in my entity class. TableView myTableView; eg:
<TableColumn fx:id="tradeOidTableColumn" prefWidth="130.0" text="Trade Oid">
<cellValueFactory><PropertyValueFactory property="oid"/></cellValueFactory>
</TableColumn>
But i want to show commodity short name in one column where Commodity is another entity in relationship with my Trade entity. So i can say myTradeEntity.commodity().commodityShortName(); which works perfectly. But you guys know i cannot do this though fxml. it wont support nested binding.
Not possible
<cellValueFactory><PropertyValueFactory property="commodity.commodityShortName"/></cellValueFactory>
So i am forced to use a cell value factory. I defined a class CommodityCellValueFactory and bind it. eg:
<TableColumn fx:id="commodityTableColumn" prefWidth="220.0" text="Commodity">
<cellValueFactory><CommodityCellValueFactory /></cellValueFactory>
</TableColumn>
Basically i want to get rid of the cell factories and cell value factories unless i need some formatting to be done on my value. So i thought i can create a property called
String tempCommodityShortName;
String getTempCommodityShortName()
{
return commodity.commodityShortName();
}
in my Trade entity and bind this to my table column. But i have around 15 to 20 properties. If i do this in my entity class then it will be bloated with these extra helper method which i don't want to do.
I thought of having a helper class for every entity like http://ift.tt/2aBVh7g where i can have all the helper methods and access it in the tableview columns.
My first attempt is instead of class, i choose an interface (since java 8 interface supports default methods)
interface ITradeEntityHelper
{
//all helper methods goes here
}
class TradeEntity implements ITradeEntityHelper
{
//real entity methods goes here
}
I will bind the Interface to my TableView. TableView instead of TableView Correct me if i am trying something stupid
Now the problem is how do i get my TradeEntity reference in my ITradeEntityHelper interafce so that i can ask tradeEntity.Commodity().commodityShortName().
(or) like these
interface ITrade{}
class Trade implements ITrade{}
class TradeAdditions implements ITrade{}
keep the helper methods in the Additions class.
I want to achieve the same for my Controller classes too.
Eg: Each Controller class in my Application should have base interafce where i want to have some default java Predicates and java 8 Functions defined and want to resue in the controller class.
class TradeController implements ITradeController, Initializable
{
}
Please help me out in this. Thanks in Advance!
Aucun commentaire:
Enregistrer un commentaire