{
IChemObject object = getSource(event);
logger.debug("CreateReaction action");
IChemModel model = jcpPanel.getChemModel();
IReactionSet reactionSet = model.getReactionSet();
if (reactionSet == null)
{
reactionSet = model.getBuilder().newInstance(IReactionSet.class);
}
IAtomContainer container = null;
if (object instanceof IAtom)
{
container = ChemModelManipulator.getRelevantAtomContainer(model, (IAtom) object);
} else if(object instanceof IBond)
{
container = ChemModelManipulator.getRelevantAtomContainer(model, (IBond) object);
} else
{
logger.error("Cannot add to reaction object of type: " + object.getClass().getName());
}
if (container == null)
{
logger.error("Cannot find container to add object to!");
} else
{
IChemModelRelay hub = jcpPanel.get2DHub();
IAtomContainer newContainer;
try {
newContainer = (IAtomContainer) container.clone();
if(container.getID()!=null)
newContainer.setID(container.getID());
else
newContainer.setID("ac"+System.currentTimeMillis());
} catch (CloneNotSupportedException e) {
logger.error("Could not clone IAtomContainer: ", e.getMessage());
logger.debug(e);
return;
}
logger.debug("type: ", type);
if ("addReactantToNew".equals(type))
{
ReactionHub.makeReactantInNewReaction((ControllerHub)hub, newContainer, container);
//TODO this.jcpPanel.atomAtomMappingButton.setEnabled(true);
} else if ("addReactantToExisting".equals(type))
{
if (reactionSet.getReactionCount() == 0)
{
logger.warn("Cannot add to reaction if no one exists");
JOptionPane.showMessageDialog(jcpPanel, GT.get("No reaction existing. Cannot add therefore to something!"), GT.get("No existing reactions"), JOptionPane.WARNING_MESSAGE);
return;
} else
{
Object[] ids = getReactionIDs(reactionSet);
String s = (String)ids[0];
if(ids.length>1){
s = (String) JOptionPane.showInputDialog(
null,
"Reaction Chooser",
"Choose reaction to add reaction to",
JOptionPane.PLAIN_MESSAGE,
null,
ids,
ids[0]
);
}
if ((s != null) && (s.length() > 0))
{
ReactionHub.makeReactantInExistingReaction((ControllerHub)hub, s, newContainer, container);
//TODO this.jcpPanel.atomAtomMappingButton.setEnabled(true);
} else
{
logger.error("No reaction selected");
}
}
} else if ("addProductToNew".equals(type))
{
ReactionHub.makeProductInNewReaction((ControllerHub)hub, newContainer, container);
//this.jcpPanel.atomAtomMappingButton.setEnabled(true);
} else if ("addProductToExisting".equals(type))
{
if (reactionSet.getReactionCount() == 0)
{
logger.warn("Cannot add to reaction if no one exists");
JOptionPane.showMessageDialog(jcpPanel, GT.get("No reaction existing. Cannot add therefore to something!"), GT.get("No existing reactions"), JOptionPane.WARNING_MESSAGE);
return;
} else