Cannot click ListViewCell with null value - ui-automation

The tests I am developing access the DataGrid cells the following way:
window.Get<ListView>(gridName).Rows.First().Cells.First()
Then clicking a cell with UIItem.Click() method works fine, unless the cell is bound to a null value. In such a case, I get an exception:
Failed to click on ListViewCell. AutomationId:, Name:, ControlType:text, FrameworkId:WPF, bounds empty
Which makes sense, as apparently, an AutomationElement related to that cell is a TextBlock of 0 boundaries.
Is there some possible workaround to click such a cell so the tests work?

What seems to be a good enough workaround is the following:
this.window.Mouse.Location = Point.Subtract(cellToClick.ClickablePoint, new Vector(12, 6));
this.window.Mouse.Click(this.window.Mouse.Location);
So I just set the mouse location using property TestStack.White.UIItems.Mouse so it is situated right above the cell, then click.

Related

NSTableView with custom cell view and NSArrayController bindings drawing a blank string

It took me forever to figure out how to set up editing on a custom cell view for an NSTableView. Thanks to StackOverflow I figured that much out. P.S. I was doing all of this in Interface Builder.
I have a single column table in which the cell is a custom multi-control NSTableCellView, with:
name (in bold)
description
detail
It's all text. Set up editability on the name only. The table is sorted by the name.
When I edit the name, it has the effect on the bound model that I expect. The table even re-sorts correctly. However, it's displaying incorrectly. The description and detail (not editable) still show up correctly, but the name (which was edited) is a blank. When I inspect the model, it has the correct updated value. But the cell view itself is incorrect.
This doesn't happen all the time--it typically happens if the cell is re-sorted to the top or bottom of the table, but that may be a red herring and may instead have to do with NSTableView cell caching or something.
I hacked up a workaround in which I assign a delegate to the NSTextField (automatically generated for the NSTableCellView) and intercept the textShouldEndEditing event. For some reason this event is getting triggered twice for a given edit (after I press "enter" in the text field)--once for the actual edit where fieldEditor.string is different from the model name, followed by another event where fieldEditor.string is the same as the model name. If I return false for my textShouldEndEditing handler in the latter case, then the cell contents end up being drawn correctly. That's the hack.
I feel like I'm doing something wrong here though, and that shouldn't be necessary.
Is the textShouldEndEditing event supposed to be fired twice?

GWT: Multi Selection model does not update the celltable status in some cases

I am using the GWT MultiSelectionModel within a CellTable in which I have a checkbox in one column and a widget in the other column. I have added handlers to update the selection status based on user clicks. If the user clicks on any part of either columns when the cell is selected, the status gets updated correctly and the cell turns white from light blue. Howvever, If the user clicks on the check box and the cell is selected, the check box gets unchecked but the cell is still blue. Even more strange: This issue does not happen if I have a few breakpoints before the status update code is executed.
In all other cases, the cell state and the checkbox state gets updated correctly. Note that I am not using the ProvidesKeys interface since the object do not change.
Can anyone help me with this? Thanks for your help.
Have you tried using a CheckBoxCell for your checkbox column and, specifically, the CheckboxCell(boolean dependsOnSelection, boolean handlesSelection) constructor (by passing true to both params)?
I've got almost the same problem when I use MultiSelectionModel. What's my walkaround is to see the checkbox's column as a special one and then to deal with it manually. Say:
myDataGrid.addCellPreviewHandler(
#Override
public void onCellPreview(final CellPreviewEvent<MyCellData> event){
if("click".equals(event.getNativeEvent().getType()) && 0 != event.getColumn()){
doWhatYouWant();
}
}
)

GWT 2.4 DataGrid automatic scrolling when selecting an item

