use of cbit.vcell.model.ReactionSpeciesCopy in project vcell by virtualcell.
the class ReactionCartoonTool method shapeHasMenuActionEnabled.
@Override
public boolean shapeHasMenuActionEnabled(Shape shape, String menuAction) {
if (menuAction.equals(CartoonToolMiscActions.Properties.MENU_ACTION)) {
if (shape instanceof CatalystShape) {
return false;
}
}
if (menuAction.equals(CartoonToolMiscActions.SearchReactions.MENU_ACTION)) {
if (!(shape instanceof ReactionContainerShape) || !getReactionCartoon().getStructureSuite().getStructures().contains(shape.getModelObject())) {
return false;
}
}
GraphViewAction paintingAction = ActionUtil.getAction(paintingActions, menuAction);
if (paintingAction != null) {
return paintingAction.isEnabledForShape(shape);
}
GraphViewAction groupAction = ActionUtil.getAction(groupActions, menuAction);
if (groupAction != null) {
return groupAction.isEnabledForShape(shape);
}
if (shape instanceof ReactionContainerShape) {
if (menuAction.equals(CartoonToolEditActions.PasteNew.MENU_ACTION)) {
ReactionSpeciesCopy reactionSpeciesCopy = (ReactionSpeciesCopy) VCellTransferable.getFromClipboard(VCellTransferable.REACTION_SPECIES_ARRAY_FLAVOR);
if (reactionSpeciesCopy != null) {
Structure targetStructure = ((ReactionContainerShape) shape).getStructure();
if (reactionSpeciesCopy.getReactStepArr() != null) {
for (int i = 0; i < reactionSpeciesCopy.getReactStepArr().length; i++) {
if (!reactionSpeciesCopy.getReactStepArr()[i].getStructure().getClass().equals(targetStructure.getClass())) {
return false;
}
}
}
return true;
} else {
return false;
}
} else if (menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
if (((ReactionContainerShape) shape).getStructureSuite().getStructures().size() == 1) {
return false;
}
}
}
return true;
}
use of cbit.vcell.model.ReactionSpeciesCopy 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()) {
//
// }
// }
}
}
use of cbit.vcell.model.ReactionSpeciesCopy in project vcell by virtualcell.
the class ReactionCartoonTool method menuAction.
@Override
protected void menuAction(Shape shape, String menuAction) {
if (shape == null) {
return;
}
if (menuAction.equals(CartoonToolMiscActions.Properties.MENU_ACTION)) {
if (shape instanceof FluxReactionShape) {
// showFluxReactionPropertiesDialog((FluxReactionShape) shape);
} else if (shape instanceof SimpleReactionShape) {
// showSimpleReactionPropertiesDialog((SimpleReactionShape) shape);
} else if (shape instanceof ReactantShape) {
// Point locationOnScreen = shape.getSpaceManager().getAbsLoc();
// Point graphPaneLocation = getGraphPane().getLocationOnScreen();
// locationOnScreen.translate(graphPaneLocation.x,
// graphPaneLocation.y);
// showReactantPropertiesDialog((ReactantShape) shape,
// locationOnScreen);
} else if (shape instanceof ProductShape) {
// Point locationOnScreen = shape.getSpaceManager().getAbsLoc();
// Point graphPaneLocation = getGraphPane().getLocationOnScreen();
// locationOnScreen.translate(graphPaneLocation.x,
// graphPaneLocation.y);
// showProductPropertiesDialog((ProductShape) shape,
// locationOnScreen);
} else if (shape instanceof SpeciesContextShape) {
// showEditSpeciesDialog(getGraphPane(), getReactionCartoon()
// .getModel(), ((SpeciesContextShape) shape)
// .getSpeciesContext());
} else if (shape instanceof ReactionContainerShape) {
// ReactionContainerShape rcs = (ReactionContainerShape) shape;
// if (rcs.getStructure() instanceof Feature) {
// //
// // showFeaturePropertyDialog is invoked in two modes:
// //
// // 1) parent!=null and child==null
// // upon ok, it adds a new feature to the supplied parent.
// //
// // 2) parent==null and child!=null
// // upon ok, edits the feature name
// //
// showFeaturePropertiesDialog(getGraphPane(),
// (getReactionCartoon().getModel() == null ? null
// : getReactionCartoon().getModel()), null,
// (Feature) rcs.getStructure());
// } else if (rcs.getStructure() instanceof Membrane) {
// showMembranePropertiesDialog(getGraphPane(), (Membrane) rcs
// .getStructure());
// }
}
} else if (menuAction.equals(CartoonToolMiscActions.AddSpecies.MENU_ACTION)) {
if (shape instanceof ReactionContainerShape) {
getGraphModel().deselectShape(shape);
// showCreateSpeciesContextDialog(getGraphPane(),
// getReactionCartoon().getModel(),
// ((ReactionContainerShape) shape).getStructure(), null);
SpeciesContext speciesContext = getReactionCartoon().getModel().createSpeciesContext(((ReactionContainerShape) shape).getStructure());
getGraphModel().select(speciesContext);
}
} else if (menuAction.equals(CartoonToolEditActions.Copy.MENU_ACTION)) {
if (shape instanceof SpeciesContextShape || shape instanceof ReactionStepShape || // rule participants whose rule is not selected won't
shape instanceof RuleParticipantSignatureDiagramShape || // be copied since standalone they are meaningless
shape instanceof ReactionRuleDiagramShape) {
SpeciesContext[] spArray = getSelectedSpeciesContextArray();
ReactionStep[] rsArray = getSelectedReactionStepArray();
ReactionRule[] rrArray = getSelectedReactionRuleArray();
MolecularType[] mtArray = getSelectedMolecularTypeArray(rrArray, rsArray, spArray);
Structure[] structArray = getSelectedStructuresArray(rrArray, rsArray, spArray, mtArray);
Structure fromStruct = null;
ReactionContainerShape rcs = null;
Shape parentShape = shape.getParent();
if (parentShape instanceof ReactionContainerShape) {
rcs = (ReactionContainerShape) parentShape;
fromStruct = rcs.getStructure();
}
ReactionSpeciesCopy reactionSpeciesCopy = new ReactionSpeciesCopy(spArray, rsArray, rrArray, mtArray, fromStruct, structArray);
VCellTransferable.sendToClipboard(reactionSpeciesCopy);
}
} else if (/*menuAction.equals(CartoonToolEditActions.Paste.MENU_ACTION)
|| */
menuAction.equals(CartoonToolEditActions.PasteNew.MENU_ACTION)) {
if (shape instanceof ReactionContainerShape) {
pasteReactionsAndSpecies(getGraphPane().getRootPane(), ((ReactionContainerShape) shape).getStructure());
}
} else if (menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
try {
if (getGraphModel().getSelectedShape() instanceof ReactionContainerShape && menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
getModel().removeStructure(((ReactionContainerShape) getGraphModel().getSelectedShape()).getStructure());
return;
}
if (getSelectedReactionStepArray() != null || getSelectedSpeciesContextArray() != null) {
deleteReactionsAndSpecies(getGraphPane(), getSelectedReactionStepArray(), getSelectedSpeciesContextArray());
}
if (getSelectedReactionParticipantArray() != null && menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
ReactionParticipant[] reactionParticipantArr = getSelectedReactionParticipantArray();
if (ReactionCartoonTool.checkAllCatalyst(reactionParticipantArr)) {
DialogUtils.showWarningDialog(getGraphPane(), "Catalysts are determined automatically from the reaction kinetic expression.");
return;
}
String response = DialogUtils.showWarningDialog(getGraphPane(), "Delete " + reactionParticipantArr.length + " Reaction Stoichiometries", new String[] { RXSPECIES_DELETE, RXSPECIES_CANCEL }, RXSPECIES_CANCEL);
if (response != null && response.equals(RXSPECIES_DELETE)) {
for (int i = 0; i < reactionParticipantArr.length; i++) {
if (reactionParticipantArr[i] instanceof Catalyst) {
// Catalysts may only be deleted by editing kynetic / proxy parameters
continue;
}
ReactionStep reactionStep = reactionParticipantArr[i].getReactionStep();
reactionStep.removeReactionParticipant(reactionParticipantArr[i]);
}
}
}
} catch (UserCancelException uce) {
return;
} catch (PropertyVetoException e) {
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage());
} catch (Exception e) {
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
}
} else if (menuAction.equals(CartoonToolMiscActions.SearchReactions.MENU_ACTION)) {
try {
if (shape instanceof ReactionContainerShape) {
showReactionBrowserDialog(((ReactionContainerShape) shape).getStructure(), null);
}
} catch (Exception e) {
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
}
} else if (menuAction.equals(CartoonToolSaveAsImageActions.MenuAction.MENU_ACTION)) {
try {
String resType = null;
if (shape instanceof ReactionContainerShape) {
showSaveReactionImageDialog();
}
} catch (Exception e) {
e.printStackTrace();
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
}
} else if (menuAction.equals(CartoonToolMiscActions.Annotate.MENU_ACTION)) {
if (shape instanceof ReactionStepShape) {
// MIRIAMHelper.showMIRIAMAnnotationDialog(((SimpleReactionShape)shape).getReactionStep());
// System.out.println("Menu action annotate activated...");
ReactionStep rs = ((ReactionStepShape) shape).getReactionStep();
VCMetaData vcMetaData = rs.getModel().getVcMetaData();
try {
String newAnnotation = DialogUtils.showAnnotationDialog(getGraphPane(), vcMetaData.getFreeTextAnnotation(rs));
vcMetaData.setFreeTextAnnotation(rs, newAnnotation);
} catch (UtilCancelException e) {
// Do Nothing
} catch (Throwable exc) {
exc.printStackTrace(System.out);
DialogUtils.showErrorDialog(getGraphPane(), "Failed to edit annotation!\n" + exc.getMessage(), exc);
}
}
} else {
// default action is to ignore
}
}
use of cbit.vcell.model.ReactionSpeciesCopy in project vcell by virtualcell.
the class ReactionCartoonTool method pasteReactionsAndSpecies.
private void pasteReactionsAndSpecies(Structure structure) {
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(), structure, 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))) {
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(), structure, 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()) {
//
// }
// }
}
}
Aggregations