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

The following examples show how to use org.eclipse.jface.dialogs.MessageDialog#getReturnCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RefreshHandler.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
void checkLocationDeleted(final IProject project) throws CoreException {
	if (!project.exists()) { return; }
	final IFileInfo location = IDEResourceInfoUtils.getFileInfo(project.getLocationURI());
	if (!location.exists()) {
		final String message = NLS.bind(IDEWorkbenchMessages.RefreshAction_locationDeletedMessage,
				project.getName(), location.toString());

		final MessageDialog dialog = new MessageDialog(WorkbenchHelper.getShell(),
				IDEWorkbenchMessages.RefreshAction_dialogTitle, null, message, MessageDialog.QUESTION,
				new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0) {
			@Override
			protected int getShellStyle() {
				return super.getShellStyle() | SWT.SHEET;
			}
		};
		WorkbenchHelper.run(() -> dialog.open());

		// Do the deletion back in the operation thread
		if (dialog.getReturnCode() == 0) { // yes was chosen
			project.delete(true, true, null);
		}
	}
}
 
Example 2
Source File: RefreshAction.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Checks whether the given project's location has been deleted. If so, prompts the user with whether to delete the
 * project or not.
 */
void checkLocationDeleted(final IProject project) throws CoreException {
	if (!project.exists()) { return; }
	final IFileInfo location = IDEResourceInfoUtils.getFileInfo(project.getLocationURI());
	if (!location.exists()) {
		final String message = NLS.bind(IDEWorkbenchMessages.RefreshAction_locationDeletedMessage,
				project.getName(), location.toString());

		final MessageDialog dialog =
				new MessageDialog(WorkbenchHelper.getShell(), IDEWorkbenchMessages.RefreshAction_dialogTitle, null,
						message, QUESTION, new String[] { YES_LABEL, NO_LABEL }, 0) {
					@Override
					protected int getShellStyle() {
						return super.getShellStyle() | SHEET;
					}
				};
		WorkbenchHelper.run(() -> dialog.open());

		// Do the deletion back in the operation thread
		if (dialog.getReturnCode() == 0) { // yes was chosen
			project.delete(true, true, null);
		}
	}
}
 
Example 3
Source File: NativeBinaryDestinationPage.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public String queryOverwrite(String pathString) {

	final MessageDialog dialog = new MessageDialog(getShell(), 
			"Overwrite Files?", 
			null, 
			 pathString+ " already exists. Would you like to overwrite it?",
			 MessageDialog.QUESTION,
			 new String[] { IDialogConstants.YES_LABEL,
                        IDialogConstants.NO_LABEL,
                        IDialogConstants.CANCEL_LABEL },
                        0);
	String[] response = new String[] { YES,  NO, CANCEL };
       //most likely to be called from non-ui thread
	getControl().getDisplay().syncExec(new Runnable() {
           public void run() {
               dialog.open();
           }
       });
       return dialog.getReturnCode() < 0 ? CANCEL : response[dialog
               .getReturnCode()];
}
 
Example 4
Source File: WizardFolderImportPage.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * The <code>WizardDataTransfer</code> implementation of this <code>IOverwriteQuery</code> method asks the user
 * whether the existing resource at the given path should be overwritten.
 * 
 * @param pathString
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>, <code>"ALL"</code>, or
 *         <code>"CANCEL"</code>
 */
public String queryOverwrite(String pathString)
{

	Path path = new Path(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);
	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()
	{
		public void run()
		{
			dialog.open();
		}
	});
	return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}
 
Example 5
Source File: CommitSynchronizeOperation.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Prompts the user to determine how conflicting changes should be handled.
 * Note: This method is designed to be overridden by test cases.
 * @return 0 to sync conflicts, 1 to sync all non-conflicts, 2 to cancel
 */
private int promptForConflicts(Shell shell, SyncInfoSet syncSet) {
	String[] buttons = new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL};
	String title = Policy.bind("SyncAction.commit.conflict.title"); //$NON-NLS-1$
	String question = Policy.bind("SyncAction.commit.conflict.question"); //$NON-NLS-1$
	final MessageDialog dialog = new MessageDialog(shell, title, null, question, MessageDialog.QUESTION, buttons, 0);
	shell.getDisplay().syncExec(new Runnable() {
		public void run() {
			dialog.open();
		}
	});
	return dialog.getReturnCode();
}
 
