bugs about using DataGrid wrapped by StackLayoutPanel - gwt

I tried to use DataGrid and put it in the stacklayoutpanel.At the time when I provide the data for the ListDataProvider, the CellTable is not visible in the browser because it's on a non active tab (although it's visible in the DOM tree). After switching to the tab containing the CellTable there is no data in it. If the tab is active at time of data provisioning the table is filled correctly. Since I have made a column sortable, if I clicked the sorting, the data would be displayed correctly. I want the data to be displayed automatically when I click the other inative tab. This will not be the problem if I switch to use celltable.
I knew this was the bug in GWT and it is fixed in GWT 2.5 RC. But my boss does not want me to use GWT2.5RC yet. I have to workaround to fix this. I knew that someone said datagrid.redraw() could sort of fix it. I tired it, but the display is weird. For example, I have 10 rows in DataGrid, after selecting the 2nd tab, redraw() is called, the data is automatically displayed, but there is only like 10px of block displaying the data and the scroll bar. I have to scroll down to see other rows. There are lots of space in the bottom of the tab not being used. Could anyone tell me how to fix this? So did I use the wrong way to fix it?
is there anything else I can do to fix this problem.
Could anyone give me some tips please.
Thanks
Best Regards

I have been struggled with this thing for almost 3 days. Thanks for Papick G. Taboada and Thomas Broyer.
You guys' ideas are really helpful. Bascially either of your solution does not solve the problem. but after I combined both solutions, dang~ it worked!!.
So. the completed solution is that, add the selection handler on the non-active tab, then when the event is called, used datagrid.onResize() and then stackLayoutPanel.forcelayout(). This can solve my problem. I have also tried replacing datagrid.onResize() with datagrid.redraw(). It works as well.
I hope this can help other people who have the same problem before using GWT 2.5RC

I came across this problem with a DataGrid within and Panel that was in a StackPanelLayout. DataGrid implements RequiresResize, so I made the Panel that contained the DataGrid implement RequiresResize so it could call onResize() for the DataGrid.
in the Panel that contained the DataGrid
#Override
public void onResize()
{
dataGrid.onResize();
}
On the StackLayoutPanel
stackLayoutPanel.addSelectionHandler(new SelectionHandler<Integer>() {
// http://code.google.com/p/google-web-toolkit/issues/detail?id=6889
#Override
public void onSelection(SelectionEvent<Integer> event) {
Integer selectedItem = event.getSelectedItem();
StackLayoutPanel panel = (StackLayoutPanel) event.getSource();
Widget selectedWidget = panel.getWidget(selectedItem);
if (selectedWidget != null && selectedWidget instanceof RequiresResize)
{
((RequiresResize)selectedWidget).onResize();
}
}
});
I believe a more general answer would be that any container in a StackLayoutPanel that contains a widget that implements RequiresResize should also implement RequiresResize and pass it on.

Related

JavaFX TableColumns' headers not aligned with cells due to vertical scrollbar

