Vaadin, slow generation of results - java

I have to generate results of searching i Vaadin.
Probably the fastest way to do it is to put results into table, but I need some custom layout and the FormLayout for every row would be the best.
Unfortunately if I put rows formatted by FormLayout into table - the generation of the results takes about 15-20 seconds.
If i put just some labels/buttons without putting it in a layout the generation takes about a second - and that's fine.
I've read the vaadin manual about optimising UI and I still don't know what to do to shorten the time needed to generate the results.
How do you generate results in Vaadin if it can't be presented as a table?

Ok, the solution is... use CssLayout inside a table. Although CssLayout still consists of 3 div's it's much faster than FormLayout.
I think that using a FlowPanel from GWT would be even better but I didn't have enough time to check it.
And don't forget about setPageLength method of a Table - the lazy loading is the main reason to use a Table :).

Offering a few more layout options:
WeeLayout add-on: fast layout, not many expensive layout calculations in JavaScript, and a lighter DOM structure than in CssLayout
DashLayout add-on: even lighter DOM structure (but more JS calculations), and offers more flexible styling options for CSS (arbitrary margin/border/padding values).

Related

Disable Materialize Framework "Responsiveness"

I am attempting to use the materialize framework. I am very much liking the features it provides but I don't really care too much about making everything "responsive" right now. I would like to make things somewhat "static", meaning when I resize the browser, everything stays the same size (and user can scroll around in a smaller window to find what they want). I plan to later work on the full "responsiveness" to support things like mobile, window resizing, etc. Below shows whats currently happening. I downloaded the whole framework so I'm free to alter the .css that comes along with it, but I'm not really a .css expert so not really sure where to begin.
Full Screen
Resized Screen - obviously cannot stay like this forever
Any help is much appreciated.
First to answer your question directly: I assume you are using the Materialize grid? Meaning you have divs with class names like "col l6"? To have non responsive elements you should not use any materialize column class names. It will then just be regular old HTML and CSS that you define. Materialize only applies its CSS to elements that use its classnames.
Now for a recommendation: This will probably break some of the features of Materialize. Or at the very least, it will look gross and you will have to add padding/margins everywhere manually. Then if you want to go back and enable mobile responsiveness, you will have to manually remove all of that. You will also have to use old fashioned CSS rules to determine you element sizing. Every element will need a height and width rule applied to it. It is a lot harder to add mobile responsive classes later. It will save you a lot of time if you just do it now. It's quite easy in Materialize once you get the hang of it.
One of the main reasons that Materialize and Bootstrap and the like are used, is to make mobile responsive websites easy. It really is an essential skill to learn for web development these days.

JavaFx Tableview speed and sorting in Sql application

I am working on a small, toy application to expand my knowledge about Java JavaFx and Sql. I have a MySQL server in my local network, which I am able to communicate with and a simple Tableview can be populated, sorted ... etc. The data has only to be shown to the user, no editing. Everything nice and clean.
The Problems:
There are around 170 000 rows with 10 col., all chars, to display, which seems to be rather hard to do in reasonable time. The query is done during startup and it take around 1 1/2 min before I can see the table.
Also the memory footprint is enormous, the application without populated Tableview around 70 mb, with all the data it has 600-700 mb (the xml file which is used to populate the mysql is 70 mb in size ... ) !
Sorting is REALLY slow, I am using Stringproperty which should give a boost according to: JavaFx tableview sort is really slow how to improve sort speed as in java swing (If I understood that correctly) However the custom sort, I did not try so far.
My thoughts:
Similar to the application design for mobile, I think an adapter-pattern can fix these problems. Hence, I create an OberservableList with the correct size of elements, but only populate a limit of rows in the beginning. When I am scrolling done (scroll wheel) the List has to be updated with new elements in advance via sql-queries. This should give me a performance boost for the first Problem. Nice idea but what am I going to do if the user is going to scroll done via the scrollbar(click and drag down), then I would skip certain entries, but I need the information to give the user the feedback where to scroll to.
How could I fix this ?
For the sorting, I would use the sql sorting methods, so each sort will be performed on the sql server and a new OberservableList will be created. As before, only a certain amount of data would be loaded in the first query.
If this approach would also effect the memory footprint, I am not sure.
Your opinion:
Are my ideas reasonable and do-able in Java, JavaFx ?
I would love to hear your ideas about these problems.
Thank you.
I found out that JVx is capable of providing the lazy-loading function. This should do the trick

Persisting view state in Swing

