Program: 148980
Project: 148980
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");
    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) {
      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;
}