List of usage examples for org.eclipse.jface.dialogs MessageDialog QUESTION
int QUESTION
To view the source code for org.eclipse.jface.dialogs MessageDialog QUESTION.
Click Source Link
From source file:org.eclipse.ui.internal.ide.dialogs.ResourceInfoPage.java
License:Open Source License
private boolean shouldPerformRecursiveChanges(List/*<IResourceChange>*/ changes) { if (!changes.isEmpty()) { String message = IDEWorkbenchMessages.ResourceInfo_recursiveChangesSummary + "\n"; //$NON-NLS-1$ for (int i = 0; i < changes.size(); i++) { message += ((IResourceChange) changes.get(i)).getMessage(); }/*from w w w. j a v a 2 s . c o m*/ message += IDEWorkbenchMessages.ResourceInfo_recursiveChangesQuestion; MessageDialog dialog = new MessageDialog(getShell(), IDEWorkbenchMessages.ResourceInfo_recursiveChangesTitle, null, message, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1); return dialog.open() == 0; } return false; }
From source file:org.eclipse.ui.internal.ide.IDEWorkbenchErrorHandler.java
License:Open Source License
private FatalErrorDialog openInternalQuestionDialog(Shell parent, String title, String message, Throwable detail, int defaultIndex) { String[] labels;/*from w ww. j a v a 2 s .c om*/ if (detail == null) { labels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }; } else { labels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.SHOW_DETAILS_LABEL }; } FatalErrorDialog dialog = new FatalErrorDialog(parent, title, null, // accept // the // default // window // icon message, detail, MessageDialog.QUESTION, labels, defaultIndex); if (detail != null) { dialog.setDetailButton(2); } return dialog; }
From source file:org.eclipse.ui.internal.ResetPerspectiveAction.java
License:Open Source License
protected void run(IWorkbenchPage page, IPerspectiveDescriptor persp) { String message = NLS.bind(WorkbenchMessages.ResetPerspective_message, persp.getLabel()); String[] buttons = new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }; MessageDialog d = new MessageDialog(getWindow().getShell(), WorkbenchMessages.ResetPerspective_title, null, message, MessageDialog.QUESTION, buttons, 0); if (d.open() == 0) { page.resetPerspective();/*w w w . j av a 2 s. c om*/ } }
From source file:org.eclipse.ui.internal.SaveableHelper.java
License:Open Source License
/** * Saves the workbench part./*from w w w .j ava2 s . com*/ * * @param saveable the part * @param part the same part * @param window the workbench window * @param confirm request confirmation * @return <code>true</code> for continue, <code>false</code> if the operation * was canceled. */ public static boolean savePart(final ISaveablePart saveable, IWorkbenchPart part, IWorkbenchWindow window, boolean confirm) { // Short circuit. if (!saveable.isDirty()) { return true; } // If confirmation is required .. if (confirm) { int choice = AutomatedResponse; if (choice == USER_RESPONSE) { if (saveable instanceof ISaveablePart2) { choice = ((ISaveablePart2) saveable).promptToSaveOnClose(); } if (choice == USER_RESPONSE || choice == ISaveablePart2.DEFAULT) { String message = NLS.bind(WorkbenchMessages.EditorManager_saveChangesQuestion, part.getTitle()); // Show a dialog. String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; MessageDialog d = new MessageDialog(window.getShell(), WorkbenchMessages.Save_Resource, null, message, MessageDialog.QUESTION, buttons, 0) { protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; choice = d.open(); } } // Branch on the user choice. // The choice id is based on the order of button labels above. switch (choice) { case ISaveablePart2.YES: //yes break; case ISaveablePart2.NO: //no return true; default: case ISaveablePart2.CANCEL: //cancel return false; } } if (saveable instanceof ISaveablesSource) { return saveModels((ISaveablesSource) saveable, window, confirm); } // Create save block. IRunnableWithProgress progressOp = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { IProgressMonitor monitorWrap = new EventLoopProgressMonitor(monitor); saveable.doSave(monitorWrap); } }; // Do the save. return runProgressMonitorOperation(WorkbenchMessages.Save, progressOp, window); }
From source file:org.eclipse.ui.internal.SaveablesList.java
License:Open Source License
/** * Prompt the user to save the given saveables. * @param modelsToSave the saveables to be saved * @param shellProvider the provider used to obtain a shell in prompting is * required. Clients can use a workbench window for this. * @param runnableContext a runnable context that will be used to provide a * progress monitor while the save is taking place. Clients can * use a workbench window for this. * @param canCancel whether the operation can be canceled * @param stillOpenElsewhere whether the models are referenced by open parts * @return true if the user canceled/*ww w.j a v a2s . com*/ */ public boolean promptForSaving(List modelsToSave, final IShellProvider shellProvider, IRunnableContext runnableContext, final boolean canCancel, boolean stillOpenElsewhere) { // Save parts, exit the method if cancel is pressed. if (modelsToSave.size() > 0) { boolean canceled = SaveableHelper.waitForBackgroundSaveJobs(modelsToSave); if (canceled) { return true; } IPreferenceStore apiPreferenceStore = PrefUtil.getAPIPreferenceStore(); boolean dontPrompt = stillOpenElsewhere && !apiPreferenceStore .getBoolean(IWorkbenchPreferenceConstants.PROMPT_WHEN_SAVEABLE_STILL_OPEN); if (dontPrompt) { modelsToSave.clear(); return false; } else if (modelsToSave.size() == 1) { Saveable model = (Saveable) modelsToSave.get(0); // Show a dialog. String[] buttons; if (canCancel) { buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; } else { buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }; } // don't save if we don't prompt int choice = ISaveablePart2.NO; MessageDialog dialog; if (stillOpenElsewhere) { String message = NLS.bind(WorkbenchMessages.EditorManager_saveChangesOptionallyQuestion, model.getName()); MessageDialogWithToggle dialogWithToggle = new MessageDialogWithToggle(shellProvider.getShell(), WorkbenchMessages.Save_Resource, null, message, MessageDialog.QUESTION, buttons, 0, WorkbenchMessages.EditorManager_closeWithoutPromptingOption, false) { protected int getShellStyle() { return (canCancel ? SWT.CLOSE : SWT.NONE) | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL | SWT.SHEET | getDefaultOrientation(); } }; dialog = dialogWithToggle; } else { String message = NLS.bind(WorkbenchMessages.EditorManager_saveChangesQuestion, model.getName()); dialog = new MessageDialog(shellProvider.getShell(), WorkbenchMessages.Save_Resource, null, message, MessageDialog.QUESTION, buttons, 0) { protected int getShellStyle() { return (canCancel ? SWT.CLOSE : SWT.NONE) | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL | SWT.SHEET | getDefaultOrientation(); } }; } choice = SaveableHelper.testGetAutomatedResponse(); if (SaveableHelper.testGetAutomatedResponse() == SaveableHelper.USER_RESPONSE) { choice = dialog.open(); if (stillOpenElsewhere) { // map value of choice back to ISaveablePart2 values switch (choice) { case IDialogConstants.YES_ID: choice = ISaveablePart2.YES; break; case IDialogConstants.NO_ID: choice = ISaveablePart2.NO; break; case IDialogConstants.CANCEL_ID: choice = ISaveablePart2.CANCEL; break; default: break; } MessageDialogWithToggle dialogWithToggle = (MessageDialogWithToggle) dialog; if (choice != ISaveablePart2.CANCEL && dialogWithToggle.getToggleState()) { apiPreferenceStore .setValue(IWorkbenchPreferenceConstants.PROMPT_WHEN_SAVEABLE_STILL_OPEN, false); } } } // Branch on the user choice. // The choice id is based on the order of button labels // above. switch (choice) { case ISaveablePart2.YES: // yes break; case ISaveablePart2.NO: // no modelsToSave.clear(); break; default: case ISaveablePart2.CANCEL: // cancel return true; } } else { MyListSelectionDialog dlg = new MyListSelectionDialog(shellProvider.getShell(), modelsToSave, new ArrayContentProvider(), new WorkbenchPartLabelProvider(), stillOpenElsewhere ? WorkbenchMessages.EditorManager_saveResourcesOptionallyMessage : WorkbenchMessages.EditorManager_saveResourcesMessage, canCancel, stillOpenElsewhere); dlg.setInitialSelections(modelsToSave.toArray()); dlg.setTitle(WorkbenchMessages.EditorManager_saveResourcesTitle); // this "if" statement aids in testing. if (SaveableHelper.testGetAutomatedResponse() == SaveableHelper.USER_RESPONSE) { int result = dlg.open(); // Just return null to prevent the operation continuing if (result == IDialogConstants.CANCEL_ID) return true; if (dlg.getDontPromptSelection()) { apiPreferenceStore.setValue(IWorkbenchPreferenceConstants.PROMPT_WHEN_SAVEABLE_STILL_OPEN, false); } modelsToSave = Arrays.asList(dlg.getResult()); } } } // Create save block. return saveModels(modelsToSave, shellProvider, runnableContext); }
From source file:org.eclipse.ui.internal.SavePerspectiveAction.java
License:Open Source License
/** * Save a singleton over itself.//from www .jav a 2 s.c om */ private void saveSingleton(IWorkbenchPage page) { String[] buttons = new String[] { IDialogConstants.get().OK_LABEL, IDialogConstants.get().CANCEL_LABEL }; MessageDialog d = new MessageDialog(page.getWorkbenchWindow().getShell(), WorkbenchMessages.get().SavePerspective_overwriteTitle, null, WorkbenchMessages.get().SavePerspective_singletonQuestion, MessageDialog.QUESTION, buttons, 0); if (d.open() == 0) { page.savePerspective(); } }
From source file:org.eclipse.ui.internal.tweaklets.TabBehaviourMRU.java
License:Open Source License
public IEditorReference findReusableEditor(WorkbenchPage page) { boolean reuse = WorkbenchPlugin.getDefault().getPreferenceStore() .getBoolean(IPreferenceConstants.REUSE_EDITORS_BOOLEAN); if (!reuse) { return null; }//from w w w .ja v a 2 s . com IEditorReference editors[] = page.getSortedEditors(); int length = editors.length; if (length < page.getEditorReuseThreshold()) { return null; } else if (length > page.getEditorReuseThreshold()) { List<IEditorReference> refs = new ArrayList<IEditorReference>(); List<IEditorReference> keep = new ArrayList<IEditorReference>(Arrays.asList(editors)); int extra = length - page.getEditorReuseThreshold(); // look for extra editors that should be closed for (int i = 0; i < editors.length; i++) { if (extra == 0) { break; } if (editors[i].isPinned() || editors[i].isDirty()) { continue; } refs.add(editors[i]); extra--; } for (IEditorReference ref : refs) { page.closeEditor(ref, false); keep.remove(ref); } editors = keep.toArray(new IEditorReference[keep.size()]); } IEditorReference dirtyEditor = null; // find an editor to reuse, go in reverse due to activation order for (int i = editors.length - 1; i > -1; i--) { IEditorReference editor = editors[i]; if (editor.isPinned()) { // skip pinned editors continue; } if (editor.isDirty()) { // record dirty editors if (dirtyEditor == null) { dirtyEditor = editor; } continue; } // an editor is neither pinned nor dirty, use this one return editor; } // can't find anything, return null if (dirtyEditor == null) { return null; } /* fix for 11122 */ boolean reuseDirty = WorkbenchPlugin.getDefault().getPreferenceStore() .getBoolean(IPreferenceConstants.REUSE_DIRTY_EDITORS); if (!reuseDirty) { return null; } MessageDialog dialog = new MessageDialog(page.getWorkbenchWindow().getShell(), WorkbenchMessages.EditorManager_reuseEditorDialogTitle, null, // accept the default window icon NLS.bind(WorkbenchMessages.EditorManager_saveChangesQuestion, dirtyEditor.getName()), MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, WorkbenchMessages.EditorManager_openNewEditorLabel }, 0) { protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; int result = dialog.open(); if (result == 0) { // YES IEditorPart editor = dirtyEditor.getEditor(true); if (!page.saveEditor(editor, false)) { return null; } } else if ((result == 2) || (result == -1)) { return null; } return dirtyEditor; }
From source file:org.eclipse.ui.internal.wizards.preferences.WizardPreferencesPage.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 w w . ja v a 2 s . c o 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(PreferencesMessages.WizardDataTransfer_existsQuestion, pathString); } else { messageString = NLS.bind(PreferencesMessages.WizardDataTransfer_overwriteNameAndPathQuestion, path.lastSegment(), path.removeLastSegments(1).toOSString()); } final MessageDialog dialog = new MessageDialog(getContainer().getShell(), PreferencesMessages.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.ui.operations.NonLocalUndoUserApprover.java
License:Open Source License
private IStatus proceedWithOperation(IUndoableOperation operation, final String message, final String discardButton, final String title) { // if the operation cannot tell us about its modified elements, there's // nothing we can do. if (!(operation instanceof IAdvancedUndoableOperation)) { return Status.OK_STATUS; }//from w w w . jav a2 s .c om // Obtain the operation's affected objects. Object[] modifiedElements = ((IAdvancedUndoableOperation) operation).getAffectedObjects(); // Since the operation participates in describing its affected objects, // we assume for the rest of this method that an inability to // determine a match implies that a non-local operation is occurring. // This is a conservative assumption that provides more user prompting. boolean local; if (modifiedElements == null) { // The operation could not determine which elements are affected. // Consider the operation non-local. local = false; } else { // The operation answered some array of affected objects. Consider // the operation local until a non-match is found. Note that an // empty // array of affected objects is considered a local change. local = true; for (int i = 0; i < modifiedElements.length; i++) { Object modifiedElement = modifiedElements[i]; if (!elementsContains(modifiedElement)) { // the modified element is not known by the editor local = false; // one last try - try to adapt the modified element if a // preferred // comparison class has been provided. if (affectedObjectsClass != null) { Object adapter = Util.getAdapter(modifiedElement, affectedObjectsClass); if (adapter != null && elementsContains(adapter)) { local = true; } } // if the element did not match the affected objects, no // need to check any others. if (!local) { break; } } } } if (local) { return Status.OK_STATUS; } // The operation affects more than just our element. Find out if // we should proceed, cancel, or discard the undo. Must be done in // a syncExec because operation approval notifications may come from // a background thread. final int[] answer = new int[1]; PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { public void run() { MessageDialog dialog = new MessageDialog(part.getSite().getShell(), title, null, message, MessageDialog.QUESTION, new String[] { IDialogConstants.OK_LABEL, discardButton, IDialogConstants.CANCEL_LABEL }, 0); // yes is the default answer[0] = dialog.open(); } }); switch (answer[0]) { case 0: return Status.OK_STATUS; case 1: return IOperationHistory.OPERATION_INVALID_STATUS; default: // Cancel by default to include ESC key and shell close, // which return SWT.DEFAULT, and any other unexpected return codes return Status.CANCEL_STATUS; } }