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.examples.jobs.actions.CreateJobsAction.java
License:Open Source License
private boolean askForExclusive() { MessageDialog dialog = new MessageDialog(window.getShell(), "Likes to be left alone?", //$NON-NLS-1$ null, "Press yes if the jobs should be run one at a time, and no otherwise", //$NON-NLS-1$ MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1 // no is the default );/*from w w w . ja v a2 s . c om*/ return dialog.open() == 0; }
From source file:org.eclipse.ui.examples.jobs.actions.CreateJobsAction.java
License:Open Source License
private boolean askForFailure() { MessageDialog dialog = new MessageDialog(window.getShell(), "Born to fail?", //$NON-NLS-1$ null, "Should the jobs return an error status?", //$NON-NLS-1$ MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1 // no is the default );/*from w w w .j av a 2s . c o m*/ return dialog.open() == 0; }
From source file:org.eclipse.ui.ide.examples.projectsnapshot.ProjectRefreshSnapshotExportWizardPage.java
License:Open Source License
private boolean executeSnapshotOperation(final IProject[] projects) { final MultiStatus status = new MultiStatus(IDEWorkbenchPlugin.IDE_WORKBENCH, 0, Messages.ProjectRefreshSnapshotExportWizardPage_errorsOccurred, null); final IPath snapshotPath = new Path(directorySnapshotPathField.getText().trim()); for (int i = 0; i < projects.length; i++) { IProject project = projects[i];//from w ww . j a v a 2s. co m try { String projectName = project.getName(); boolean cancelled = false; IPath zipPath = snapshotPath.append(projectName + "-index.zip"); //$NON-NLS-1$ if (zipPath.toFile().exists()) { String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; String question = NLS.bind(Messages.ProjectRefreshSnapshotExportWizardPage_overwrite, zipPath.toString()); MessageDialog d = new MessageDialog(getShell(), Messages.ProjectRefreshSnapshotExportWizardPage_question, null, question, MessageDialog.QUESTION, buttons, 0) { protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; int overwrite = d.open(); switch (overwrite) { case 0: // Yes break; case 1: // No continue; case 2: // Cancel default: cancelled = true; break; } } if (cancelled) break; URI snapshotLocation = org.eclipse.core.filesystem.URIUtil.toURI(zipPath); project.saveSnapshot(IProject.SNAPSHOT_TREE, snapshotLocation, null); } catch (CoreException e) { status.merge(e.getStatus()); } } if (!status.isOK()) { IDEWorkbenchPlugin.log("", status); //$NON-NLS-1$ ErrorDialog.openError(getContainer().getShell(), getErrorDialogTitle(), null, // no special message status); return false; } return true; }
From source file:org.eclipse.ui.ide.examples.projectsnapshot.ProjectRefreshSnapshotImportWizardPage.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. * /*w w w . j ava2s. 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(Messages.ProjectRefreshSnapshotImportWizardPage_overwrite, pathString); } else { messageString = NLS.bind(Messages.ProjectRefreshSnapshotImportWizardPage_overwriteInFolder, path.lastSegment(), path.removeLastSegments(1).toOSString()); } final MessageDialog dialog = new MessageDialog(getContainer().getShell(), Messages.ProjectRefreshSnapshotImportWizardPage_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()]; }
From source file:org.eclipse.ui.ide.undo.WorkspaceUndoUtil.java
License:Open Source License
private static int queryDeleteOutOfSync(IResource resource, IAdaptable uiInfo) { Shell shell = getShell(uiInfo);// w ww .j av a2s. c o m final MessageDialog dialog = new MessageDialog(shell, UndoMessages.AbstractResourcesOperation_deletionMessageTitle, null, NLS.bind(UndoMessages.AbstractResourcesOperation_outOfSyncQuestion, resource.getName()), MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 0) { protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; shell.getDisplay().syncExec(new Runnable() { public void run() { dialog.open(); } }); int result = dialog.getReturnCode(); if (result == 0) { return IDialogConstants.YES_ID; } if (result == 1) { return IDialogConstants.YES_TO_ALL_ID; } if (result == 2) { return IDialogConstants.NO_ID; } return IDialogConstants.CANCEL_ID; }
From source file:org.eclipse.ui.internal.dialogs.SavePerspectiveDialog.java
License:Open Source License
/** * Notifies that the ok button of this dialog has been pressed. * <p>// www .j a va 2 s . c o m * The default implementation of this framework method sets * this dialog's return code to <code>Window.OK</code> * and closes the dialog. Subclasses may override. * </p> */ protected void okPressed() { perspName = text.getText(); persp = perspReg.findPerspectiveWithLabel(perspName); if (persp != null) { // Confirm ok to overwrite String message = NLS.bind(WorkbenchMessages.SavePerspective_overwriteQuestion, perspName); String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; MessageDialog d = new MessageDialog(this.getShell(), WorkbenchMessages.SavePerspective_overwriteTitle, null, message, MessageDialog.QUESTION, buttons, 0) { protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; switch (d.open()) { case 0: //yes break; case 1: //no return; case 2: //cancel cancelPressed(); return; default: return; } } super.okPressed(); }
From source file:org.eclipse.ui.internal.EditorManager.java
License:Open Source License
/** * Saves the given dirty editors and views, optionally prompting the user. * //from w ww . j a va2 s. c o m * @param dirtyParts * the dirty views and editors * @param confirm * <code>true</code> to prompt whether to save, * <code>false</code> to save without prompting * @param closing * <code>true</code> if the parts are being closed, * <code>false</code> if just being saved without closing * @param addNonPartSources * true if non-part sources should be saved too * @param runnableContext * the context in which to run long-running operations * @param shellProvider * providing the shell to use as the parent for the dialog that * prompts to save multiple dirty editors and views * @return <code>true</code> on success, <code>false</code> if the user * canceled the save */ public static boolean saveAll(List dirtyParts, final boolean confirm, final boolean closing, boolean addNonPartSources, final IRunnableContext runnableContext, final IShellProvider shellProvider) { // clone the input list dirtyParts = new ArrayList(dirtyParts); if (closing) { // if the parts are going to be closed, then we only save those that // need to be saved when closed, see bug 272070 for (Iterator it = dirtyParts.iterator(); it.hasNext();) { ISaveablePart saveablePart = (ISaveablePart) it.next(); if (!saveablePart.isSaveOnCloseNeeded()) { it.remove(); } } } List modelsToSave; if (confirm) { boolean saveable2Processed = false; // Process all parts that implement ISaveablePart2. // These parts are removed from the list after saving // them. We then need to restore the workbench to // its previous state, for now this is just last // active perspective. // Note that the given parts may come from multiple // windows, pages and perspectives. ListIterator listIterator = dirtyParts.listIterator(); WorkbenchPage currentPage = null; Perspective currentPageOriginalPerspective = null; while (listIterator.hasNext()) { IWorkbenchPart part = (IWorkbenchPart) listIterator.next(); if (part instanceof ISaveablePart2) { WorkbenchPage page = (WorkbenchPage) part.getSite().getPage(); if (!Util.equals(currentPage, page)) { if (currentPage != null && currentPageOriginalPerspective != null) { if (!currentPageOriginalPerspective.equals(currentPage.getActivePerspective())) { currentPage.setPerspective(currentPageOriginalPerspective.getDesc()); } } currentPage = page; currentPageOriginalPerspective = page.getActivePerspective(); } if (confirm) { if (part instanceof IViewPart) { Perspective perspective = page.getFirstPerspectiveWithView((IViewPart) part); if (perspective != null) { page.setPerspective(perspective.getDesc()); } } // show the window containing the page? IWorkbenchWindow partsWindow = page.getWorkbenchWindow(); if (partsWindow != partsWindow.getWorkbench().getActiveWorkbenchWindow()) { Shell shell = partsWindow.getShell(); if (shell.getMinimized()) { shell.setMinimized(false); } shell.setActive(); } page.bringToTop(part); } // try to save the part int choice = SaveableHelper.savePart((ISaveablePart2) part, page.getWorkbenchWindow(), confirm); if (choice == ISaveablePart2.CANCEL) { // If the user cancels, don't restore the previous // workbench state, as that will // be an unexpected switch from the current state. return false; } else if (choice != ISaveablePart2.DEFAULT) { saveable2Processed = true; listIterator.remove(); } } } // try to restore the workbench to its previous state if (currentPage != null && currentPageOriginalPerspective != null) { if (!currentPageOriginalPerspective.equals(currentPage.getActivePerspective())) { currentPage.setPerspective(currentPageOriginalPerspective.getDesc()); } } // if processing a ISaveablePart2 caused other parts to be // saved, remove them from the list presented to the user. if (saveable2Processed) { listIterator = dirtyParts.listIterator(); while (listIterator.hasNext()) { ISaveablePart part = (ISaveablePart) listIterator.next(); if (!part.isDirty()) { listIterator.remove(); } } } modelsToSave = convertToSaveables(dirtyParts, closing, addNonPartSources); // If nothing to save, return. if (modelsToSave.isEmpty()) { return true; } boolean canceled = SaveableHelper.waitForBackgroundSaveJobs(modelsToSave); if (canceled) { return false; } // Use a simpler dialog if there's only one if (modelsToSave.size() == 1) { Saveable model = (Saveable) modelsToSave.get(0); String message = NLS.bind(WorkbenchMessages.get().EditorManager_saveChangesQuestion, model.getName()); // Show a dialog. String[] buttons = new String[] { IDialogConstants.get().YES_LABEL, IDialogConstants.get().NO_LABEL, IDialogConstants.get().CANCEL_LABEL }; MessageDialog d = new MessageDialog(shellProvider.getShell(), WorkbenchMessages.get().Save_Resource, null, message, MessageDialog.QUESTION, buttons, 0) { protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; int choice = SaveableHelper.testGetAutomatedResponse(); if (SaveableHelper.testGetAutomatedResponse() == SaveableHelper.USER_RESPONSE) { 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; } } else { ListSelectionDialog dlg = new ListSelectionDialog(shellProvider.getShell(), modelsToSave, new ArrayContentProvider(), new WorkbenchPartLabelProvider(), RESOURCES_TO_SAVE_MESSAGE) { protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; dlg.setInitialSelections(modelsToSave.toArray()); dlg.setTitle(SAVE_RESOURCES_TITLE); // this "if" statement aids in testing. if (SaveableHelper.testGetAutomatedResponse() == SaveableHelper.USER_RESPONSE) { int result = dlg.open(); //Just return false to prevent the operation continuing if (result == IDialogConstants.CANCEL_ID) { return false; } modelsToSave = Arrays.asList(dlg.getResult()); } } } else { modelsToSave = convertToSaveables(dirtyParts, closing, addNonPartSources); } // If the editor list is empty return. if (modelsToSave.isEmpty()) { return true; } // Create save block. final List finalModels = modelsToSave; IRunnableWithProgress progressOp = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { IProgressMonitor monitorWrap = new EventLoopProgressMonitor(monitor); monitorWrap.beginTask(WorkbenchMessages.get().Saving_Modifications, finalModels.size()); for (Iterator i = finalModels.iterator(); i.hasNext();) { Saveable model = (Saveable) i.next(); // handle case where this model got saved as a result of saving another if (!model.isDirty()) { monitor.worked(1); continue; } SaveableHelper.doSaveModel(model, new SubProgressMonitor(monitorWrap, 1), shellProvider, closing || confirm); if (monitorWrap.isCanceled()) { break; } } monitorWrap.done(); } }; // Do the save. return SaveableHelper.runProgressMonitorOperation(WorkbenchMessages.get().Save_All, progressOp, runnableContext, shellProvider); }
From source file:org.eclipse.ui.internal.editors.text.SpellingConfigurationBlock.java
License:Open Source License
private ComboViewer createProviderViewer() { /* list viewer */ final ComboViewer viewer = new ComboViewer(fProviderCombo); viewer.setContentProvider(new IStructuredContentProvider() { /*//w w w . ja v a2 s. c o m * @see org.eclipse.jface.viewers.IContentProvider#dispose() */ public void dispose() { } /* * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) */ public void inputChanged(Viewer v, Object oldInput, Object newInput) { } /* * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) */ public Object[] getElements(Object inputElement) { return fProviderDescriptors.values().toArray(); } }); viewer.setLabelProvider(new LabelProvider() { /* * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) */ public Image getImage(Object element) { return null; } /* * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) */ public String getText(Object element) { return ((SpellingEngineDescriptor) element).getLabel(); } }); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection sel = (IStructuredSelection) event.getSelection(); if (sel.isEmpty()) return; if (fCurrentBlock != null && fStatusMonitor.getStatus() != null && fStatusMonitor.getStatus().matches(IStatus.ERROR)) if (isPerformRevert()) { ISafeRunnable runnable = new ISafeRunnable() { public void run() throws Exception { fCurrentBlock.performRevert(); } public void handleException(Throwable x) { } }; SafeRunner.run(runnable); } else { revertSelection(); return; } fStore.setValue(SpellingService.PREFERENCE_SPELLING_ENGINE, ((SpellingEngineDescriptor) sel.getFirstElement()).getId()); updateListDependencies(); } private boolean isPerformRevert() { Shell shell = viewer.getControl().getShell(); MessageDialog dialog = new MessageDialog(shell, TextEditorMessages.SpellingConfigurationBlock_error_title, null, TextEditorMessages.SpellingConfigurationBlock_error_message, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1); return dialog.open() == 0; } private void revertSelection() { try { viewer.removeSelectionChangedListener(this); SpellingEngineDescriptor desc = EditorsUI.getSpellingService() .getActiveSpellingEngineDescriptor(fStore); if (desc != null) viewer.setSelection(new StructuredSelection(desc), true); } finally { viewer.addSelectionChangedListener(this); } } }); viewer.setInput(fProviderDescriptors); viewer.refresh(); return viewer; }
From source file:org.eclipse.ui.internal.handlers.ResetPerspectiveHandler.java
License:Open Source License
public Object execute(ExecutionEvent event) { IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event); if (activeWorkbenchWindow != null) { WorkbenchPage page = (WorkbenchPage) activeWorkbenchWindow.getActivePage(); if (page != null) { IPerspectiveDescriptor descriptor = page.getPerspective(); if (descriptor != null) { boolean offerRevertToBase = false; if (descriptor instanceof PerspectiveDescriptor) { PerspectiveDescriptor desc = (PerspectiveDescriptor) descriptor; offerRevertToBase = desc.isPredefined() && desc.hasCustomDefinition(); }//from ww w. j a v a2 s.co m if (offerRevertToBase) { String message = NLS.bind(WorkbenchMessages.RevertPerspective_message, descriptor.getLabel()); boolean toggleState = false; MessageDialogWithToggle dialog = MessageDialogWithToggle.open(MessageDialog.QUESTION, activeWorkbenchWindow.getShell(), WorkbenchMessages.RevertPerspective_title, message, WorkbenchMessages.RevertPerspective_option, toggleState, null, null, SWT.SHEET); if (dialog.getReturnCode() == IDialogConstants.YES_ID) { if (dialog.getToggleState()) { PerspectiveRegistry reg = (PerspectiveRegistry) PlatformUI.getWorkbench() .getPerspectiveRegistry(); reg.revertPerspective(descriptor); } page.resetPerspective(); } } else { String message = NLS.bind(WorkbenchMessages.ResetPerspective_message, descriptor.getLabel()); boolean result = MessageDialog.open(MessageDialog.QUESTION, activeWorkbenchWindow.getShell(), WorkbenchMessages.ResetPerspective_title, message, SWT.SHEET); if (result) { page.resetPerspective(); } } } } } return null; }
From source file:org.eclipse.ui.internal.handlers.SavePerspectiveHandler.java
License:Open Source License
/** * Save a singleton over itself./* w w w . ja v a 2 s . com*/ */ private void saveSingleton(IWorkbenchPage page) { String[] buttons = new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }; MessageDialog d = new MessageDialog(page.getWorkbenchWindow().getShell(), WorkbenchMessages.SavePerspective_overwriteTitle, null, WorkbenchMessages.SavePerspective_singletonQuestion, MessageDialog.QUESTION, buttons, 0); if (d.open() == 0) { page.savePerspective(); } }