Search in sources :

Example 1 with RXParticipantResolverPanel

use of cbit.vcell.model.gui.RXParticipantResolverPanel in project vcell by virtualcell.

the class ReactionCartoonTool method pasteReactionsAndSpecies.

private void pasteReactionsAndSpecies(Component requester, Structure pasteToStructure) {
    final String RXSPECIES_PASTERX = "Reactions";
    final String RXSPECIES_SPECIES = "Species";
    ReactionSpeciesCopy reactionSpeciesCopy = (ReactionSpeciesCopy) SimpleTransferable.getFromClipboard(VCellTransferable.REACTION_SPECIES_ARRAY_FLAVOR);
    if (reactionSpeciesCopy != null) {
        // TODO: here we may want to warn the user about compartment number / type / name mismatch
        // between the source and the destination
        String response = null;
        if ((reactionSpeciesCopy.getReactStepArr() != null || reactionSpeciesCopy.getReactionRuleArr() != null) && reactionSpeciesCopy.getSpeciesContextArr() != null) {
            String msg = "There are ";
            msg += reactionSpeciesCopy.getSpeciesContextArr().length + " Species and ";
            int rlen = 0;
            if (reactionSpeciesCopy.getReactStepArr() != null)
                rlen += reactionSpeciesCopy.getReactStepArr().length;
            if (reactionSpeciesCopy.getReactionRuleArr() != null)
                rlen += reactionSpeciesCopy.getReactionRuleArr().length;
            msg += rlen + " Reactions / Rules on the clipboard, choose which set to paste.";
            response = DialogUtils.showWarningDialog(getGraphPane(), "Choose Species or Reactions to paste", msg, new String[] { RXSPECIES_SPECIES, RXSPECIES_PASTERX, RXSPECIES_CANCEL }, RXSPECIES_CANCEL);
            if (response == null || response.equals(RXSPECIES_CANCEL)) {
                return;
            }
        }
        if (reactionSpeciesCopy.getSpeciesContextArr() != null && (response == null || response.equals(RXSPECIES_SPECIES))) {
            IdentityHashMap<Species, Species> speciesHash = new IdentityHashMap<Species, Species>();
            Vector<BioModelEntityObject> pastedSpeciesContextV = new Vector<BioModelEntityObject>();
            for (int i = 0; i < reactionSpeciesCopy.getSpeciesContextArr().length; i++) {
                String rootSC = speciesContextRootFinder(reactionSpeciesCopy.getSpeciesContextArr()[i]);
                pastedSpeciesContextV.add(pasteSpecies(getGraphPane(), reactionSpeciesCopy.getSpeciesContextArr()[i].getSpecies(), rootSC, getModel(), pasteToStructure, true, speciesHash, null));
                copyRelativePosition(getGraphModel(), reactionSpeciesCopy.getSpeciesContextArr()[i], pastedSpeciesContextV.lastElement());
            }
            ReactionCartoonTool.selectAndSaveDiagram(ReactionCartoonTool.this, pastedSpeciesContextV);
        }
        if (reactionSpeciesCopy.getReactStepArr() != null && reactionSpeciesCopy.getReactionRuleArr() == null && (response == null || response.equals(RXSPECIES_PASTERX))) {
            BioModel bioModel = null;
            try {
                bioModel = findBioModel(requester);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                DialogUtils.showErrorDialog(requester, e.getMessage());
                return;
            }
            ReactionDescription reactionDescription = DBReactionWizardPanel.createReactionDescription(reactionSpeciesCopy.getReactStepArr()[0], null, reactionSpeciesCopy.getFromStructure().getKey());
            RXParticipantResolverPanel rxParticipantResolverPanel = new RXParticipantResolverPanel();
            // rxParticipantResolverPanel.setPasteToModel(getModel());
            rxParticipantResolverPanel.setupRX(reactionDescription, getModel(), pasteToStructure);
            // JDialog j = new JDialog();
            // j.setModal(true);
            // j.setAlwaysOnTop(true);
            // j.getContentPane().add(rxParticipantResolverPanel);
            // j.pack();
            // j.setVisible(true);
            // int result = DialogUtils.showComponentOKCancelDialog(getGraphPane(), rxParticipantResolverPanel, "Assign Reaction elements");
            // if(result != JOptionPane.OK_OPTION) {
            // return;
            // }
            BioCartoonTool.AssignmentHelper assignmentHelper = new BioCartoonTool.AssignmentHelper() {

                @Override
                public JComboBox[] getStructureAssignmentJCB() {
                    return rxParticipantResolverPanel.getStructureAssignmentJCB();
                }

                @Override
                public JComboBox[] getSpeciesAssignmentJCB() {
                    return rxParticipantResolverPanel.getSpeciesAssignmentJCB();
                }

                @Override
                public ArrayList<JTextField> getFinalNames() {
                    // TODO Auto-generated method stub
                    return rxParticipantResolverPanel.getFinalNamesJTF();
                }

                @Override
                public Component getParent() {
                    return getGraphPane();
                }

                @Override
                public Component getAssignmentInterface() {
                    return rxParticipantResolverPanel;
                }

                @Override
                public void close() {
                // Do Nothing
                }
            };
            BioCartoonTool.pasteReactionSteps(requester, ReactionCartoonTool.this, reactionDescription, reactionSpeciesCopy.getReactStepArr()[0].getModel(), reactionSpeciesCopy.getFromStructure(), reactionSpeciesCopy.getReactStepArr()[0], bioModel.getModel(), pasteToStructure, assignmentHelper);
        // pasteReactionSteps(getGraphPane(),reactionSpeciesCopy.getReactStepArr(), getModel(),structure,true, null,ReactionCartoonTool.this);
        } else if (reactionSpeciesCopy.getReactionRuleArr() != null && (response == null || response.equals(RXSPECIES_PASTERX))) {
            pasteReactionsAndRules(getGraphPane(), reactionSpeciesCopy, getModel(), pasteToStructure, ReactionCartoonTool.this);
        }
    // try {
    // for(MolecularType mtOurs : mtNewList) {
    // rbmmcOurs.addMolecularType(mtOurs, false);
    // }
    // } catch (ModelException | PropertyVetoException e) {
    // e.printStackTrace();
    // }
    // 
    // // ReactionRules
    // if(reactionSpeciesCopy.getReactionRuleArr() != null) {
    // for(ReactionRule rrTheirs : reactionSpeciesCopy.getReactionRuleArr()) {
    // 
    // }
    // }
    }
}
Also used : ReactionSpeciesCopy(cbit.vcell.model.ReactionSpeciesCopy) RXParticipantResolverPanel(cbit.vcell.model.gui.RXParticipantResolverPanel) JComboBox(javax.swing.JComboBox) IdentityHashMap(java.util.IdentityHashMap) BioModelEntityObject(cbit.vcell.model.BioModelEntityObject) JTextField(javax.swing.JTextField) Point(java.awt.Point) PropertyVetoException(java.beans.PropertyVetoException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) BioModel(cbit.vcell.biomodel.BioModel) ReactionDescription(cbit.vcell.model.ReactionDescription) Species(cbit.vcell.model.Species) Vector(java.util.Vector)

Aggregations

BioModel (cbit.vcell.biomodel.BioModel)1 BioModelEntityObject (cbit.vcell.model.BioModelEntityObject)1 ReactionDescription (cbit.vcell.model.ReactionDescription)1 ReactionSpeciesCopy (cbit.vcell.model.ReactionSpeciesCopy)1 Species (cbit.vcell.model.Species)1 RXParticipantResolverPanel (cbit.vcell.model.gui.RXParticipantResolverPanel)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 Point (java.awt.Point)1 PropertyVetoException (java.beans.PropertyVetoException)1 IdentityHashMap (java.util.IdentityHashMap)1 Vector (java.util.Vector)1 JComboBox (javax.swing.JComboBox)1 JTextField (javax.swing.JTextField)1 UserCancelException (org.vcell.util.UserCancelException)1 UtilCancelException (org.vcell.util.UtilCancelException)1