Program: 136940
Project: 136940
Buggy source:
private void addMouseListenerForChart(final ChartComposite chartComp,final IDataExplorer explorer,final Analysis analysis){
  chartComp.addChartMouseListener(new ChartMouseListener(){
    public void chartMouseClicked(    ChartMouseEvent event){
      boolean flag=event.getTrigger().getButton() != MouseEvent.BUTTON3;
      chartComp.setDomainZoomable(flag);
      chartComp.setRangeZoomable(flag);
      if (flag) {
        return;
      }
      final ExecutionLanguage currentEngine=analysis.getParameters().getExecutionLanguage();
      if (ExecutionLanguage.JAVA == currentEngine && !analysis.getParameters().isStoreData()) {
        return;
      }
      ChartEntity chartEntity=event.getEntity();
      if (chartEntity != null && chartEntity instanceof CategoryItemEntity) {
        CategoryItemEntity cateEntity=(CategoryItemEntity)chartEntity;
        ICustomerDataset dataEntity=(ICustomerDataset)cateEntity.getDataset();
        final ChartDataEntity currentDataEntity=getCurrentChartDateEntity(cateEntity,dataEntity);
        if (currentDataEntity != null) {
          final Indicator currentIndicator=currentDataEntity.getIndicator();
          if (!currentIndicator.isUsedMapDBMode()) {
            if (ExecutionLanguage.JAVA == currentEngine && 0 == analysis.getResults().getIndicToRowMap().size()) {
              return;
            }
            if (currentIndicator instanceof DatePatternFreqIndicator && null == analysis.getResults().getIndicToRowMap().get(currentIndicator).getFrequencyData()) {
              return;
            }
          }
          Menu menu=new Menu(chartComp.getShell(),SWT.POP_UP);
          chartComp.setMenu(menu);
          int createPatternFlag=0;
          MenuItemEntity[] itemEntities=ChartTableMenuGenerator.generate(explorer,analysis,currentDataEntity);
          for (          final MenuItemEntity itemEntity : itemEntities) {
            MenuItem item=new MenuItem(menu,SWT.PUSH);
            item.setText(itemEntity.getLabel());
            item.setImage(itemEntity.getIcon());
            item.setEnabled(DrillDownUtils.isMenuItemEnable(currentDataEntity,itemEntity,analysis));
            item.addSelectionListener(new SelectionAdapter(){
              @Override public void widgetSelected(              SelectionEvent e){
                if (ExecutionLanguage.JAVA == currentEngine) {
                  try {
                    DrillDownEditorInput input=new DrillDownEditorInput(analysis,currentDataEntity,itemEntity);
                    if (input.computeColumnValueLength(input.filterAdaptDataList())) {
                      CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input,"String_Node_Str");
                    }
 else {
                      MessageDialog.openWarning(null,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"));
                    }
                  }
 catch (                  PartInitException e1) {
                    log.error(e1,e1);
                  }
                }
 else {
                  Display.getDefault().asyncExec(new Runnable(){
                    public void run(){
                      Connection tdDataProvider=SwitchHelpers.CONNECTION_SWITCH.doSwitch(analysis.getContext().getConnection());
                      String query=itemEntity.getQuery();
                      String editorName=currentIndicator.getName();
                      SqlExplorerUtils.getDefault().runInDQViewer(tdDataProvider,query,editorName);
                    }
                  }
);
                }
              }
            }
);
            if (ChartTableFactory.isPatternFrequencyIndicator(currentIndicator) && createPatternFlag == 0) {
              ChartTableFactory.createMenuOfGenerateRegularPattern(analysis,menu,currentDataEntity);
            }
            createPatternFlag++;
          }
          ChartTableFactory.addJobGenerationMenu(menu,analysis,currentIndicator);
          menu.setVisible(true);
        }
      }
    }
    /** 
 * DOC xqliu Comment method "getCurrentChartDateEntity". bug 15745.
 * @param cateEntity
 * @param dataEntity
 * @return
 */
    private ChartDataEntity getCurrentChartDateEntity(    CategoryItemEntity cateEntity,    ICustomerDataset dataEntity){
      ChartDataEntity currentDataEntity=null;
      ChartDataEntity[] dataEntities=dataEntity.getDataEntities();
      if (dataEntities.length == 1) {
        currentDataEntity=dataEntities[0];
      }
 else {
        for (        ChartDataEntity entity : dataEntities) {
          if (cateEntity.getColumnKey().compareTo(entity.getLabel()) == 0) {
            currentDataEntity=entity;
          }
 else {
            if (cateEntity.getRowKey().compareTo(entity.getLabel()) == 0) {
              currentDataEntity=entity;
            }
          }
        }
      }
      return currentDataEntity;
    }
    public void chartMouseMoved(    ChartMouseEvent event){
    }
  }
);
  chartComp.addDisposeListener(new DisposeListener(){
    public void widgetDisposed(    DisposeEvent e){
      chartComp.dispose();
    }
  }
);
}

