Create New Form

This script creates a new form view.

Defaults for this script are set for the Pubchem demo data tree in the sample project included in IJC.


import com.chemaxon.ijc.form.api.*
import com.chemaxon.ijc.form.api.renderers.*
import com.chemaxon.ijc.commons.datarequest.api.FieldReference

ety = dataTree.rootVertex.entity

// Main script body
form = new Form()
form.addWidget(createLabelWidget("Form demo"))
form.addWidget(createTableWidget())
form.addWidget(createTextBoxWidget())
form.addWidget(createMolWidget())
form.addWidget(createSheetWidget())
DFViews.create(dataTree, form, "Sample form")


// widgets creation methods
def createLabelWidget(label) {
    widget = new LabelWidget(label)
    widget.setName("My Label 123")
    widget.setSize(100, 50)
    widget.setFont(new Font("Arial", Font.Style.BOLD, 16))
    return widget
}

def createTableWidget() {
    table = new TableWidget()
    table.setPosition(0, 50)
    table.setSize(400, 500)
    table.setRowHeight(60)

    table.addColumn(newFieldReference("CdId"), new IntegerRenderer())
    structureColumn = table.addColumn(newFieldReference("Structure"), new StructureRenderer())
    structureColumn.setColumnWidth(150)
    table.addColumn(newFieldReference("Formula"), new TextRenderer())
    table.addColumn(newFieldReference("Donors"), new IntegerRenderer())

    return table
}

def createTextBoxWidget() {
    widget = new TextBoxWidget()
    widget.setPosition(0, 550)
    widget.setSize(400, 50)

    widget.setField(newFieldReference("IUPAC name"))
    widget.setRenderer(new TextRenderer())
    return widget
}

def createMolWidget() {
    widget = new MolWidget()
    widget.setPosition(400, 50)
    widget.setSize(300, 300)

    widget.setField(newFieldReference("Structure"))
    widget.setRenderer(new StructureRenderer())
    return widget
}

def createSheetWidget() {
    sheet = new SheetWidget()
    sheet.setPosition(400, 350)
    sheet.setSize(300, 250)

    sheet.addRow(newFieldReference("CdId"), new IntegerRenderer())
    sheet.addRow(newFieldReference("Structure"), new StructureRenderer())
    sheet.addRow(newFieldReference("Formula"), new TextRenderer())
    sheet.addRow(newFieldReference("Donors"), new IntegerRenderer())

    return sheet
}

def newFieldReference(name) {
  field = ety.fields.items.find { it.name == name }
  new FieldReference(ety.id, field.id)
}


Versions: This script has been tested on IJC version 6.1. This script will not work in IJC versions prior 6.1.



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