Extending the Rich UI widget set
You can use EGL to create a new widget type or can use JavaScript™.
Rich UI widgets
RUIWidget (specifically, egl.ui.rui.RUIWidget).
You often need to do only as follows:- Specify an HTML tag name in property tagName. Alternatively,
specify a declared Widget in property targetWidget, in which
case the following statements apply:
- The HTML tag that is the basis of the referenced widget's type is the basis of the Widget type that you are defining
- You can use the name of the referenced widget to access the functions and properties defined for that widget's type
If you specify both tagName and targetWidget, the latter applies.
- Specify some or all of the properties that are listed in a later section.
- Specify an on-construction function and set a CSS class name in that function.
- Build the functionality from other widgets.
Handler H3 type RUIWidget{tagName = "h3", onConstructionFunction = start,
@VEWidget{
category = "New Widgets",
template = "my.package.H3{ text=\"The Heading Text\" }",
smallIcon = "icons/h3small.gif",
largeIcon = "icons/h3large.gif" }}
text String { @EGLProperty { getMethod=getText, setMethod=setText },
@VEProperty{}};
function start()
class = "EglRuiH3";
end
function setText(textIn String in)
text = textIn;
this.innerText = textIn;
end
function getText() returns (String)
return (text);
end
endui Box { children = [
new H3 { text = "Summary" }
]}; External type widgets
You can create an external type widget by writing custom JavaScript™ or by accessing specialized JavaScript™ libraries.
- Create a JavaScript™ file
to contain the code for the widget. Invoke egl.defineWidget and specify
the following arguments:
- The name of the package in which the custom JavaScript™ resides. The package name
is required, is case sensitive, and identifies the WebContent subfolder
that contains the JavaScript™.
Include dots in place of a forward slash for every subfolder under the first. For example, if your JavaScript™ is in folder
WebContent/myPkg/test, the packageName value ismyPkg.test. - The name of the widget class (for example, Button); that class name is the name of the external type that you will create.
- The package name of the EGL external type for the parent widget. You might be extending an external type of your own; but in most cases, the parent type is Widget, which is provided for you and is the basis of other EGL external-type widgets. If the parent type is Widget, the package name is egl.ui.rui.
- The name of the EGL external type (for example, Widget) for the parent widget.
- The tag name (for example, button) of the DOM element for the new widget.
Here is the example:egl.defineWidget( 'egl.rui.widgets', 'Button', 'egl.rui.widgets', 'Widget', 'button', { } ); - The name of the package in which the custom JavaScript™ resides. The package name
is required, is case sensitive, and identifies the WebContent subfolder
that contains the JavaScript™.
- Within the curly brackets ( { } ), define the JavaScript™ functions to reflect the following
outline, separating one function from the next with a comma:
"functionName" : function(/*parameters*/) { //JavaScript Source }Here is an example:"getSelected" : function() { return this.check.checked; }, "setSelected" : function(value) { this.check.checked = value; }, "toString" : function() { return "[CheckBox, text=\""+this.egl$$DOMElement.innerHTML+"\"]"; } - Each widget can specify the following functions for the JavaScript™ runtime to invoke:
- The function constructor is invoked whenever a new widget instance is created, and that function can be used, for example, to initialize data
- The function egl$$initializeDOMElement is invoked whenever the HTML element is being created for the widget, and that function can be used, for example, to set initial properties on the element
- The function childrenChanged is invoked whenever the application developer updates the new widget's children property, if any.
Each widget also has a field called this.egl$$DOMElement, which represents the HTML element (or top-level HTML element) created for the widget.
- In an EGL source file, create an EGL external type that extends
from egl.ui.rui.Widget or from an existing widget. The External Type
needs a stereotype of JavaScriptObject,
as described in External type for JavaScript™.
When you create the external type, specify some or all of the properties that are listed in the next section.
EGL properties for extending the widget set
- When you create a new EGL or external-type widget, set some or
all of the following EGL properties to ensure that the widget is handled
in the same way as any other widget:
- @EGLProperty is a field-level property
for identifying the functions that get or set property values. Those
values are set when a developer declares or updates a widget that
is based on the widget type that you are creating.
The @EGLProperty property is only for Rich UI widgets. The equivalent property for external-type widgets is @JavaScriptProperty, as described in External type for JavaScript™ code.
- @MVCView is a part property that enables users to use the widget as a controller view. For background information on controllers and controller views, see Rich UI validating and formatting.
- @Override is a function property used to indicate that you are overriding a function typically provided for any Rich UI or external-type widget.
- @VEEvent
- @VEProperty
- @VEWidget is a part property used by the EGL editor to add a widget-specific entry to the palette when you refresh the palette.
- @EGLProperty is a field-level property
for identifying the functions that get or set property values. Those
values are set when a developer declares or updates a widget that
is based on the widget type that you are creating.