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.

ScriptButton
Provided Variables
dataTree
Only for scripts in a 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 RS for dataTree)
def parent = dataTree.rootVertex.entity
def rs = parent.schema.dataProvider.getDefaultResultSet(dataTree, false, DFEnvironmentRO.DEV_NULL)
def rs = widget.form.resultSet
DataTree (inherited) def dataTree = rs.dataTree
Automatically imported packages

Packages from DIF API:

  • com.im.df.api
  • com.im.df.api.capabilities
  • com.im.df.api.chem
  • com.im.df.api.ddl
  • com.im.df.api.dml
  • com.im.df.api.dml.calculated
  • com.im.df.api.support
  • com.im.df.api.util

Packages from Commons - NetBeans related

  • com.im.commons.progress
All mentioned

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:



Copyright © 1999-2012 ChemAxon Ltd.    All rights reserved.