### Eclipse Workspace Patch 1.0 #P org.eclipse.mtj.core Index: src/org/eclipse/mtj/core/internal/launching/EmulatorLaunchConfigDelegate.java =================================================================== --- src/org/eclipse/mtj/core/internal/launching/EmulatorLaunchConfigDelegate.java (revision 345) +++ src/org/eclipse/mtj/core/internal/launching/EmulatorLaunchConfigDelegate.java (working copy) @@ -9,6 +9,7 @@ * Craig Setera (EclipseME) - Initial implementation * Diego Sandin (Motorola) - Refactoring package name to follow * eclipse standards + * Gang Ma (Sybase) - Add check debugger setting support */ package org.eclipse.mtj.core.internal.launching; @@ -22,6 +23,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchManager; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate; import org.eclipse.jdt.launching.IVMRunner; @@ -26,8 +28,8 @@ import org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate; import org.eclipse.jdt.launching.IVMRunner; import org.eclipse.jdt.launching.VMRunnerConfiguration; +import org.eclipse.mtj.core.IMTJCoreConstants; import org.eclipse.mtj.core.MTJCoreStrings; -import org.eclipse.mtj.core.IMTJCoreConstants; import org.eclipse.mtj.core.internal.MTJCorePlugin; import org.eclipse.mtj.core.launching.ILaunchConstants; import org.eclipse.mtj.core.model.device.DeviceRegistry; @@ -164,7 +166,7 @@ boolean continueLaunch = super.preLaunchCheck(configuration, mode, monitor); if (continueLaunch) { - continueLaunch = verifyEmulationSettings(configuration, monitor); + continueLaunch = verifyEmulationSettings(configuration, mode, monitor); } return continueLaunch; @@ -223,10 +225,17 @@ * @return * @throws CoreException */ - private boolean verifyEmulationSettings(ILaunchConfiguration configuration, + private boolean verifyEmulationSettings(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException { boolean valid = true; - + //if in debug mode,check the debugger setting + if(ILaunchManager.DEBUG_MODE.equals(mode)){ + IStatus status = new Status(IStatus.INFO, + IMTJCoreConstants.PLUGIN_ID, + IMTJCoreConstants.INFO_DEBUGGER_SETTINGS_CHECK, "", null); + valid = promptWhetherToContinue(status); + if(!valid)return valid; + } // If this is OTA, there should be at least one midlet // defined in the JAD file. boolean doOTA = configuration.getAttribute(ILaunchConstants.DO_OTA, @@ -240,7 +249,7 @@ if (desc != null) { valid = (desc.getMidletCount() > 0); if (!valid) { - valid = promptWhetherToContinue(); + valid = promptWhetherToContinue(NO_MIDLET_STATUS); } } } @@ -256,9 +265,9 @@ * @return * @throws CoreException */ - private boolean promptWhetherToContinue() throws CoreException { + private boolean promptWhetherToContinue(IStatus status) throws CoreException { Boolean shouldContinue = (Boolean) MTJCorePlugin.statusPrompt( - NO_MIDLET_STATUS, this); + status, this); return (shouldContinue != null) ? shouldContinue.booleanValue() : false; } } Index: src/org/eclipse/mtj/core/IMTJCoreConstants.java =================================================================== --- src/org/eclipse/mtj/core/IMTJCoreConstants.java (revision 345) +++ src/org/eclipse/mtj/core/IMTJCoreConstants.java (working copy) @@ -136,4 +136,11 @@ /** Need signature passwords (not really an error, but triggers a dialog) */ public static final int INFO_NEED_SIGNATURE_PASSWORDS = 103; + + /** + * Need check for debug setting(not really an error, but triggers a dialog if the current + * debugger setting is not satisfied to debug a midlet) + * + */ + public static final int INFO_DEBUGGER_SETTINGS_CHECK = 104; } #P org.eclipse.mtj.ui Index: plugin.xml =================================================================== --- plugin.xml (revision 345) +++ plugin.xml (working copy) @@ -431,6 +431,12 @@ class="org.eclipse.mtj.ui.internal.statusHandlers.SignaturePasswordHandler" id="org.eclipse.mtj.statusHandler.SignaturePasswordHandler" plugin="org.eclipse.mtj.core"/> + + Index: src/org/eclipse/mtj/ui/MTJUIPluginResources.properties =================================================================== --- src/org/eclipse/mtj/ui/MTJUIPluginResources.properties (revision 345) +++ src/org/eclipse/mtj/ui/MTJUIPluginResources.properties (working copy) @@ -123,7 +123,7 @@ # debugWarning.title=Debug Setting Warning debugWarning.toggleMessage=Don't warn me again -debugWarning.warningMessage=There are some problems with your Java Debug settings. Do you want to fix it? +debugWarning.warningMessage=There are some problems with your Java Debug settings for MTJ debug. Do you want to fix it? debugWarning.suspendOnUnCaughtExpWarning=The Suspend execution on uncaught exceptions option must not be checked on java debug preference page. debugWarning.suspendOnCompileErrWarning=The Suspend execution on compilation errors option must not be checked on java debug preference page. debugWarning.reqestTimeoutWarning=The Debugger timeout(ms) must be set equal or greater than {0} on java debug preference page. Index: src/org/eclipse/mtj/ui/internal/launching/EmulatorLaunchShortcut.java =================================================================== --- src/org/eclipse/mtj/ui/internal/launching/EmulatorLaunchShortcut.java (revision 345) +++ src/org/eclipse/mtj/ui/internal/launching/EmulatorLaunchShortcut.java (working copy) @@ -398,8 +398,6 @@ } if (type != null) { - // configure the debugger settings - DebuggerSettingHelper.getDefault().configDebuggerSetting(mode); ILaunchConfiguration config = findLaunchConfiguration(type, mode); if (config != null) { try { Index: src/org/eclipse/mtj/ui/internal/launching/JadLaunchShortcut.java =================================================================== --- src/org/eclipse/mtj/ui/internal/launching/JadLaunchShortcut.java (revision 345) +++ src/org/eclipse/mtj/ui/internal/launching/JadLaunchShortcut.java (working copy) @@ -103,8 +103,7 @@ if (config == null) { return; } - // configure the debugger settings - DebuggerSettingHelper.getDefault().configDebuggerSetting(mode); + // launch DebugUITools.launch(config, mode); } Index: src/org/eclipse/mtj/ui/internal/launching/DebuggerSettingHelper.java =================================================================== --- src/org/eclipse/mtj/ui/internal/launching/DebuggerSettingHelper.java (revision 345) +++ src/org/eclipse/mtj/ui/internal/launching/DebuggerSettingHelper.java (working copy) @@ -1,299 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Sybase Inc. 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: - * Feng Wang (Sybase) - Initial implementation. Extracted from - * EmulatorLaunchShortcut class. - *******************************************************************************/ - -package org.eclipse.mtj.ui.internal.launching; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.ILaunchManager; -import org.eclipse.jdt.debug.core.JDIDebugModel; -import org.eclipse.jdt.debug.ui.JavaDebugUtils; -import org.eclipse.jdt.internal.debug.ui.IJDIPreferencesConstants; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.mtj.ui.IMTJUIConstants; -import org.eclipse.mtj.ui.MTJUIStrings; -import org.eclipse.mtj.ui.internal.MTJUIPlugin; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IWorkbenchWindow; - -public class DebuggerSettingHelper { - /** - * The preference key of debug setting warning, if user select - * "don't warn me again", the preference will be stored. - */ - public static final String PREF_DEBUGSETTING_WARNING = IMTJUIConstants.PLUGIN_ID - + ".debugSettingWarning"; - /** - * Debugger time out must be set more than 15000 - */ - public static final int MIN_DEBUGGERTIMEOUT_SETTING = 15000; - /** - * Suspend execution on uncaught exception must not be checked - */ - public static final boolean CORRECT_SUSPENDONUNCAUGHTEXP_SETTING = false; - /** - * Suspend execution on compilation errors must not be checked - */ - public static final boolean CORRECT_SUSPENDONCOMPILEERR_SETTING = false; - - private static DebuggerSettingHelper fgDefault; - - public static synchronized DebuggerSettingHelper getDefault() { - if (fgDefault == null) { - fgDefault = new DebuggerSettingHelper(); - } - return fgDefault; - } - - private DebuggerSettingHelper() { - } - - /** - * configure the debug setting for user - */ - public void configDebuggerSetting(String mode) { - // only need to configure debugger setting while in debug mode - if (!ILaunchManager.DEBUG_MODE.equalsIgnoreCase(mode)) - return; - IStatus debugSettingStatus = debugSettingSatisfied(); - // only need to configure debugger setting while the setting is not - // satisfied - if (debugSettingStatus.isOK()) - return; - - String preferenceKey = PREF_DEBUGSETTING_WARNING; - String debugWarningDesc = MTJUIPlugin.getDefault().getPreferenceStore() - .getString(preferenceKey); - // if the user have ever checked "Don't warn me again",don't warn that - if (ErrorDialogWithToggle.NO_WARING.equals(debugWarningDesc)) { - return; - } - // show the warning dialog - Shell shell = getShell(); - ErrorDialogWithToggle dialog = new ErrorDialogWithToggle(shell, - MTJUIStrings.getString("debugWarning.title"), null, - debugSettingStatus, preferenceKey, MTJUIStrings - .getString("debugWarning.toggleMessage"), MTJUIPlugin - .getDefault().getPreferenceStore()); - dialog.open(); - - boolean answer = (dialog.getReturnCode() == IDialogConstants.YES_ID); - if (answer) { - JDIDebugModel.getPreferences().setValue( - JDIDebugModel.PREF_REQUEST_TIMEOUT, - MIN_DEBUGGERTIMEOUT_SETTING); - JavaDebugUtils - .getPreferenceStore() - .setValue( - IJDIPreferencesConstants.PREF_SUSPEND_ON_UNCAUGHT_EXCEPTIONS, - CORRECT_SUSPENDONUNCAUGHTEXP_SETTING); - JavaDebugUtils - .getPreferenceStore() - .setValue( - IJDIPreferencesConstants.PREF_SUSPEND_ON_COMPILATION_ERRORS, - CORRECT_SUSPENDONCOMPILEERR_SETTING); - - } - - } - - /** - * check if the debug setting is satisfied if it is satisfied for debugging - * return status ok else return status warning. - * - * @return IStatus - */ - private IStatus debugSettingSatisfied() { - boolean suspendOnUnCaughtExp = JavaDebugUtils - .getPreferenceStore() - .getBoolean( - IJDIPreferencesConstants.PREF_SUSPEND_ON_UNCAUGHT_EXCEPTIONS); - boolean suspendOnCompileErr = JavaDebugUtils - .getPreferenceStore() - .getBoolean( - IJDIPreferencesConstants.PREF_SUSPEND_ON_COMPILATION_ERRORS); - int currReqTimeout = JDIDebugModel.getPreferences().getInt( - JDIDebugModel.PREF_REQUEST_TIMEOUT); - - if (!suspendOnUnCaughtExp && !suspendOnCompileErr - && currReqTimeout >= MIN_DEBUGGERTIMEOUT_SETTING) { - return new Status(IStatus.OK, IMTJUIConstants.PLUGIN_ID, ""); - } else { - MultiStatus warningStatus = new MultiStatus( - IMTJUIConstants.PLUGIN_ID, IStatus.WARNING, MTJUIStrings - .getString("debugWarning.warningMessage"), null); - - if (suspendOnUnCaughtExp) { - warningStatus - .add(new Status( - IStatus.WARNING, - IMTJUIConstants.PLUGIN_ID, - MTJUIStrings - .getString("debugWarning.suspendOnUnCaughtExpWarning"))); - } - if (suspendOnCompileErr) { - warningStatus - .add(new Status( - IStatus.WARNING, - IMTJUIConstants.PLUGIN_ID, - MTJUIStrings - .getString("debugWarning.suspendOnCompileErrWarning"))); - - } - if (currReqTimeout < MIN_DEBUGGERTIMEOUT_SETTING) { - warningStatus - .add(new Status( - IStatus.WARNING, - IMTJUIConstants.PLUGIN_ID, - MTJUIStrings - .getString( - "debugWarning.reqestTimeoutWarning", - new Integer[] { MIN_DEBUGGERTIMEOUT_SETTING }))); - } - return warningStatus; - } - } - - /** - * Get the active workbench window's shell. - * - * @return - */ - private Shell getShell() { - Shell shell = null; - - IWorkbenchWindow workbenchWindow = MTJUIPlugin.getDefault() - .getWorkbench().getActiveWorkbenchWindow(); - if (workbenchWindow != null) { - shell = workbenchWindow.getShell(); - } - - return shell; - } - - /** - * - * this is a dialog with toggle message, "Yes" "No" and "Details" buttons. - * - * @author gma - * - */ - class ErrorDialogWithToggle extends ErrorDialog { - - public static final String NO_WARING = "neverWaring"; - - /** - * The selected state of the toggle. - */ - private boolean toggleState; - /** - * The preference key which is set by the toggle button. - * - */ - private String fPreferenceKey = null; - /** - * The message displayed to the user, with the toggle button - */ - private String fToggleMessage = null; - private Button fToggleButton = null; - /** - * The preference store which will be affected by the toggle button - */ - IPreferenceStore prefStore = null; - - public ErrorDialogWithToggle(Shell parentShell, String dialogTitle, - String message, IStatus status, String preferenceKey, - String toggleMessage, IPreferenceStore store) { - super(parentShell, dialogTitle, message, status, IStatus.WARNING - | IStatus.ERROR | IStatus.INFO); - prefStore = store; - fPreferenceKey = preferenceKey; - fToggleMessage = toggleMessage; - } - - protected Control createDialogArea(Composite parent) { - Composite dialogComposite = (Composite) super - .createDialogArea(parent); - dialogComposite.setFont(parent.getFont()); - setToggleButton(createCheckButton(dialogComposite, fToggleMessage)); - applyDialogFont(dialogComposite); - return dialogComposite; - } - - /** - * Creates a button with the given label and sets the default - * configuration data. - */ - private Button createCheckButton(Composite parent, String label) { - final Button button = new Button(parent, SWT.CHECK | SWT.LEFT); - button.setText(label); - - GridData data = new GridData(SWT.NONE); - data.horizontalSpan = 2; - data.horizontalAlignment = GridData.CENTER; - button.setLayoutData(data); - button.setFont(parent.getFont()); - button.addSelectionListener(new SelectionAdapter() { - - public void widgetSelected(SelectionEvent e) { - toggleState = button.getSelection(); - } - }); - - return button; - } - - protected void buttonPressed(int buttonId) { - - if (buttonId != IDialogConstants.DETAILS_ID) { - if (toggleState && prefStore != null && fPreferenceKey != null) { - prefStore.setValue(fPreferenceKey, NO_WARING); - } - setReturnCode(buttonId); - close(); - } - super.buttonPressed(buttonId); - } - - protected Button getToggleButton() { - return fToggleButton; - } - - protected void setToggleButton(Button button) { - fToggleButton = button; - } - - /** - * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) - */ - protected void createButtonsForButtonBar(Composite parent) { - createButton(parent, IDialogConstants.YES_ID, - IDialogConstants.YES_LABEL, true); - createButton(parent, IDialogConstants.NO_ID, - IDialogConstants.NO_LABEL, true); - createDetailsButton(parent); - - getButton(IDialogConstants.YES_ID).setFocus(); - } - } -} Index: src/org/eclipse/mtj/ui/internal/statusHandlers/DebuggerSettingCheckHandler.java =================================================================== --- src/org/eclipse/mtj/ui/internal/statusHandlers/DebuggerSettingCheckHandler.java (revision 0) +++ src/org/eclipse/mtj/ui/internal/statusHandlers/DebuggerSettingCheckHandler.java (revision 0) @@ -0,0 +1,299 @@ +/** + * Copyright (c) 2003,2008 Sybase 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: + * Gang Ma (Sybase) - Initial implementation + * + */ +package org.eclipse.mtj.ui.internal.statusHandlers; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.IStatusHandler; +import org.eclipse.jdt.debug.core.JDIDebugModel; +import org.eclipse.jdt.debug.ui.JavaDebugUtils; +import org.eclipse.jdt.internal.debug.ui.IJDIPreferencesConstants; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.mtj.ui.IMTJUIConstants; +import org.eclipse.mtj.ui.MTJUIStrings; +import org.eclipse.mtj.ui.internal.MTJUIPlugin; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchWindow; +/** + * Status handler for configuring debug settings. + * @author gma + * + */ +public class DebuggerSettingCheckHandler implements IStatusHandler { + + public Object handleStatus(IStatus status, Object source) + throws CoreException { + configDebuggerSetting(); + //always continue debugging + return Boolean.TRUE; + } + + /** + * The preference key of debug setting warning, if user select + * "don't warn me again", the preference will be stored. + */ + public static final String PREF_DEBUGSETTING_WARNING = IMTJUIConstants.PLUGIN_ID + + ".debugSettingWarning"; + /** + * Debugger time out must be set more than 15000 + */ + public static final int MIN_DEBUGGERTIMEOUT_SETTING = 15000; + /** + * Suspend execution on uncaught exception must not be checked + */ + public static final boolean CORRECT_SUSPENDONUNCAUGHTEXP_SETTING = false; + /** + * Suspend execution on compilation errors must not be checked + */ + public static final boolean CORRECT_SUSPENDONCOMPILEERR_SETTING = false; + + + + /** + * configure the debug setting for user + */ + public void configDebuggerSetting() { + + IStatus debugSettingStatus = debugSettingSatisfied(); + // only need to configure debugger setting while the setting is not + // satisfied + if (debugSettingStatus.isOK()) + return; + + String preferenceKey = PREF_DEBUGSETTING_WARNING; + String debugWarningDesc = MTJUIPlugin.getDefault().getPreferenceStore() + .getString(preferenceKey); + // if the user have ever checked "Don't warn me again",don't warn that + if (ErrorDialogWithToggle.NO_WARING.equals(debugWarningDesc)) { + return; + } + // show the warning dialog + Shell shell = getShell(); + ErrorDialogWithToggle dialog = new ErrorDialogWithToggle(shell, + MTJUIStrings.getString("debugWarning.title"), null, + debugSettingStatus, preferenceKey, MTJUIStrings + .getString("debugWarning.toggleMessage"), MTJUIPlugin + .getDefault().getPreferenceStore()); + dialog.open(); + + boolean answer = (dialog.getReturnCode() == IDialogConstants.YES_ID); + if (answer) { + JDIDebugModel.getPreferences().setValue( + JDIDebugModel.PREF_REQUEST_TIMEOUT, + MIN_DEBUGGERTIMEOUT_SETTING); + JavaDebugUtils + .getPreferenceStore() + .setValue( + IJDIPreferencesConstants.PREF_SUSPEND_ON_UNCAUGHT_EXCEPTIONS, + CORRECT_SUSPENDONUNCAUGHTEXP_SETTING); + JavaDebugUtils + .getPreferenceStore() + .setValue( + IJDIPreferencesConstants.PREF_SUSPEND_ON_COMPILATION_ERRORS, + CORRECT_SUSPENDONCOMPILEERR_SETTING); + + } + + } + + /** + * check if the debug setting is satisfied if it is satisfied for debugging + * return status ok else return status warning. + * + * @return IStatus + */ + private IStatus debugSettingSatisfied() { + boolean suspendOnUnCaughtExp = JavaDebugUtils + .getPreferenceStore() + .getBoolean( + IJDIPreferencesConstants.PREF_SUSPEND_ON_UNCAUGHT_EXCEPTIONS); + boolean suspendOnCompileErr = JavaDebugUtils + .getPreferenceStore() + .getBoolean( + IJDIPreferencesConstants.PREF_SUSPEND_ON_COMPILATION_ERRORS); + int currReqTimeout = JDIDebugModel.getPreferences().getInt( + JDIDebugModel.PREF_REQUEST_TIMEOUT); + + if (!suspendOnUnCaughtExp && !suspendOnCompileErr + && currReqTimeout >= MIN_DEBUGGERTIMEOUT_SETTING) { + return new Status(IStatus.OK, IMTJUIConstants.PLUGIN_ID, ""); + } else { + MultiStatus warningStatus = new MultiStatus( + IMTJUIConstants.PLUGIN_ID, IStatus.WARNING, MTJUIStrings + .getString("debugWarning.warningMessage"), null); + + if (suspendOnUnCaughtExp) { + warningStatus + .add(new Status( + IStatus.WARNING, + IMTJUIConstants.PLUGIN_ID, + MTJUIStrings + .getString("debugWarning.suspendOnUnCaughtExpWarning"))); + } + if (suspendOnCompileErr) { + warningStatus + .add(new Status( + IStatus.WARNING, + IMTJUIConstants.PLUGIN_ID, + MTJUIStrings + .getString("debugWarning.suspendOnCompileErrWarning"))); + + } + if (currReqTimeout < MIN_DEBUGGERTIMEOUT_SETTING) { + warningStatus + .add(new Status( + IStatus.WARNING, + IMTJUIConstants.PLUGIN_ID, + MTJUIStrings + .getString( + "debugWarning.reqestTimeoutWarning", + new Integer[] { MIN_DEBUGGERTIMEOUT_SETTING }))); + } + return warningStatus; + } + } + + /** + * Get the active workbench window's shell. + * + * @return + */ + private Shell getShell() { + Shell shell = null; + + IWorkbenchWindow workbenchWindow = MTJUIPlugin.getDefault() + .getWorkbench().getActiveWorkbenchWindow(); + if (workbenchWindow != null) { + shell = workbenchWindow.getShell(); + } + + return shell; + } + + /** + * + * this is a dialog with toggle message, "Yes" "No" and "Details" buttons. + * + * @author gma + * + */ + class ErrorDialogWithToggle extends ErrorDialog { + + public static final String NO_WARING = "neverWaring"; + + /** + * The selected state of the toggle. + */ + private boolean toggleState; + /** + * The preference key which is set by the toggle button. + * + */ + private String fPreferenceKey = null; + /** + * The message displayed to the user, with the toggle button + */ + private String fToggleMessage = null; + private Button fToggleButton = null; + /** + * The preference store which will be affected by the toggle button + */ + IPreferenceStore prefStore = null; + + public ErrorDialogWithToggle(Shell parentShell, String dialogTitle, + String message, IStatus status, String preferenceKey, + String toggleMessage, IPreferenceStore store) { + super(parentShell, dialogTitle, message, status, IStatus.WARNING + | IStatus.ERROR | IStatus.INFO); + prefStore = store; + fPreferenceKey = preferenceKey; + fToggleMessage = toggleMessage; + } + + protected Control createDialogArea(Composite parent) { + Composite dialogComposite = (Composite) super + .createDialogArea(parent); + dialogComposite.setFont(parent.getFont()); + setToggleButton(createCheckButton(dialogComposite, fToggleMessage)); + applyDialogFont(dialogComposite); + return dialogComposite; + } + + /** + * Creates a button with the given label and sets the default + * configuration data. + */ + private Button createCheckButton(Composite parent, String label) { + final Button button = new Button(parent, SWT.CHECK | SWT.LEFT); + button.setText(label); + + GridData data = new GridData(SWT.NONE); + data.horizontalSpan = 2; + data.horizontalAlignment = GridData.CENTER; + button.setLayoutData(data); + button.setFont(parent.getFont()); + button.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent e) { + toggleState = button.getSelection(); + } + }); + + return button; + } + + protected void buttonPressed(int buttonId) { + + if (buttonId != IDialogConstants.DETAILS_ID) { + if (toggleState && prefStore != null && fPreferenceKey != null) { + prefStore.setValue(fPreferenceKey, NO_WARING); + } + setReturnCode(buttonId); + close(); + } + super.buttonPressed(buttonId); + } + + protected Button getToggleButton() { + return fToggleButton; + } + + protected void setToggleButton(Button button) { + fToggleButton = button; + } + + /** + * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) + */ + protected void createButtonsForButtonBar(Composite parent) { + createButton(parent, IDialogConstants.YES_ID, + IDialogConstants.YES_LABEL, true); + createButton(parent, IDialogConstants.NO_ID, + IDialogConstants.NO_LABEL, true); + createDetailsButton(parent); + + getButton(IDialogConstants.YES_ID).setFocus(); + } + } + +}