Java JFace TableViewer fix/freeze row - java

I've build an application in Java with the help of JFace/SWT. I am using mainly the TableViewer of JFace and sometime the SWT table behind with myTableViewer.getTable().
My table has a header (filled with the column names) and the first row is rendered with CCombos in CellEditors (drop down menus for filters).
Now I want to fix this first row ("filter-row") in the table, so it is always shown, independently if I am scrolling down or not..
Do you know any opportunity to do this (instead of splitting one table in two tables, as I found it in the internet)?

The SWT Table does not support fixed rows or columns.
If the combos were inteded to hold a limited number of choices you may use context menus on the column headers instead.
There are also alternative Table-like implementations in varying degrees of maturity that you may consider:
Nebula Grid
XViewer
NatTable
If non of the above fits your requirements you will have to either use a distinct table that holds the combo widgets or implement a custom 'header' control.

Related

Jface tableviewer - Columns are not spaced out even with tablecolumnlayout

I am using a jface tableviewer with a tablecolumnlayout (for it's parent composite) in my eclipse RCP application.
I see that, in my view, the columns are equally spaced out to cover the entire width of the table.. So far so good.
We have a functionality where we need to save & load the table layout . Basically user can hide/ re-order any number of columns and he wishes to save that particular layout..
I am using the eclipse preferences API to save/retrieve the table layout.
The view opens with a default layout (with all columns & with the default ordering ) when the view is opened for the 1st time. Hence, I would save a DEFAULT layout(with the default ordering & column widths) whenever the view loads so that user can come back to the original layout at any time.
But, the problem here is when I try to load the default layout, I see that the columns are NOT equally spaced out and there is an empty column at the end.
What can i possibly do to achieve the default behaviour where columns get equally spaced out to cover the width of the table?
Note: I tried invoking the layout() of table's parent composite or calling the redraw of both table as well as composite but it did not work out.
I solved the above mentioned issue.
SWT increases the given width of the columns during view rendering so that the entire table width is occupied.
I was able to get the increased width of each column only when the view was about to be rendered (during part Activation ).
If I asked for the column width just after using the tablecolumnlayout, I was still getting the predefined width.
As a solution to this, I moved my code to save the default layout during part activation so that the actual increased width is obtained.

Java TableItem, TableEditor, texts and buttons - all dynamically created

I want to create a table (that will finally exist in a new eclipse view). This table has a few text columns, and a column that has a different behavior based on the other columns. It can either be a field to enter text, or to popup a dialog for users to select data from (and it has to be a popup or a dynamically created combo). Anyway, I know which of the two I need for each row in the column.
My table is built using TableViewer and a few TableViewerColumn's in it. I later fill them with String data in TableItem's up to 4 columns. The fifth is the one I have this special behavior.
I tried experimenting with TableEditor, but failed:
When I used one for each TableItem it somehow got misaligned with the table rows and columns
When I use one for the entire table, I fail to set a Text entry on specific rows
What I need help with is figuring out exactly how to achieve this:
A Table that has 4 String columns, where the data is constant (cannot be changed by the user)
A fifth column where the cell contents is either a Text for the user to enter, or a (preferably transparent) Button that has a popup as action, or a Combo that I dynamically fill with data upon table creation
Any idea would be highly appreciated.
OK, got this figured out. The example here helped a lot:
http://www.java2s.com/Tutorial/Java/0280__SWT/TableCellEditorComboTextandButton.htm
Oren

How to make table with multiple lines per row?

I'm trying to find a way to make a Java table (Swing component) that can wrap the list of columns into multiple lines per row.
/[ Column Hdr A ][ Column Hdr B ]
Hdr |[ Column Hdr C ][columnHdr D ][ColumnHdr E ]
\[ column Hdr F ][COlhdr G][colhdr H][CH I]
/[ Cell 1 A ][ Cell 1 B ]
Row 1|[ Cell 1 C ][cell 1 D ][Cell 1 E ]
\[ Cell 1 F ][Cell 1 G][Cell 1 H][C 1I]
...
Where each column size is independent of any other. IE: I'm not doing spanning or column header grouping. It should retain the column resizing, hiding and sorting features. Drag and drop re-ordering would be nice but isn't necessary.
So I've searched everywhere for something like this. All I've found are various schemes for spanning cells or using fixed width sub-columns. There was one person who claimed to have done it by overriding getRect, but there was no code to look at, so I'm not sure how that would work wrt to resizing or hiding columns, and how would you specify which columns went where?
I've considered just extending TableColumn to include a "sub-row" property but that means also having custom TableColumnModel, JTableHeader and Jtable, AND Jpanel. And I suspect that the renderer and all the LookandFeel UIs would also have to be modified.
An ugly hack that occurred to me is to create one table per sub-row of columns, and then use some form of mutant jpanel to expose the rendered rows interleaved down the y axis. I'm not sure that would work with scroll bars though.
So, does anyone have a neat, concise way to implement this? Any suggestions about how to proceed?
I would hope that you would re-organize the output to be more human readable. While this does fit the data onto the page, a human reading it would have a great deal of problems trying to understand what table cell belonged to what header and which row was which.
Can you create rows with only the 'important' data visible first, then the user could click (or some gesture) to open the more detailed results? Or include multiple cell values together in a multi-line cell to reduce the data to a single row per record?
This gives you two great benefits. First the data will be understandable at a glance, and second, you can use the existing table implementations and save yourself the significant development work.
Finally, have you tried using an HTML widget to display the data? You could create the table as divs in HTML and have the widget wrap the rows. Then you could style the cells for each column to be a fixed width.
I can't offer you any code, but you could look into customizing the table model (class MyTableModel extends AbstractTableModel {...}).
The approach could be to overload the SetValueAt(Object value, int row, int col) method so that writing row 1, col 3 for example would actually write row 2 , col 1 and so on to display multiple lines for 1 line of you data table
Do you indeed need the behaviour which prevents some columns from scrolling?
It is a quite standard usability solution. I would recommend you to come up with a dialog allowing to hide and freeze columns. In this case users could organize the viewport the way they feel best at the moment. Here is an example of scroll freezing.
The second option may well be HTML. You can generate whatever you want this way. Though this solution may have a limitation if you need to edit your data.
Ergonomics uggestions:
Is it acceptable to present headers or data vertically? Sometimes it is better readable.
Basically JTable supports adding swing components including nested tables or cells. please refer to the ff links
com.lang.java.gui discussion
a similar thread

GWT Celltable fixed columns

Is there a way to make, let say first 3 out of 7, columns fixed in Cell table. I want to be able to see always first three columns and have horizontal scroll on others.
You will have to create a custom widget that consists of a ScrollPanel, which includes two CellTable widgets set side by side. The right table should be wrapped in a FlowPanel with overflow-x property set to AUTO (overflow-y should remain at HIDDEN).
You can use the same DataProvider for both tables to synchronize all changes. Be careful with the SelectionModel though, if you need it. I would limit selection to the first column of checkboxes and disable selection by clicking on a row.
Make sure that your widget fits into its space, or you may end up with two horizontal scrollbars - one for the ScrollPanel and one for the right table. Finally, remember to set sizes on both tables so that they have the same height.

Eclipse plugin - is TableViewer suitable when multiple tables required

I'm writing an Eclipse plugin for a screen definition editor. The preview page will have multiple tables of different rows/columns definitions, the contents of each cell is effectively a control definition (i.e. Label, TextBox, etc). Some basic requirements of the preview are:
User selection on any cell publishes the control properties to another view.
The cell styling is applied depending upon the control type.
Currently using JFace TableViewers but have the following issues:
1. Only one TableViewer can be registered as a selection provider via the getSite().setSelectionProvider(). How to listen for selection changes on all my tables?
2. TableViewer does not appear to allow for cell styling.
3. Cell selection programatically handling with a TableCursor, but the cell in a previous table is still highlighted when I select another cell in another table.
Are there more suitable layouts to use than TableViewer for my purposes?
Regarding point #2, cell styling, TableViewers do allow for customization of the display of cell data. Take a look here for some ideas on how to get started with that.
You can use this approach for supporting selection in multiple tables with some modification (add listener to each of your table viewers so if one of them is selected it automatically becomes the delegate).

Categories

Resources