Why does GWT's RichTextArea implement HasInitializeHandlers? - gwt

...and what can I do with my RichTextArea after the onInitialize method has been called that I cannot do before?
N.B. This is a cross-post from the GWT Google group, which produced no response.

An InitializeEvent is fired just after the widget is attached to it's parent. Code that depends on the widget being attached to it's parents and thus the DOM shouldn't be executed before that point.
The RichTextArea widget uses an iframe and this seems to be the cause that some functionality is only available after creation, also depending on the specific browser. I have no full list of all specific cases where you need to initialize code after the widget is attached. But one example specific the RichTextArea widget is if you want to set the focus on the widget the widget must be attached.
You could get the same behavior by extending the RichTextArea widget and overriding the onLoad method, but that requires creating a new class.

Related

Communication between Flutter widgets

Flutter widget update pattern is a little bit confusing when coming from "old/classic" win32.
For instance :
I have a widget "button" => I click on it => I update a cell in a widget "datatable".
With classic API (VCL, Net Forms, ...) I get the address of button (by name, id, ...) and call directly
datatable_address.cell[x,y] = new_value;
I understand that I have to use setState() but do I need to create an "event" in Datatable (to run its setState()) and fire up this event from my button ?
(BloC seems pretty close to Qt signals)
The difference is composition vs aggregation. The widgets themselves are immutable so you can't change the value inside a widget.
What you can do is create a new object with latest values. Flutter framework will take care of the rest. For example,
when you do setState in parent widget of both button as well as datatable, you build method of said widget is called. Now, you will create a new datatable object with updated cell values. Internally, flutter will handle this.
You can only do setState in State class which is not immutable which is linked to Stateful widget which themselves are immutable.
This architecture comes with its own set of problems like if you need to update some UI based on some button press, you will have to have the logic inside the common widget of both the affected widget and button. That's where Stream/Bloc comes into picture.

How to refresh or call set state for a particular container widget in flutter

In my project i have different container widgets that are placed one above the another in a stack layout and i have performed set of canvas drawing on each container widget based on my scenario. My question is "how to refresh or call set state for a particular container widget without rendering all the widgets"?.
Thanks in advance,
Ashwin
You will need transform your "Container" in a custom statefull widget and then make his state management by your needs. Take a look at BLoC pattern here. With this pattern you will be able to update a specific widget in all widget tree without recreate all widgets.

Is it possible to add/inject an instance of a Widget into many panels?

I've tried doing this but only one panel gets the Widget shown. What is the approach to add an instance of a Widget into many panels? Or is it even possible?
If by inject, you mean use some DI tool (like Guice), then yes, you can inject the instance into many other instances as a singleton (just like any other singleton).
However, a given Widget can only be rendered in one place at a time. Elements can be cloned, but there is no general method of copying a widget to draw it in more than one place, mostly due to all of the event handlers that have to be added again.
How would then this method work?
Widget getParent()
Gets this widget's parent panel.
So you have to create multiple instances. Btw what's your use case?

why GWT Cell widgets are fater?

I wanted to know how cell widgets are faster compared normal (old) GWT widgets?
I have gone through the gwt article
Developer's Guide - Cell Widgets
It says
A cell widget renders its user interface as an HTML string, using innerHTML instead of traditional DOM manipulation
Can anyone please explain the above? and How?
In a normal GWT Grid you have to add each Widget separately, which means the browser can not optimize this in any way. Each widget you add also has its own event handler.
So you will create at least one DOM Element per Widget you add and append it into the grid.
CellWidgets first render all childs into a String which is then added to the DOM, by calling setInnerHTML (the browser can optimize this call and add all childs in a batch) and the event handling is only done once by the CellWidget.

embed GWT component TWICE and more in HTML page

I need to embed my GWT component which is a text area which do some functionalities in the key up and key down events twice and more on the same HTML page, in fact when i try to embed it in two different DIVs it appears only one time.
can any one help figure that problem?
A widget can only have one parent in the DOM. The widget will be contained by the last parent to which it is added. If you need to have a widget type appear more than once on the page you need to create more than one instance of the widget.