after having spent the last few hours searching the web for this issue I decided that I need your help.
The issue is similar to this topic: Javafx: Tableview header is not aligned with rows
No answer has been provided there and also, I think, my case is slightly different:
I have a properly setup TableView with reused CellFactories and CellValueFactories. Data-wise, everything works 100% the way I intended. However once I populated my table with more rows than my view can show it naturally started to show a vertical scrollbar. From that moment on (see first screenshot) the column headers weren't aligned with the columns anymore. It appears that it is exactly the width of the scrollbar that distorted the widths distribution (I'm using ConstraintResizePolicy with a few fixed width columns and the rest relying on computed width, again, otherwise working flawlessly).
As soon as I scroll with the mouse wheel, click on an entry, tab into focus or resize the window/view, the headers snap into place (see second screenshot).
Based on the topic posted in the beginning, I think this is a bug and I'm therefore not only looking for a solution (which might not exist) but also for a workaround. I tried:
table.scrollTo()
table.scrollToColumnIndex()
table.layout()
table.requestFocus()
table.requestLayout()
table.refresh()
I know not all of those make sense but still I tried and none of them made the column headers be in line with their columns on application launch.
Every suggestion is welcomed.
I don't feel that sharing code helps here, but ask if you want something specific. The view was built with SceneBuilder 8 and consists of an AnchorPane, a TableView in the middle, and 6 TableColumns, nothing else.
Thank you very much!
I've had the same problem. It seems a bug. Try this. It works for me
Platform.runLater(() -> tableView.refresh());
I know this is an old message but I tried everything to get the headers aligned and nothing was working until I stepped away from the problem. I then tried this and it worked. Headers jump but I am ok with that. I hope this helps someone else.
Task<Boolean> task = new Task<Boolean>() {
#Override protected Boolean call() throws Exception {
Thread.sleep(300) // needs this to make sure the table is displayed
table.refresh();
table.scrollTo(0);
return true;
}
};
new Thread(task).start();
I also have the situation of TableColumns' Headers not aligend with cells.But I am not because Scrollbar.I am because of setting a border color for cells.After the CSS modified, I got the correct result.
Incorrect CSS:
.table-row-cell {
-fx-border-color: black;
}
changed to:
.table-row-cell {
-fx-table-cell-border-color: black;
}
Reference documentation: https://community.oracle.com/tech/developers/discussion/2505963/tableview-column-headers-do-not-line-up-with-rows
None of the other solutions worked for me. I noticed that the issue only occurs when the horizontal scrollbar is on the far right and then the table is cleared (table.getItems().clear()) while other content changes didn't cause the bug even if the scrollbar disappears and reappears.
I checked this bug report https://bugs.openjdk.java.net/browse/JDK-8149615 (and the linked changeset) and at first dismissed the workaround because scrolling to the first column (table.scrollToColumnIndex(0)) wasn't working for me either.
But it started working once I called scrollToColumnIndex before clearing the table with getItems().clear().
The bug report suggests reacting to the visibility change of the placeholder node. I didn't test this because I had already solved it (hopefully) and no sample code is provided. But if I ever need to revisit this I would try writing a listener for the placeholder visibility as an alternative solution.

SmartGwt get VLayout height after add members

