List of usage examples for org.eclipse.jface.dialogs MessageDialog getReturnCode
public int getReturnCode()
From source file:org.erlide.ui.wizards.ErlangProjectImportWizardPage.java
License:Open Source License
/** * 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. * //from ww w . j a va2 s . com * @param pathString * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>, * <code>"ALL"</code>, or <code>"CANCEL"</code> */ @Override public String queryOverwrite(final String pathString) { final 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(WizardMessages.WizardDataTransfer_existsQuestion, pathString); } else { messageString = NLS.bind(WizardMessages.WizardDataTransfer_overwriteNameAndPathQuestion, path.lastSegment(), path.removeLastSegments(1).toOSString()); } final MessageDialog dialog = new MessageDialog(getContainer().getShell(), WizardMessages.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) { }; final 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()]; }
From source file:org.fastcode.util.SourceUtil.java
License:Open Source License
/** * @param msg/*from ww w . jav a2 s. c o m*/ * @return */ public static int openMessageDilalog(final String msg, final String button1Name, final String button2Name) { final MessageDialog dialog = new MessageDialog(new Shell(), "Warning", null, msg, MessageDialog.WARNING, new String[] { button1Name, button2Name }, 0) { @Override protected void buttonPressed(final int buttonId) { setReturnCode(buttonId); close(); } }; dialog.open(); return dialog.getReturnCode(); }
From source file:org.jboss.tools.runtime.ui.internal.wizard.DownloadRuntimeOperationUIUtility.java
License:Open Source License
public static IOverwrite createOverwriteFileQuery() { IOverwrite overwriteQuery = new IOverwrite() { public int overwrite(File file) { final String msg = NLS.bind(Messages.DownloadRuntimesSecondPage_The_file_already_exists, file.getAbsolutePath()); final String[] options = { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL, IDialogConstants.CANCEL_LABEL }; final int[] retVal = new int[1]; Display.getDefault().syncExec(new Runnable() { public void run() { Shell shell = PlatformUI.getWorkbench().getModalDialogShellProvider().getShell(); MessageDialog dialog = new MessageDialog(shell, Messages.DownloadRuntimesSecondPage_Question, null, msg, MessageDialog.QUESTION, options, 0) { protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; }/*from w ww. j a v a 2s . c om*/ }; dialog.open(); retVal[0] = dialog.getReturnCode(); } }); return retVal[0]; } }; return overwriteQuery; }
From source file:org.jboss.tools.runtime.ui.internal.wizard.DownloadRuntimeOperationUtility.java
License:Open Source License
private static IOverwrite createOverwriteFileQuery() { IOverwrite overwriteQuery = new IOverwrite() { public int overwrite(File file) { final String msg = NLS.bind(Messages.DownloadRuntimesSecondPage_The_file_already_exists, file.getAbsolutePath()); final String[] options = { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL, IDialogConstants.CANCEL_LABEL }; final int[] retVal = new int[1]; Display.getDefault().syncExec(new Runnable() { public void run() { Shell shell = PlatformUI.getWorkbench().getModalDialogShellProvider().getShell(); MessageDialog dialog = new MessageDialog(shell, Messages.DownloadRuntimesSecondPage_Question, null, msg, MessageDialog.QUESTION, options, 0) { protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; }//from ww w. j ava2s . c om }; dialog.open(); retVal[0] = dialog.getReturnCode(); } }); return retVal[0]; } }; return overwriteQuery; }
From source file:org.jboss.tools.windup.ui.internal.wizards.WindupReportExportWizardPage1.java
License:Open Source License
/** * 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. * //from w ww .j a va 2 s. c om * @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(Messages.WindupReportExport_question_fileExists, pathString); } else { messageString = NLS.bind(Messages.WindupReportExport_question_overwriteNameAndPath, path.lastSegment(), path.removeLastSegments(1).toOSString()); } final MessageDialog dialog = new MessageDialog(getContainer().getShell(), Messages.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()]; }
From source file:org.mendix.eclipse.util.EclipseUtil.java
License:Open Source License
/** * Show a question in a modal dialog box and return the user's answer. * /*from ww w . j a v a2 s . co m*/ * @param title * Text for the title bar of the dialog window * @param message * The text of the message * @return true if users selects ok, false if he selected Cancel */ static public boolean showQuestion(String title, String message) { boolean goThrough; // accept the default window icon // TODO error in SWT cannot find WARNING icon final MessageDialog dialog = new MessageDialog(null, title, null, message, MessageDialog.NONE, new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0); Display.getDefault().syncExec(new Runnable() { public void run() { dialog.open(); } }); if (dialog.getReturnCode() == Window.OK) { goThrough = true; } else { goThrough = false; } return goThrough; }
From source file:org.objectstyle.wolips.ui.actions.FindUnusedWOCodeAction.java
License:Open Source License
public void run(IAction action) { IWorkbench workbench = PlatformUI.getWorkbench(); shell = workbench.getActiveWorkbenchWindow().getShell(); if (selection instanceof IStructuredSelection) { for (Iterator it = ((IStructuredSelection) selection).iterator(); it.hasNext();) { Object element = it.next(); IProject project = null;/* w ww . j ava 2s . c om*/ if (element instanceof IProject) { project = (IProject) element; } else if (element instanceof IAdaptable) { project = (IProject) ((IAdaptable) element).getAdapter(IProject.class); } if (project != null) { if (MessageDialog.openConfirm(shell, "Confirm action", "Processing project: " + project.getName() + "\n\n" + "Please save changes before and check that no compiler errors exist.")) { try { IJavaProject javaProject = JavaCore.create(project); MethodSearch methodSearcher = new MethodSearch(javaProject); IRunnableWithProgress op = methodSearcher; ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell); progressDialog.run(true, true, op); // output format? MessageDialog formatDialog = new MessageDialog(shell, "Output Format", null, "What kind of output do you want?", 0, new String[] { "cancel", "Comments", "Text File", }, 1); formatDialog.open(); if (formatDialog.getReturnCode() == 2) { // text file InputDialog inputDialog = new InputDialog(shell, "Output text file", "Where do you want to save the file?", "file path including name", null); inputDialog.open(); if (inputDialog.getReturnCode() == Window.OK) { String path = inputDialog.getValue(); while (path == null || path.length() == 0) { inputDialog.open(); inputDialog.setErrorMessage("Wrong Input"); path = inputDialog.getValue(); } methodSearcher.writePossiblyUnusedMethodsToFile(new File(path)); } } else if (formatDialog.getReturnCode() == 1) { // comments if (!methodSearcher.setComments()) { throw new InterruptedException(); } } } catch (InvocationTargetException e) { StackTraceElement[] stackTraces = e.getStackTrace(); String stackTraceString = ""; for (int i = 0; i < stackTraces.length; i++) { stackTraceString += stackTraces[i].toString() + "\n"; } MessageDialog.openError(shell, "Error", "Error searching for unused WO code:\n\n" + e.toString() + "\n\n" + e.getCause().toString()); } catch (InterruptedException e) { MessageDialog.openWarning(shell, "Process Canceled", "Search for unsused WO code canceled"); } } } } } }
From source file:org.python.pydev.navigator.actions.copied.CopyFilesAndFoldersOperation.java
License:Open Source License
/** * Check if the user wishes to overwrite the supplied resource or all * resources./*from w w w . jav a 2 s .com*/ * * @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() { 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]; }
From source file:org.python.pydev.navigator.actions.copied.CopyFilesAndFoldersOperation.java
License:Open Source License
/** * Performs an import of the given stores into the provided container. * Returns a status indicating if the import was successful. * * @param stores/* w w w. j a va 2s .c o m*/ * stores that are to be imported * @param target * container to which the import will be done * @param monitor * a progress monitor for showing progress and for cancelation */ private void performFileImport(IFileStore[] stores, IContainer target, IProgressMonitor monitor) { IOverwriteQuery query = new IOverwriteQuery() { public String queryOverwrite(String pathString) { if (alwaysOverwrite) { return ALL; } final String returnCode[] = { CANCEL }; final String msg = NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteQuestion, pathString); final String[] options = { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; messageShell.getDisplay().syncExec(new Runnable() { public void run() { MessageDialog dialog = new MessageDialog(messageShell, IDEWorkbenchMessages.CopyFilesAndFoldersOperation_question, null, msg, MessageDialog.QUESTION, options, 0); dialog.open(); int returnVal = dialog.getReturnCode(); String[] returnCodes = { YES, ALL, NO, CANCEL }; returnCode[0] = returnVal == -1 ? CANCEL : returnCodes[returnVal]; } }); if (returnCode[0] == ALL) { alwaysOverwrite = true; } else if (returnCode[0] == CANCEL) { canceled = true; } return returnCode[0]; } }; ImportOperation op = new ImportOperation(target.getFullPath(), stores[0].getParent(), FileStoreStructureProvider.INSTANCE, query, Arrays.asList(stores)); op.setContext(messageShell); op.setCreateContainerStructure(false); try { op.run(monitor); } catch (InterruptedException e) { return; } catch (InvocationTargetException e) { if (e.getTargetException() instanceof CoreException) { displayError(((CoreException) e.getTargetException()).getStatus()); } else { display(e); } return; } // Special case since ImportOperation doesn't throw a CoreException on // failure. IStatus status = op.getStatus(); if (!status.isOK()) { if (errorStatus == null) { errorStatus = new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.ERROR, getProblemsMessage(), null); } errorStatus.merge(status); } }
From source file:org.symbian.tools.wrttools.wizards.projectimport.WrtProjectLocationWizardPage.java
License:Open Source License
/** * 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//from w w w .j a va 2 s . co m * @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); if (path.segmentCount() > 1 && ".settings".equals(path.segment(1))) { return NO; } 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()]; }