Button Widget

Basics

The Button widget is the Widget that just works like button. It has this icon in the form builder design mode toolbar: images/download/attachments/48989075/button.png

This widget perform an action which is defined in the Groovy language.

Sample scripts

When a button is created, it implicitly contains the script for moving single row selection to the next row. The script is disabled by default and to use it some lines must be uncommented. There are comments which explains what the code does.

The button widget has four calls itself, these are used in script-code to invoke response to an action. The most important is evaluate closure. It's invoked when you click on the button and the script for button is not valid without this call. You may want to use others as well:

  • Init : Invoked when the form is opening.

  • Destroy : Invoked when closing form.

  • Evaluate : Called when the button is pushed.

  • On_change : Called when the root vertex changed.
    Init and Destroy are places where initial and post actions take place. This could be establishment and close of a connection with server for instance.

On_change action is called whenever there is a change in root vertex entity. That means change of selection, editing rows, etc. It's only register change on the root node. If you have a child entity bound to table and change the selection or whatever, it does not invoke on_change.
This is only closures which makes widget button directly accessible from scripts. See back-next buttons script for example.

The following script can be used for searching IUPAC names on the Internet by using Google which is opened in the default browser. Remember that the table must contains this column. If it is not present, you can simply create it by adding new chemical terms field.

/*
Opens default web browser and search for a field value on Google.
This code is designed for IJC 6.0
*/
 
import org.openide.awt.HtmlBrowser.URLDisplayer
 
// evaluate is called when the button is clicked to perform action
//
// widget is IJCWidget instance
evaluate = { widget ->
// here is an example of interesting objects accessible through passed parameters
def dataTree = widget.form.resultSet.dataTree
def parent = dataTree.rootVertex.entity
def rs = parent.schema.dataProvider.getDefaultResultSet(dataTree, false, DFEnvironmentRO.DEV_NULL)
print "hello\n"
 
// do the work here
field = null
for(f in parent.fields.items) {
if (f.name.equals("IUPAC name")) {
field = f
}
}
// This is a new method in API in 6.0
iupac = DFDataTrees.getDataForFirstSelectedRow(dataTree, [field]).values()[0]
print iupac + "\n"
url = "http://www.google.com/search?q=" + URLEncoder.encode(iupac)
URLDisplayer.getDefault().showURL(new URL(url))
}

More information can be found on scripting page .
Bunch of script examples is available in developers guide where separate page is dedicated to button scripting .

HTML

HTML is also supported. The user should first add a button widget as normal. Then edit the settings and when editing the 'Text' property you can specify HTML into the text for the widget. Only basic HTML features are supported. Some example HTML might be:

<html><center>Two lines<br><b>button</b></center></html>

The button widget with above HTML embedded, border is set to Line border: images/download/attachments/48989075/widget-button.png

Settings

To edit the settings in Design or Browse mode select the Widget by single clicking on it and then click on the Widget Settings icon ( images/download/attachments/48989075/IJCWidgetProperties.png ) in the Form toolbar. The settings editor will open. Alternatively in Design mode double-click on the widget or r-click and select Customize Widget Settings . Border, font, script and text fields can be edited.