Java Code Examples for org.eclipse.jface.dialogs.MessageDialog.getReturnCode()

The following are Jave code examples for showing how to use getReturnCode() of the org.eclipse.jface.dialogs.MessageDialog class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: convertigo-eclipse   File: MultipleDeletionDialog.java   Source Code and License Vote up 5 votes
private boolean confirmOverwrite(String msg) {
	if (shell == null) return false;
	final MessageDialog dialog = 
		new MessageDialog(shell, title, null, msg, MessageDialog.QUESTION, buttons, 0);

	shell.getDisplay().syncExec(
		new Runnable() {
			public void run() {
				dialog.open();
			}
		});
	if (hasMultiple) {
		switch (dialog.getReturnCode()) {
			case 0:
				return true;
			case 1:
				confirmation = YES_TO_ALL; 
				return true;
			case 2:
				return false;
			case 3:
				confirmation = NO_TO_ALL;
			default:
				return false;
		}
	} else {
		switch (dialog.getReturnCode()) {
		case 0:
			return true;
		case 1:
			return false;
		case 2:
		default:
			return false;
		}
	}
}
 
Example 2
Project: n4js   File: AbstractExportToSingleFileWizardPage.java   Source Code and License Vote up 4 votes
/**
 * The default implementation of this <code>IOverwriteQuery</code> method asks the user whether the existing
 * resource at the given path should be overwritten.
 *
 * @param pathString
 *            the path of the archive
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>, <code>"ALL"</code>, or
 *         <code>"CANCEL"</code>
 */
@Override
public String queryOverwrite(String pathString) {

	IPath path = Path.fromOSString(pathString);

	String messageString;
	// Break the message up if there is a file name and a directory
	// and there are at least 2 segments.
	if (path.getFileExtension() == null || path.segmentCount() < 2) {
		messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString);
	} else {
		messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion,
				path.lastSegment(),
				path.removeLastSegments(1).toOSString());
	}

	final MessageDialog dialog = new MessageDialog(getContainer()
			.getShell(), IDEWorkbenchMessages.Question,
			null, messageString, MessageDialog.QUESTION, new String[] {
		IDialogConstants.YES_LABEL,
		IDialogConstants.YES_TO_ALL_LABEL,
		IDialogConstants.NO_LABEL,
		IDialogConstants.NO_TO_ALL_LABEL,
		IDialogConstants.CANCEL_LABEL }, 0) {
		@Override
		protected int getShellStyle() {
			return super.getShellStyle() | SWT.SHEET;
		}
	};
	String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
	// run in syncExec because callback is from an operation,
	// which is probably not running in the UI thread.
	getControl().getDisplay().syncExec(new Runnable() {
		@Override
		public void run() {
			dialog.open();
		}
	});
	return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}