Search in sources :

Example 1 with UserResolvedRxElements

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);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) UserResolvedRxElements(cbit.vcell.graph.gui.BioCartoonTool.UserResolvedRxElements) Hashtable(java.util.Hashtable) BioCartoonTool(cbit.vcell.graph.gui.BioCartoonTool) SpeciesContext(cbit.vcell.model.SpeciesContext) UserResolvedRxElements(cbit.vcell.graph.gui.BioCartoonTool.UserResolvedRxElements) ReactionStep(cbit.vcell.model.ReactionStep) Model(cbit.vcell.model.Model) Structure(cbit.vcell.model.Structure) DBFormalSpecies(cbit.vcell.model.DBFormalSpecies) Species(cbit.vcell.model.Species) DBNonFormalUnboundSpecies(cbit.vcell.dictionary.DBNonFormalUnboundSpecies)

Aggregations

AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1 DBNonFormalUnboundSpecies (cbit.vcell.dictionary.DBNonFormalUnboundSpecies)1 BioCartoonTool (cbit.vcell.graph.gui.BioCartoonTool)1 UserResolvedRxElements (cbit.vcell.graph.gui.BioCartoonTool.UserResolvedRxElements)1 DBFormalSpecies (cbit.vcell.model.DBFormalSpecies)1 Model (cbit.vcell.model.Model)1 ReactionStep (cbit.vcell.model.ReactionStep)1 Species (cbit.vcell.model.Species)1 SpeciesContext (cbit.vcell.model.SpeciesContext)1 Structure (cbit.vcell.model.Structure)1 Hashtable (java.util.Hashtable)1