Program: 92852
Project: 92852
Buggy source:
/** 
 * This is a callback that will allow us to create the viewer and initialize it.
 */
@Override public void createPartControl(Composite parent){
  scrollFrame=new ScrolledComposite(parent,SWT.V_SCROLL);
  scrollFrame.setExpandVertical(true);
  scrollFrame.setExpandHorizontal(true);
  scrollFrame.setAlwaysShowScrollBars(true);
  SashForm sash=new SashForm(scrollFrame,SWT.NONE);
  scrollFrame.setContent(sash);
  tableViewer=new TableViewer(sash,SWT.FULL_SELECTION | SWT.H_SCROLL);
  tableViewer.setContentProvider(new ViewContentProvider(tableViewer));
  tableViewer.setLabelProvider(new ViewLabelProvider());
  Table table=tableViewer.getTable();
  tableViewer.addSelectionChangedListener(new ISelectionChangedListener(){
    @Override public void selectionChanged(    SelectionChangedEvent event){
      ISelection sel=event.getSelection();
      if (!sel.isEmpty()) {
        Object firstSel=null;
        if (sel instanceof IStructuredSelection) {
          firstSel=((IStructuredSelection)sel).getFirstElement();
          updateScrollOrigin();
          if (firstSel instanceof ITmfTimeAnalysisEntry) {
            ITmfTimeAnalysisEntry trace=(ITmfTimeAnalysisEntry)firstSel;
            tsfviewer.setSelectedTrace(trace);
          }
        }
      }
    }
    /** 
 * Make sure the selected item is visible
 */
    private void updateScrollOrigin(){
      Table table=tableViewer.getTable();
      if (table != null && table.getItemCount() > 0) {
        TableItem item=table.getSelection()[0];
        if (item == null) {
          return;
        }
        Rectangle itemRect=item.getBounds();
        int step=itemRect.height;
        int hscrolly=0;
        ScrollBar hbar=scrollFrame.getHorizontalBar();
        if (hbar != null) {
          hscrolly=hbar.getSize().y;
        }
        int visibleHeight=scrollFrame.getSize().y - hscrolly;
        Point origin=scrollFrame.getOrigin();
        int endy=origin.y + visibleHeight;
        int itemStartPos=itemRect.y + table.getHeaderHeight() + table.getBorderWidth()+ table.getParent().getBorderWidth();
        int itemEndPos=itemStartPos + step;
        if (origin.y >= step && itemStartPos < origin.y) {
          scrollFrame.setOrigin(origin.x,origin.y - step);
        }
        if (itemEndPos > endy) {
          scrollFrame.setOrigin(origin.x,origin.y + step);
        }
      }
    }
  }
);
  tableViewer.getTable().addKeyListener(new KeyListener(){
    @Override public void keyPressed(    KeyEvent e){
      Table table=tableViewer.getTable();
      Point origin=scrollFrame.getOrigin();
      if (table == null || table.getItemCount() < 1) {
        return;
      }
      TableItem item;
      int count;
switch (e.keyCode) {
case SWT.PAGE_DOWN:
        updateScrollPageDown();
      break;
case SWT.PAGE_UP:
    updateScrollUp();
  break;
case SWT.HOME:
count=table.getItemCount();
item=table.getItem(0);
scrollFrame.setOrigin(origin.x,0);
break;
case SWT.END:
count=table.getItemCount();
item=table.getItem(count - 1);
int itemStartPos=item.getBounds().y;
scrollFrame.setOrigin(origin.x,itemStartPos);
break;
default :
break;
}
}
@Override public void keyReleased(KeyEvent e){
}
/** 
 * Scroll one page down
 */
private void updateScrollPageDown(){
Table table=tableViewer.getTable();
int step=table.getItemHeight();
int hscrolly=0;
ScrollBar hbar=scrollFrame.getHorizontalBar();
if (hbar != null) {
hscrolly=hbar.getSize().y;
}
Point origin=scrollFrame.getOrigin();
int visibleHeight=scrollFrame.getSize().y - hscrolly;
int endy=origin.y + visibleHeight;
scrollFrame.setOrigin(origin.x,endy - step);
}
/** 
 * Scroll one page up
 */
private void updateScrollUp(){
Table table=tableViewer.getTable();
int step=table.getItemHeight();
int hscrolly=0;
ScrollBar hbar=scrollFrame.getHorizontalBar();
if (hbar != null) {
hscrolly=hbar.getSize().y;
}
Point origin=scrollFrame.getOrigin();
int visibleHeight=scrollFrame.getSize().y - hscrolly;
int pageUpPos=origin.y - visibleHeight + step;
pageUpPos=pageUpPos > 0 ? pageUpPos : 0;
scrollFrame.setOrigin(origin.x,pageUpPos);
}
}
);
applyTableLayout(table);
int borderWidth=table.getBorderWidth();
int itemHeight=table.getItemHeight() + getTableItemHeightAdjustement();
int headerHeight=table.getHeaderHeight();
table.getVerticalBar().setVisible(false);
tsfviewer=TmfViewerFactory.createViewer(sash,new TimeRangeViewerProvider(getParamsUpdater()));
tsfviewer.groupTraces(false);
tsfviewer.setItemHeight(itemHeight);
tsfviewer.setBorderWidth(borderWidth);
tsfviewer.setHeaderHeight(headerHeight);
tsfviewer.setVisibleVerticalScroll(false);
tsfviewer.setNameWidthPref(0);
tsfviewer.setAcceptSelectionAPIcalls(true);
tsfviewer.addWidgetSelectionListner(this);
tsfviewer.addFilterSelectionListner(this);
tsfviewer.addWidgetTimeScaleSelectionListner(this);
sash.setWeights(new int[]{1,1});
PlatformUI.getWorkbench().getHelpSystem().setHelp(tableViewer.getControl(),"String_Node_Str");
makeActions();
hookContextMenu();
hookDoubleClickAction();
contributeToActionBars();
int timeSpaceWidth=tsfviewer.getTimeSpace();
if (timeSpaceWidth < 0) {
timeSpaceWidth=-timeSpaceWidth;
}
TmfExperiment<?> experiment=TmfExperiment.getCurrentExperiment();
if (experiment != null) {
TmfTimeRange experimentTRange=experiment.getTimeRange();
TmfTimeRange adjustedTimeRange=initialExperimentDataRequest(this,experimentTRange);
ModelUpdateInit(experimentTRange,adjustedTimeRange,this);
}
 else {
TraceDebug.debug("String_Node_Str");
}
}

