blob: 5028971b6bf2936e47a8030bb4b7cf7bee17f588 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.debug.ui;
import java.text.MessageFormat;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
/**
* An error dialog reporting a problem with a debug
* target which gives the user the option to continue
* or terminate/disconnect the target.
*/
public class HotCodeReplaceErrorDialog extends ErrorDialogWithToggle {
protected IDebugTarget target;
// The ID of the terminate button. Set to the sum of the other possible IDs generated by
// this dialog to ensure the ID's uniqueness.
protected int TERMINATE_ID= IDialogConstants.OK_ID + IDialogConstants.DETAILS_ID + IDialogConstants.CANCEL_ID;
protected int DISCONNECT_ID= IDialogConstants.OK_ID + IDialogConstants.DETAILS_ID + IDialogConstants.CANCEL_ID + 1;
/**
* Creates a new dialog which can terminate the given debug target.
*
* @param target the debug target
* @see ErrorDialogWithToggle#ErrorDialogWithToggle(Shell, String, String, IStatus, String, String, IPreferenceStore)
*/
public HotCodeReplaceErrorDialog(Shell parentShell, String dialogTitle, String message, IStatus status, String preferenceKey, String toggleMessage, IPreferenceStore store, IDebugTarget target) {
super(parentShell, dialogTitle, message, status, preferenceKey, toggleMessage, store);
this.target = target;
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
*/
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
getButton(IDialogConstants.OK_ID).setText(DebugUIMessages.getString("HotCodeReplaceErrorDialog.0")); //$NON-NLS-1$
if (target.canTerminate()) {
createButton(parent, TERMINATE_ID, DebugUIMessages.getString("HotCodeReplaceErrorDialog.1"), false); //$NON-NLS-1$
}
if (target.canDisconnect()) {
createButton(parent, DISCONNECT_ID, DebugUIMessages.getString("HotCodeReplaceErrorDialog.3"), false); //$NON-NLS-1$
}
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
*/
protected void buttonPressed(final int id) {
if (id == TERMINATE_ID || id == DISCONNECT_ID) {
final DebugException[] ex = new DebugException[1];
final String[] operation = new String[1];
ex[0] = null;
Runnable r = new Runnable() {
public void run() {
try {
if (id == TERMINATE_ID) {
operation[0]= DebugUIMessages.getString("HotCodeReplaceErrorDialog.5"); //$NON-NLS-1$
target.terminate();
} else {
operation[0]= DebugUIMessages.getString("HotCodeReplaceErrorDialog.6"); //$NON-NLS-1$
target.disconnect();
}
} catch (DebugException e) {
ex[0] = e;
}
}
};
BusyIndicator.showWhile(getShell().getDisplay(), r);
if (ex[0] != null) {
JDIDebugUIPlugin.errorDialog(MessageFormat.format(DebugUIMessages.getString("HotCodeReplaceErrorDialog.2"), operation), ex[0].getStatus()); //$NON-NLS-1$
}
okPressed();
} else {
super.buttonPressed(id);
}
}
}