use of cbit.vcell.graph.gui.BioCartoonTool.UserResolvedRxElements in project vcell by virtualcell.
the class DBReactionWizardPanel method applySelectedReactionElements.
/**
* Comment
*/
private void applySelectedReactionElements() {
AsynchClientTask getRXSourceModelTask = new AsynchClientTask("Get RX source model", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
// Get the complete original model the user selected reaction is from
Model fromModel = getDocumentManager().getBioModel(resolvedReaction.getVCellBioModelID()).getModel();
// find the user selected ReactionStep in the original model
ReactionStep fromRXStep = null;
ReactionStep[] rxArr = fromModel.getReactionSteps();
for (int i = 0; i < rxArr.length; i++) {
if (rxArr[i].getKey().equals(resolvedReaction.getVCellRXID())) {
fromRXStep = rxArr[i];
break;
}
}
// Create user assignment preferences
BioCartoonTool.UserResolvedRxElements userResolvedRxElements = new BioCartoonTool.UserResolvedRxElements();
userResolvedRxElements.fromSpeciesContextArr = new SpeciesContext[resolvedReaction.elementCount()];
userResolvedRxElements.toSpeciesArr = new Species[resolvedReaction.elementCount()];
userResolvedRxElements.toStructureArr = new Structure[resolvedReaction.elementCount()];
StringBuffer warningsSB = new StringBuffer();
for (int i = 0; i < resolvedReaction.elementCount(); i++) {
System.out.println(resolvedReaction.getOrigSpeciesContextName(i));
userResolvedRxElements.fromSpeciesContextArr[i] = fromModel.getSpeciesContext(resolvedReaction.getOrigSpeciesContextName(i));
userResolvedRxElements.toSpeciesArr[i] = (speciesAssignmentJCB[i].getSelectedItem() instanceof Species ? (Species) speciesAssignmentJCB[i].getSelectedItem() : null);
userResolvedRxElements.toStructureArr[i] = (Structure) structureAssignmentJCB[i].getSelectedItem();
if (userResolvedRxElements.toSpeciesArr[i] != null) {
SpeciesContext fromSpeciesContext = userResolvedRxElements.fromSpeciesContextArr[i];
Species toSpecies = userResolvedRxElements.toSpeciesArr[i];
if (fromSpeciesContext.getSpecies().getDBSpecies() != null && !Compare.isEqualOrNull(toSpecies.getDBSpecies(), fromSpeciesContext.getSpecies().getDBSpecies())) {
warningsSB.append((warningsSB.length() > 0 ? "\n" : "") + "'" + fromSpeciesContext.getSpecies().getCommonName() + "' formal(" + (fromSpeciesContext.getSpecies().getDBSpecies() != null ? fromSpeciesContext.getSpecies().getDBSpecies().getPreferredName() : "null") + ")" + "\nwill be re-assigned to\n" + "'" + toSpecies.getCommonName() + "' formal(" + (toSpecies.getDBSpecies() != null ? toSpecies.getDBSpecies().getPreferredName() : "null") + ")");
}
}
}
if (warningsSB.length() > 0) {
final String proceed = "Add reaction anyway";
final String cancel = "Cancel";
String result = DialogUtils.showWarningDialog(DBReactionWizardPanel.this, "A user choice selected under 'Assign to Model species' will force re-assignment of " + "the formal reference for one of the species in the reaction.\n" + warningsSB, new String[] { proceed, cancel }, cancel);
if (result.equals(cancel)) {
throw UserCancelException.CANCEL_GENERIC;
}
}
hashTable.put("fromRXStep", fromRXStep);
hashTable.put("userResolvedRxElements", userResolvedRxElements);
}
};
AsynchClientTask pasteReactionTask = new AsynchClientTask("Paste reaction", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
// TODO Auto-generated method stub
Model pasteToModel = DBReactionWizardPanel.this.getModel();
Structure pasteToStructure = DBReactionWizardPanel.this.getStructure();
BioCartoonTool.pasteReactionSteps(DBReactionWizardPanel.this, new ReactionStep[] { (ReactionStep) hashTable.get("fromRXStep") }, pasteToModel, pasteToStructure, false, (UserResolvedRxElements) hashTable.get("userResolvedRxElements"), rxPasteInterface);
closeParent();
}
};
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { getRXSourceModelTask, pasteReactionTask }, false, false, null, true);
}
Aggregations