I have problem a with getting VLayout height after I add a member to it
VLayot layout = new VLayout();
in presenter I have code
display.getAnswerPanel().removeMembers(display.getAnswerPanel().getMembers());
which clear all members, and I add another (I have buttons, when I clik them, it clears all VLayout and adds new members)
layout.addMember(new Button("Example"));
I need to get offsetHeight of this VLayout on start and everytime I click the button, my problem is that in first time when I load the page, my `offsetHeigh is 1px, each next time when I click button is ok, it shows me the correct value. Can someone help me?
I tried to use this code
scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
layout.getOffsetHeight();
}
but the situation is the same, First time I don't have the correct value.
we can get the height and width of any widget only after the widget is being loaded or on button click.
Scheduler#scheduleDeferred() executes at the end of the GWT loop, so there's still no time for the layout to update either. I guess there's not much you can do besides using the traditional timer hack (in case any reader is in doubt, yes, I meant using setTimeout() or Scheduler.get().scheduleWithFixedDelay(cmd, 200) ).

Get the GWT ScrollPanel to start its vertical scrollbar at the bottom

I know there are some questions out there about the GWT ScrollPanel and how it works, but allow me to explain the situation.
I'm working on a project to implement QoS on routers. I'm now at the developping stage of the project and I need to make a webinterface to add protocols such as ssh and http and give them their bandwidth.
To save memory usage and network traffic, I do not use GWT-EXT or Smart GWT. So to set the bandwidths I use a ScrollPanel with an empty SimplePanel in it (which is way too big), leaving only the scrollbar.
Now here's the problem:
I want each scrollbar for each added protocol to start at the bottom, not the top. I can get it working through the code if I manually move the scrollbar first, then any function works, like a scrollToBottom(), or a setScrollPosition(). If I want to move scrollbars through code before moving the scrollbar manually, however, I can't call a function on it.
(I would post a picture but I can't yet - new user)
Summary:
So if I add a protocol (using a button called btnAjouter), the two slidebars (One for guaranteed bandwidth and one for the maximum bandwidth) for each protocol start at the top. I want them to start at the bottom on the load of the widget.
Is there a way to do this?
Thanks in advance!
Glenn
Okay, my colleage found the solution. It's a rather dirty one, though.
The thing is, the functions only work when the element in question is attached to the DOM. I did do a check with a Window.alert() to see if it was attached, and it was. But the prolem was that the functions were called to early, for example on a buttonclick it would've worked. The creation and attachment of the elements all happens very fast, so the Javascript can't keep up, this is the solution:
Timer t1 = new Timer()
{
#Override
public void run()
{
s1.getScroll().scrollToBottom();
s2.getScroll().scrollToBottom();
}
};
t1.schedule(20);
Using a timer isn't the most clean solution around, but it works. s1 and s2 are my custom slidebars, getScroll() gets the ScrollPanel attached to it.
You can extend ScrollPanel and override the onLoad method. This method is called immediately after a widget becomes attached to the browser's document.
#Override
protected void onLoad() {
scrollToBottom();
}
Could you attach a handler to listen to the add event and inside that handler do something like this:
panel.getElement().setScrollTop(panel.getElement().getScrollHeight());
"panel" is the panel that you add your protocol to. It doesn't have to be a ScrollPanel. An HTMLPanel will work.
You can wrap this method in a command and pass it to Schedule.scheduleDeferred if it needs to be called after the browser event loop returns:
Schedule.scheduleDeferred(new Scheduler.ScheduledCommand(
public void execute() {
panel.getElement().setScrollTop(panel.getElement().getScrollHeight());
}
));

CellEditor in EditorGrid loses content when you scroll the grid

I have an issue where a user enters some data in an EditorGrid cell. Then the user scrolls the grid without clicking anywhere first. Upon scrolling, the edited cell gets reset and the entered data is lost. I recorded this behavior using the GXT editablegrid sample:
recording: http://goo.gl/dqqhK
I am trying to prevent the entered data loss if the users scrolls. I have been experimenting with the CellEditor's onBlur(...) method, which is called when the users scrolls, but it seems that its FieldEvent argument has already lost the entered value. So the completeEdit() just stores nothing.
Is there any way that I can prevent that "data loss" when a user scrolls? Any help is greatly appreciated.
Thank you.
Thomas Amsler
Sakai Project (UC Davis)
This works for me, hope it helps:
grid.addListener(Events.OnMouseWheel, new Listener<BaseEvent>() {
#Override
public void handleEvent(BaseEvent be) {
grid.stopEditing();
}
});
Events.BodyScroll works, because when you click up/down arrow of scroll bar or click anywhere of scroll bar is not a MouseWheel event.
I think this should be a GXT bug, hope it will be fixed in the future.

Eclipse RCP get elements by ID

I don't know RCP very well yet, but I've been reading a lot of the docs. I don't know if my question makes sense; I apologize if not and beg that you try to work out what I mean and come up with some kind of answer.
I have a tree view element, which has a double click listener on it. In another part of the window there is a layout folder which contains views that are supposed to be inspectors for the items double-clicked on.
The only way I know to make another inspector appear is:
getActivePage().showView(Inspector.ID).
showView() doesn't give any opportunity to pass extra information to the view, so can it know which element to inspect?
Pointers in different directions appreciated. The Vogel tutorial doesn't seem to cover this, or I don't understand it.
You could check if the article "Link to Editor" can help you here.
That is, instead of trying to access the right view, define a Listener for the Editors:
private IPartListener2 partListener2 = new IPartListener2() {
public void partActivated(IWorkbenchPartReference ref) {
if (ref.getPart(true) instanceof IEditorPart)
editorActivated(getViewSite().getPage().getActiveEditor());
}
That way, you can get back the right Editor, and ask that Editor all you need for your View to update accordingly.
You can use the SelectionService. The Inspector view should register as a SelectionListener. And the other view with the tree should register a SelectionProvider. This view should listen for the double click in the tree and then update the selection