Program: 92038
Project: 92038
Buggy source:
/** 
 * Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
 * @param parent a widget which will be the parent of the new instance (cannot be null)
 * @param style the style of widget to construct
 */
public TimeGraphCombo(Composite parent,int style){
  super(parent,style);
  setLayout(new FillLayout());
  final SashForm sash=new SashForm(this,SWT.NONE);
  fTreeViewer=new TreeViewer(sash,SWT.FULL_SELECTION | SWT.H_SCROLL);
  final Tree tree=fTreeViewer.getTree();
  tree.setHeaderVisible(true);
  tree.setLinesVisible(true);
  fTimeGraphViewer=new TimeGraphViewer(sash,SWT.NONE);
  fTimeGraphViewer.setItemHeight(getItemHeight(tree));
  fTimeGraphViewer.setHeaderHeight(tree.getHeaderHeight());
  fTimeGraphViewer.setBorderWidth(tree.getBorderWidth());
  fTimeGraphViewer.setNameWidthPref(0);
  fFilter=new RawViewerFilter();
  addFilter(fFilter);
  fFilterDialog=new TimeGraphFilterDialog(getShell());
  tree.addControlListener(new ControlAdapter(){
    private int depth=0;
    @Override public void controlResized(    ControlEvent e){
      if (depth == 0) {
        depth++;
        tree.getVerticalBar().setEnabled(false);
        tree.getVerticalBar().setVisible(false);
        depth--;
      }
      fTimeGraphViewer.setHeaderHeight(tree.getHeaderHeight());
    }
  }
);
  fTreeViewer.addTreeListener(new ITreeViewerListener(){
    @Override public void treeCollapsed(    TreeExpansionEvent event){
      fTimeGraphViewer.setExpandedState((ITimeGraphEntry)event.getElement(),false);
      List<TreeItem> treeItems=getVisibleExpandedItems(tree);
      if (treeItems.size() == 0) {
        return;
      }
      TreeItem treeItem=treeItems.get(fTimeGraphViewer.getTopIndex());
      tree.setTopItem(treeItem);
    }
    @Override public void treeExpanded(    TreeExpansionEvent event){
      fTimeGraphViewer.setExpandedState((ITimeGraphEntry)event.getElement(),true);
      List<TreeItem> treeItems=getVisibleExpandedItems(tree);
      if (treeItems.size() == 0) {
        return;
      }
      final TreeItem treeItem=treeItems.get(fTimeGraphViewer.getTopIndex());
      getDisplay().asyncExec(new Runnable(){
        @Override public void run(){
          tree.setTopItem(treeItem);
        }
      }
);
    }
  }
);
  fTimeGraphViewer.addTreeListener(new ITimeGraphTreeListener(){
    @Override public void treeCollapsed(    TimeGraphTreeExpansionEvent event){
      fTreeViewer.setExpandedState(event.getEntry(),false);
    }
    @Override public void treeExpanded(    TimeGraphTreeExpansionEvent event){
      fTreeViewer.setExpandedState(event.getEntry(),true);
    }
  }
);
  tree.addListener(SWT.MouseDown,new Listener(){
    @Override public void handleEvent(    Event event){
      TreeItem treeItem=tree.getItem(new Point(event.x,event.y));
      if (treeItem == null || treeItem.getData() == FILLER) {
        event.doit=false;
        List<TreeItem> treeItems=getVisibleExpandedItems(tree);
        if (treeItems.size() == 0) {
          fTreeViewer.setSelection(new StructuredSelection());
          fTimeGraphViewer.setSelection(null);
          return;
        }
        tree.select(treeItems.get(treeItems.size() - 1));
        fTreeViewer.setSelection(new StructuredSelection());
        fTimeGraphViewer.setSelection(null);
      }
    }
  }
);
  tree.addListener(SWT.MouseWheel,new Listener(){
    @Override public void handleEvent(    Event event){
      event.doit=false;
      Slider scrollBar=fTimeGraphViewer.getVerticalBar();
      fTimeGraphViewer.setTopIndex(scrollBar.getSelection() - event.count);
      List<TreeItem> treeItems=getVisibleExpandedItems(tree);
      if (treeItems.size() == 0) {
        return;
      }
      TreeItem treeItem=treeItems.get(fTimeGraphViewer.getTopIndex());
      tree.setTopItem(treeItem);
    }
  }
);
  tree.addListener(SWT.KeyDown,new Listener(){
    @Override public void handleEvent(    Event event){
      List<TreeItem> treeItems=getVisibleExpandedItems(tree);
      if (treeItems.size() == 0) {
        fTreeViewer.setSelection(new StructuredSelection());
        event.doit=false;
        return;
      }
      if (event.keyCode == SWT.ARROW_DOWN) {
        int index=Math.min(fTimeGraphViewer.getSelectionIndex() + 1,treeItems.size() - 1);
        fTimeGraphViewer.setSelection((ITimeGraphEntry)treeItems.get(index).getData());
        event.doit=false;
      }
 else       if (event.keyCode == SWT.PAGE_DOWN) {
        int height=tree.getSize().y - tree.getHeaderHeight() - tree.getHorizontalBar().getSize().y;
        int countPerPage=height / getItemHeight(tree);
        int index=Math.min(fTimeGraphViewer.getSelectionIndex() + countPerPage - 1,treeItems.size() - 1);
        fTimeGraphViewer.setSelection((ITimeGraphEntry)treeItems.get(index).getData());
        event.doit=false;
      }
 else       if (event.keyCode == SWT.END) {
        fTimeGraphViewer.setSelection((ITimeGraphEntry)treeItems.get(treeItems.size() - 1).getData());
        event.doit=false;
      }
      TreeItem treeItem=treeItems.get(fTimeGraphViewer.getTopIndex());
      tree.setTopItem(treeItem);
      if (fTimeGraphViewer.getSelectionIndex() >= 0) {
        fTreeViewer.setSelection(new StructuredSelection(fTimeGraphViewer.getSelection()));
      }
 else {
        fTreeViewer.setSelection(new StructuredSelection());
      }
    }
  }
);
  fTimeGraphViewer.getTimeGraphControl().addControlListener(new ControlAdapter(){
    @Override public void controlResized(    ControlEvent e){
      List<TreeItem> treeItems=getVisibleExpandedItems(tree);
      if (treeItems.size() == 0) {
        return;
      }
      TreeItem treeItem=treeItems.get(fTimeGraphViewer.getTopIndex());
      tree.setTopItem(treeItem);
    }
  }
);
  fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener(){
    @Override public void selectionChanged(    SelectionChangedEvent event){
      if (fInhibitTreeSelection) {
        return;
      }
      if (event.getSelection() instanceof IStructuredSelection) {
        Object selection=((IStructuredSelection)event.getSelection()).getFirstElement();
        if (selection instanceof ITimeGraphEntry) {
          fTimeGraphViewer.setSelection((ITimeGraphEntry)selection);
        }
        List<TreeItem> treeItems=getVisibleExpandedItems(tree);
        if (treeItems.size() == 0) {
          return;
        }
        TreeItem treeItem=treeItems.get(fTimeGraphViewer.getTopIndex());
        tree.setTopItem(treeItem);
      }
    }
  }
);
  fTimeGraphViewer.addSelectionListener(new ITimeGraphSelectionListener(){
    @Override public void selectionChanged(    TimeGraphSelectionEvent event){
      ITimeGraphEntry entry=fTimeGraphViewer.getSelection();
      fInhibitTreeSelection=true;
      if (entry != null) {
        StructuredSelection selection=new StructuredSelection(entry);
        fTreeViewer.setSelection(selection);
      }
 else {
        fTreeViewer.setSelection(new StructuredSelection());
      }
      fInhibitTreeSelection=false;
      List<TreeItem> treeItems=getVisibleExpandedItems(tree);
      if (treeItems.size() == 0) {
        return;
      }
      TreeItem treeItem=treeItems.get(fTimeGraphViewer.getTopIndex());
      tree.setTopItem(treeItem);
    }
  }
);
  fTimeGraphViewer.getVerticalBar().addSelectionListener(new SelectionAdapter(){
    @Override public void widgetSelected(    SelectionEvent e){
      List<TreeItem> treeItems=getVisibleExpandedItems(tree);
      if (treeItems.size() == 0) {
        return;
      }
      TreeItem treeItem=treeItems.get(fTimeGraphViewer.getTopIndex());
      tree.setTopItem(treeItem);
    }
  }
);
  fTimeGraphViewer.getTimeGraphControl().addMouseWheelListener(new MouseWheelListener(){
    @Override public void mouseScrolled(    MouseEvent e){
      List<TreeItem> treeItems=getVisibleExpandedItems(tree);
      if (treeItems.size() == 0) {
        return;
      }
      TreeItem treeItem=treeItems.get(fTimeGraphViewer.getTopIndex());
      tree.setTopItem(treeItem);
    }
  }
);
  fTreeViewer.getControl().addMouseTrackListener(new MouseTrackAdapter(){
    @Override public void mouseEnter(    MouseEvent e){
      if (fTimeGraphViewer.getTimeGraphControl().isFocusControl()) {
        fTreeViewer.getControl().setFocus();
      }
    }
  }
);
  fTimeGraphViewer.getTimeGraphControl().addMouseTrackListener(new MouseTrackAdapter(){
    @Override public void mouseEnter(    MouseEvent e){
      if (fTreeViewer.getControl().isFocusControl()) {
        fTimeGraphViewer.getTimeGraphControl().setFocus();
      }
    }
  }
);
  fTimeGraphViewer.getTimeGraphScale().addMouseTrackListener(new MouseTrackAdapter(){
    @Override public void mouseEnter(    MouseEvent e){
      if (fTreeViewer.getControl().isFocusControl()) {
        fTimeGraphViewer.getTimeGraphControl().setFocus();
      }
    }
  }
);
  fNumFillerRows=Display.getDefault().getBounds().height / getItemHeight(tree);
  sash.setWeights(new int[]{1,1});
}

