Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

GWT 2.4 - problems with space key handling and FieldUpdater for TextInputCell inside CompositeCell in CellTree

779 views
Skip to first unread message

James Scott

unread,
Dec 28, 2011, 3:49:11 PM12/28/11
to Google Web Toolkit
Hi all-

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);
}
}
}
};
}

James Scott

unread,
Dec 29, 2011, 11:08:09 AM12/29/11
to Google Web Toolkit
Looks like it boils down to events. After looking at the TextInputCell
and AbstractInputCell source, I added "focus" and "change" events to
the list of events consumed by the CompositeCell, and that addressed
both issues.

Incidentally, I tried out the EditTextCell in the CompositeCell, and
to get that working, I needed to add "keyup" and "keydown" events to
the CompositeCell.

Clearly I do not yet have my mind wrapped around how the events are
propagated in a CompositeCell, but at least I've solved my immediate
problems.

JLS

On Dec 28, 3:49 pm, James Scott <j...@jls.cx> wrote:
> Hi all-
>
> 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.[snip]

BhaskerT

unread,
Aug 29, 2012, 6:30:10 AM8/29/12
to google-we...@googlegroups.com
Hi James,
Thanks for the post and reply.
I am facing similar issue. I am not able to type the white space character in the MyEditCell extends AbstractInputCell.
i have also over ridden the below method:

public Set<String> getConsumedEvents() {

Set<String> events = new HashSet<String>();

events.add("focus");

events.add("blur");

events.add("keydown");

events.add("change");

return events;

}
But, Still no luck.
Can you please suggest something.
 
Thanks,
Bhasker

Nicholas Loke

unread,
Oct 21, 2013, 3:32:04 PM10/21/13
to google-we...@googlegroups.com
The issue is due to CellTree preventing the default browser event on space. The reason for that is to prevent scrolling.
 
You can listen for KEYDOWN in TextInputCells  and then add the space in the input manually. As to how to get the input element, you can traverse the DOM from the parent Element or use something like GQuery.
 
Nicholas
 

On Wednesday, May 8, 2013 7:24:03 AM UTC-4, Michael Altmann wrote:
I am facing the same issue and cannot figure out how the original poster set up event handling to get this working.  Any help would be greatly appreciated.  Right now my CellTree with TextInputCells will not accepts spaces.
Reply all
Reply to author
Forward
0 new messages