Beispiel #1
0
  /** Redo actions */
  public void redo() {

    if (type.equals("setRoot") || type.equals("setSubstitute")) {

      if (isNewRgrp) {
        hub.setRGroupHandler(rgrpHandler);
      }

      IRGroupQuery rgrpQ = rgrpHandler.getrGroupQuery();
      for (Iterator<IAtom> atItr = existingAtomDistr.keySet().iterator(); atItr.hasNext(); ) {
        IAtom atom = atItr.next();
        existingAtomDistr.get(atom).removeAtom(atom);
      }
      for (Iterator<IBond> bndItr = existingBondDistr.keySet().iterator(); bndItr.hasNext(); ) {
        IBond bond = bndItr.next();
        existingBondDistr.get(bond).removeBond(bond);
      }
      hub.getChemModel().getMoleculeSet().addAtomContainer(userSelection);

      if (type.equals("setRoot")) {
        rgrpQ.setRootStructure(redoRootStructure);
        rgrpQ.getRootStructure().setProperty(CDKConstants.TITLE, RGroup.ROOT_LABEL);
        rgrpQ.setRootAttachmentPoints(redoRootAttachmentPoints);
      } else if (type.equals("setSubstitute")) {
        if (redoRgroupLists != null) {
          for (Iterator<Integer> rNums = redoRgroupLists.keySet().iterator(); rNums.hasNext(); ) {
            int rNum = rNums.next();
            rgrpQ.getRGroupDefinitions().put(rNum, redoRgroupLists.get(rNum));
          }
        }
      }
    } else if (type.startsWith("setAtomApoAction")) {
      RGroup redoRGroup = redoRGroupApo.keySet().iterator().next();
      for (Iterator<Integer> rnumItr =
              hub.getRGroupHandler().getrGroupQuery().getRGroupDefinitions().keySet().iterator();
          rnumItr.hasNext(); ) {
        for (RGroup rgrp :
            hub.getRGroupHandler()
                .getrGroupQuery()
                .getRGroupDefinitions()
                .get(rnumItr.next())
                .getRGroups()) {
          if (rgrp.equals(redoRGroup)) {
            IAtom apo1 = redoRGroupApo.get(redoRGroup).get(1);
            IAtom apo2 = redoRGroupApo.get(redoRGroup).get(2);
            rgrp.setFirstAttachmentPoint(apo1);
            rgrp.setSecondAttachmentPoint(apo2);
          }
        }
      }
    } else if (type.startsWith("setBondApoAction")) {
      for (Iterator<IAtom> atItr = redoRootAttachmentPoints.keySet().iterator();
          atItr.hasNext(); ) {
        IAtom rAtom = atItr.next();
        Map<Integer, IBond> apoBonds =
            hub.getRGroupHandler().getrGroupQuery().getRootAttachmentPoints().get(rAtom);

        apoBonds.remove(1);
        apoBonds.remove(2);
        Map<Integer, IBond> redoApo = redoRootAttachmentPoints.get(rAtom);

        if (redoApo.get(1) != null) {
          apoBonds.put(1, redoApo.get(1));
        }
        if (redoApo.get(2) != null) {
          apoBonds.put(2, redoApo.get(2));
        }
      }
    } else if (type.equals("clearRgroup")) {
      hub.unsetRGroupHandler();
    }
  }