import
com.im.df.api.dml.*
import
com.im.df.api.*
import
com.im.df.api.support.SelectionDescription
import
com.im.ijc.core.api.util.IJCCoreUtils
import
com.im.ijc.sketchreg.*
import
chemaxon.struc.Molecule
import
chemaxon.formats.MolExporter
import
chemaxon.formats.MolImporter
import
com.im.df.api.chem.MarvinStructure
init = { widget ->
}
destroy = { widget ->
}
evaluate = { widget ->
def
ety = dataTree.rootVertex.entity
def
edp = ety.schema.dataProvider.getEntityDataProvider(ety)
def
molFld = ety.fields.items.
find
{ it.name ==
'Structure'
}
def
rs = ety.schema.dataProvider.getDefaultResultSet(dataTree, false, DFEnvironmentRO.DEV_NULL)
def
rootVS = rs.getVertexState(dataTree.rootVertex)
List ids = rootVS.getSelectedRowsIds()
if
(ids.
size
==
1
) {
Map rows = rootVS.getData(ids, DFEnvironmentRO.DEV_NULL)
Map row = rows[ids[
0
]]
MarvinStructure mol = row[molFld.id]
Molecule cxnMol = mol.getNative()
molSmiles = cxnMol.toFormat(
"smiles:u"
)
SketchRegistry registry = SketchRegistry.getDefault()
Sketch sketcher = registry.getDefaultFactory().createSketcher()
sketcher.setDialogTitle(
'My Molecule sketcher'
)
sketcher.setMolecule(MolImporter.importMol(molSmiles))
sketcher.setSketchFeedback(
new
SketchFeedback() {
public
boolean
buttonPressed(Sketch sketch, String buttonName) {
println
'Button pressed: '
+ buttonName
}
public
void
moleculeChanged(Sketch sketch) {
def
dataToUpdate = [(molFld.id):MolExporter.exportToFormat(sketch.getMolecule(),
'smiles'
)]
def
lock = edp.lockable.withLock(
'Updating'
) { envRW ->
def
ud = DFUpdateDescription.create(ety, ids[
0
], dataToUpdate)
def
submitList = Collections.singletonList(ud)
edp.update(submitList, DFUndoConfig.OFF, envRW)
}
println
"Molecule edited"
}
})
sketcher.openSketcher()
}
else
{
println
"Bad Selection"
}
}
on_change = { widget, button ->
}