I've got large Swing application with more than 50 views (forms, dialogs, menus, popups, etc..). What I need is some intelligent way of persisting view states and bringing them back to life. There are lots of tables, splitters, check boxes and other visual elements which users would want to have preserved. Of course I'd be able to do this manually.. but on such a scale it would be a monstrously tedious coding and bugs all around the place.
The question:
Is there any framework, library or a product which does this without too much hassle? The problem sounds to be pretty common place, so I'd rather find something solid instead of re-inventing the wheel.
First, separate your data (model) from your Swing components (view)
Once you have a complete data model, you can use an XML generator / XML parser to save and restore your data model, respectively. You can use a relational database to save and restore your data model. Whatever makes the most sense for the amount of data in your model.
I have an example of a Java Swing model and a view in this answer.
Edited to add: One of Dima's assertions is Take for example a JTable with 20 columns 5 of which user made visible while hiding others and also making columns of a certain width.
Fine. The TableModel, column visibility booleans, and column width integers or doubles had better be somewhere in your model.
Follow the link to my other answer and see that my GUI state data is part of the model.

"Quick find" for an SWT Table

I have a table that displays the output from a database, this can often be up to or over 10,000 rows. I'm looking to implement a 'quick find' function that will allow the user to easily scroll to a row with the value for which they search.
The idea is for this to be very similar to Chrome or Firefox's quick find. So:
User hits 'CTRL+F'
A box pops up:
The user can then quickly skim through the table pushing / or /\ to each matching value
My question is, does such a table already exist? I have looked at NatTable and XViewer but they both seem like rather large additions for a relatively minor change.
Another library I've looked at that is close to fitting the billl is Lucene TableSearcher unfortunately this is designed for filtering rather than highlighting. However it may be an avenue worth investigating.
It's not quite the same, but JFace does have support for filtering views. You type in a text box and view contents shrink to what matches the filter. It's basically another way to present search/find functionality to the user.
You can see this in action in Eclipse Preferences (the filter text field about the navigation tree in the dialog). See org.eclipse.ui.dialogs.FilteredTree class. I don't believe there is a FilteredTable or equivalent, but underlying facilities are pretty generic, so it shouldn't take much work to put one together. Take a look at FilteredTree source and go from there.
The solution I chose wasn't as simple as I'd hoped but has a satisfactory performance.
The tables involved are virtual tables that can be very large. So on top of this upon loading the dataset we start a thread to build an index in the form of a list. Because these tables can be very large (but aren't often) we set a 50mb limit to this list and stop indexing it when we hit it. For most cases this is perfectly acceptable but for the larger tables it means that whilst it may be slower, it is considerably more stable than other options.
The 'search' is a simple SWT textbox with ModifyListener that iterates over the list, performing a 'contains' on each entry. Upon a match the row and column are calculated from the index number (0=0,0, 1=0,1 ..).
It would have been nice to have a simple 'drop in' solution for this but all of the tables on offer had too many features.
Use FilteredItemsSelectionDialog dialog box

Swing: what to do when a JTree update takes too long and freezes other GUI elements?

I know that GUI code in Java Swing must be put inside
SwingUtilities.invokeAndWait or SwingUtilities.invokeLater.
This way threading works fine.
Sadly, in my situation, the GUI update it that thing which takes much longer than background thread(s). More specific: I update a JTree with about just 400 entries, nesting depth is maximum 4, so should be nothing scary, right? But it takes sometimes one second! I need to ensure that the user is able to type in a JTextPane without delays. Well, guess what, the slow JTree updates do cause delays for JTextPane during input. It refreshes only as soon as the tree gets updated.
I am using Netbeans and know empirically that a Java app can update lots of information without freezing the rest of the UI.
How can it be done?
NOTE 1: All those DefaultMutableTreeNodes are prepared outside the invokeAndWait.
NOTE 2: When I replace invokeAndWait with invokeLater the tree doesn't get updated.
NOTE 3: Fond out that recursive tree expansion takes far the most time.
NOTE 4: I'm using custom tree cell renderer, will try without and report.
NOTE 4a: My tree cell renderer uses a map to cache and reuse created JTextComponents, depending on tree node (as a key).
CLUE 1: Wow! Without setting custom cell renderer it's 10 times faster. I think, I'll need few good tutorials on writing custom tree cell renderers. Sadly, I need a custom cell renderer.
This tutorial involving lazy loading might help, I'll work this through.
[There are some details missing, such as: what type of processing is happening each time the user updates the JTextPane? Is the whole tree being rebuilt?]
Anyway, what has worked for me in the past (when I experienced significant slowdown due to JTree updates) is that I rolled out my own TreeModel.
Most programmers choose to use DefaultTreeModel. This is indeed an off-the-shelf solution that works well in most cases. However, it is quite slow when significant parts of the tree needs to be updated. Obviously, Writing your own TableModel is more work than using a canned solution, but it is much less painful than you think.
In particular, my custom tree model is fast because it does not build any tree, per-se. It just observes my domain model and computes the answers to the method invoked on it (getChild(), getParent(), ...) by extracting the relevant information from that model. Try it. It works like a charm.
I do not know why it only works with invokeAndWait() (this is strange), but a simple hack would be to invoke this method in a new background thread.
I would also advise you not to populate all the tree at once. This is often a huge amount of work that just cannot be easily sped up. Instead, update only those nodes that are visible and update more nodes as the user expands them.

Categories

Resources