I am using GWT 2.4's new DataGrid in a project. I configured the DataGrid with a pagesize of 50.
The available screen is not big enough to display all items and thus a vertical scrollbar is shown (this is actually the main purpose for using a DataGrid in the first place).
I attached a SingleSelectionModel to the DataGrid in order to be able to select items.
This works fine so far.
However I also have another widget with which the user can interact. Based on that user action a item from the DataGrid should be selected.
Sometimes the selected item is not in the visible screen region and the user has to scroll down in the DataGrid to see it.
Is there any way to automatically or manually scroll down, so that the selected item is visible?
I checked the JavaDocs of the DataGrid and found no appropriate method or function for doing that.
Don't know if this works, but you could try to get the row element for the selection and use the scrollIntoView Method.
Example Code:
dataGrid.getRowElement(INDEX_OF_SELECTED_ITEM).scrollIntoView();
The answer above works pretty well, though if the grid is wider than your window and has a horizontal scroll bar, it also scrolls all the way to the right which is pretty annoying. I was able to get it to scroll down and stay scrolled left by getting the first cell in the selected row and then having it scroll that into view.
dataGrid.getRowElement(dataGrid.getVisibleItems().indexOf(object)).getCells().getItem(0).scrollIntoView();
Don't have time to try it out, but DataGrid implements the interface HasRows, and HasRows has, among other things, a method called setVisibleRange. You just need to figure out the row number of the item that you want to focus on, and then set the visible range from that number n to n+50. That way the DataGrid will reset to put that item at the top (or near the top if it is in the last 50 elements of the list backing the DataGrid). Don't forget to redraw your DataGrid.
Have you already looked at this? If so, I'd be surprised that it didn't work.
Oh, and since this is one widget talking to another, you probably have some messaging set up and some message handlers so that when the user interacts with that second widget and "selects" the item, the message fires on the EventBus and a handler for that message fixes up the DataGrid along the lines I've described. I think you'll have to do this wiring yourself.
My solution, a little better:
dataGrid.getRow(model).scrollIntoView();
I got a Out of bounds exception doing the above.
I solved it getting the ScrollPanel in the DataGrid and used .scrollToTop() and so on on the ScrollPanel. However, to access the ScrollPanel in the DataGrid I had to use this comment:
http://code.google.com/p/google-web-toolkit/issues/detail?id=6865
As Kem pointed out, it's annoying the "scrollToRight" effect after the scrollIntoView. After me, Kem's solution gives a better behaviour than the base one as usually the first columns in a table are the more meaningful.
I improved a bit his approach, which scrolls horizontally to the first column of the row we want to be visible, by calculating the first visible column on the left before applying the scroll and then scrolling to it.
A final note: Columns absolute left is tested against "51". This is a value I found "experimentally" by looking the JS values in the browser's developer tool, I think it depends on the table's style, you may need to change/calculate it.
Below the code:
public void scrollIntoView(T next) {
int index = datagrid.getVisibleItems().indexOf(next);
NodeList<TableCellElement> cells = datagrid.getRowElement(index).getCells();
int firstVisibleIndex = -1;
for(int i=0; i<cells.getLength() && firstVisibleIndex<0;i++)
if(UIObject.isVisible(cells.getItem(i)) && (cells.getItem(i).getAbsoluteLeft() > 51) && (cells.getItem(i).getAbsoluteTop() > 0))
firstVisibleIndex = i;
cells.getItem(firstVisibleIndex>=0? firstVisibleIndex : 0).scrollIntoView();
}

GWT: access a ListBox inside a Panel inside a Panel

I've got a panel, which contains a bunch of (multiselect) ListBoxes each inside their own panel, and I need to figure out what the selected values in the ListBoxes are. Going through the API, the only way I can see of doing this is (pseudocode):
for (Wigdet w : outerPanel)
Panel innerPanel = (Panel) w;
for (Widget s : innerPanel) // only has the ListBox in it
ListBox box = (ListBox) s;
// do stuff with the ListBox to populate the list of selected options
The trouble is with the casting - eclipse doesn't complain and it compiles fine, but when run it produces a ClassCastException (on the first cast - I assume it would also have the same problem on the second, but since I can't get to it I can't say for sure)
What is the correct way to do this?
Got it working. Apparently GWT inserts its own widgets into your panel, besides the ones you add yourself (so creating a Panel then adding a ListBox to in will result in more than just the one widget on iteration).
So to solve the problem, throw in an instanceof check before the casting
Why can't you just declare them as instance variables?

I want my CheckboxCell to control the selected state of each row

I've got a CellTable with a column rendered with a CheckboxCell. I want to check the boxes to select the rows.
The default behavior with CheckboxCell(false, false) is tantalizingly close to my goal - selecting a row checks the checkbox, and de-selecting a row unchecks the checkbox. However, if I click a checkbox, it unselects any already-selected rows. Even worse, when I uncheck a checkbox, the row is not deselected. Argh!
I'm looking at coding my own cell now (or messing with the SelectionModel?), but this seems like behavior Google might have been trying for. I've tried every permutation of values in the constructor, to no avail. Is there a simple override I can add to finally make my dream... a reality?
You know how you can search for 30 minutes, and then 20 seconds after you post your question you find your answer?
Well, it turns out that to unleash the power of the CheckboxCell, you need to pass a Handler that is equipped to deal with the complexities of the situation. Try
setSelectionModel(selectionModel, DefaultSelectionEventManager.<T> createCheckboxManager());
with your MultiSelectionModel selectionModel - the selectionModel itself is not enough!