Program: 168077
Project: 168077
Buggy source:
@Override protected void createMasterPart(final IManagedForm managedForm,Composite parent){
  FormToolkit toolkit=managedForm.getToolkit();
  Section section=toolkit.createSection(parent,Section.DESCRIPTION | Section.TITLE_BAR);
  section.setText("String_Node_Str");
  Composite client=toolkit.createComposite(section,SWT.WRAP);
  GridLayout layout=new GridLayout();
  layout.numColumns=2;
  layout.marginWidth=2;
  layout.marginHeight=2;
  client.setLayout(layout);
  toolkit.paintBordersFor(client);
  final TreeViewer corpusViewer=new TreeViewer(client,SWT.BORDER);
  GridData gd=new GridData(GridData.FILL_BOTH);
  gd.heightHint=400;
  gd.widthHint=100;
  corpusViewer.getTree().setLayoutData(gd);
  Composite buttonComposite=new Composite(client,SWT.NONE);
  GridLayout buttonLayout=new GridLayout();
  buttonLayout.marginWidth=buttonLayout.marginHeight=0;
  buttonLayout.makeColumnsEqualWidth=true;
  buttonComposite.setLayout(buttonLayout);
  buttonComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL));
  Button addCorpus=toolkit.createButton(buttonComposite,"String_Node_Str",SWT.PUSH);
  GridDataFactory.fillDefaults().grab(false,false).span(1,1).applyTo(addCorpus);
  final Button addClass=toolkit.createButton(buttonComposite,"String_Node_Str",SWT.PUSH);
  GridDataFactory.fillDefaults().grab(false,false).span(1,1).applyTo(addClass);
  Button remove=toolkit.createButton(buttonComposite,"String_Node_Str",SWT.PUSH);
  GridDataFactory.fillDefaults().grab(false,false).span(1,1).applyTo(remove);
  final Button export=toolkit.createButton(buttonComposite,"String_Node_Str",SWT.PUSH);
  GridDataFactory.fillDefaults().grab(false,false).span(1,1).applyTo(export);
  export.setEnabled(false);
  Button refresh=toolkit.createButton(buttonComposite,"String_Node_Str",SWT.PUSH);
  GridDataFactory.fillDefaults().grab(false,false).span(1,1).applyTo(refresh);
  section.setClient(client);
  final SectionPart spart=new SectionPart(section);
  managedForm.addPart(spart);
  corpusViewer.addSelectionChangedListener(new ISelectionChangedListener(){
    @Override public void selectionChanged(    SelectionChangedEvent event){
      managedForm.fireSelectionChanged(spart,event.getSelection());
      Object c=((IStructuredSelection)event.getSelection()).getFirstElement();
      if (c instanceof ICorpusClass) {
        if (((CorpusClass)c).getParent().getDatatype() != CMDataType.PLAIN_TEXT)         export.setEnabled(true);
 else         export.setEnabled(false);
      }
 else       export.setEnabled(false);
    }
  }
);
  corpusViewer.setContentProvider(new MasterContentProvider());
  corpusViewer.setLabelProvider(new MasterLabelProvider());
  for (  ICorpus corpus : corpusList) {
    ((Corpus)corpus).setViewer(corpusViewer);
    for (    ICorpusClass cc : corpus.getClasses()) {
      ((CorpusClass)cc).setViewer(corpusViewer);
    }
  }
  corpusViewer.setInput(corpusList);
  refresh.addSelectionListener(new SelectionAdapter(){
    @Override public void widgetSelected(    SelectionEvent e){
      corpusManagement=new ManageCorpora();
      corpusList=corpusManagement.getAllCorpusDetails();
      corpusViewer.setInput(corpusList);
    }
  }
);
  export.addSelectionListener(new SelectionAdapter(){
    @Override public void widgetSelected(    SelectionEvent e){
      seperateFiles=false;
      final TacitCorpusFilterDialog filterDialog=new TacitCorpusFilterDialog(export.getShell());
      final CorpusClass cls=(CorpusClass)((IStructuredSelection)corpusViewer.getSelection()).getFirstElement();
      IQueryProcessor qp=new QueryProcesser(cls);
      Map<String,QueryDataType> keys=null;
      try {
        keys=qp.getJsonKeys();
        filterDialog.setFilterDetails(keys);
        filterDialog.addExistingFilters(cls.getFilters());
      }
 catch (      JsonSyntaxException e1) {
        e1.printStackTrace();
      }
catch (      JsonIOException e1) {
        e1.printStackTrace();
      }
catch (      FileNotFoundException e1) {
        e1.printStackTrace();
      }
      IWizardData wizardDataModel=new IWizardData(){
        @Override public void getData(        List<Filter> filter){
          cls.refreshFilters(filter);
        }
        @Override public void getPath(        String path){
          outputLoc=path;
        }
        @Override public void getDivision(        boolean seperate){
          seperateFiles=true;
        }
        @Override public void getExportSelection(        String selection){
          exportSelection=selection;
        }
      }
;
      WizardDialog wizardDialog=new WizardDialog(export.getShell(),new ExportWizard(filterDialog,wizardDataModel));
      if (wizardDialog.open() == Window.OK) {
        System.out.println("String_Node_Str");
        if (exportSelection.equals(ExportSelectionConstants.EXPORT_CSV_FORMAT)) {
          System.out.println("String_Node_Str");
          try {
            writeCSV(outputLoc,cls);
          }
 catch (          Exception e1) {
            ConsoleView.printlInConsoleln("String_Node_Str");
            e1.printStackTrace();
          }
        }
 else         if (exportSelection.equals(ExportSelectionConstants.EXPORT_ROBJ_FORMAT)) {
          System.out.println("String_Node_Str");
          try {
            writeRObj(outputLoc,cls);
          }
 catch (          Exception e1) {
            ConsoleView.printlInConsoleln("String_Node_Str");
            e1.printStackTrace();
          }
        }
 else         if (exportSelection.equals(ExportSelectionConstants.EXPORT_TXT_FORMAT)) {
          Preprocessor ppObj=null;
          List<String> inFiles=null;
          List<Object> inputFiles=new ArrayList<Object>();
          inputFiles.add(cls);
          File delFile=null;
          try {
            ppObj=new Preprocessor("String_Node_Str",true);
            inFiles=ppObj.processData("String_Node_Str",inputFiles,seperateFiles);
            if (!inFiles.isEmpty()) {
              delFile=new File(inFiles.get(0));
            }
          }
 catch (          Exception e1) {
            e1.printStackTrace();
          }
          String outputDir=outputLoc + File.separator + cls.getParent().getCorpusName()+ "String_Node_Str"+ cls.getClassName();
          System.out.println(outputDir);
          File dir=new File(outputDir);
          if (!dir.exists()) {
            dir.mkdir();
          }
          for (          String i : inFiles) {
            try {
              int l=i.lastIndexOf(File.separator);
              String export=outputDir + File.separator + i.substring(l + 1);
              File exportFile=new File(export);
              FileUtils.copyFile(new File(i),exportFile);
              ConsoleView.printlInConsoleln("String_Node_Str" + exportFile.getName() + "String_Node_Str"+ outputDir);
            }
 catch (            FileNotFoundException e1) {
              e1.printStackTrace();
            }
catch (            IOException e1) {
              e1.printStackTrace();
            }
          }
          if (!inFiles.isEmpty()) {
            try {
              FileUtils.deleteDirectory(delFile.getParentFile().getParentFile());
            }
 catch (            IOException e1) {
              e1.printStackTrace();
            }
          }
        }
      }
 else {
        System.out.println("String_Node_Str");
      }
    }
  }
);
  addCorpus.addSelectionListener(new SelectionAdapter(){
    @Override public void widgetSelected(    SelectionEvent e){
      StringBuilder corpusTempName=new StringBuilder("String_Node_Str");
      corpusTempName.append(corpusList.size() + 1);
      Corpus c=new Corpus(new String(corpusTempName),CMDataType.PLAIN_TEXT,corpusViewer);
      c.addClass(new CorpusClass("String_Node_Str",ICorpusManagementConstants.DEFAULT_CLASSPATH,corpusViewer));
      corpusList.add(c);
      Object[] expandedItems=corpusViewer.getExpandedElements();
      corpusViewer.setInput(corpusList);
      corpusViewer.setExpandedElements(expandNewCorpus(expandedItems,c));
      corpusViewer.setSelection(new StructuredSelection(c),true);
    }
  }
);
  addClass.addSelectionListener(new SelectionAdapter(){
    @Override public void widgetSelected(    SelectionEvent e){
      IStructuredSelection selection=(IStructuredSelection)corpusViewer.getSelection();
      try {
        ICorpus corpusSelected=(selection.getFirstElement() instanceof ICorpus) ? (ICorpus)selection.getFirstElement() : (ICorpus)((ICorpusClass)selection.getFirstElement()).getParent();
        int corpusIndex=corpusList.indexOf(corpusSelected);
        StringBuilder classTempName=new StringBuilder("String_Node_Str");
        classTempName.append(corpusList.get(corpusIndex).getClasses().size() + 1);
        CorpusClass newClass=new CorpusClass(new String(classTempName),ICorpusManagementConstants.DEFAULT_CLASSPATH,corpusViewer);
        ((Corpus)corpusSelected).addClass(newClass);
        corpusList.set(corpusIndex,corpusSelected);
        corpusViewer.refresh();
        corpusViewer.setExpandedElements(expandNewCorpus(corpusViewer.getExpandedElements(),(Corpus)corpusList.get(corpusIndex)));
        corpusViewer.setSelection(new StructuredSelection(newClass),true);
      }
 catch (      Exception exp) {
      }
    }
  }
);
  final MessageDialog dg=new MessageDialog(corpusMgmtViewform.getShell(),"String_Node_Str",null,"String_Node_Str",MessageDialog.QUESTION_WITH_CANCEL,new String[]{IDialogConstants.YES_LABEL,IDialogConstants.NO_LABEL},0);
  remove.addSelectionListener(new SelectionAdapter(){
    @Override public void widgetSelected(    SelectionEvent e){
      IStructuredSelection selection=(IStructuredSelection)corpusViewer.getSelection();
      try {
switch (dg.open()) {
case 1:
          return;
      }
      Object selectedObj=selection.getFirstElement();
      if (selectedObj instanceof ICorpus) {
        ICorpus selectedCorpus=(ICorpus)selection.getFirstElement();
        corpusList.remove(selectedCorpus);
        ManageCorpora.removeCorpus((Corpus)selectedCorpus,true);
        deleteCorpus((Corpus)selectedCorpus);
      }
 else       if (selectedObj instanceof ICorpusClass) {
        ITreeSelection classSelection=(ITreeSelection)selection;
        ICorpusClass selectedClass=(ICorpusClass)selection.getFirstElement();
        Corpus parentCorpus=(Corpus)classSelection.getPaths()[0].getParentPath().getLastSegment();
        parentCorpus.removeClass(selectedClass);
        ManageCorpora.removeCorpus(parentCorpus,false);
      }
      corpusViewer.refresh();
      Display.getDefault().asyncExec(new Runnable(){
        @Override public void run(){
          corpusViewer.refresh();
        }
      }
);
    }
 catch (    Exception exp) {
    }
  }
}
);
}

