Program: 148538
Project: 148538
Buggy source:
public IStatus doAction(){
  try {
    IStructuredSelection selection=(IStructuredSelection)page.getTreeViewer().getSelection();
    if (selection.getFirstElement() instanceof XSDComplexTypeDefinition) {
      XSDComplexTypeDefinition ctd=(XSDComplexTypeDefinition)selection.getFirstElement();
      if (!(ctd.getContent() instanceof XSDParticle))       return Status.CANCEL_STATUS;
      if (!(((XSDParticle)ctd.getContent()).getTerm() instanceof XSDModelGroup))       return Status.CANCEL_STATUS;
      ;
      group=(XSDModelGroup)((XSDParticle)ctd.getContent()).getTerm();
    }
 else     if (selection.getFirstElement() instanceof XSDParticle) {
      group=(XSDModelGroup)((XSDParticle)selection.getFirstElement()).getTerm();
    }
 else {
      System.out.println("String_Node_Str" + selection.getFirstElement().getClass().getName() + "String_Node_Str"+ selection.getFirstElement());
      return Status.CANCEL_STATUS;
    }
    dialog=new BusinessElementInputDialog(this,page.getSite().getShell(),"String_Node_Str",false);
    dialog.setBlockOnOpen(true);
    int ret=dialog.open();
    if (ret == Dialog.CANCEL) {
      return Status.CANCEL_STATUS;
    }
    XSDFactory factory=XSDSchemaBuildingTools.getXSDFactory();
    XSDElementDeclaration decl=factory.createXSDElementDeclaration();
    decl.setName(this.elementName);
    decl.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(),"String_Node_Str"));
    XSDParticle particle=factory.createXSDParticle();
    particle.setContent(decl);
    particle.setMinOccurs(this.minOccurs);
    particle.setMaxOccurs(this.maxOccurs);
    group.getContents().add(0,particle);
    group.updateElement();
    page.refresh();
    page.getTreeViewer().setSelection(new StructuredSelection(particle),true);
    page.markDirty();
  }
 catch (  Exception e) {
    e.printStackTrace();
    MessageDialog.openError(page.getSite().getShell(),"String_Node_Str","String_Node_Str" + e.getLocalizedMessage());
    return Status.CANCEL_STATUS;
  }
  return Status.OK_STATUS;
}

Fixed version (ground truth):
public IStatus doAction(){
  try {
    IStructuredSelection selection=(IStructuredSelection)page.getTreeViewer().getSelection();
    if (selection.getFirstElement() instanceof XSDComplexTypeDefinition) {
      ctd=(XSDComplexTypeDefinition)selection.getFirstElement();
      if (!(ctd.getContent() instanceof XSDParticle))       return Status.CANCEL_STATUS;
      if (!(((XSDParticle)ctd.getContent()).getTerm() instanceof XSDModelGroup))       return Status.CANCEL_STATUS;
      ;
      group=(XSDModelGroup)((XSDParticle)ctd.getContent()).getTerm();
    }
 else     if (selection.getFirstElement() instanceof XSDParticle) {
      group=(XSDModelGroup)((XSDParticle)selection.getFirstElement()).getTerm();
    }
 else     if (selection.getFirstElement() instanceof XSDModelGroup) {
      group=(XSDModelGroup)selection.getFirstElement();
    }
 else {
      System.out.println("String_Node_Str" + selection.getFirstElement().getClass().getName() + "String_Node_Str"+ selection.getFirstElement());
      return Status.CANCEL_STATUS;
    }
    dialog=new BusinessElementInputDialog(this,page.getSite().getShell(),"String_Node_Str",true);
    dialog.setBlockOnOpen(true);
    int ret=dialog.open();
    if (ret == Dialog.CANCEL) {
      return Status.CANCEL_STATUS;
    }
    XSDFactory factory=XSDSchemaBuildingTools.getXSDFactory();
    XSDElementDeclaration decl=factory.createXSDElementDeclaration();
    decl.setName(this.elementName);
    decl.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(),"String_Node_Str"));
    XSDParticle particle=factory.createXSDParticle();
    particle.setContent(decl);
    particle.setMinOccurs(this.minOccurs);
    particle.setMaxOccurs(this.maxOccurs);
    group.getContents().add(group.getContents().size(),particle);
    group.updateElement();
    if (dialog.isInherit()) {
      XSDTerm totm=particle.getTerm();
      XSDElementDeclaration concept=null;
      concept=(XSDElementDeclaration)Util.getParent(particle);
      XSDAnnotation fromannotation=null;
      if (concept != null)       fromannotation=concept.getAnnotation();
      if (fromannotation != null) {
        XSDAnnotationsStructure struc=new XSDAnnotationsStructure(totm);
        if (((XSDElementDeclaration)totm).getType() != null)         addAnnotion(struc,fromannotation);
      }
    }
    page.refresh();
    page.getTreeViewer().setSelection(new StructuredSelection(particle),true);
    page.markDirty();
  }
 catch (  Exception e) {
    e.printStackTrace();
    MessageDialog.openError(page.getSite().getShell(),"String_Node_Str","String_Node_Str" + e.getLocalizedMessage());
    return Status.CANCEL_STATUS;
  }
  return Status.OK_STATUS;
}