Program: 68172
Project: 68172
Buggy source:
public void handleEvent(Event event){
  if (event.type == IChartDataSheet.EVENT_QUERY) {
    if (event.detail == IChartDataSheet.DETAIL_UPDATE_COLOR_AND_TEXT) {
      updateColorAndText();
    }
 else     if (event.detail == IChartDataSheet.DETAIL_UPDATE_COLOR && event.data instanceof ISelectDataComponent) {
      refreshTableColor();
    }
    return;
  }
  if (event.type == CustomPreviewTable.MOUSE_RIGHT_CLICK_TYPE) {
    if (getDataServiceProvider().getDataSet() != null || getDataServiceProvider().getInheritedDataSet() != null) {
      if (event.widget instanceof Button) {
        Button header=(Button)event.widget;
        boolean isSharingChart=dataProvider.checkState(IDataServiceProvider.SHARE_CHART_QUERY);
        if (header.getMenu() == null && !isSharingChart) {
          header.setMenu(createMenuManager(event.data).createContextMenu(tablePreview));
        }
        if (event.doit && !isSharingChart) {
          header.getMenu().setVisible(true);
        }
      }
    }
  }
 else   if (event.type == SWT.Selection) {
    if (event.widget instanceof MenuItem) {
      MenuItem item=(MenuItem)event.widget;
      IAction action=(IAction)item.getData();
      action.setChecked(!action.isChecked());
      action.run();
    }
 else     if (event.widget == btnFilters) {
      if (invokeEditFilter() == Window.OK) {
        refreshDataPreviewPane();
        fireEvent(btnFilters,EVENT_PREVIEW);
      }
    }
 else     if (event.widget == btnParameters) {
      if (invokeEditParameter() == Window.OK) {
        refreshDataPreviewPane();
        fireEvent(btnParameters,EVENT_PREVIEW);
      }
    }
 else     if (event.widget == btnBinding) {
      if (invokeDataBinding() == Window.OK) {
        refreshDataPreviewPane();
        fireEvent(btnBinding,EVENT_PREVIEW);
      }
    }
    try {
      if (event.widget == btnInherit) {
        ColorPalette.getInstance().restore();
        if (!btnInherit.getSelection()) {
          return;
        }
        if (bIsInheritSelected) {
          return;
        }
        bIsInheritSelected=true;
        getDataServiceProvider().setReportItemReference(null);
        getDataServiceProvider().setDataCube(null);
        getDataServiceProvider().setDataSet(null);
        switchDataSet(null);
        cmbDataItems.select(0);
        currentData=null;
        cmbDataItems.setEnabled(false);
        cmbInherit.setEnabled(!isInheritingSummaryTable() && getDataServiceProvider().getInheritedDataSet() != null && ChartReportItemUtil.isContainerInheritable(itemHandle));
        setEnabledForButtons();
        updateDragDataSource();
        updatePredefinedQueries();
      }
 else       if (event.widget == btnUseData) {
        if (!btnUseData.getSelection()) {
          return;
        }
        if (!bIsInheritSelected) {
          return;
        }
        bIsInheritSelected=false;
        getDataServiceProvider().setReportItemReference(null);
        getDataServiceProvider().setDataSet(null);
        selectDataSet();
        cmbDataItems.setEnabled(true);
        cmbInherit.setEnabled(false);
        setEnabledForButtons();
        updateDragDataSource();
        updatePredefinedQueries();
      }
 else       if (event.widget == cmbInherit) {
        getContext().setInheritColumnsOnly(cmbInherit.getSelectionIndex() == 1);
        setEnabledForButtons();
        fireEvent(btnBinding,EVENT_QUERY);
        refreshDataPreviewPane();
      }
 else       if (event.widget == cmbDataItems) {
        ColorPalette.getInstance().restore();
        int selectedIndex=cmbDataItems.getSelectionIndex();
        Integer selectState=selectDataTypes.get(selectedIndex);
switch (selectState.intValue()) {
case SELECT_NONE:
          btnInherit.setSelection(true);
        btnUseData.setSelection(false);
      btnInherit.notifyListeners(SWT.Selection,new Event());
    break;
case SELECT_NEXT:
  selectedIndex++;
selectState=selectDataTypes.get(selectedIndex);
cmbDataItems.select(selectedIndex);
break;
}
switch (selectState.intValue()) {
case SELECT_DATA_SET:
if (getDataServiceProvider().getReportItemReference() == null && getDataServiceProvider().getDataSet() != null && getDataServiceProvider().getDataSet().equals(ChartUIUtil.getText(cmbDataItems))) {
return;
}
getDataServiceProvider().setDataSet(ChartUIUtil.getText(cmbDataItems));
currentData=ChartUIUtil.getText(cmbDataItems);
switchDataSet(ChartUIUtil.getText(cmbDataItems));
setEnabledForButtons();
updateDragDataSource();
break;
case SELECT_DATA_CUBE:
getDataServiceProvider().setDataCube(ChartUIUtil.getText(cmbDataItems));
currentData=ChartUIUtil.getText(cmbDataItems);
updateDragDataSource();
setEnabledForButtons();
DataDefinitionTextManager.getInstance().refreshAll();
fireEvent(tablePreview,EVENT_PREVIEW);
break;
case SELECT_REPORT_ITEM:
if (ChartUIUtil.getText(cmbDataItems).equals(getDataServiceProvider().getReportItemReference())) {
return;
}
getDataServiceProvider().setReportItemReference(ChartUIUtil.getText(cmbDataItems));
ChartReportItemUtil.reviseChartModel(ChartReportItemUtil.REVISE_REFERENCE_REPORT_ITEM,this.getContext().getModel(),itemHandle);
if (this.getDataServiceProvider().checkState(IDataServiceProvider.SHARE_CHART_QUERY)) {
ChartAdapter.beginIgnoreNotifications();
this.getDataServiceProvider().update(ChartUIConstants.COPY_SERIES_DEFINITION,null);
ChartAdapter.endIgnoreNotifications();
}
currentData=ChartUIUtil.getText(cmbDataItems);
DataDefinitionTextManager.getInstance().refreshAll();
fireEvent(tablePreview,EVENT_PREVIEW);
setEnabledForButtons();
updateDragDataSource();
break;
case SELECT_NEW_DATASET:
int result=invokeNewDataSet();
if (result == Window.CANCEL) {
if (currentData == null) {
cmbDataItems.select(0);
}
 else {
cmbDataItems.setText(currentData);
}
return;
}
cmbDataItems.removeAll();
cmbDataItems.setItems(createDataComboItems());
String[] datasets=getDataServiceProvider().getAllDataSets();
currentData=datasets[datasets.length - 1];
getDataServiceProvider().setDataSet(currentData);
cmbDataItems.setText(currentData);
setEnabledForButtons();
updateDragDataSource();
break;
case SELECT_NEW_DATACUBE:
if (getDataServiceProvider().getAllDataSets().length == 0) {
invokeNewDataSet();
}
int count=getDataServiceProvider().getAllDataCubes().length;
if (getDataServiceProvider().getAllDataSets().length != 0) {
new NewCubeAction().run();
}
String[] datacubes=getDataServiceProvider().getAllDataCubes();
cmbDataItems.removeAll();
cmbDataItems.setItems(createDataComboItems());
if (datacubes.length == count) {
if (currentData == null) {
cmbDataItems.select(0);
}
 else {
cmbDataItems.setText(currentData);
}
return;
}
currentData=datacubes[datacubes.length - 1];
getDataServiceProvider().setDataCube(currentData);
cmbDataItems.setText(currentData);
updateDragDataSource();
setEnabledForButtons();
DataDefinitionTextManager.getInstance().refreshAll();
fireEvent(tablePreview,EVENT_PREVIEW);
break;
}
updatePredefinedQueries();
}
 else if (event.widget == btnShowDataPreviewA || event.widget == btnShowDataPreviewB) {
Button w=(Button)event.widget;
getContext().setShowingDataPreview(Boolean.valueOf(w.getSelection()));
updateDragDataSource();
}
checkColBindingForCube();
ChartWizard.removeException(ChartWizard.StaChartDSh_switch_ID);
}
 catch (ChartException e1) {
ChartWizard.showException(ChartWizard.StaChartDSh_switch_ID,e1.getLocalizedMessage());
}
}
}

