Thank you so much! Using what you said I was able to get it working
in just a few minutes. I'm using your sample project to help arrange
some other stuff better as well.
I probably need to work on my event handling rather than just using
History.newItem(), but here's the code I have in my presenter now.
// In my constructor.
selectionModel = new SingleSelectionModel<LightOwner>();
display.getOwnerTable().setSelectionModel(selectionModel);
// In the function I use for setting up all event handling.
selectionModel.addSelectionChangeHandler(new
SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
LightOwner selected = selectionModel.getSelectedObject();
if (selected != null) {
History.newItem("edit-owner/"+selected.getId());
}
}
});
Thanks again!
On Jan 16, 1:53 am, David Chandler <[email protected]> wrote:
> Hi Raymond,
>
> I've taken a stab at this in the listwidget sample project. I wanted the
> view screen to be its own Place for bookmarking, so I created a
> HyperlinkCell and use utility methods in RequestFactory and
> PlaceHistoryMapper to create a URL from an ID / Place. Here's the relevant
> code from ListsViewImpl (arguably doesn't really belong in the view, but I
> haven't moved it out yet):
>
> Column<ItemListProxy, Hyperlink> linkColumn = new Column<ItemListProxy,
> Hyperlink>(new HyperlinkCell())
>
> {
>
> @Override
>
> public Hyperlink getValue(ItemListProxy list)
>
> {
>
> String proxyToken =
> clientFactory.getRequestFactory().getHistoryToken(list.stableId());
>
> String historyToken =
> clientFactory.getHistoryMapper().getToken(newEditListPlace(proxyToken));
>
> Hyperlink h = new Hyperlink(list.getName(),historyToken);
>
> return h;
>
> }
>
> };
>
> cellTable.addColumn(linkColumn, "Edit");
>
> and HyperlinkCell:
>
> public class HyperlinkCell extends AbstractCell<Hyperlink>
>
> {
>
> @Override
>
> public void render(com.google.gwt.cell.client.Cell.Context context,
>
> Hyperlink h, SafeHtmlBuilder sb)
>
> {
>
> // WARNING Make sure there's no user-provided content in
> your link!
>
> sb.append(SafeHtmlUtils.fromTrustedString(h.toString()));
>
> }
> }
>
> To decode the URL, use the companion method in RequestFactory:
>
> final ListwidgetRequestFactory req = clientFactory.getRequestFactory();
>
> EntityProxyId<ItemListProxy> proxyId = req.getProxyId(this.itemListToken);
>
> All this is necessary only if you want the detail screen to be a
> bookmarkable Place; otherwise, you can use a SelectionModel as shown
> inhttp://gwt.google.com/samples/Showcase/Showcase.html#!CwCellList
>
> I'm inclined to put SelectionModel in the presenter since it's a model, not
> a widget. And CellTable et al implement non-widget interfaces so you can
> safely reference them in the view interface like this:
>
> HasData<SomeProxy> getSomeProxyDisplay();
>
> then in your presenter:
> view.getSomeProxyDisplay().setSelectionModel(...);
>
> The listwidget sample project is athttp://code.google.com/p/listwidget/
>
> HTH,
> /dmc
>
>
>
>
>
>
>
>
>
> On Fri, Jan 14, 2011 at 8:56 PM, rlhawk1 <[email protected]> wrote:
> > I'm trying to create a CellTable where when you click on a row, it
> > goes to another screen, and I'm trying to keep a correct MVP
> > architecture.
>
> > I have two questions. First, do I initialize my CellTable in the
> > view, or the presenter?
>
> > Right now I have something like this in my view code, but with more
> > columns.
>
> > TextColumn<LightOwner> nameColumn = new TextColumn<LightOwner>() {
> > public String getValue(LightOwner o) {
> > return o.getName();
> > }
> > };
> > ownersTable.addColumn(nameColumn, "Name");
>
> > It works fine, but is it okay for the view to be knowing about my
> > LightOwner type like that.
>
> > Secondly, I need it to bring up the owner edit screen for the id of
> > the row clicked when they click on a row. Reading around, it /sounds/
> > like I need to use the SelectionModel class for this, but I'm unsure
> > rather that should be in the presenter or view also.
>
> > By their example, I need to add code something like this:
>
> > final SingleSelectionModel<String> selectionModel = new
> > SingleSelectionModel<String>();
> > ownersTable.setSelectionModel(selectionModel);
> > selectionModel.addSelectionChangeHandler(new
> > SelectionChangeEvent.Handler() {
> > public void onSelectionChange(SelectionChangeEvent event) {
> > String selected = selectionModel.getSelectedObject();
> > if (selected != null) {
> > // Go to edit screen with selected.getId();
> > }
> > }
> > });
>
> > But what I'm used to is having a HasClickHandlers in the view and
> > attaching the event in the presenter. How am I supposed to use
> > SingleSelectionModel with MVP? Or am I going about this totally wrong?
>
> > --
> > 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]<google-web-toolkit%2Bunsubs
> > [email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-web-toolkit?hl=en.
>
> --
> David Chandler
> Developer Programs Engineer, Google Web Toolkit
> w:http://code.google.com/
> b:http://googlewebtoolkit.blogspot.com/
> t: @googledevtools
--
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.