Example 6
Source File: PromptingDialog.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Opens the confirmation dialog based on the prompt condition settings.
 */
private boolean confirmOverwrite(String msg) throws InterruptedException { 
	if (!confirmOverwrite) {
		return true;
	}
	final MessageDialog dialog = 
		new MessageDialog(shell, title, null, msg, MessageDialog.QUESTION, buttons, 0);

	// run in syncExec because callback is from an operation,
	// which is probably not running in the UI thread.
	shell.getDisplay().syncExec(
		new Runnable() {
			public void run() {
				dialog.open();
			}
		});
	if (hasMultipleResources) {
		switch (dialog.getReturnCode()) {
			case 0://Yes
				return true;
			case 1://Yes to all
				confirmOverwrite = false; 
				return true;
			case 2://No
				return false;
			case 3://Cancel
			default:
				throw new InterruptedException();
		}
	} else {
		return dialog.getReturnCode() == 0;
	}
}
 
Example 7
Source File: DeleteTermHandler.java    From slr-toolkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
	if (selection == null || !(selection instanceof IStructuredSelection)) {
		return null;
	}
	IStructuredSelection currentSelection = (IStructuredSelection) selection;
	if (currentSelection.size() > 0) {			
		MessageDialog dialog = new MessageDialog(null,
				"Delete Term",
				null,
				"Are you sure you want to delete terms: " + 
						currentSelection.toList()
							.stream()
							.filter(s -> s instanceof Term)
							.map(s -> ((Term) s).getName())
							.collect(Collectors.joining(", ")),
				MessageDialog.QUESTION,
				new String[]{"Yes", "Cancel"},
				0);
		dialog.setBlockOnOpen(true);
		if (dialog.open() == MessageDialog.OK && dialog.getReturnCode() == MessageDialog.OK) {
			List<Term> termsToDelete = new ArrayList<>(currentSelection.size());
			currentSelection.toList().stream()
					.filter(s -> s instanceof Term)
					.forEach(s -> termsToDelete.add((Term) s));;
			TermDeleter.delete(termsToDelete);
		}
	}
	
	return null;
}
 
Example 8
Source File: ReorgQueries.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Runnable createQueryRunnable(final String question, final int[] result){
	return new Runnable() {
		public void run() {
			MessageDialog dialog= new MessageDialog(
				fShell,
				fDialogTitle,
				null,
				question,
				MessageDialog.QUESTION,
				getButtonLabels(),
				0);
			dialog.open();

			switch (dialog.getReturnCode()) {
				case -1 : //MessageDialog closed without choice => cancel | no
					//see also https://bugs.eclipse.org/bugs/show_bug.cgi?id=48400
					result[0]= IDialogConstants.CANCEL_ID;
					break;
				default:
					result[0]= dialog.getReturnCode();
			}
		}

		private String[] getButtonLabels() {
			return new String[] {IDialogConstants.SKIP_LABEL, ReorgMessages.ReorgQueries_skip_all, IDialogConstants.CANCEL_LABEL};
		}
	};
}
 
Example 9
Source File: MultiPageEditor.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Revert to last valid.
 *
 * @param msg the msg
 * @param msgDetails the msg details
 * @return true, if successful
 */
private boolean revertToLastValid(String msg, String msgDetails) {
  String[] buttonLabels = new String[2];
  buttonLabels[0] = Messages.getString("MultiPageEditor.revertToLastValid"); //$NON-NLS-1$
  buttonLabels[1] = Messages.getString("MultiPageEditor.EditExisting"); //$NON-NLS-1$
  MessageDialog dialog = new MessageDialog(getEditorSite().getShell(), msg, null, msgDetails,
          MessageDialog.WARNING, buttonLabels, 0);
  dialog.open();
  // next line depends on return code for button 1 (which is 1)
  // and CANCEL code both being == 1
  return dialog.getReturnCode() == 0;
}
 
