Tablelayout and LinearLayout - visible and invisble - tablelayout

I want to have a table layout inside a linear layout so that there is text before and after the table layout. The issue is that I want to be able to switch between 2 tables (Table1 and Table2) but keep the text before and after the same. I thought that this would be manageable using visible and invisible features of tablelayout and define the whole thing in one layout but this doesnt seem to be the case. What I get is that when I make Table2 visible and Table1 invisble that Table2 is shifted down because I have defined it after Table 1 in the layout.
What I want is:-
SomeTextHere
Table1
SomeTextHere too
or
SomeTextHere
Table2
SomeTextHere too
What I get is:-
SomeTextHere
Table1
SomeTextHere too
SomeTextHere
Table2
SomeTextHere too
I have tried:-
LinearLayout
TableLayout1 make visible
TableLayout2 make invisible
LinearLayout
Any ideas?

If i got your question correctly i think what you can do is adding two more LinearLayout in your main LinearLayout.Then put the group (Text,Table,Text) in each LinearLayout and then you can work with each Linear Layout instead of working with text,table,text
So that your layout hierarchy looks like
< LinearLayout>
< LinearLayout>
< Text>
< TableLayout>
< Text>
< /LinearLayout>
< LinearLayout>
< Text>
< TableLayout>
< Text
< /LinearLayout>
< /LinearLayout>

Your problem is you're using View.INVISIBLE to hide the sections. You need to use View.GONE if you want a view to not take up space in a layout.
Also if only the table is changed then you don't need to duplicate just put the tables one after the other and set the visibility of the one that shouldn't be visible by default set to gone. Then you can just toggle them in code.

Related

How to create the Horizontal ScrollBar at the bottom of DataGrid as in GWT CellSampler example?

I like DataGrid since it has fixed header so wen user scrolldown they are still be able to see the column header.
However, if there are too many columns then the DataGrid will manage to fit all columns within the Fixed Width of the widget that contain it.
For example, if a 30 column DataGrid was put inside a center (with 100px) of a DockLayoutPanel then all 30 columns will be divided evenly within 100px, which is make it unreadable cos the with of each column is too small.
So, I would love to use DataGrid but the DataGrid should have a Horizontal ScrollBar at the bottom so if there are many column then the user can just scroll horizontally to the right to see the data.
If we do correctly, then it should be like the GWT CellSampler example http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCellSampler
Clearly, the CellSampler used DataGid, but I didn't see any Horizontal ScrollBar code in there.
So how to make DataGrid to display as in the CellSampler example?
You should set the minimum width for your DataGrid:
myDataGrid.setMinimumTableWidth(600, Unit.PX);
I have done following for My Table Datagrid.
FlowPanel tablePanel = new FlowPanel();
tablePanel.add( table );
tablePanel.getElement().setAttribute( "style",
"overflow-x: auto;width: " + ( Window.getClientWidth() - 37 ) + "px;clear: both" );
add( tablePanel );

How to remove border of Eclipse SWT Table

I am adding a SWT Table in Eclipse Form, but I want to remove the outer border of the Table.
How to do the needful.
Above is the Table I created, But I dont want the Boundary/Border around it.
Don't know if this is the case, but from the picture the outer border looks like the one painted when SWT.Border flag is used. Maybe you are adding your table to composite that has this flag used as style constant. Remove this constant and the outer border will be gone
This border is rendered even if you don't use SWT.BORDER.
But if there is no TableColumn, no border is rendered.
Just remove TableColumn, if you want to remove border.
Try to look for SWT.BORDER and replace it with something else, like SWT.NONE
It could be where you create the table or the container.

Eclipse layout for table and two buttons

I am trying to lay out a form for an Eclipse editor and running into a few problems.
The idea is to have a page which contains 2 sections - the left hand section contains a table and two buttons. The table should line up with the top of the section and expand right to the bottom. I want the buttons to sit to the right of the table in the section with each button under the other and for them to align with the top of the table.
Does anyone know what settings for GridLayouts I need to make this work? I've tried every combination I can think of with no luck.
The closest I can get ends up with the second button at the bottom of the page.
Here is an excerpt of my code so far:-
Section section = toolkit.createSection(sashForm, ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.NO_TITLE_FOCUS_BOX);
section.setText("All Items");
Composite client = toolkit.createComposite(section);
section.setClient(client);
client.setLayout(new GridLayout(2, false));
Table table = toolkit.createTable(client, SWT.NULL);
table.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
TableViewer viewer = new TableViewer(table);
Button addButton = toolkit.createButton(client, "Add", SWT.PUSH);
addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
Button removeButton = toolkit.createButton(client, "Remove", SWT.PUSH);
removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
Have a look at SWT Layout Tutorials it has a good section on GridLayout.
You will want to use the GridData.verticalSpan for the table to get it to cover two rows. That should put the two buttons on the right. But then the buttons will take the same space as the table which is probably not what you want, so you may need to give vertical size hint to the table.

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

ScrolledComposite splits the screen vertically and content is displayed in the right half

I am using the ScrolledComposite for a existing control(with many children) based on the method2 mentioned here :http://www.placelab.org/toolkit/doc/javadoc/org/placelab/util/swt/SwtScrolledComposite.html
The only change is instead of creating a new shell & display I am using the existing control's parent.
I am seeing the scroll bars as expected but the existing control/content is displayed form the centre & not from the start. The first half(vertically split) of the layout is empty & the actual control/content gets displayed in the right-half.
I checked bounds, Origin, size etc. they seem to be fine.
screenshot putup here :http://img818.imageshack.us/i/contentstartsfrommiddle.jpg
Any clues
Thanks in advance
Did you delete the Composite c1? maybe that is in the left side.
You could also provide what is exactly your change to the code.