Fixed version (ground truth):
/** 
 * This is a callback that will allow us to create the viewer and initialize it.
 */
@Override public void createPartControl(Composite parent){
  scrollFrame=new ScrolledComposite(parent,SWT.V_SCROLL);
  scrollFrame.setExpandVertical(true);
  scrollFrame.setExpandHorizontal(true);
  scrollFrame.setAlwaysShowScrollBars(true);
  SashForm sash=new SashForm(scrollFrame,SWT.NONE);
  scrollFrame.setContent(sash);
  tableViewer=new TableViewer(sash,SWT.FULL_SELECTION | SWT.H_SCROLL);
  tableViewer.setContentProvider(new ViewContentProvider(tableViewer));
  tableViewer.setLabelProvider(new ViewLabelProvider());
  Table table=tableViewer.getTable();
  tableViewer.addSelectionChangedListener(new ISelectionChangedListener(){
    @Override public void selectionChanged(    SelectionChangedEvent event){
      ISelection sel=event.getSelection();
      if (!sel.isEmpty()) {
        Object firstSel=null;
        if (sel instanceof IStructuredSelection) {
          firstSel=((IStructuredSelection)sel).getFirstElement();
          updateScrollOrigin();
          if (firstSel instanceof ITmfTimeAnalysisEntry) {
            ITmfTimeAnalysisEntry trace=(ITmfTimeAnalysisEntry)firstSel;
            tsfviewer.setSelectedTrace(trace);
          }
        }
      }
    }
    /** 
 * Make sure the selected item is visible
 */
    private void updateScrollOrigin(){
      Table table=tableViewer.getTable();
      if (table != null && table.getItemCount() > 0) {
        TableItem item=table.getSelection()[0];
        if (item == null) {
          return;
        }
        Rectangle itemRect=item.getBounds();
        int step=itemRect.height;
        int hscrolly=0;
        ScrollBar hbar=scrollFrame.getHorizontalBar();
        if (hbar != null) {
          hscrolly=hbar.getSize().y;
        }
        int visibleHeight=scrollFrame.getSize().y - hscrolly;
        Point origin=scrollFrame.getOrigin();
        int endy=origin.y + visibleHeight;
        int itemStartPos=itemRect.y + table.getHeaderHeight() + table.getBorderWidth()+ table.getParent().getBorderWidth();
        int itemEndPos=itemStartPos + step;
        if (origin.y >= step && itemStartPos < origin.y) {
          scrollFrame.setOrigin(origin.x,origin.y - step);
        }
        if (itemEndPos > endy) {
          scrollFrame.setOrigin(origin.x,origin.y + step);
        }
      }
    }
  }
);
  tableViewer.getTable().addKeyListener(new KeyListener(){
    @Override public void keyPressed(    KeyEvent e){
      Table table=tableViewer.getTable();
      Point origin=scrollFrame.getOrigin();
      if (table == null || table.getItemCount() < 1) {
        return;
      }
      TableItem item;
      int count;
switch (e.keyCode) {
case SWT.PAGE_DOWN:
        updateScrollPageDown();
      break;
case SWT.PAGE_UP:
    updateScrollUp();
  break;
case SWT.HOME:
count=table.getItemCount();
item=table.getItem(0);
scrollFrame.setOrigin(origin.x,0);
break;
case SWT.END:
count=table.getItemCount();
item=table.getItem(count - 1);
int itemStartPos=item.getBounds().y;
scrollFrame.setOrigin(origin.x,itemStartPos);
break;
default :
break;
}
}
@Override public void keyReleased(KeyEvent e){
}
/** 
 * Scroll one page down
 */
private void updateScrollPageDown(){
Table table=tableViewer.getTable();
int step=table.getItemHeight();
int hscrolly=0;
ScrollBar hbar=scrollFrame.getHorizontalBar();
if (hbar != null) {
hscrolly=hbar.getSize().y;
}
Point origin=scrollFrame.getOrigin();
int visibleHeight=scrollFrame.getSize().y - hscrolly;
int endy=origin.y + visibleHeight;
scrollFrame.setOrigin(origin.x,endy - step);
}
/** 
 * Scroll one page up
 */
private void updateScrollUp(){
Table table=tableViewer.getTable();
int step=table.getItemHeight();
int hscrolly=0;
ScrollBar hbar=scrollFrame.getHorizontalBar();
if (hbar != null) {
hscrolly=hbar.getSize().y;
}
Point origin=scrollFrame.getOrigin();
int visibleHeight=scrollFrame.getSize().y - hscrolly;
int pageUpPos=origin.y - visibleHeight + step;
pageUpPos=pageUpPos > 0 ? pageUpPos : 0;
scrollFrame.setOrigin(origin.x,pageUpPos);
}
}
);
applyTableLayout(table);
int borderWidth=table.getBorderWidth();
int itemHeight=table.getItemHeight() + getTableItemHeightAdjustement();
int headerHeight=table.getHeaderHeight();
table.getVerticalBar().setVisible(false);
tsfviewer=TmfViewerFactory.createViewer(sash,new FlowTimeRangeViewerProvider(getParamsUpdater()));
tsfviewer.groupTraces(false);
tsfviewer.setItemHeight(itemHeight);
tsfviewer.setBorderWidth(borderWidth);
tsfviewer.setHeaderHeight(headerHeight);
tsfviewer.setVisibleVerticalScroll(false);
tsfviewer.setNameWidthPref(0);
tsfviewer.setAcceptSelectionAPIcalls(true);
tsfviewer.addWidgetSelectionListner(this);
tsfviewer.addFilterSelectionListner(this);
tsfviewer.addWidgetTimeScaleSelectionListner(this);
sash.setWeights(new int[]{1,1});
PlatformUI.getWorkbench().getHelpSystem().setHelp(tableViewer.getControl(),"String_Node_Str");
makeActions();
hookContextMenu();
hookDoubleClickAction();
contributeToActionBars();
int timeSpaceWidth=tsfviewer.getTimeSpace();
if (timeSpaceWidth < 0) {
timeSpaceWidth=-timeSpaceWidth;
}
TmfExperiment<?> experiment=TmfExperiment.getCurrentExperiment();
if (experiment != null) {
TmfTimeRange experimentTRange=experiment.getTimeRange();
TmfTimeRange adjustedTimeRange=initialExperimentDataRequest(this,experimentTRange);
ModelUpdateInit(experimentTRange,adjustedTimeRange,this);
}
 else {
TraceDebug.debug("String_Node_Str");
}
}