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.csstudio.opibuilder.runmode.RunModeService.java
License:Open Source License
public static void runOPIInView(final IPath path, final DisplayOpenManager displayOpenManager, final MacrosInput macrosInput, final Position position) { OPIView.setOpenedByUser(true);/*from w ww .j a v a 2 s .c o m*/ final RunnerInput runnerInput = new RunnerInput(path, displayOpenManager, macrosInput); UIBundlingThread.getInstance().addRunnable(new Runnable() { public void run() { final IWorkbench workbench = PlatformUI.getWorkbench(); final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); final IWorkbenchPage page = window.getActivePage(); try { IViewReference[] viewReferences = page.getViewReferences(); //If it is already opened. for (IViewReference viewReference : viewReferences) { if (viewReference.getId().equals(OPIView.ID)) { final IViewPart view = viewReference.getView(true); if (view instanceof IOPIRuntime) { final IOPIRuntime opi_view = (IOPIRuntime) view; if (runnerInput.equals(opi_view.getOPIInput())) { page.showView(OPIView.ID, viewReference.getSecondaryId(), IWorkbenchPage.VIEW_ACTIVATE); return; } } else { OPIBuilderPlugin.getLogger().log(Level.WARNING, "Found view " + view.getTitle() + " but its type is " + view.getClass().getName()); } } } // Open a new view if (position != Position.DETACHED && position != Position.DEFAULT_VIEW && !(page.getPerspective().getId().equals(OPIRunnerPerspective.ID))) { if (!OPIBuilderPlugin.isRAP()) { if (PreferencesHelper.isShowOpiRuntimePerspectiveDialog()) { TipDialog dialog = new TipDialog(window.getShell(), MessageDialog.QUESTION, "Switch to OPI Runtime Perspective", "To open the OPI View in expected position, you need to switch to OPI Runtime perspective." + "\nDo you want to switch to it now?"); PreferencesHelper.setSwitchToOpiRuntimePerspective(dialog.open() == Window.OK); if (!dialog.isShowThisDialogAgain()) { PreferencesHelper.setShowOpiRuntimePerspectiveDialog(false); } } if (PreferencesHelper.isSwitchToOpiRuntimePerspective()) { PerspectiveHelper.showPerspective(OPIRunnerPerspective.ID, window.getActivePage()); } } } // View will receive input from us, should ignore previous memento OPIView.ignoreMemento(); // TODO Opening in selected location does not work this way // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=408891, https://github.com/ControlSystemStudio/cs-studio/issues/142 final String secondID = OPIView.createSecondaryID() + position.name(); final IViewPart view = page.showView(OPIView.ID, secondID, IWorkbenchPage.VIEW_ACTIVATE); if (!(view instanceof OPIView)) throw new PartInitException("Expected OPIView, got " + view); final OPIView opiView = (OPIView) view; opiView.setOPIInput(runnerInput); if (position == Position.DETACHED) SingleSourcePlugin.getUIHelper().detachView(opiView); } catch (PartInitException e) { ErrorHandlerUtil.handleError(NLS.bind("Failed to run OPI {1} in view.", path), e); } } }); }
From source file:org.csstudio.sds.util.SaveAsDialog.java
License:Open Source License
/** * {@inheritDoc}/*from ww w .j av a 2 s . co m*/ */ protected void okPressed() { // Get new path. IPath path = _resourceGroup.getContainerFullPath().append(_resourceGroup.getResource()); // If the user does not supply a file extension and if the save // as dialog was provided a default file name append the extension // of the default filename to the new name if (path.getFileExtension() == null) { if (_originalFile != null && _originalFile.getFileExtension() != null) { path = path.addFileExtension(_originalFile.getFileExtension()); } else if (_originalName != null) { int pos = _originalName.lastIndexOf('.'); if (++pos > 0 && pos < _originalName.length()) { path = path.addFileExtension(_originalName.substring(pos)); } } } // If the path already exists then confirm overwrite. IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); if (file.exists()) { String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; String question = NLS.bind(Messages.SaveAsDialog_OVERWRITE_QUESTION, path.toOSString()); MessageDialog d = new MessageDialog(getShell(), Messages.SaveAsDialog_QUESTION, null, question, MessageDialog.QUESTION, buttons, 0); int overwrite = d.open(); switch (overwrite) { case 0: // Yes break; case 1: // No return; case 2: // Cancel default: cancelPressed(); return; } } // Store path and close. _result = path; close(); }
From source file:org.easotope.client.core.part.EasotopePart.java
License:Open Source License
public boolean raiseQuestion(String message) { return MessageDialog.open(MessageDialog.QUESTION, shell, Messages.modalMessage_genericErrorTitle, message, SWT.SHEET); }
From source file:org.ebayopensource.turmeric.eclipse.typelibrary.ui.actions.DeleteTypeAction.java
License:Open Source License
/** * {@inheritDoc}//from w w w .ja v a2 s . c om */ @Override public void run(final IAction action) { if (SOALogger.DEBUG) logger.entering(action, selection); try { if (selection == null) { showErrorDialog(); return; } if (!UIUtil.openChoiceDialog("Confirm Type Delete", "Are you sure you want to delete this type?", MessageDialog.QUESTION)) return; if (TypeLibraryUtil.isValidXSDFile(selection.getFirstElement())) { final IFile xsdFile = (IFile) selection.getFirstElement(); final IProject project = xsdFile.getProject(); final String fileName = StringUtils.substringBeforeLast(xsdFile.getName(), "." + xsdFile.getFileExtension()); final IFile episodeFile = project .getFile("gen-meta-src/META-INF/" + project.getName() + "/" + fileName + ".episode"); final IStatus status = ActionUtil.validateTypeDependencyAndProjectConfigFile(project, episodeFile); final String messages = ValidateUtil.getFormattedStatusMessagesForAction(status); if (messages != null) { UIUtil.showErrorDialog(UIUtil.getActiveShell(), "Error", messages, (Throwable) null); return; } File eFile = episodeFile.getLocation().toFile(); if (eFile.exists() == true) { File tmpFile = new File(eFile.getCanonicalPath() + ".bak"); try { if (tmpFile.exists()) { tmpFile.delete(); } if (eFile.renameTo(tmpFile) == false) { UIUtil.showErrorDialog(UIUtil.getActiveShell(), "Error", SOAMessages.ERR_DELETE_TYPE + eFile); return; } } catch (Exception e) { //the file could not be deleted, warn the user UIUtil.showErrorDialog(UIUtil.getActiveShell(), "Error", SOAMessages.ERR_DELETE_TYPE + eFile); return; } finally { if (tmpFile.exists()) { tmpFile.renameTo(eFile); } } } DeleteTypeAction.executeTypeDeletionTask((IFile) selection.getFirstElement()); } else { showErrorDialog(); return; } } catch (Exception e) { logger.error(e); UIUtil.showErrorDialog(e); } finally { if (SOALogger.DEBUG) logger.exiting(); } }
From source file:org.eclipse.ajdt.internal.buildpath.SaveBCAction.java
License:Open Source License
private boolean askUserOverwrite(String fileName) { String[] options = { UIMessages.BCDialog_Overwrite_yes, UIMessages.BCDialog_Overwrite_no }; String title = UIMessages.BCDialog_Overwrite_title; String msg = UIMessages.BCDialog_Overwrite_message.replaceAll("%fileName", fileName); //$NON-NLS-1$ MessageDialog mdiag = new MessageDialog(null, title, null, msg, MessageDialog.QUESTION, options, 1); return (mdiag.open() == 0); }
From source file:org.eclipse.ajdt.internal.ui.preferences.AJCompilerPreferencePage.java
License:Open Source License
@SuppressWarnings("deprecation") public boolean performOk() { if (isProjectPreferencePage()) { return projectPerformOK(); } else {//from w w w . jav a2s .com IPreferenceStore store = getPreferenceStore(); Preferences ajCorePreferences = getAspectJCorePLuginPreferences(); boolean lintChanges = false; for (int i = fComboBoxes.size() - 1; i >= 0; i--) { Combo curr = (Combo) fComboBoxes.get(i); ControlData data = (ControlData) curr.getData(); String currValue = data.getValue(curr.getSelectionIndex()); String storedValue = usesAspectJCorePreferences(curr) ? ajCorePreferences.getString(data.getKey()) : store.getString(data.getKey()); if (!currValue.equals(storedValue)) { lintChanges = true; if (usesAspectJCorePreferences(curr)) { ajCorePreferences.setValue(data.getKey(), currValue); } else { store.setValue(data.getKey(), currValue); } } } boolean advancedOrOtherChanges = false; for (int i = fCheckBoxes.size() - 1; i >= 0; i--) { Button curr = (Button) fCheckBoxes.get(i); // has the data changed? ControlData data = (ControlData) curr.getData(); boolean currValue = curr.getSelection(); boolean storedValue = usesAspectJCorePreferences(curr) ? ajCorePreferences.getBoolean(data.getKey()) : store.getBoolean(data.getKey()); if (currValue != storedValue) { // check to see if we should ignore the change in the checkbox // change should be ignored if the NO_BUILD_ON_CHANGE flag exists if (curr.getData(NO_BUILD_ON_CHANGE) == null) { advancedOrOtherChanges = true; } // determine where this preference is stored if (usesAspectJCorePreferences(curr)) { ajCorePreferences.setValue(data.getKey(), currValue); } else { store.setValue(data.getKey(), currValue); } } } boolean compilerChanges = false; String value = nonStandardOptionsEditor.getStringValue(); if (!value.equals(store.getString(AspectJPreferences.COMPILER_OPTIONS))) { store.setValue(AspectJPreferences.COMPILER_OPTIONS, nonStandardOptionsEditor.getStringValue()); AJLog.log("Non Standard Compiler properties changed: " //$NON-NLS-1$ + store.getString(AspectJPreferences.COMPILER_OPTIONS)); compilerChanges = true; } AspectJUIPlugin.getDefault().savePluginPreferences(); AspectJPlugin.getDefault().savePluginPreferences(); if (lintChanges || advancedOrOtherChanges || compilerChanges) { String[] strings = getFullBuildDialogStrings(); if (strings != null) { MessageDialog dialog = new MessageDialog(getShell(), strings[0], null, strings[1], MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 2); if (isTesting) { dialog.setBlockOnOpen(false); } int res = dialog.open(); // simulate user input if we're testing if (isTesting) { // choices are "Yes", "No" or "Cancel" dialog.close(); if (buildNow) { res = Window.OK; } else { res = Window.CANCEL; // simulating cancel or no being pressed. } } if (res == 0) { projects = (ResourcesPlugin.getWorkspace().getRoot().getProjects()); } else if (res != 1) { return false; // cancel pressed } } // PreferencePageBuilder handles building so // don't need to do it here // if (doBuild) { // doFullBuild(); // } } return true; } }
From source file:org.eclipse.ajdt.internal.ui.preferences.AJCompilerPreferencePage.java
License:Open Source License
private boolean projectPerformOK() { boolean projectSettingsChanged = updateProjectSettings(); boolean projectWorkspaceChanges = false; if (AspectJPreferences.isUsingProjectSettings(getProject()) != useProjectSettings()) { projectWorkspaceChanges = true;//from www . j a va 2 s . c o m // don't want to overwrite existing project settings // because have just set them in the above call to // updateProjectSettings(); AspectJPreferences.setUsingProjectSettings(getProject(), useProjectSettings(), false); } AspectJUIPlugin.getDefault().savePluginPreferences(); if (projectWorkspaceChanges || (projectSettingsChanged && useProjectSettings())) { String[] strings = getProjectBuildDialogStrings(); if (strings != null) { MessageDialog dialog = new MessageDialog(getShell(), strings[0], null, strings[1], MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 2); // if we're testing then we don't want to block // the dialog on open otherwise we require real user input // rather than being able to simulate it if (isTesting) { dialog.setBlockOnOpen(false); } int res = dialog.open(); // simulate user input if we're testing if (isTesting) { // choices are "Yes", "No" or "Cancel" dialog.close(); if (buildNow) { res = Window.OK; } else { res = Window.CANCEL; // simulating cancel or no being pressed. } } if ((res == 0)) { // by only setting compilerSettingsUpdated to be true here, // means that // the user wont select "don't want to build" here and then // get a build // from other pages. } else if (res != 1) { return false; // cancel pressed } } } return true; }
From source file:org.eclipse.andmore.android.common.utilities.EclipseUtils.java
License:Apache License
/** * Show a question message using the given title and message * // w w w.j av a 2 s.co m * @param title * of the dialog * @param message * to be displayed in the dialog. */ public static int showQuestionWithCancelDialog(final String title, final String message) { class IntWrapper { public int diagReturn = 0; } final IntWrapper intWrapper = new IntWrapper(); Display.getDefault().syncExec(new Runnable() { @Override public void run() { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow ww = workbench.getActiveWorkbenchWindow(); Shell shell = ww.getShell(); MessageDialog dialog = new MessageDialog(shell, title, null, message, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 0); int diagResults = dialog.open(); switch (diagResults) { case 0: intWrapper.diagReturn = SWT.YES; break; case 1: intWrapper.diagReturn = SWT.NO; break; case 2: default: intWrapper.diagReturn = SWT.CANCEL; break; } } }); return intWrapper.diagReturn; }
From source file:org.eclipse.andmore.android.common.utilities.EclipseUtils.java
License:Apache License
/** * Show a question message using the given title and message * //ww w . j a v a 2s . co m * @param title * of the dialog * @param message * to be displayed in the dialog. */ public static int showQuestionYesAllCancelDialog(final String title, final String message) { class IntWrapper { public int diagReturn = 0; } final IntWrapper intWrapper = new IntWrapper(); Display.getDefault().syncExec(new Runnable() { @Override public void run() { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow ww = workbench.getActiveWorkbenchWindow(); Shell shell = ww.getShell(); MessageDialog dialog = new MessageDialog(shell, title, null, message, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL }, 0); int diagResults = dialog.open(); switch (diagResults) { case 0: intWrapper.diagReturn = IDialogConstants.YES_ID; break; case 1: intWrapper.diagReturn = IDialogConstants.YES_TO_ALL_ID; break; case 2: default: intWrapper.diagReturn = IDialogConstants.NO_ID; break; } } }); return intWrapper.diagReturn; }
From source file:org.eclipse.andmore.internal.assetstudio.CreateAssetSetWizard.java
License:Open Source License
@Override public boolean performFinish() { Map<String, Map<String, BufferedImage>> categories = ConfigureAssetSetPage.generateImages(mValues, false, null);//from w w w . jav a2 s . c om IProject project = mValues.project; // Write out the images into the project boolean yesToAll = false; mCreatedFiles = new ArrayList<IResource>(); for (Map<String, BufferedImage> previews : categories.values()) { for (Map.Entry<String, BufferedImage> entry : previews.entrySet()) { String relativePath = entry.getKey(); IPath dest = new Path(relativePath); IFile file = project.getFile(dest); if (file.exists()) { // Warn that the file already exists and ask the user what to do if (!yesToAll) { MessageDialog dialog = new MessageDialog(null, "File Already Exists", null, String.format("%1$s already exists.\nWould you like to replace it?", file.getProjectRelativePath().toOSString()), MessageDialog.QUESTION, new String[] { // Yes will be moved to the end because it's the default "Yes", "No", "Cancel", "Yes to All" }, 0); int result = dialog.open(); switch (result) { case 0: // Yes break; case 3: // Yes to all yesToAll = true; break; case 1: // No continue; case SWT.DEFAULT: case 2: // Cancel return false; } } try { file.delete(true, new NullProgressMonitor()); } catch (CoreException e) { AndmoreAndroidPlugin.log(e, null); } } AdtUtils.createWsParentDirectory(file.getParent()); BufferedImage image = entry.getValue(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); try { ImageIO.write(image, "PNG", stream); //$NON-NLS-1$ byte[] bytes = stream.toByteArray(); InputStream is = new ByteArrayInputStream(bytes); file.create(is, true /*force*/, null /*progress*/); mCreatedFiles.add(file); } catch (IOException e) { AndmoreAndroidPlugin.log(e, null); } catch (CoreException e) { AndmoreAndroidPlugin.log(e, null); } try { file.getParent().refreshLocal(1, new NullProgressMonitor()); } catch (CoreException e) { AndmoreAndroidPlugin.log(e, null); } } } // Finally select the files themselves selectFiles(project, mCreatedFiles); return true; }