I feel like I'm missing something obvious here, but I haven't been
able to figure this out. In short, I have a CellTree whose leaf nodes
are populated with CompositeCells. Each CompositeCell has an
ImageResourceCell, a TextCell, and a TextInputCell. These are
displaying in the tree correctly. I have attached an onClick event to
the ImageResourceCell that deletes the item from the tree, and that
works as expected. The intent for the TextInputCell is to display a
field from the entity associated with the cell, and update the field
on the entity when the user changes the value in the TextInputCell.
However, I'm having a couple of problems with the TextInputCell.
First, when I type in the TextInputCell, the space key is ignored -
well, it's probably being consumed by something else but the upshot is
that when I type a space character, it doesn't appear in the
TextInputCell. I thought this might have to do with the SelectionModel
or KeyboardSelectionPolicy on the CellTree, but I've set the tree to
KeyboardSelectionPolicy.DISABLED and the TreeViewModel to
NoSelectionModel and it's still happening.
Furthermore, the up, down and right arrow keys are also ignored, but
the left arrow key causes the CellTree to disappear entirely.
Curiously, if I override the onBrowserEvent in the TextInputCell to
show a Window.alert, the space character DOES make its way into the
TextInputCell, but the alert doesn't affect what happens on arrow key.
Second - the point of having the TextInputCell there is that I want to
update the entity object associated with that tree node. In the
HasCell that describes the TextInputCell, I overrode getFieldUpdater
to return a reference to the object that should do the updating, but
its update method apparently never gets called. Do I need to do
something in the CompositeCell's or TextInputCell's onBrowserEvent to
invoke the update myself?
Code below - sorry for the length.
JLS
//construct composite cell for code descriptions
List<HasCell<CcdDTO, ?>> descripHasCells = new
ArrayList<HasCell<CcdDTO, ?>>();
descripHasCells.add(new HasCell<CcdDTO, ImageResource>() {
private ImageResourceCell cell = new ImageResourceCell();
public Cell<ImageResource> getCell() {
return cell;
}
public FieldUpdater<CcdDTO, ImageResource> getFieldUpdater() {
return null;
}
public ImageResource getValue(CcdDTO object) {
return pImages.delete();
}
});
descripHasCells.add(new HasCell<CcdDTO, String>() {
private TextCell cell = new TextCell();
@Override
public Cell<String> getCell() {
return cell;
}
@Override
public FieldUpdater<CcdDTO, String> getFieldUpdater() {
return null;
}
@Override
public String getValue(CcdDTO value) {
if (value instanceof CcdGroupDTO) {
return ((CcdGroupDTO)value).getGroupName();
} else {
return "All";
}
}
});
descripHasCells.add(new HasCell<CcdDTO, String>() {
private TextInputCell cell = new TextInputCell() {
@Override
public Set<String> getConsumedEvents() {
HashSet<String> events = new HashSet<String>();
events.add("click");
events.add("keydown");
return events;
}
// uncomment this and the space key appears in the text input,
after the alert
// public void onBrowserEvent(Context context, Element elem,
String value, NativeEvent event, ValueUpdater<String> arg4) {
// Window.alert("text input event:" + event.getType());
// };
};
@Override
public Cell<String> getCell() {
return cell;
}
@Override
public FieldUpdater<CcdDTO, String> getFieldUpdater() {
return CcdTabPanel.this.controller;
}
@Override
public String getValue(CcdDTO value) {
return value.getDescription();
}
});
groupDescripCell = new CompositeCell<CcdDTO>(descripHasCells) {
@Override
public Set<String> getConsumedEvents() {
HashSet<String> events = new HashSet<String>();
events.add("click");
events.add("keydown");
return events;
}
@Override
public void onBrowserEvent(Context context, Element elem,
CcdDTO object, NativeEvent event, ValueUpdater<CcdDTO> updater)
{
super.onBrowserEvent(context, elem, object, event, updater);
if ("click".equals(event.getType())) {
GWT.log("group descrip on browser event");
Element el = event.getEventTarget().cast();
if ("img".equalsIgnoreCase(el.getTagName())) {
List<CcdSummaryDTO> dtoList = summaryDtoListProvider.getList();
int originalSize = dtoList.size();
//controller.deleteDescription modifies the list that
summaryDtoListProvider refers to
int index = controller.deleteDescription(object);
if (originalSize == dtoList.size() && index != -1) {
// workaround for GWT issue 6979 - see
http://code.google.com/p/google-web-toolkit/issues/detail?id=6979
// making an edit to the tree that doesn't change the number
of top-level nodes
// won't cause the tree to refresh. To work around, we'll
close and open the
// child element where we made the change
CcdTabPanel.this.descripTree.getRootTreeNode().setChildOpen(index,
false);
CcdTabPanel.this.descripTree.getRootTreeNode().setChildOpen(index,
true);
}
summaryDtoListProvider.setList(dtoList);
}
}
}
};
}
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment