Buttons vs. Scripts

Buttons and scripts are functionally the same with a few noteworthy differences. Script function can change depending on where it is installed (database root vs. a data tree root). A button is a script attached to a form and has an absolute root. The resultset is defined as the resultset that is applied to the form, as this represents a snapshot of the data, and thus the vertex is already defined. In the case of a script, you must specify the vertex, and then the resultset. A script, however, will automatically inherit the dataTree definition based on where it is installed. Since a resultset could represent data relating to a different dataTree, the dataTree must be defined for a button.

A new button will contain the code for how to move to the next record in a selection. This is commented out, but provides some framework. Of particular importance are the definitions of the resultset and datatree. The differences in base variables are shown below.

Additional information can be also found in user documentation: WBButtonWidget .

 

Script

Button

Provided Variables

dataTree - Only for scripts in Data Tree. API docs: DFDataTree

schema - Only for scripts directly in a Schema. API Docs: DFSchema

Scripts in a Data Tree can access schema this way:

def schema = dataTree.schema

Only through closure parameters such as widget

Result Set

default resultSet for Data Tree:

def parent = dataTree.rootVertex.entity
def rs = parent.schema.dataProvider.getDefaultResultSet(dataTree, false, DFEnvironmentRO.DEV_NULL)
def rs = widget.form.resultSet

Data Tree

inherited

def dataTree = rs.dataTree

Automatically Imported Packages

Packages from DIF API :

Packages from Progress and Background Tasks Support :

 

Buttons react to various events, unlike scripts which run top to bottom. You can handle these events by creating closures which get executed as appropriate. New buttons come with example code for each of the closures:

  • init(widget) : Called everytime the form is opened.

    • widget: [ IJCWidget |http://www.chemaxon.com/instantjchem/ijc_latest/docs/developer/api/com-im-ijc-core/com/im/ijc/core/api/views/IJCWidget.html] representing the button

  • destroy(widget) : Called each time the form is closed.

    • widget: [ IJCWidget |http://www.chemaxon.com/instantjchem/ijc_latest/docs/developer/api/com-im-ijc-core/com/im/ijc/core/api/views/IJCWidget.html] representing the button

  • evaluate(widget) : Called when user clicks the button.

    • widget: [ IJCWidget |http://www.chemaxon.com/instantjchem/ijc_latest/docs/developer/api/com-im-ijc-core/com/im/ijc/core/api/views/IJCWidget.html] representing the button

  • on_change(widget, button) : Called when some vertex state is changed. You can then for example update the button appearance using the button parameter.

    • widget: [ IJCWidget |http://www.chemaxon.com/instantjchem/ijc_latest/docs/developer/api/com-im-ijc-core/com/im/ijc/core/api/views/IJCWidget.html] representing the button

    • button: JButton representing the button in Browse mode