R-Beans (RADi Beans)
How to create an R-Bean
Propagating properties of nested components
R-Beans and Internationalization
An R-Bean is some visual entity (either a single component, a composition of components or a containment hierarchy), supposed to appear in several layouts of a project.
Every R-Bean starts as an ordinary layout, then you convert this layout into an R-Bean (the layout is exported and compiled and its "R-Bean" flag is set). You can then insert instances of the R-Bean in other layouts of the current project, just as you do with imported Beans. (From the target layout's point of view, the R-Bean is just an instance of a Java class, this is why R-Beans must be compiled).
Advantages of R-Beans are that changes on an R-Bean are performed in one central place (the R-Bean layout) and are immediately reflected in all instances. To make R-Beans more useful, RADi allows to extend their public interface with new properties in two ways: Either propagate some property of a nested component to the outside world or specify a completely new property.
How to create an R-Bean Top of page
Any layout can be converted to an R-Bean (this implies that an R-Bean can contain both JavaBeans and other R-Beans).
Imagine a help button: A button with an icon, the label "Help" and a
setHelpID(String) method, supposed to appear in most dialogs of your application (see the example layout '34 RBean HelpButton').
To implement the help button as an R-Bean, follow these steps:
Propagating properties of nested components Top of page
With R-Beans composed of several components you may have the need to access some property of a nested component through the R-Bean class. Defining such a property wrapper is simple. I illustrate this on the example R-Bean "36 RBean InfoPanel" which consists of two labels, one displaying an icon and one responsible for displaying the info text.
Select 'Layout | Edit R-Bean' to display the 'Edit R-Bean' dialog.
The resulting code looks like this (comments omitted):
Again getter and setter methods are
public, independently of the export settings, again the property is a bound property.
Using R-Beans Top of page
You select R-Beans from a popup menu, similar to the one provided for selecting JavaBeans.
Double-clicking an R-Bean instance will display the R-Bean layout. There appears a button at the top-right corner of the editor area, clicking it will return you to the referencing layout.
To edit an R-Bean's public interface, select 'Edit R-Bean' either from the 'Layout' menu or from the context menu of the R-Bean layout.
Though R-Beans are in project scope, you can copy an R-Bean layout to a different project, but you must immediately export and compile a new R-Bean class (else the R-Bean attribute will be removed from the layout).
If you remove an R-Bean layout from a project, all R-Bean instances will automatically be removed from their respective layouts.
Event handling: R-Bean instances can be event sources or targets as well as property sources or targets. Event and property handlers defined in the R-Bean layout allow for event and property propagation between nested components.
R-Beans and Internationalization Top of page
If you are new to RADi, you may want to read the section about Internationalization first.
Changing the current locale of a localized project (using the 'I18n' menu) will affect the R-Bean layout, but not R-Bean instances. These are processed by the RADi runtime, which always loads properties files for the default locale (the one you did specify before saving properties files the first time).
R-Bean FAQs Top of page
When should I use R-Beans?
If some visual entity is supposed to appear in several layouts.
What is the super type of an exported R-Bean?
When is the R-Bean class reloaded?
Each time you switch from an R-Bean layout to another layout, the R-Bean's class file will be checked and will be reloaded if it has changed. (This means that, after editing and recompiling the code of an R-Bean class, you must select the R-Bean layout and then some other layout, else the class will not be reloaded).
When should I re-compile an R-Bean?
What is the difference between JavaBeans and R-Beans?
What about R-Bean performance?
Inside RADi, R-Beans do cause a performance fault, because classes of the runtime library must be loaded (this happens at startup while loading layouts. After this, reloading classes and instantiating R-Beans is a matter of a few milliseconds).
In a running application there is no performance fault, because classes of the runtime library already are loaded.