Create New Panel

    This script creates a new panel in a 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()
    panel = createPanelWidget("My first panel")
    panel.addWidget(createLabelWidget("Panel demo"))
    panel.addWidget(createTableWidget())
    panel.addWidget(createTextBoxWidget())
    panel.addWidget(createMolWidget())
    panel.addWidget(createSheetWidget())
    form.addWidget(panel)
    DFViews.create(dataTree, form, "Panel form")
     
     
    // widgets creation methods
    def createPanelWidget(title) {
        panel = new PanelWidget(title)
        panel.setSize(710, 630)
        panel.setBackgroundColor("/display/docs/create-new-panel.md#0080AF")
        return panel
    }
     
    def createLabelWidget(label) {
        widget = new LabelWidget(label)
        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)
    }