I got a question about the NatTable SWT datagrid widget which I want to use to display a huge log file.
As the log file can be several GB in size, I cannot load it in memory entirely. The application should use as little heap space as possible. Thus, my IDataProvider implements its getDataValue method to read a log file line on the fly, with the help of a little caching mechanism and a cache for raw line positions within the file. When opening a file, almost nothing is known about its contents - not even the amount of rows the table will eventually have to display.
This leads to several problems which currently freak me out:
1) I have to estimate the total row count (using average line length) until the file has been scanned entirely and a maximum line count is really known for sure. As soon this is the case my getRowCount method returns the actual, correct number of rows. This seems to freak out the NatTable widget, it loses its current position entirely and jumps to row # 1!
2) When doing something intuitive as double-clicking on the border of a column (to auto-size the column, just like in Excel), my application freezes completely as suddenly ALL rows cells contents is queried using my provider and the whole concept is abused! I did not want anything to trigger a full file read!
Does anybody have some hints for me? The documentation is so little and so bad...
Any hint is greatly appreciated! How can I prevent my application from freezing??
Thanks!
1) Sounds like the selection isn't preserved when you change the row count - a row count change implies a backing data change hence it's probably playing safe and setting the selection to the first row. You could query the selected row before changing the row count and then reset the selection after you change the row count.
2) In order to figure out what the max-width of the column is, the table has to query each value for that cell in every row... Either you have to implement a paging mechanism such that you return something resulting in zero width when the row isn't visible, or you'll probably want to raise a bug against NatTable to request a feature for an auto-resize mode based on only the visible columns!
Related
I want to ask a question which is related to apache poi and generated file printing. What I am doing is I am opening a .docx file, inserting some data and saving and printing it.
I am having a file with only 1 table which is something like:
document table
Now, if there are 'n' items, I am generating n-1 rows which copies the format of row 3.
First item is inserted in row 3, if there's another item I am adding a row in the table and saving it likewise I am creating the rows.
Now I want to make this table length = page length. For this I am counting exactly how many rows this page can incorporate and based on that I am inserting empty lines without inside top and bottom border.
The file does not have any header/ footer or any other details as of now.
While I am creating the file I am shown the file which is coming in print preview of covering the whole page of size A4.
But this document is printed only on 80% of paper. I am having 0.3 cm margins but in print the whole page is not printed.
This does not seem to be the printer issue because if other software like Google Chrome are used then it prints the complete page.
So I want to ask that how can I solve this? I tried to search about this but till now I couldn't solve it. I think of this as an issue that whenever I am using XWPFDocument, its margins and all are changed set to default size. I don't know whether this is the issue or something other is, do I need to write some commands to preserve the margins and all or there's something that I need to do.
How can I solve this thing?
Thank you.
I have a strange problem with Jasper Reports`iReport:
I have to use Version 3.7.6 and in this version I have to create a dynamic table.
The user is able to define how many columns the table will have and I am calculating this table in the Java - Backend before report initialization and present it to the user. I am not using the table component for this but instead a List of Textfields:
The Java Representation looks like this (very simple):
List<List<String>>
What I am doing is to take a list component that is using subreports to print the contents of the many strings into the report. The List component is printing columns of text fields next to each other (Print Order Horizontal). The subreport consists of nothing but a textfield. This textfield is printed over and over for every column and in the end I have a nice table.
This works very well.
What doesn´t work is when I try to make the text field in the subreport wider.
When it has the standard size of 53px the table looks very well.
When I increase the size I notice that the textfield itself gets wider but the list component still thinks the next column should be 53px. So the text fields overlap each other because the list component refuses to increase its size.
Is there any way to tell the list component to increase its column size when printing horizontal ?
Ok, here is the answer:
The size of the columns for the list component is derived from the columnWidth property of the report. When I change this I can create wider textfields ...
Is anyone out there familiar with a way to lock a row in a spreadsheet created with Apache POI 3.7? By locking I mean that I want the title row for the columns to remain visible when the user is scrolling through the rows. My created spreadsheet will have 500 rows and it would be beneficial if the column’s names were always visible.
In case you need to Freeze any particular row anywhere in the sheet you can use (Within org.apache.poi.ss.usermodel.Sheet) (Available in POI 3.7 as well)
Sheet.createFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow)
In your case if you want to freeze just your first x rows then the int leftmostColumn, int topRow section will get removed and you can use just
Sheet.createFreezePane(int colSplit, int rowSplit)
for example
sheet1.createFreezePane(0, 5); // this will freeze first five rows
To do this, you can create a freeze pane as follows:
workbook.getSheetAt(workbook.getActiveSheetIndex()).createFreezePane(0, 1);
This will freeze the first row in place. There's another method with more options, so check out the API.
The only thing to note would be if you're using XSSF workbooks - there is a mention of a bugfix in version 3.8-beta3 that fixed the behavior of freeze panes using XSSF spreadsheets:
50884 - XSSF and HSSF freeze panes now behave the same(poi-developers)
I don't know the details of this, but it would be worth investigating if you're in that boat.
You can not freeze a middle row without getting the rows above it also freezed.
Say you have 100 rows and your header row is at line 50. You might expect that only row 50 gets locked so that when scrolling from line 1-49, everything is scrolled up and when it reaches line 50, the 50th row scrolls to the top and stays there when lines 51-100 is scrolled.
But, there is a workaround. What you can do is, group the rows and then freeze them.
First, group the rows from 1-49 and then freeze panes from 1-50. Now the user can minimize the group and then work with the table with the table header locked and at the top.
sheet.groupRow(0, 49);
sheet.createFreezePane(0, 50);
There is a small catch though. MS Excel won't let you expand/collapse a group if the sheet is protected. For this you need to write a Macro.
In my project, I have a TableViewer which displays about 1k rows of data from database. The ContentProvider is an ArrayContentProvider.
When I change input the List (setInput() on TableViewer object) to another one with the same amount of data, everything is Ok. But when I want to update it with List<T> with different size than the previous one, the application freezes for about 10x the time of changing with same amount of data.
The first list has a size of 1k, and the second list a size of about 960. Execution freezes directly on setInput() method.
Does anybody know why this happens?
I think the reason is that when you set a List with a different size the whole native TableItems are recreated. So to speed up your table you should use a SWT.Virtual style table. With virtual table only the tableitems which are displayed are created. The others are created when you scroll.
See http://git.eclipse.org/c/platform/eclipse.platform.ui.git/tree/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/viewers/Snippet029VirtualTableViewer.java for an example.
I got stuck with a performance problem while writing my program and I need your help! :)
I'm using a JTable to view test results taken from a vector I made and it has 4 columns in it. When I click on a row the details from a saved txt file of that test are shown in a child window. Also, when I click on the columns header the event sends the vector to a function that sorts it according to the pressed column. Every time a new value needs to be entered the sorting function is called again.
My program works fine with a small number of rows. But, when I enter say, 150 rows, every time I enter a new row the Table flicks (the sort probably takes a lot of time), but I have to keep the vector synchronized with the jable because of the "push to view the result" option.
I would really appreciate some help with this.
thanks
You shouldn't have to do any sorting yourself. JTable supports sorting natively, and has the convertRowIndexToModel and convertRowIndexToView methods to go from the view index to the model index and vice-versa.
See http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#sorting.
Use JTable's internal sorter (DefaultRowSorter). Do not re-create the vector which holds the data - use Vector's add() method to add new records. In many years of Java GUI development I haven't seen a single case where I had to keep records in the TableModel sorted. Make sure getColumnClass() returns a proper type, so the default sorter knows how to sort the column, and that is all.