User 2d015c38e4
10-06-2009 02:06:50
I have a NetBeans plugin to IJC where I select a molecule in a table, run a query on the selected molecule (which consists of passing the molecule to some custom algorithmic code that returns a list of result molecules), and then I display these results in a new table. I now want to be able to highlight or color some of the atoms in the result molecules that I have displayed in the new table. Looking over the forums and code examples it looks like I need to be able to access a MViewPane object for the new table so that I can do something like the following:
MViewPane mpan ...;
mpan.setAtomSetColor(0, Color.black);
mpan.setAtomSetColor(1, Color.red);
Unfortunately I can't figure out where to find the MViewPane instance and am not that familiar with Swing...can anyone help me with this? The following is an example of the code that I'm using to create the new table and populate it with Molecules. Thanks.
final DFEntity entity ... // DFEntity from currently selected node in original table
final Molecule mol ... // Selected molecule to use for query
DFSchema schema = entity.getSchema();
final DFNewType entityNewTypeForNewJChemBaseEntity = DIFUtilities.findFirstAppropriateNewType(
schema.getEntities().getNewTypes(),
false,
new Class[] { JChemBaseEntityCapability.class },
new Class[0]);
assert entityNewTypeForNewJChemBaseEntity != null;
if (!(opt instanceof DFNewTypeWellKnownOptions.NewJChemBaseEntity)) {
System.out.println("Something is wrong, the options should be of this type!");
}
DFNewTypeOptions opt = entityNewTypeForNewJChemBaseEntity.getOptions();
DFNewTypeWellKnownOptions.NewJChemBaseEntity options = (DFNewTypeWellKnownOptions.NewJChemBaseEntity) opt;
String queryName = String.format("Query");
options.setNewDFItemNameSafe(queryName);
// Table names can't have spaces in them and must be unique
options.setTableName(options.getNewDFItemName().replaceAll(" ", "")); // set your table name here
UIBackgroundRunnerRW runner = new UIBackgroundRunnerRW(schema.getLockable(), "Promoting jchem table to entity", false) {
DFEntity newEntity;
@Override
public void phase1InRequestProcessor() {
// It's expected that this new type creates only one entity.
Collection newEntityCol = entityNewTypeForNewJChemBaseEntity.create(getEnvironment());
newEntity = newEntityCol.iterator().next();
// Utility to create a datatree for entity the simple way. DFNewTypes can be used as well.
DFDataTree dataTree = DIFUtilities.createDataTreeForEntity(newEntity, getEnvironment());
DIFUtilities.createViewForDataTree(dataTree, null, true, getEnvironment());
ArrayList<Molecule> results = runQuery(mol);
}
@Override
public void phase2InAWT() {
updateEntityWithResults(newEntity, results);
}
}
runner.start();
public static void updateEntityWithResults(DFEntity entity, ArrayList<Molecule> results) {
DFEntityDataProvider edp = DIFUtilities.findEntityDataProvider(entity);
String structureFieldId = "none";
for (DFField f : entity.getFields().getItems()) {
DFFieldStructureCapability structCapability = (DFFieldStructureCapability) DIFUtilities.findCapability(f, DFFieldStructureCapability.class);
if (structCapability != null) {
structureFieldId = f.getId();
break;
}
}
// create a lock for the edp...
DFLock edpLock = DIFUtilities.getLockable(edp).obtainLock("updating field");
DFEnvironmentRW edpEnv = EnvUtils.createDefaultEnvironmentRW(edpLock, "Populating query results", false);
Map<String, Object> rowValues = new HashMap<String, Object>();
Iterator<Molecule> results_itr = results.iterator();
while (results_itr.hasNext()) {
Molecule mol = results_itr.next();
// Color MolAtoms here ....
MarvinStructure structure = new MarvinStructure(mol);
rowValues.put(structureFieldId, structure);
try {
edp.insert(rowValues, null, edpEnv);
} catch (Exception e) {
System.out.println(String.format("Failed to add %s to query results.", structure));
e.printStackTrace();
}
}
edpLock.release();
edpEnv.getFeedback().finish();
}