Hi, I would like to elegantly code my application. I am rather
confused as to how to code for multiple button/field.
such as: multiple delete buttons, or multiple update text fields
I have a working sample of it, however it is very messy and I would
like to know if there is any other way to do it.
Currently my code is as such:
SomePresenter.java
//.... some code
private void addStock(JsArray<Stock> stocks) {
FlexTable viewStockTable = new FlexTable();
viewStockTable.removeAllRows();
viewStockTable.setText(0, 0, "Symbol");
viewStockTable.setText(0, 1, "Name");
viewStockTable.setText(0, 2, "Price");
viewStockTable.setText(0, 3, "Change");
viewStockTable.setText(0, 4, "Remove");
int row = 1;
for (int i = 0; i < stocks.length(); i++) {
viewStockTable.setText(row, 0, stocks.get(i).getCode());
viewStockTable.setText(row, 1, stocks.get(i).getName());
viewStockTable.setText(row, 2, "$ " +
roundDouble(getPrice(stocks.get(i).getStockPrice(), 0), 2));
viewStockTable.setText(row, 3,
roundDouble(getPriceChange(stocks.get(i).getStockPrice(), 0), 2) + "
%");
Button removeButton = new Button("x");
final String code = stocks.get(i).getCode();
//--------------------Here is the problem------------------
removeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
deleteStock(code);
}
});
//----------------------------------------------------------------
viewStockTable.setWidget(row, 4, removeButton);
row++;
}
display.addStock(viewStockTable);
}
SomeView.java
private DecoratorPanel leftPanel = new DecoratorPanel();
private VerticalPanel leftStack = new VerticalPanel();
private SimplePanel viewPanel = new SimplePanel();
private FlexTable viewStockTable = new FlexTable();
public HomeView() {
//... some code
// assemble left panel
leftStack.add(addPanel);
viewPanel.add(viewStockTable);
leftStack.add(viewPanel);
leftPanel.add(leftStack);
//... some code
}
//... some code
public void addStock(FlexTable table) {
viewPanel.clear();
viewPanel.add(table);
// -------------- Can't be done unless I put it in another container
like the panel -------
// viewStockPanel = table;
//
----------------------------------------------------------------------------------------------------------
}
My structure:
SomePresenter.java
- addStock method - retrieve data from rpc then is creates the table
to view and pass the table to SomeView.java
I also do not like all the buttons are created in the view, if so what
is the point of MVP while I can also create them in Model and
Presenter alone. Since I created all the buttons in the Presenter,
when I pass the table to View, It can't be done with (viewStockTable =
table).
I do not like this is structured, is there another way to do it?
Thank you.
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.