Fixed version (ground truth):
private void addMouseListenerForChart(final ChartComposite chartComp,final IDataExplorer explorer,final Analysis analysis){
  chartComp.addChartMouseListener(new ChartMouseListener(){
    public void chartMouseClicked(    ChartMouseEvent event){
      boolean flag=event.getTrigger().getButton() != MouseEvent.BUTTON3;
      chartComp.setDomainZoomable(flag);
      chartComp.setRangeZoomable(flag);
      if (flag) {
        return;
      }
      final ExecutionLanguage currentEngine=analysis.getParameters().getExecutionLanguage();
      if (ExecutionLanguage.JAVA == currentEngine && !analysis.getParameters().isStoreData()) {
        return;
      }
      ChartEntity chartEntity=event.getEntity();
      if (chartEntity != null && chartEntity instanceof CategoryItemEntity) {
        CategoryItemEntity cateEntity=(CategoryItemEntity)chartEntity;
        ICustomerDataset dataEntity=(ICustomerDataset)cateEntity.getDataset();
        final ChartDataEntity currentDataEntity=getCurrentChartDateEntity(cateEntity,dataEntity);
        if (currentDataEntity != null) {
          final Indicator currentIndicator=currentDataEntity.getIndicator();
          if (!currentIndicator.isUsedMapDBMode()) {
            if (ExecutionLanguage.JAVA == currentEngine && 0 == analysis.getResults().getIndicToRowMap().size()) {
              return;
            }
            if (currentIndicator instanceof DatePatternFreqIndicator && null == analysis.getResults().getIndicToRowMap().get(currentIndicator).getFrequencyData()) {
              return;
            }
          }
          Menu menu=new Menu(chartComp.getShell(),SWT.POP_UP);
          chartComp.setMenu(menu);
          int createPatternFlag=0;
          MenuItemEntity[] itemEntities=ChartTableMenuGenerator.generate(explorer,analysis,currentDataEntity);
          for (          final MenuItemEntity itemEntity : itemEntities) {
            MenuItem item=new MenuItem(menu,SWT.PUSH);
            item.setText(itemEntity.getLabel());
            item.setImage(itemEntity.getIcon());
            item.setEnabled(DrillDownUtils.isMenuItemEnable(currentDataEntity,itemEntity,analysis));
            item.addSelectionListener(new SelectionAdapter(){
              @Override public void widgetSelected(              SelectionEvent e){
                if (ExecutionLanguage.JAVA == currentEngine) {
                  try {
                    DrillDownEditorInput input=new DrillDownEditorInput(analysis,currentDataEntity,itemEntity);
                    if (SqlExplorerUtils.getDefault().getSqlexplorerService() != null) {
                      CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input,"String_Node_Str");
                    }
                  }
 catch (                  PartInitException e1) {
                    log.error(e1,e1);
                  }
                }
 else {
                  Display.getDefault().asyncExec(new Runnable(){
                    public void run(){
                      Connection tdDataProvider=SwitchHelpers.CONNECTION_SWITCH.doSwitch(analysis.getContext().getConnection());
                      String query=itemEntity.getQuery();
                      String editorName=currentIndicator.getName();
                      SqlExplorerUtils.getDefault().runInDQViewer(tdDataProvider,query,editorName);
                    }
                  }
);
                }
              }
            }
);
            if (ChartTableFactory.isPatternFrequencyIndicator(currentIndicator) && createPatternFlag == 0) {
              ChartTableFactory.createMenuOfGenerateRegularPattern(analysis,menu,currentDataEntity);
            }
            createPatternFlag++;
          }
          ChartTableFactory.addJobGenerationMenu(menu,analysis,currentIndicator);
          menu.setVisible(true);
        }
      }
    }
    /** 
 * DOC xqliu Comment method "getCurrentChartDateEntity". bug 15745.
 * @param cateEntity
 * @param dataEntity
 * @return
 */
    private ChartDataEntity getCurrentChartDateEntity(    CategoryItemEntity cateEntity,    ICustomerDataset dataEntity){
      ChartDataEntity currentDataEntity=null;
      ChartDataEntity[] dataEntities=dataEntity.getDataEntities();
      if (dataEntities.length == 1) {
        currentDataEntity=dataEntities[0];
      }
 else {
        for (        ChartDataEntity entity : dataEntities) {
          if (cateEntity.getColumnKey().compareTo(entity.getLabel()) == 0) {
            currentDataEntity=entity;
          }
 else {
            if (cateEntity.getRowKey().compareTo(entity.getLabel()) == 0) {
              currentDataEntity=entity;
            }
          }
        }
      }
      return currentDataEntity;
    }
    public void chartMouseMoved(    ChartMouseEvent event){
    }
  }
);
  chartComp.addDisposeListener(new DisposeListener(){
    public void widgetDisposed(    DisposeEvent e){
      chartComp.dispose();
    }
  }
);
}