Example 10
Source File: ReorgQueries.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private Runnable createQueryRunnable(final String question, final int[] result) {
	return new Runnable() {
		public void run() {
			int[] resultId= getResultIDs();

			MessageDialog dialog= new MessageDialog(
				fShell,
				fDialogTitle,
				null,
				question,
				MessageDialog.QUESTION,
				getButtonLabels(),
				0);
			dialog.open();

			if (dialog.getReturnCode() == -1) { //MessageDialog closed without choice => cancel | no
				//see also https://bugs.eclipse.org/bugs/show_bug.cgi?id=48400
				result[0]= fAllowCancel ? IDialogConstants.CANCEL_ID : IDialogConstants.NO_ID;
			} else {
				result[0]= resultId[dialog.getReturnCode()];
			}
		}

		private String[] getButtonLabels() {
			if (YesYesToAllNoNoToAllQuery.this.fAllowCancel)
				return new String[] {
					IDialogConstants.YES_LABEL,
					IDialogConstants.YES_TO_ALL_LABEL,
					IDialogConstants.NO_LABEL,
					IDialogConstants.NO_TO_ALL_LABEL,
					IDialogConstants.CANCEL_LABEL };
			else
				return new String[] {
					IDialogConstants.YES_LABEL,
					IDialogConstants.YES_TO_ALL_LABEL,
					IDialogConstants.NO_LABEL,
					IDialogConstants.NO_TO_ALL_LABEL};
		}

		private int[] getResultIDs() {
			if (YesYesToAllNoNoToAllQuery.this.fAllowCancel)
				return new int[] {
					IDialogConstants.YES_ID,
					IDialogConstants.YES_TO_ALL_ID,
					IDialogConstants.NO_ID,
					IDialogConstants.NO_TO_ALL_ID,
					IDialogConstants.CANCEL_ID};
			else
				return new int[] {
					IDialogConstants.YES_ID,
					IDialogConstants.YES_TO_ALL_ID,
					IDialogConstants.NO_ID,
					IDialogConstants.NO_TO_ALL_ID};
		}
	};
}
 
Example 11
Source File: ReorgQueries.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private Runnable createQueryRunnable(final String question, final int[] result){
	return new Runnable() {
		public void run() {
			MessageDialog dialog= new MessageDialog(
				fShell,
				fDialogTitle,
				null,
				question,
				MessageDialog.QUESTION,
				getButtonLabels(),
				0);
			dialog.open();

			switch (dialog.getReturnCode()) {
				case -1 : //MessageDialog closed without choice => cancel | no
					//see also https://bugs.eclipse.org/bugs/show_bug.cgi?id=48400
					result[0]= fAllowCancel ? IDialogConstants.CANCEL_ID : IDialogConstants.NO_ID;
					break;
				case 0 :
					result[0]= IDialogConstants.YES_ID;
					break;
				case 1 :
					result[0]= IDialogConstants.NO_ID;
					break;
				case 2 :
					if (fAllowCancel)
						result[0]= IDialogConstants.CANCEL_ID;
					else
						Assert.isTrue(false);
					break;
				default :
					Assert.isTrue(false);
					break;
			}
		}

		private String[] getButtonLabels() {
			if (fAllowCancel)
				return new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
			else
				return new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL};
		}
	};
}
 
Example 12
Source File: ImportProjectWizardPage.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The <code>WizardDataTransfer</code> implementation of this
 * <code>IOverwriteQuery</code> method asks the user whether the existing
 * resource at the given path should be overwritten.
 * 
 * @param pathString
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>,
 * 	<code>"ALL"</code>, or <code>"CANCEL"</code>
 */
public String queryOverwrite(String pathString) {

	Path path = new Path(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) {
		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() {
		public void run() {
			dialog.open();
		}
	});
	return dialog.getReturnCode() < 0 ? CANCEL : response[dialog
			.getReturnCode()];
}
 
Example 13
Source File: ImportProjectWizardPage.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The <code>WizardDataTransfer</code> implementation of this
 * <code>IOverwriteQuery</code> method asks the user whether the existing
 * resource at the given path should be overwritten.
 * 
 * @param pathString
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>,
 * 	<code>"ALL"</code>, or <code>"CANCEL"</code>
 */
public String queryOverwrite(String pathString) {

	Path path = new Path(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) {
		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() {
		public void run() {
			dialog.open();
		}
	});
	return dialog.getReturnCode() < 0 ? CANCEL : response[dialog
			.getReturnCode()];
}