Fixed version (ground truth):
public void handleEvent(Event event){
  if (event.type == IChartDataSheet.EVENT_QUERY) {
    if (event.detail == IChartDataSheet.DETAIL_UPDATE_COLOR_AND_TEXT) {
      updateColorAndText();
    }
 else     if (event.detail == IChartDataSheet.DETAIL_UPDATE_COLOR && event.data instanceof ISelectDataComponent) {
      refreshTableColor();
    }
    return;
  }
  if (event.type == CustomPreviewTable.MOUSE_RIGHT_CLICK_TYPE) {
    if (getDataServiceProvider().getDataSet() != null || getDataServiceProvider().getInheritedDataSet() != null) {
      if (event.widget instanceof Button) {
        Button header=(Button)event.widget;
        boolean isSharingChart=dataProvider.checkState(IDataServiceProvider.SHARE_CHART_QUERY);
        if (header.getMenu() == null && !isSharingChart) {
          header.setMenu(createMenuManager(event.data).createContextMenu(tablePreview));
        }
        if (event.doit && !isSharingChart) {
          header.getMenu().setVisible(true);
        }
      }
    }
  }
 else   if (event.type == SWT.Selection) {
    if (event.widget instanceof MenuItem) {
      MenuItem item=(MenuItem)event.widget;
      IAction action=(IAction)item.getData();
      action.setChecked(!action.isChecked());
      action.run();
    }
 else     if (event.widget == btnFilters) {
      if (invokeEditFilter() == Window.OK) {
        refreshDataPreviewPane();
        fireEvent(btnFilters,EVENT_PREVIEW);
      }
    }
 else     if (event.widget == btnParameters) {
      if (invokeEditParameter() == Window.OK) {
        refreshDataPreviewPane();
        fireEvent(btnParameters,EVENT_PREVIEW);
      }
    }
 else     if (event.widget == btnBinding) {
      if (invokeDataBinding() == Window.OK) {
        refreshDataPreviewPane();
        fireEvent(btnBinding,EVENT_PREVIEW);
      }
    }
    try {
      if (event.widget == btnInherit) {
        ColorPalette.getInstance().restore();
        if (!btnInherit.getSelection()) {
          return;
        }
        if (bIsInheritSelected) {
          return;
        }
        bIsInheritSelected=true;
        getDataServiceProvider().setReportItemReference(null);
        getDataServiceProvider().setDataCube(null);
        getDataServiceProvider().setDataSet(null);
        switchDataSet(null);
        cmbDataItems.select(0);
        currentData=null;
        cmbDataItems.setEnabled(false);
        cmbInherit.setEnabled(!isInheritingSummaryTable() && getDataServiceProvider().getInheritedDataSet() != null && ChartReportItemUtil.isContainerInheritable(itemHandle));
        if (cmbInherit.isEnabled()) {
          getContext().setInheritColumnsOnly(cmbInherit.getSelectionIndex() == 1);
        }
        setEnabledForButtons();
        updateDragDataSource();
        updatePredefinedQueries();
      }
 else       if (event.widget == btnUseData) {
        if (!btnUseData.getSelection()) {
          return;
        }
        if (!bIsInheritSelected) {
          return;
        }
        bIsInheritSelected=false;
        getDataServiceProvider().setReportItemReference(null);
        getDataServiceProvider().setDataSet(null);
        selectDataSet();
        cmbDataItems.setEnabled(true);
        cmbInherit.setEnabled(false);
        setEnabledForButtons();
        updateDragDataSource();
        updatePredefinedQueries();
      }
 else       if (event.widget == cmbInherit) {
        getContext().setInheritColumnsOnly(cmbInherit.getSelectionIndex() == 1);
        setEnabledForButtons();
        fireEvent(btnBinding,EVENT_QUERY);
        refreshDataPreviewPane();
      }
 else       if (event.widget == cmbDataItems) {
        ColorPalette.getInstance().restore();
        int selectedIndex=cmbDataItems.getSelectionIndex();
        Integer selectState=selectDataTypes.get(selectedIndex);
switch (selectState.intValue()) {
case SELECT_NONE:
          btnInherit.setSelection(true);
        btnUseData.setSelection(false);
      btnInherit.notifyListeners(SWT.Selection,new Event());
    break;
case SELECT_NEXT:
  selectedIndex++;
selectState=selectDataTypes.get(selectedIndex);
cmbDataItems.select(selectedIndex);
break;
}
switch (selectState.intValue()) {
case SELECT_DATA_SET:
if (getDataServiceProvider().getReportItemReference() == null && getDataServiceProvider().getDataSet() != null && getDataServiceProvider().getDataSet().equals(ChartUIUtil.getText(cmbDataItems))) {
return;
}
getDataServiceProvider().setDataSet(ChartUIUtil.getText(cmbDataItems));
currentData=ChartUIUtil.getText(cmbDataItems);
switchDataSet(ChartUIUtil.getText(cmbDataItems));
setEnabledForButtons();
updateDragDataSource();
break;
case SELECT_DATA_CUBE:
getDataServiceProvider().setDataCube(ChartUIUtil.getText(cmbDataItems));
currentData=ChartUIUtil.getText(cmbDataItems);
updateDragDataSource();
setEnabledForButtons();
DataDefinitionTextManager.getInstance().refreshAll();
fireEvent(tablePreview,EVENT_PREVIEW);
break;
case SELECT_REPORT_ITEM:
if (ChartUIUtil.getText(cmbDataItems).equals(getDataServiceProvider().getReportItemReference())) {
return;
}
getDataServiceProvider().setReportItemReference(ChartUIUtil.getText(cmbDataItems));
ChartReportItemUtil.reviseChartModel(ChartReportItemUtil.REVISE_REFERENCE_REPORT_ITEM,this.getContext().getModel(),itemHandle);
if (this.getDataServiceProvider().checkState(IDataServiceProvider.SHARE_CHART_QUERY)) {
ChartAdapter.beginIgnoreNotifications();
this.getDataServiceProvider().update(ChartUIConstants.COPY_SERIES_DEFINITION,null);
ChartAdapter.endIgnoreNotifications();
}
currentData=ChartUIUtil.getText(cmbDataItems);
DataDefinitionTextManager.getInstance().refreshAll();
fireEvent(tablePreview,EVENT_PREVIEW);
setEnabledForButtons();
updateDragDataSource();
break;
case SELECT_NEW_DATASET:
int result=invokeNewDataSet();
if (result == Window.CANCEL) {
if (currentData == null) {
cmbDataItems.select(0);
}
 else {
cmbDataItems.setText(currentData);
}
return;
}
cmbDataItems.removeAll();
cmbDataItems.setItems(createDataComboItems());
String[] datasets=getDataServiceProvider().getAllDataSets();
currentData=datasets[datasets.length - 1];
getDataServiceProvider().setDataSet(currentData);
cmbDataItems.setText(currentData);
setEnabledForButtons();
updateDragDataSource();
break;
case SELECT_NEW_DATACUBE:
if (getDataServiceProvider().getAllDataSets().length == 0) {
invokeNewDataSet();
}
int count=getDataServiceProvider().getAllDataCubes().length;
if (getDataServiceProvider().getAllDataSets().length != 0) {
new NewCubeAction().run();
}
String[] datacubes=getDataServiceProvider().getAllDataCubes();
cmbDataItems.removeAll();
cmbDataItems.setItems(createDataComboItems());
if (datacubes.length == count) {
if (currentData == null) {
cmbDataItems.select(0);
}
 else {
cmbDataItems.setText(currentData);
}
return;
}
currentData=datacubes[datacubes.length - 1];
getDataServiceProvider().setDataCube(currentData);
cmbDataItems.setText(currentData);
updateDragDataSource();
setEnabledForButtons();
DataDefinitionTextManager.getInstance().refreshAll();
fireEvent(tablePreview,EVENT_PREVIEW);
break;
}
updatePredefinedQueries();
}
 else if (event.widget == btnShowDataPreviewA || event.widget == btnShowDataPreviewB) {
Button w=(Button)event.widget;
getContext().setShowingDataPreview(Boolean.valueOf(w.getSelection()));
updateDragDataSource();
}
checkColBindingForCube();
ChartWizard.removeException(ChartWizard.StaChartDSh_switch_ID);
}
 catch (ChartException e1) {
ChartWizard.showException(ChartWizard.StaChartDSh_switch_ID,e1.getLocalizedMessage());
}
}
}