DebugModePromptStatusHandler.java :  » IDE-Eclipse » debug » org » eclipse » debug » internal » ui » launchConfigurations » Java Open Source

Java Open Source » IDE Eclipse » debug 
debug » org » eclipse » debug » internal » ui » launchConfigurations » DebugModePromptStatusHandler.java
/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.internal.ui.launchConfigurations;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.IStatusHandler;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.widgets.Shell;


public class DebugModePromptStatusHandler implements IStatusHandler {
  
  /* (non-Javadoc)
   * @see org.eclipse.debug.core.IStatusHandler#handleStatus(org.eclipse.core.runtime.IStatus, java.lang.Object)
   */
  public Object handleStatus(IStatus status, Object source) throws CoreException {
    if (source instanceof ILaunchConfiguration) {
      ILaunchConfiguration config = (ILaunchConfiguration)source;
      if (DebugUITools.isPrivate(config)) {
        return Boolean.FALSE;
      }  
    }
    
    IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
        ILaunchConfiguration configuration = (ILaunchConfiguration)source;
        String pref = store.getString(IInternalDebugUIConstants.PREF_RELAUNCH_IN_DEBUG_MODE); 
        if (pref != null) {
            if (pref.equals(MessageDialogWithToggle.NEVER)) {
                return Boolean.FALSE;
            } else if (pref.equals(MessageDialogWithToggle.ALWAYS)) { 
                relaunchInDebugMode(configuration);
                return Boolean.TRUE;
            }
        }
        
    Shell activeShell = DebugUIPlugin.getShell();
    String title = LaunchConfigurationsMessages.DebugModePromptStatusHandler_0; 
    String message = LaunchConfigurationsMessages.DebugModePromptStatusHandler_1; 
    
    MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(activeShell, title, message, null, false, store, IInternalDebugUIConstants.PREF_RELAUNCH_IN_DEBUG_MODE); 
    int buttonId = dialog.getReturnCode();
    if (buttonId == IDialogConstants.YES_ID) { 
      relaunchInDebugMode(configuration);
      return Boolean.TRUE; // stops launch
    } else if (buttonId == IDialogConstants.NO_ID) {
      return Boolean.FALSE; // continue launch
    } else { //CANCEL 
      return Boolean.TRUE; // stops the launch
    }
  }
  /**
   * @param configuration
   */
  private void relaunchInDebugMode(ILaunchConfiguration configuration) {
    DebugUITools.launch(configuration, ILaunchManager.DEBUG_MODE);
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.