Fixed version (ground truth):
@Override protected void createMasterPart(final IManagedForm managedForm,Composite parent){
  FormToolkit toolkit=managedForm.getToolkit();
  Section section=toolkit.createSection(parent,Section.DESCRIPTION | Section.TITLE_BAR);
  section.setText("String_Node_Str");
  Composite client=toolkit.createComposite(section,SWT.WRAP);
  GridLayout layout=new GridLayout();
  layout.numColumns=2;
  layout.marginWidth=2;
  layout.marginHeight=2;
  client.setLayout(layout);
  toolkit.paintBordersFor(client);
  final TreeViewer corpusViewer=new TreeViewer(client,SWT.BORDER);
  GridData gd=new GridData(GridData.FILL_BOTH);
  gd.heightHint=400;
  gd.widthHint=100;
  corpusViewer.getTree().setLayoutData(gd);
  Composite buttonComposite=new Composite(client,SWT.NONE);
  GridLayout buttonLayout=new GridLayout();
  buttonLayout.marginWidth=buttonLayout.marginHeight=0;
  buttonLayout.makeColumnsEqualWidth=true;
  buttonComposite.setLayout(buttonLayout);
  buttonComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL));
  Button addCorpus=toolkit.createButton(buttonComposite,"String_Node_Str",SWT.PUSH);
  GridDataFactory.fillDefaults().grab(false,false).span(1,1).applyTo(addCorpus);
  final Button addClass=toolkit.createButton(buttonComposite,"String_Node_Str",SWT.PUSH);
  GridDataFactory.fillDefaults().grab(false,false).span(1,1).applyTo(addClass);
  Button remove=toolkit.createButton(buttonComposite,"String_Node_Str",SWT.PUSH);
  GridDataFactory.fillDefaults().grab(false,false).span(1,1).applyTo(remove);
  final Button export=toolkit.createButton(buttonComposite,"String_Node_Str",SWT.PUSH);
  GridDataFactory.fillDefaults().grab(false,false).span(1,1).applyTo(export);
  export.setEnabled(false);
  Button refresh=toolkit.createButton(buttonComposite,"String_Node_Str",SWT.PUSH);
  GridDataFactory.fillDefaults().grab(false,false).span(1,1).applyTo(refresh);
  section.setClient(client);
  final SectionPart spart=new SectionPart(section);
  managedForm.addPart(spart);
  corpusViewer.addSelectionChangedListener(new ISelectionChangedListener(){
    @Override public void selectionChanged(    SelectionChangedEvent event){
      managedForm.fireSelectionChanged(spart,event.getSelection());
      Object c=((IStructuredSelection)event.getSelection()).getFirstElement();
      if (c instanceof ICorpusClass) {
        if (((CorpusClass)c).getParent().getDatatype() != CMDataType.PLAIN_TEXT)         export.setEnabled(true);
 else         export.setEnabled(false);
      }
 else       export.setEnabled(false);
    }
  }
);
  corpusViewer.setContentProvider(new MasterContentProvider());
  corpusViewer.setLabelProvider(new MasterLabelProvider());
  for (  ICorpus corpus : corpusList) {
    ((Corpus)corpus).setViewer(corpusViewer);
    for (    ICorpusClass cc : corpus.getClasses()) {
      ((CorpusClass)cc).setViewer(corpusViewer);
    }
  }
  corpusViewer.setInput(corpusList);
  refresh.addSelectionListener(new SelectionAdapter(){
    @Override public void widgetSelected(    SelectionEvent e){
      corpusManagement=new ManageCorpora();
      corpusList=corpusManagement.getAllCorpusDetails();
      corpusViewer.setInput(corpusList);
    }
  }
);
  export.addSelectionListener(new SelectionAdapter(){
    @Override public void widgetSelected(    SelectionEvent e){
      seperateFiles=false;
      final TacitCorpusFilterDialog filterDialog=new TacitCorpusFilterDialog(export.getShell());
      final CorpusClass cls=(CorpusClass)((IStructuredSelection)corpusViewer.getSelection()).getFirstElement();
      IQueryProcessor qp=new QueryProcesser(cls);
      Map<String,QueryDataType> keys=null;
      try {
        keys=qp.getJsonKeys();
        filterDialog.setFilterDetails(keys);
        filterDialog.addExistingFilters(cls.getFilters());
      }
 catch (      JsonSyntaxException e1) {
        e1.printStackTrace();
      }
catch (      JsonIOException e1) {
        e1.printStackTrace();
      }
catch (      FileNotFoundException e1) {
        e1.printStackTrace();
      }
      IWizardData wizardDataModel=new IWizardData(){
        @Override public void getData(        List<Filter> filter){
          cls.refreshFilters(filter);
        }
        @Override public void getPath(        String path){
          outputLoc=path;
        }
        @Override public void getDivision(        boolean seperate){
          seperateFiles=true;
        }
        @Override public void getExportSelection(        String selection){
          exportSelection=selection;
        }
      }
;
      WizardDialog wizardDialog=new WizardDialog(export.getShell(),new ExportWizard(filterDialog,wizardDataModel));
      if (wizardDialog.open() == Window.OK) {
        System.out.println("String_Node_Str");
        if (exportSelection.equals(ExportSelectionConstants.EXPORT_CSV_FORMAT)) {
          System.out.println("String_Node_Str");
          try {
            writeCSV(outputLoc,cls);
          }
 catch (          Exception e1) {
            ConsoleView.printlInConsoleln("String_Node_Str");
            e1.printStackTrace();
          }
        }
 else         if (exportSelection.equals(ExportSelectionConstants.EXPORT_ROBJ_FORMAT)) {
          System.out.println("String_Node_Str");
          try {
            writeRObj(outputLoc,cls);
          }
 catch (          Exception e1) {
            ConsoleView.printlInConsoleln("String_Node_Str");
            e1.printStackTrace();
          }
        }
 else         if (exportSelection.equals(ExportSelectionConstants.EXPORT_TXT_FORMAT)) {
          Preprocessor ppObj=null;
          List<String> inFiles=null;
          List<Object> inputFiles=new ArrayList<Object>();
          inputFiles.add(cls);
          File delFile=null;
          try {
            ppObj=new Preprocessor("String_Node_Str",false);
            inFiles=ppObj.processData("String_Node_Str",inputFiles,seperateFiles);
            if (!inFiles.isEmpty()) {
              delFile=new File(inFiles.get(0));
            }
          }
 catch (          Exception e1) {
            e1.printStackTrace();
          }
          String outputDir=outputLoc + File.separator + cls.getParent().getCorpusName()+ "String_Node_Str"+ cls.getClassName();
          System.out.println(outputDir);
          File dir=new File(outputDir);
          if (!dir.exists()) {
            dir.mkdir();
          }
          for (          String i : inFiles) {
            try {
              int l=i.lastIndexOf(File.separator);
              String export=outputDir + File.separator + i.substring(l + 1);
              File exportFile=new File(export);
              FileUtils.copyFile(new File(i),exportFile);
              ConsoleView.printlInConsoleln("String_Node_Str" + exportFile.getName() + "String_Node_Str"+ outputDir);
            }
 catch (            FileNotFoundException e1) {
              e1.printStackTrace();
            }
catch (            IOException e1) {
              e1.printStackTrace();
            }
          }
        }
      }
 else {
        System.out.println("String_Node_Str");
      }
    }
  }
);
  addCorpus.addSelectionListener(new SelectionAdapter(){
    @Override public void widgetSelected(    SelectionEvent e){
      StringBuilder corpusTempName=new StringBuilder("String_Node_Str");
      corpusTempName.append(corpusList.size() + 1);
      Corpus c=new Corpus(new String(corpusTempName),CMDataType.PLAIN_TEXT,corpusViewer);
      c.addClass(new CorpusClass("String_Node_Str",ICorpusManagementConstants.DEFAULT_CLASSPATH,corpusViewer));
      corpusList.add(c);
      Object[] expandedItems=corpusViewer.getExpandedElements();
      corpusViewer.setInput(corpusList);
      corpusViewer.setExpandedElements(expandNewCorpus(expandedItems,c));
      corpusViewer.setSelection(new StructuredSelection(c),true);
    }
  }
);
  addClass.addSelectionListener(new SelectionAdapter(){
    @Override public void widgetSelected(    SelectionEvent e){
      IStructuredSelection selection=(IStructuredSelection)corpusViewer.getSelection();
      try {
        ICorpus corpusSelected=(selection.getFirstElement() instanceof ICorpus) ? (ICorpus)selection.getFirstElement() : (ICorpus)((ICorpusClass)selection.getFirstElement()).getParent();
        int corpusIndex=corpusList.indexOf(corpusSelected);
        StringBuilder classTempName=new StringBuilder("String_Node_Str");
        classTempName.append(corpusList.get(corpusIndex).getClasses().size() + 1);
        CorpusClass newClass=new CorpusClass(new String(classTempName),ICorpusManagementConstants.DEFAULT_CLASSPATH,corpusViewer);
        ((Corpus)corpusSelected).addClass(newClass);
        corpusList.set(corpusIndex,corpusSelected);
        corpusViewer.refresh();
        corpusViewer.setExpandedElements(expandNewCorpus(corpusViewer.getExpandedElements(),(Corpus)corpusList.get(corpusIndex)));
        corpusViewer.setSelection(new StructuredSelection(newClass),true);
      }
 catch (      Exception exp) {
      }
    }
  }
);
  final MessageDialog dg=new MessageDialog(corpusMgmtViewform.getShell(),"String_Node_Str",null,"String_Node_Str",MessageDialog.QUESTION_WITH_CANCEL,new String[]{IDialogConstants.YES_LABEL,IDialogConstants.NO_LABEL},0);
  remove.addSelectionListener(new SelectionAdapter(){
    @Override public void widgetSelected(    SelectionEvent e){
      IStructuredSelection selection=(IStructuredSelection)corpusViewer.getSelection();
      try {
switch (dg.open()) {
case 1:
          return;
      }
      Object selectedObj=selection.getFirstElement();
      if (selectedObj instanceof ICorpus) {
        ICorpus selectedCorpus=(ICorpus)selection.getFirstElement();
        corpusList.remove(selectedCorpus);
        ManageCorpora.removeCorpus((Corpus)selectedCorpus,true);
        deleteCorpus((Corpus)selectedCorpus);
      }
 else       if (selectedObj instanceof ICorpusClass) {
        ITreeSelection classSelection=(ITreeSelection)selection;
        ICorpusClass selectedClass=(ICorpusClass)selection.getFirstElement();
        Corpus parentCorpus=(Corpus)classSelection.getPaths()[0].getParentPath().getLastSegment();
        parentCorpus.removeClass(selectedClass);
        ManageCorpora.removeCorpus(parentCorpus,false);
      }
      corpusViewer.refresh();
      Display.getDefault().asyncExec(new Runnable(){
        @Override public void run(){
          corpusViewer.refresh();
        }
      }
);
    }
 catch (    Exception exp) {
    }
  }
}
);
}