Vaadin 8 Grid - perform action on changing (row) focus - GridFastNavigation - java

when searching for anything related to a Vaadin grid focus listener or similar, they keep pointing me to the GridFastNavigation add-on... and I tried it...
The only thing I want to do is to perform a simple action (two lines of code - refresh a preview) when the (row) focus in the Grid changes, i.e. when up or down keys are pressed. Nothing editable there, the grid is used only for display.
We extended the grid, and like in the demo project, I initialize the navigation stuff in the constructor of our grid. This is the code I currently have there
FastNavigation<M> nav = new FastNavigation<>(this, true, false);
nav.setChangeColumnAfterLastRow(true);
nav.addRowFocusListener(event -> {
if (event.getRow() >= 0) {
M model = (M) event.getItem();
refreshDetailLayout(model);
}
});
This looks very straightforward, but nothing happens, when navigating the grid. I tried debugging, and the only thing I could find out is that the code in the listener doesn't even get executed.
Are there any certain prerequisites for this add-on to work? Are there any known restrictions like other listeners right on the grid (such as ItemClick- or ShortcutListener) interfering with it?
I'm currently at Vaadin 8.4.5 and GridFastNavigation 2.3.5

Related

very weird behavior with dragAndDropBy(), dragAndDrop(), moveToElement, etc

Not sure if its due to how the application im automating has its UI set up but what Im trying to do is open up a side drawer that holds a couple table rows. I need to drag a table row into another specific area and drop it there to move it.
So heres an Idea of what the interface looks like:
NOTE: All that whitespace is not a valid area to drop the table row the tablerows are only droppable in a very specific area that becomes visible when the tablerow is right above it.
Im trying to drag the items on the right hand drawer to the left hand side.
When I try to use dragAndDropBy to move to the respective x and y offsets it looks like it doesnt move to the correct location.
I have modified my code now to at least help me see whats wrong and it seems like its not moving to the x coordinate set in my code below:
Actions actions = new Actions(driver);
System.out.println(productArrangement.getLocation());
actions.clickAndHold(productArrangement).moveByOffset(-408, 308).perform();
System.out.println(productArrangement.getLocation());
Thread.sleep(4000);
As you guys can see all this is trying to do at the moment is see where my element is being moved too and logging if the element is actually moving to the respective direction and it seems like its not being moved at the x coordinate and is moving at the wrong Y coordinate(but at least its moving).
here is my console
I would expect the second coordinate log to have moved to the specified offSets I put in but I have gotten similar behavior for all the methods I've tried so far.
Please advise assistance would be greatly appreciated.
Use direct dargAndDrop method like below:
Actions actions = new Actions(driver);
actions.dragAndDropBy(productArrangement,-408, 308).perform();

Avoid vaadin grid automatic horizontal scroll after click

I'm using vaadin 8.1 in my project.
I needed to give an extra large width to a grid column (the latest at the right), and when user clicks in one field of this extra large column, vaadin move horizontal scroll automatically at the end of the grid. I would like stop this vaadin behaviour. I researched and I tried different things but I didn't find anything,
How can I do it?
Thank you,
Best regards
There is no API in Vaadin to turn it off (You can find feature request here: https://github.com/vaadin/framework/issues/7667). There is one trick you could try, namely disable pointer events in Grid cells. It is a bit harsh method, since it will disable also selection and item click.
In your code
grid.setStyleGenerator(item -> { return "disable-events";});
And your theme
.disable-events {
pointer-events: none;
}
It is possible to add the style generator also for one Column only, which could be option to you as well

Vaadin7 - Grid disable unselecting

How to disable unselecting Grid row in Vaadin 7, but with permission to select another row using keyboard or mouse click?
Grid grid = new Grid(container);
grid.setSelectionMode(Grid.SelectionMode.SINGLE);
For example this is possible for older Table component - SO answer. But I widely use Grid so I want use it also in this case.
I found one interesting solution, but unfortunately not perfect.
To prevent deselect row we could write a SelectionListener and put there some logic:
grid.setSelectionMode(Grid.SelectionMode.SINGLE);
grid.addSelectionListener(event -> {
Set<Object> selected = event.getSelected();
if (selected == null || selected.isEmpty()) {
Set<Object> removed = event.getRemoved();
removed.stream().filter(Objects::nonNull).forEach(someGrid::select);
}
});
So assuming single selection mode, if current selection is empty, then previous selected row should be selected again. But if current selection isn't empty it means that somebody select another row - this doesn't require any action.
It is cool but not enough - every click (selection) cause http call and network transmission. This is disadvantage.
In Vaadin 8 you may use:
grid.setSelectionMode(SINGLE);
((SingleSelectionModel) grid.getSelectionModel()).setDeselectAllowed(false);

UI not aligning

I am using LibGDX and Scene2D to create a simple menu for my game.
Here is a simple example that works for me:
table.add(gameLogo).row();
table.add(button1).row();
table.add(button2).row();
table.add(button3).row();
I didn't include the irrelevant code(including the table into the stage for example).
If I don't include .row() to each object that I add to the table, then the menu isn't aligning to the center, which is very odd, for example:
table.add(gameLogo).row();
table.add(button1);
table.add(button2).row();
table.add(button3);
Why is the menu behaving like that? should I use more tables or add some HorizontalGroups perhaps?
If you need any additional information, or images I can provide, although it does the same for even the simplest menu implemention possible with LibGDX and Scene2d.
This is a colspan problem.
Looking at your code, this is what you are currently doing :
I assume that you would like to display your menu like that :
In order to do that, as you can see, you need to set the colspan size of your gamelogo to 2, so that it will take as much size as 2 regular cells.
So, to achieve this result, your code should be :
table.add(gameLogo).colspan(2).center().row();
table.add(button1);
table.add(button2).row();
table.add(button3);
The align(Align.center) or center() methods will not work alone, since these methods are only used to align the widget inside it's own cell.
If you experience more problems with libgdx ui table, remember that you can enable a debug renderer to display the cells border :
table.setDebug(true);

Minor Refactoring in Java Swing application causes huge slowdown

I've been tasked with doing refactoring to a Java Swing application we have here that's pretty crufty. My job is to clean up the code and make it more dynamic as we're going to start using it with a second project and it needs to be able to adjust appropriately. There is a small portion of one window that contains
A button
A JFormattedTextField that is used to select dates.
A 3X4 table of JLabels that display data.
The person who originally wrote this simply used a GridBagLayout JPanel and then hardcoded everything, including the table's header and row label's and left empty JLabel's in the dynamic data position. When the dynamic information is received setText is called with the text data. Part of my refactoring will cause the entire table to be dynamic in dimension as well as content so I decided to make the table a sub-panel with a GridLayout and dynamically set the contents and dimensions with this piece of code:
public void updateInfoPanel(ArrayList rows) {
System.out.println("Updating Info Panel!");
//genericInfo is the new sub panel in question.
genericInfo.removeAll();
GridLayout layout = new GridLayout();
layout.setColumns(rows.get(0).length);
layout.setRows(rows.size());
genericInfo.setLayout(layout);
for(String[] row : rows) {
for(String element : row) {
genericInfo.add(new Label(element));
}
}
}
I have verified that this is only ever getting called one time per window creation but the entire window is now incredibly sluggish. It can take >5 seconds to respond to clicks in other parts of the frame that used to respond in fractions of a second. Does anyone know what would cause this? Is there something about GridLayouts that I don't understand?
Try calling this code on the EDT.
No it appears you understand GridLayouts. The problem is elsewhere, look at other code that you might have changed, and do some profiling to determine the true source of the slowdown.

Categories

Resources