GWT: When to use Button and when to use ButtonCell - java

I watched a Google I/O video on GWT performance that recommended using Cell Widgets as much as possible because they are faster and lighter-weight than normal Widgets.
I am trying to determine if I should use either:
com.google.gwt.user.client.ui.Button (Button Widget); or
com.google.gwt.cell.client.ButtonCell (Cell Widget)
I have read somewhat conflicting literature on widgets and cells; some authors say to only use cells when you don't have any events that need to be responded to.
So I ask: is it true that cell widgets don't have handlers and can't respond to events? If so, what's the use of a ButtonCell that will surely be clicked! And if it's not true, then it kind of seems like cell widgets are a total replacement for the "old" widget framework - is that true, or are there still use cases for Button and its other "old" widget kindred?

Strictly speaking, ButtonCell is not a "cell widget", it's a "cell", which is used by cell widget like CellList or CellTable to render it's content.
Cell widgets used for displaying large amount of similar-structured data (lists/tables), and for rendering a particular "cell" in such tables - you should use these lightweight stateless widgets (ButtonCell, TextCell). The benefits come from less amount of resulting dom-elements and JS. Also, CellWidgets still can receive browser events, but you should specify it explicitly. More on this topic - see official Google's guide.
If you do not use cell widgets - you don't need to use cells, for example if you want to make a user-input form and put some labels and buttons - use Label and Button widgets, if you need to show a list of >100 rows - you might want to use TextCell and ButtonCell within CellList widget.

Related

JFace Tableviewer empty - display string

I'm developing an eclipse RCP/RAP application. I have several GUI-classes that use the JFace TableViewer (internal org.eclipse.swt.widgets.Table).
Some of my clients mentioned that it is a little confusing wether the "database-select failed" or there are just no elements.
So here's my question. Is there any way to display a "greyed out" text saying "No elements". There is something similar for the org.eclipse.swt.widgets.Text:
edtTest.setMessage("Please enter something");
Couldn't find anything like that.
Thank you in advance.
There isn't any simple support for this.
You could simulate this by adding a dummy row to the table and making your label provider implement IColorProvider so you can set the color of the row (or use one of the label providers based on StyledCellLabelProvider.
Alternatively use a separate label control and use StackLayout to make either the table of the label the visible control.

Vaadin - adding components as elements of another components

I've been using a ComboBox to store some values and make a selection from those values, but the problem is, ComboBox, as it is, only allows one selection at the time and I need multiple selections, ie checkboxes, but that cannot be done via Vaadin. I figured if I could present checkboxes as the elements of the ComboBox, that would solve the issue, except adding components to a component that is not a layout doesn't seem to be possible.
I've done this tutorial https://vaadin.com/docs/-/part/framework/components/components-customcomponent.html
Basically it combines two Vaadin components into one panel and displays them together, but that's not what I need, as I need certain components to be placed inside a parent component.
So what are my options if I'm to do this?
This is not an answer to the question that you are asking (component within a component), but rather the underlying problem that you present. In other words, I believe your question is an example of an XY problem.
I think you want to use a Grid with multi-select turned on. In this mode, check boxes are automatically added to each row and there is a checkbox in the header to allow toggling all on/off, ability to filter, ability to sort columns, etc. See the documentation for more details.

Combine javafx 2 ListView and GridPane features

My target is to display an abbreviation list with two entries per line: the abbreviation and the corresponding long version. For a nice layout I used a GridPane because of the vertical alignment over all entries - it's nice to read.
But I also want to scroll to the clicked abbreviation and set the focus on it like in a ListView version of it.
For example the # on page links in good old HTML. Is there another javafx layout element I miss to achieve this?
I don't believe there is a provided control that will work for the specific scenario you are describing. However, I think one of these options might work for you...
Use the TableView control and add two columns for the information you want to show (one for the abbreviation and another for the long version). TableViews also have the scrollTo and setFocus functionality you're looking for. Here is a good resource to get you started with the Tableview control. You can also style the Tableview with CSS to look less like a table and more like a list if thats what your intention is.
The second option is to set a custom cell factory on your ListView that builds custom cells using HBoxes, VBoxes, Labels, etc. to achieve your desired look. You would also want to use the cell factory to populate each ListView cell with an object that contains both the abbreviated text and long version text. A couple good resources, 1, 2
Although I think both option will work fine, I would suggest option 1 since in option 2 you are sort of building a table type structure anyway. I hope this is helpful!

JList text alignment

I have a JList with items that I want to show two values. Is there a way to have it show a string name and then have a right justified string to show a value. Looking something like this:
Title__________________120
Title2_________________135
Is it possible to pass in two string to an item and have the first string display on the left and the second one on the right?
Sure, implement a custom renderer. You might return a JPanel with BorderLayout as the rendering component, with the LHS text in the WEST, and the RHS text in the EAST.
Another way is to shove HTML into the default renderer (a JLabel), using an HTML table that stretches across 100% of the width. Though the custom renderer would be a better choice for a number of reasons (e.g. not presuming the type of the default renderer is a label).
BTW - perhaps you should consider using a JTable for this kind of functionality. No hacks or custom classes needed.
..does the jtable allow selecting items?
Of course! Here is an example taken directly from How to Use Tables in the tutorial. 'Jane' is selected.
A table is a little more effort to set up and get right, but it is well worth the effort.
Would a JTable perform just as a JList ..
No, the table ultimately provides more functionality. But the things it does which a list can also do, work (for the user) in much the same way.

JList with custom cell renderer vs Jtable

My current application uses a JList and everything is well (the only customization I did was to set the italic font on some of the rows).
Now I want to "upgrade" the user interface and instead of just labels in the List, I want a checkbox and a text field to be able to update the entry.
I started changing the code and adding a custom cell renderer and a custom cell model. My current problem is that the JPanel that the cell renderer is returning is not using the whole width of the container, so several list items are actually shown on the same line.
But now, I am wondering whether I should just change the whole thing to use JTable. I still need to add / remove items in the list though...
Any suggestion which one is better ? and if going with the JList, how should I go about fixing my current problem ?
In my experience using JTable is usually easier as it allows more complex data and functionality out-of-the-box. Usually when I try to do something the JList can't do, I just switch to JTable without a second thought. What you want sounds like something that should be pretty trivial to implement in a table. I suggest you try it out with some mock data to see if you can make it look and work the way you like (especially in case you want it to look like a list).
Try calling setLayoutOrientation(JList.VERTICAL) on your JList. That will restrict JList to a single column.

Categories