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

The following examples show how to use org.eclipse.jface.dialogs.MessageDialog#getReturnCode() . These examples are extracted from open source projects. 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
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 Project: gama   File: RefreshAction.java    License: 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
@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
/**
 * 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
/**
 * 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
/**
 * 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
@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
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 Project: uima-uimaj   File: MultiPageEditor.java    License: 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
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
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
/**
 * 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
/**
 * 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 14
/**
 * Check if the user wishes to overwrite the supplied resource or all
 * resources.
 *
 * @param source
 *            the source resource
 * @param destination
 *            the resource to be overwritten
 * @return one of IDialogConstants.YES_ID, IDialogConstants.YES_TO_ALL_ID,
 *         IDialogConstants.NO_ID, IDialogConstants.CANCEL_ID indicating
 *         whether the current resource or all resources can be overwritten,
 *         or if the operation should be canceled.
 */
private int checkOverwrite(final IResource source, final IResource destination) {
    final int[] result = new int[1];

    // Dialogs need to be created and opened in the UI thread
    Runnable query = new Runnable() {
        @Override
        public void run() {
            String message;
            int resultId[] = { IDialogConstants.YES_ID, IDialogConstants.YES_TO_ALL_ID, IDialogConstants.NO_ID,
                    IDialogConstants.CANCEL_ID };
            String labels[] = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };

            if (destination.getType() == IResource.FOLDER) {
                if (homogenousResources(source, destination)) {
                    message = NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteMergeQuestion,
                            destination.getFullPath().makeRelative());
                } else {
                    if (destination.isLinked()) {
                        message = NLS.bind(
                                IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteNoMergeLinkQuestion,
                                destination.getFullPath().makeRelative());
                    } else {
                        message = NLS.bind(
                                IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteNoMergeNoLinkQuestion,
                                destination.getFullPath().makeRelative());
                    }
                    resultId = new int[] { IDialogConstants.YES_ID, IDialogConstants.NO_ID,
                            IDialogConstants.CANCEL_ID };
                    labels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                            IDialogConstants.CANCEL_LABEL };
                }
            } else {
                String[] bindings = new String[] { IDEResourceInfoUtils.getLocationText(destination),
                        IDEResourceInfoUtils.getDateStringValue(destination),
                        IDEResourceInfoUtils.getLocationText(source),
                        IDEResourceInfoUtils.getDateStringValue(source) };
                message = NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteWithDetailsQuestion,
                        bindings);
            }
            MessageDialog dialog = new MessageDialog(messageShell,
                    IDEWorkbenchMessages.CopyFilesAndFoldersOperation_resourceExists, null, message,
                    MessageDialog.QUESTION, labels, 0);
            dialog.open();
            if (dialog.getReturnCode() == SWT.DEFAULT) {
                // A window close returns SWT.DEFAULT, which has to be
                // mapped to a cancel
                result[0] = IDialogConstants.CANCEL_ID;
            } else {
                result[0] = resultId[dialog.getReturnCode()];
            }
        }
    };
    messageShell.getDisplay().syncExec(query);
    return result[0];
}