This script creates a copy of an existing form view, modifies that copy and saves it as a new form.
Defaults for this script are set for the Pubchem demo data tree in the sample project included in IJC.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import com.chemaxon.ijc.form.api.*; import com.chemaxon.ijc.form.api.renderers.*; import com.chemaxon.ijc.commons.datarequest.api.FieldReference; import com.im.df.api.ddl.DFView; ety = dataTree.rootVertex.entity // load some form - e.g. template DFView view = getViewByName( "Sample form" ) form = DFViews.loadForm(view) // tweak the template // change label label = form.getFirstWidgetByName( "My Label 123" ) label.setText(label. getText () + " (Copy)" ) label.setSize(label.getWidth() + 50 , label.getHeight()) // add new textbox textBox = new TextBoxWidget() textBox.setPosition( 0 , 600 ) textBox.setSize( 400 , 50 ) textBox.setField(newFieldReference( "Formula" )) textBox.setRenderer( new TextRenderer()) form.addWidget(textBox) // save DFViews.create(dataTree, form, view.name + " (Copy)" ) // utility methods def newFieldReference(name) { field = ety.fields.items. find { it.name == name } new FieldReference(ety.id, field.id) } def getViewByName(name) { dataTree.views.items. find { it.name == name } } |
Versions: This script has been tested on IJC version 6.1. This script will not work in IJC versions prior 6.1.