protected void prepareUseStepFilter(ILaunchConfiguration config) throws CoreException {
   if (isUseStepFilter(config)) {
     // This listener does not remove itself from the debug plug-in
     // as an event listener (there is no dispose notification for
     // launch delegates). However, since there is only one delegate
     // instantiated per config type, this is tolerable.
     DebugPlugin.getDefault().addDebugEventListener(this);
     IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
     store.addPropertyChangeListener(CjStepFilterOptionManager.getDefault());
   }
 }
  /**
   * Handles the "stop-in-main" and "use-step-filter" option.
   *
   * @param events the debug events.
   * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(DebugEvent[])
   */
  public void handleDebugEvents(DebugEvent[] events) {
    for (int i = 0; i < events.length; i++) {
      DebugEvent event = events[i];
      if (event.getKind() == DebugEvent.CREATE && event.getSource() instanceof IJavaDebugTarget) {

        IJavaDebugTarget target = (IJavaDebugTarget) event.getSource();
        ILaunch launch = target.getLaunch();
        if (launch != null) {
          ILaunchConfiguration configuration = launch.getLaunchConfiguration();
          if (configuration != null) {
            try {
              if (isStopInMain(configuration)) {
                String mainType = getMainTypeName(configuration);
                if (mainType != null) {
                  Map map = new HashMap();
                  map.put(
                      IJavaLaunchConfigurationConstants.ATTR_STOP_IN_MAIN,
                      IJavaLaunchConfigurationConstants.ATTR_STOP_IN_MAIN);

                  IJavaMethodBreakpoint bp =
                      JDIDebugModel.createMethodBreakpoint(
                          ResourcesPlugin.getWorkspace().getRoot(),
                          mainType,
                          "main", //$NON-NLS-1$
                          "([Ljava/lang/String;)V", //$NON-NLS-1$
                          true,
                          false,
                          false,
                          -1,
                          -1,
                          -1,
                          1,
                          false,
                          map); //$NON-NLS-1$
                  bp.setPersisted(false);
                  target.breakpointAdded(bp);
                }
              }
              if (isUseStepFilter(configuration)) {
                CjStepFilterOptionManager.getDefault().activateCaesarStepFilter(target);
              }
              DebugPlugin.getDefault().removeDebugEventListener(this);

            } catch (CoreException e) {
              LaunchingPlugin.log(e);
            }
          }
        }
      }
    }
  }