Fixed version (ground truth):
/** 
 * Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
 * @param parent a widget which will be the parent of the new instance (cannot be null)
 * @param style the style of widget to construct
 */
public TimeGraphCombo(Composite parent,int style){
  super(parent,style);
  setLayout(new FillLayout());
  final SashForm sash=new SashForm(this,SWT.NONE);
  fTreeViewer=new TreeViewer(sash,SWT.FULL_SELECTION | SWT.H_SCROLL);
  final Tree tree=fTreeViewer.getTree();
  tree.setHeaderVisible(true);
  tree.setLinesVisible(true);
  fTimeGraphViewer=new TimeGraphViewer(sash,SWT.NONE);
  fTimeGraphViewer.setItemHeight(getItemHeight(tree));
  fTimeGraphViewer.setHeaderHeight(tree.getHeaderHeight());
  fTimeGraphViewer.setBorderWidth(tree.getBorderWidth());
  fTimeGraphViewer.setNameWidthPref(0);
  fFilter=new RawViewerFilter();
  addFilter(fFilter);
  fFilterDialog=new TimeGraphFilterDialog(getShell());
  tree.addControlListener(new ControlAdapter(){
    private int depth=0;
    @Override public void controlResized(    ControlEvent e){
      if (depth == 0) {
        depth++;
        tree.getVerticalBar().setEnabled(false);
        tree.getVerticalBar().setVisible(false);
        depth--;
      }
      fTimeGraphViewer.setHeaderHeight(tree.getHeaderHeight());
    }
  }
);
  fTreeViewer.addTreeListener(new ITreeViewerListener(){
    @Override public void treeCollapsed(    TreeExpansionEvent event){
      fTimeGraphViewer.setExpandedState((ITimeGraphEntry)event.getElement(),false);
      List<TreeItem> treeItems=getVisibleExpandedItems(tree);
      if (treeItems.size() == 0) {
        return;
      }
      TreeItem treeItem=treeItems.get(fTimeGraphViewer.getTopIndex());
      tree.setTopItem(treeItem);
    }
    @Override public void treeExpanded(    TreeExpansionEvent event){
      ITimeGraphEntry entry=(ITimeGraphEntry)event.getElement();
      fTimeGraphViewer.setExpandedState(entry,true);
      for (      ITimeGraphEntry child : entry.getChildren()) {
        boolean expanded=fTreeViewer.getExpandedState(child);
        fTimeGraphViewer.setExpandedState(child,expanded);
      }
      List<TreeItem> treeItems=getVisibleExpandedItems(tree);
      if (treeItems.size() == 0) {
        return;
      }
      final TreeItem treeItem=treeItems.get(fTimeGraphViewer.getTopIndex());
      getDisplay().asyncExec(new Runnable(){
        @Override public void run(){
          tree.setTopItem(treeItem);
        }
      }
);
    }
  }
);
  fTimeGraphViewer.addTreeListener(new ITimeGraphTreeListener(){
    @Override public void treeCollapsed(    TimeGraphTreeExpansionEvent event){
      fTreeViewer.setExpandedState(event.getEntry(),false);
    }
    @Override public void treeExpanded(    TimeGraphTreeExpansionEvent event){
      ITimeGraphEntry entry=event.getEntry();
      fTreeViewer.setExpandedState(entry,true);
      for (      ITimeGraphEntry child : entry.getChildren()) {
        boolean expanded=fTreeViewer.getExpandedState(child);
        fTimeGraphViewer.setExpandedState(child,expanded);
      }
    }
  }
);
  tree.addListener(SWT.MouseDown,new Listener(){
    @Override public void handleEvent(    Event event){
      TreeItem treeItem=tree.getItem(new Point(event.x,event.y));
      if (treeItem == null || treeItem.getData() == FILLER) {
        event.doit=false;
        List<TreeItem> treeItems=getVisibleExpandedItems(tree);
        if (treeItems.size() == 0) {
          fTreeViewer.setSelection(new StructuredSelection());
          fTimeGraphViewer.setSelection(null);
          return;
        }
        tree.select(treeItems.get(treeItems.size() - 1));
        fTreeViewer.setSelection(new StructuredSelection());
        fTimeGraphViewer.setSelection(null);
      }
    }
  }
);
  tree.addListener(SWT.MouseWheel,new Listener(){
    @Override public void handleEvent(    Event event){
      event.doit=false;
      Slider scrollBar=fTimeGraphViewer.getVerticalBar();
      fTimeGraphViewer.setTopIndex(scrollBar.getSelection() - event.count);
      List<TreeItem> treeItems=getVisibleExpandedItems(tree);
      if (treeItems.size() == 0) {
        return;
      }
      TreeItem treeItem=treeItems.get(fTimeGraphViewer.getTopIndex());
      tree.setTopItem(treeItem);
    }
  }
);
  tree.addListener(SWT.KeyDown,new Listener(){
    @Override public void handleEvent(    Event event){
      List<TreeItem> treeItems=getVisibleExpandedItems(tree);
      if (treeItems.size() == 0) {
        fTreeViewer.setSelection(new StructuredSelection());
        event.doit=false;
        return;
      }
      if (event.keyCode == SWT.ARROW_DOWN) {
        int index=Math.min(fTimeGraphViewer.getSelectionIndex() + 1,treeItems.size() - 1);
        fTimeGraphViewer.setSelection((ITimeGraphEntry)treeItems.get(index).getData());
        event.doit=false;
      }
 else       if (event.keyCode == SWT.PAGE_DOWN) {
        int height=tree.getSize().y - tree.getHeaderHeight() - tree.getHorizontalBar().getSize().y;
        int countPerPage=height / getItemHeight(tree);
        int index=Math.min(fTimeGraphViewer.getSelectionIndex() + countPerPage - 1,treeItems.size() - 1);
        fTimeGraphViewer.setSelection((ITimeGraphEntry)treeItems.get(index).getData());
        event.doit=false;
      }
 else       if (event.keyCode == SWT.END) {
        fTimeGraphViewer.setSelection((ITimeGraphEntry)treeItems.get(treeItems.size() - 1).getData());
        event.doit=false;
      }
      TreeItem treeItem=treeItems.get(fTimeGraphViewer.getTopIndex());
      tree.setTopItem(treeItem);
      if (fTimeGraphViewer.getSelectionIndex() >= 0) {
        fTreeViewer.setSelection(new StructuredSelection(fTimeGraphViewer.getSelection()));
      }
 else {
        fTreeViewer.setSelection(new StructuredSelection());
      }
    }
  }
);
  fTimeGraphViewer.getTimeGraphControl().addControlListener(new ControlAdapter(){
    @Override public void controlResized(    ControlEvent e){
      List<TreeItem> treeItems=getVisibleExpandedItems(tree);
      if (treeItems.size() == 0) {
        return;
      }
      TreeItem treeItem=treeItems.get(fTimeGraphViewer.getTopIndex());
      tree.setTopItem(treeItem);
    }
  }
);
  fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener(){
    @Override public void selectionChanged(    SelectionChangedEvent event){
      if (fInhibitTreeSelection) {
        return;
      }
      if (event.getSelection() instanceof IStructuredSelection) {
        Object selection=((IStructuredSelection)event.getSelection()).getFirstElement();
        if (selection instanceof ITimeGraphEntry) {
          fTimeGraphViewer.setSelection((ITimeGraphEntry)selection);
        }
        List<TreeItem> treeItems=getVisibleExpandedItems(tree);
        if (treeItems.size() == 0) {
          return;
        }
        TreeItem treeItem=treeItems.get(fTimeGraphViewer.getTopIndex());
        tree.setTopItem(treeItem);
      }
    }
  }
);
  fTimeGraphViewer.addSelectionListener(new ITimeGraphSelectionListener(){
    @Override public void selectionChanged(    TimeGraphSelectionEvent event){
      ITimeGraphEntry entry=fTimeGraphViewer.getSelection();
      fInhibitTreeSelection=true;
      if (entry != null) {
        StructuredSelection selection=new StructuredSelection(entry);
        fTreeViewer.setSelection(selection);
      }
 else {
        fTreeViewer.setSelection(new StructuredSelection());
      }
      fInhibitTreeSelection=false;
      List<TreeItem> treeItems=getVisibleExpandedItems(tree);
      if (treeItems.size() == 0) {
        return;
      }
      TreeItem treeItem=treeItems.get(fTimeGraphViewer.getTopIndex());
      tree.setTopItem(treeItem);
    }
  }
);
  fTimeGraphViewer.getVerticalBar().addSelectionListener(new SelectionAdapter(){
    @Override public void widgetSelected(    SelectionEvent e){
      List<TreeItem> treeItems=getVisibleExpandedItems(tree);
      if (treeItems.size() == 0) {
        return;
      }
      TreeItem treeItem=treeItems.get(fTimeGraphViewer.getTopIndex());
      tree.setTopItem(treeItem);
    }
  }
);
  fTimeGraphViewer.getTimeGraphControl().addMouseWheelListener(new MouseWheelListener(){
    @Override public void mouseScrolled(    MouseEvent e){
      List<TreeItem> treeItems=getVisibleExpandedItems(tree);
      if (treeItems.size() == 0) {
        return;
      }
      TreeItem treeItem=treeItems.get(fTimeGraphViewer.getTopIndex());
      tree.setTopItem(treeItem);
    }
  }
);
  fTreeViewer.getControl().addMouseTrackListener(new MouseTrackAdapter(){
    @Override public void mouseEnter(    MouseEvent e){
      if (fTimeGraphViewer.getTimeGraphControl().isFocusControl()) {
        fTreeViewer.getControl().setFocus();
      }
    }
  }
);
  fTimeGraphViewer.getTimeGraphControl().addMouseTrackListener(new MouseTrackAdapter(){
    @Override public void mouseEnter(    MouseEvent e){
      if (fTreeViewer.getControl().isFocusControl()) {
        fTimeGraphViewer.getTimeGraphControl().setFocus();
      }
    }
  }
);
  fTimeGraphViewer.getTimeGraphScale().addMouseTrackListener(new MouseTrackAdapter(){
    @Override public void mouseEnter(    MouseEvent e){
      if (fTreeViewer.getControl().isFocusControl()) {
        fTimeGraphViewer.getTimeGraphControl().setFocus();
      }
    }
  }
);
  fNumFillerRows=Display.getDefault().getBounds().height / getItemHeight(tree);
  sash.setWeights(new int[]{1,1});
}