List of usage examples for org.eclipse.jface.dialogs MessageDialog getReturnCode
public int getReturnCode()
From source file:org.eclipse.jubula.client.ui.rcp.handlers.StopAutHandler.java
License:Open Source License
/** * {@inheritDoc}// www .ja v a 2s .c om */ public Object executeImpl(ExecutionEvent event) throws ExecutionException { ISelection sel = HandlerUtil.getCurrentSelectionChecked(event); if (sel instanceof IStructuredSelection) { IStructuredSelection structSel = (IStructuredSelection) sel; Set<AutIdentifier> autsToStop = new HashSet<AutIdentifier>(); for (Object selectedObj : structSel.toArray()) { if (selectedObj instanceof AutIdentifier) { autsToStop.add((AutIdentifier) selectedObj); } } if (!autsToStop.isEmpty() && Plugin.getDefault().getPreferenceStore().getBoolean(Constants.ASKSTOPAUT_KEY)) { MessageDialog dialog = getConfirmDialog(); if (dialog.getReturnCode() != Window.OK) { if (isJobRunning()) { m_jobManager.cancel(m_jobFamily); } return null; } } for (AutIdentifier autId : autsToStop) { TestExecutionContributor.getInstance().stopAUT(autId); } } return null; }
From source file:org.eclipse.papyrus.diagram.composite.custom.edit.command.SetTypeWithDialogCommand.java
License:Open Source License
@Override protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { CommandResult result;//www .ja v a 2 s.com Object currentValue = getElementToEdit().eGet(request.getFeature()); if (currentValue != null) { String[] labels = new String[2]; labels[0] = "OK"; labels[1] = "Cancel"; MessageDialog dialog = new MessageDialog(new Shell(), "Confirm changes", null, "Do you want to replace current type ?", MessageDialog.QUESTION_WITH_CANCEL, labels, 0); dialog.open(); switch (dialog.getReturnCode()) { case MessageDialog.OK: result = super.doExecuteWithResult(monitor, info); break; default: result = CommandResult.newOKCommandResult(); break; } ; } else { result = super.doExecuteWithResult(monitor, info); } return result; }
From source file:org.eclipse.ptp.etfw.tau.selinst.popup.actions.IncrementInstrument.java
License:Open Source License
public static String getPhaseTimeLine(String file, int start, int stop) { class ValidateName implements IInputValidator { public String isValid(String newText) { if (newText.equals("")) { return Messages.IncrementInstrument_EnterValidText; }/*from www . j ava2 s . c o m*/ return null; } } final String[] opts = { "static timer", "dynamic timer", "static phase", "dynamic phase", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ Messages.IncrementInstrument_Cancel }; final MessageDialog timephase = new MessageDialog(CUIPlugin.getActiveWorkbenchShell(), Messages.IncrementInstrument_InstTypeSelect, null, Messages.IncrementInstrument_SelectOneOfFollowing, MessageDialog.QUESTION, opts, 0); if (timephase.open() == 4) { return null; } final int optline = timephase.getReturnCode(); final InputDialog namedialog = new InputDialog(CUIPlugin.getActiveWorkbenchShell(), Messages.IncrementInstrument_UserDefEventName, Messages.IncrementInstrument_EnterUniqueName, "", new ValidateName()); if (namedialog.open() == Window.CANCEL) { return null; } final String testline = namedialog.getValue(); return opts[optline] + " name=\"TAU__" + testline.replaceAll("\\W", "") + "\" file=\"" + file + "\" line=" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$ + start + " to line=" + stop; //$NON-NLS-1$ }
From source file:org.eclipse.rcptt.ui.actions.edit.PasteAction.java
License:Open Source License
/** * Check if the user wishes to overwrite the supplied resource or all * resources. Copied from// w w w . ja v a 2s. c o m * org.eclipse.ui.actions.CopyFilesAndFoldersOperation. * * @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 }; 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(shell, IDEWorkbenchMessages.CopyFilesAndFoldersOperation_resourceExists, null, message, MessageDialog.QUESTION, labels, 0) { protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; 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()]; } } }; shell.getDisplay().syncExec(query); return result[0]; }
From source file:org.eclipse.rcptt.ui.actions.edit.Q7CopyFilesAndFoldersOperation.java
License:Open Source License
/** * Check if the user wishes to overwrite the supplied resource or all * resources./* w w w. j a v a 2s. c o m*/ * * @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() { @SuppressWarnings("restriction") 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( org.eclipse.ui.internal.ide.IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteMergeQuestion, destination.getFullPath().makeRelative()); } else { if (destination.isLinked()) { message = NLS.bind( org.eclipse.ui.internal.ide.IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteNoMergeLinkQuestion, destination.getFullPath().makeRelative()); } else { message = NLS.bind( org.eclipse.ui.internal.ide.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[] { org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils.getLocationText(destination), org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils .getDateStringValue(destination), org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils.getLocationText(source), org.eclipse.ui.internal.ide.dialogs.IDEResourceInfoUtils.getDateStringValue(source) }; message = NLS.bind( org.eclipse.ui.internal.ide.IDEWorkbenchMessages.CopyFilesAndFoldersOperation_overwriteWithDetailsQuestion, bindings); } MessageDialog dialog = new MessageDialog(messageShell, org.eclipse.ui.internal.ide.IDEWorkbenchMessages.CopyFilesAndFoldersOperation_resourceExists, null, message, MessageDialog.QUESTION, labels, 0) { protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; 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.eclipse.rcptt.ui.actions.edit.Q7CopyFilesAndFoldersOperation.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. * //from ww w. ja v a 2 s .c om * @param stores * 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() { @SuppressWarnings("restriction") public String queryOverwrite(String pathString) { if (alwaysOverwrite) { return ALL; } final String returnCode[] = { CANCEL }; final String msg = NLS.bind( org.eclipse.ui.internal.ide.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, org.eclipse.ui.internal.ide.IDEWorkbenchMessages.CopyFilesAndFoldersOperation_question, null, msg, MessageDialog.QUESTION, options, 0) { protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; 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); op.setVirtualFolders(createVirtualFoldersAndLinks); op.setCreateLinks(createLinks); op.setRelativeVariable(relativeVariable); 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.eclipse.rcptt.ui.resources.wizards.WizardFileSystemResourceImportPage1.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. * /* www . ja v a 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( org.eclipse.ui.internal.ide.IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString); } else { messageString = NLS.bind( org.eclipse.ui.internal.ide.IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion, path.lastSegment(), path.removeLastSegments(1).toOSString()); } final MessageDialog dialog = new MessageDialog(getContainer().getShell(), org.eclipse.ui.internal.ide.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()]; }
From source file:org.eclipse.rcptt.ui.wizards.imports.BaseProjectsImportPage.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 av a2 s . co m*/ * @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.BaseProjectsImportPage_29, pathString); } else { messageString = NLS.bind(Messages.BaseProjectsImportPage_30, path.lastSegment(), path.removeLastSegments(1).toOSString()); } final MessageDialog dialog = new MessageDialog(getContainer().getShell(), Messages.BaseProjectsImportPage_31, 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.eclipse.team.internal.ccvs.ui.wizards.GenerateDiffFileWizard.java
License:Open Source License
public boolean validateFile(File file) { if (file == null) return false; /**//from www.j a v a 2 s . co m * Consider file valid if it doesn't exist for now. */ if (!file.exists()) return true; /** * The file exists. */ if (!file.canWrite()) { final String title = CVSUIMessages.GenerateCVSDiff_1; final String msg = CVSUIMessages.GenerateCVSDiff_2; final MessageDialog dialog = new MessageDialog(getShell(), title, null, msg, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0); dialog.open(); return false; } final String title = CVSUIMessages.GenerateCVSDiff_overwriteTitle; final String msg = CVSUIMessages.GenerateCVSDiff_overwriteMsg; final MessageDialog dialog = new MessageDialog(getShell(), title, null, msg, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.CANCEL_LABEL }, 0); dialog.open(); if (dialog.getReturnCode() != 0) return false; return true; }
From source file:org.eclipse.team.internal.ui.dialogs.MultipleYesNoPrompter.java
License:Open Source License
/** * Opens the confirmation dialog based on the prompt condition settings. *//*from ww w . ja v a 2s . c o m*/ private boolean confirmOverwrite(String msg) throws InterruptedException { Shell shell = shellProvider.getShell(); if (shell == null) return false; 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 (hasMultiple) { switch (dialog.getReturnCode()) { case 0://Yes return true; case 1://Yes to all confirmation = YES_TO_ALL; return true; case 2://No (or CANCEL for all-or-nothing) if (allOrNothing) { throw new InterruptedException(); } return false; case 3://No to all confirmation = NO_TO_ALL; return false; case 4://Cancel default: throw new InterruptedException(); } } else { switch (dialog.getReturnCode()) { case 0:// Yes return true; case 1:// No return false; case 2:// Cancel default: throw new InterruptedException(); } } }