List of usage examples for org.eclipse.jface.dialogs MessageDialogWithToggle openYesNoQuestion
public static MessageDialogWithToggle openYesNoQuestion(Shell parent, String title, String message, String toggleMessage, boolean toggleState, IPreferenceStore store, String key)
From source file:au.gov.ga.earthsci.catalog.part.CatalogBrowserController.java
License:Apache License
private boolean isFullNodePathRequiredOnAdd() { if (preferences.getAddNodeStructureMode() != UserActionPreference.ASK) { return preferences.getAddNodeStructureMode() == UserActionPreference.ALWAYS; }/*from w w w . j av a 2s.com*/ MessageDialogWithToggle message = MessageDialogWithToggle.openYesNoQuestion(null, Messages.CatalogBrowserController_AddNodePathDialogTitle, Messages.CatalogBrowserController_AddNodePathDialogMessage, Messages.CatalogBrowserController_DialogDontAsk, false, null, null); UserActionPreference preference = (message.getReturnCode() == IDialogConstants.YES_ID) ? UserActionPreference.ALWAYS : UserActionPreference.NEVER; preferences.setAddNodeStructureMode(message.getToggleState() ? preference : UserActionPreference.ASK); return preference == UserActionPreference.ALWAYS; }
From source file:au.gov.ga.earthsci.catalog.part.CatalogBrowserController.java
License:Apache License
private boolean isEmptyFolderDeletionRequiredOnRemoval() { if (preferences.getDeleteEmptyFoldersMode() != UserActionPreference.ASK) { return preferences.getDeleteEmptyFoldersMode() == UserActionPreference.ALWAYS; }// w w w .j av a2s . co m MessageDialogWithToggle message = MessageDialogWithToggle.openYesNoQuestion(null, Messages.CatalogBrowserController_DeleteEmptyFoldersDialogTitle, Messages.CatalogBrowserController_DeleteEmptyFoldersMessage, Messages.CatalogBrowserController_DialogDontAsk, false, null, null); UserActionPreference preference = (message.getReturnCode() == IDialogConstants.YES_ID) ? UserActionPreference.ALWAYS : UserActionPreference.NEVER; preferences.setDeleteEmptyFoldersMode(message.getToggleState() ? preference : UserActionPreference.ASK); return preference == UserActionPreference.ALWAYS; }
From source file:ca.uvic.cs.tagsea.monitor.jobs.UploadJob.java
License:Open Source License
@Override protected synchronized IStatus run(IProgressMonitor monitor) { //get the logs that have to be uploaded. monitor.beginTask(getName(), 101);//from w w w . ja v a 2 s .co m IPreferenceStore prefs = TagSEAMonitorPlugin.getDefault().getPreferenceStore(); String date = prefs.getString(MonitorPreferences.LAST_DATE_PREF); DateFormat f = DateFormat.getDateInstance(DateFormat.SHORT); Date today = new Date(System.currentTimeMillis()); NetworkLogging logging = new NetworkLogging(); int id = TagSEAPlugin.getDefault().getUserID(); //ask to register if we haven't already. if (id < 0 && !MonitorPreferences.hasAskedToRegister()) { Display disp = TagSEAMonitorPlugin.getDefault().getWorkbench().getDisplay(); disp.syncExec(new Runnable() { public void run() { Shell shell = TagSEAMonitorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow() .getShell(); MessageDialogWithToggle d = MessageDialogWithToggle.openYesNoQuestion(shell, "Register TagSEA", "TagSEA is not registered.\n\n" + "You have requested that a log of your interactions with TagSEA be" + " uploaded to the University of Victoria for research purposes, but" + " you have not yet registered TagSEA with the University of Victoria." + " You must register before these logs can be uploaded.\n\n " + "Selecting 'Yes' will prompt you to register TagSEA. Selecting 'No'" + " will cancel the current upload.\n\n" + " You may manually upload your logging data, by selecting the 'Upload'" + " action in the TagSEA log view (Window>Show Views>Other>TagSEA>TagSEA Log)" + " You may also register at any time using the TagSEA preference page.\n\n" + "Would you like to register now?", " Don't ask again.", false, null, null); int result = 0; int code = d.getReturnCode(); if (code == IDialogConstants.YES_ID) { result = TagSEAPlugin.getDefault().askForUserID(); } if (d.getToggleState() && result != -2) { MonitorPreferences.setAskedToRegister(true); } } }); } id = TagSEAPlugin.getDefault().getUserID(); if (id < 0) { //id is still 0. cancel monitor.done(); this.status = Status.CANCEL_STATUS; return Status.CANCEL_STATUS; } try { today = f.parse(f.format(today)); ArrayList<Date> newDates = new ArrayList<Date>(); if (!"".equals(date)) { Date last = f.parse(date); Date[] ds = TagSEAMonitorPlugin.getDefault().getLogDates(); Arrays.sort(ds); for (Date current : ds) { if (current.after(last) && current.before(today)) { newDates.add(current); } else if (current.after(today)) { //shouldn't happen break; } } } else { Date[] ds = TagSEAMonitorPlugin.getDefault().getLogDates(); for (Date current : ds) { if (current.before(today)) { newDates.add(current); } } } monitor.worked(1); int work = (int) Math.floor(100.0 / newDates.size()); for (Date current : newDates) { monitor.subTask(DateFormat.getDateInstance().format(current)); if (!logging.uploadForDate(current)) { monitor.done(); this.status = new Status(Status.ERROR, TagSEAMonitorPlugin.PLUGIN_ID, 0, "Unable to upload log.", null); return this.status; } monitor.worked(work); } } catch (ParseException e) { TagSEAMonitorPlugin.getDefault().log(e); return new Status(Status.ERROR, TagSEAMonitorPlugin.PLUGIN_ID, 0, e.getLocalizedMessage(), e); } catch (IOException e) { TagSEAMonitorPlugin.getDefault().log(e); return new Status(Status.ERROR, TagSEAMonitorPlugin.PLUGIN_ID, 0, e.getLocalizedMessage(), e); } finally { monitor.done(); } this.status = Status.OK_STATUS; return Status.OK_STATUS; }
From source file:ca.uvic.cs.tagsea.statistics.svn.jobs.SVNCommentScanningJob.java
License:Open Source License
/** * @return/* w w w . ja va2 s .c om*/ */ private int askForID() { Display disp = Display.getDefault(); if (SVNStatistics.getDefault().getPreferenceStore().getBoolean("register.asked")) { return -1; } disp.syncExec(new Runnable() { public void run() { Shell shell = SVNStatistics.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(); MessageDialogWithToggle d = MessageDialogWithToggle.openYesNoQuestion(shell, "Register TagSEA", "TagSEA is not registered.\n\n" + "You have installed the TagSEA Subversion plugin. By doing so, you have" + " agreed that you would like to send the developers of TagSEA some information" + " about how you comment your code. This can be done, however, you must first" + " register TagSEA.\n\n" + "Would you like to register now?", " Don't ask again.", false, null, null); int result = 0; int code = d.getReturnCode(); if (code == IDialogConstants.YES_ID) { result = TagSEAPlugin.getDefault().askForUserID(); } if (d.getToggleState() && result != -2) { SVNStatistics.getDefault().getPreferenceStore().setValue("register.asked", true); } } }); return TagSEAPlugin.getDefault().getUserID(); }
From source file:ccw.leiningen.NewLeiningenProjectWizard.java
License:Open Source License
/** * Prompts the user for whether to switch perspectives. * //from w w w . j av a2s . c o m * @param window * The workbench window in which to switch perspectives; must not * be <code>null</code> * @param finalPersp * The perspective to switch to; must not be <code>null</code>. * * @return <code>true</code> if it's OK to switch, <code>false</code> * otherwise */ private static boolean confirmPerspectiveSwitch(IWorkbenchWindow window, IPerspectiveDescriptor finalPersp) { IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore(); String pspm = store.getString(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE); if (!IDEInternalPreferences.PSPM_PROMPT.equals(pspm)) { // Return whether or not we should always switch return IDEInternalPreferences.PSPM_ALWAYS.equals(pspm); } String desc = finalPersp.getDescription(); String message; if (desc == null || desc.length() == 0) message = NLS.bind(ResourceMessages.NewProject_perspSwitchMessage, finalPersp.getLabel()); else message = NLS.bind(ResourceMessages.NewProject_perspSwitchMessageWithDesc, new String[] { finalPersp.getLabel(), desc }); MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(window.getShell(), ResourceMessages.NewProject_perspSwitchTitle, message, null /* use the default message for the toggle */, false /* toggle is initially unchecked */, store, IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE); int result = dialog.getReturnCode(); // If we are not going to prompt anymore propogate the choice. if (dialog.getToggleState()) { String preferenceValue; if (result == IDialogConstants.YES_ID) { // Doesn't matter if it is replace or new window // as we are going to use the open perspective setting preferenceValue = IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_REPLACE; } else { preferenceValue = IWorkbenchPreferenceConstants.NO_NEW_PERSPECTIVE; } // update PROJECT_OPEN_NEW_PERSPECTIVE to correspond PrefUtil.getAPIPreferenceStore().setValue(IDE.Preferences.PROJECT_OPEN_NEW_PERSPECTIVE, preferenceValue); } return result == IDialogConstants.YES_ID; }
From source file:com.aptana.ide.core.ui.DialogUtils.java
License:Open Source License
/** * openIgnoreMessageDialogConfirm/*from ww w . j a v a2 s .co m*/ * * @param shell * @param title * @param message * @param store * @param key Key to store the show/hide this message. Message will be hidden if true * @return int */ public static int openIgnoreMessageDialogConfirm(Shell shell, String title, String message, IPreferenceStore store, String key) { if (!store.getString(key).equals(MessageDialogWithToggle.ALWAYS)) { MessageDialogWithToggle d = MessageDialogWithToggle.openYesNoQuestion(shell, title, message, Messages.DialogUtils_HideThisMessageInFuture, false, store, key); if (d.getReturnCode() == 3) { return MessageDialog.CANCEL; } else { return MessageDialog.OK; } } else { return MessageDialog.OK; } }
From source file:com.aptana.ide.wizards.LibraryProjectWizard.java
License:Open Source License
/** * Prompts the user for whether to switch perspectives. * // ww w .ja va 2s . c om * @param window * The workbench window in which to switch perspectives; must not be <code>null</code> * @param finalPersp * The perspective to switch to; must not be <code>null</code>. * @return <code>true</code> if it's OK to switch, <code>false</code> otherwise */ private static boolean confirmPerspectiveSwitch(IWorkbenchWindow window, IPerspectiveDescriptor finalPersp) { IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore(); String pspm = store.getString(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE); if (!IDEInternalPreferences.PSPM_PROMPT.equals(pspm)) { // Return whether or not we should always switch return IDEInternalPreferences.PSPM_ALWAYS.equals(pspm); } MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(window.getShell(), ResourceMessages.NewProject_perspSwitchTitle, NLS.bind(ResourceMessages.NewProject_perspSwitchMessage, finalPersp.getLabel()), null /* use the default message for the toggle */, false /* toggle is initially unchecked */, store, IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE); int result = dialog.getReturnCode(); // If we are not going to prompt anymore propogate the choice. if (dialog.getToggleState()) { String preferenceValue; if (result == IDialogConstants.YES_ID) { // Doesn't matter if it is replace or new window // as we are going to use the open perspective setting preferenceValue = IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_REPLACE; } else { preferenceValue = IWorkbenchPreferenceConstants.NO_NEW_PERSPECTIVE; } // update PROJECT_OPEN_NEW_PERSPECTIVE to correspond PrefUtil.getAPIPreferenceStore().setValue(IDE.Preferences.PROJECT_OPEN_NEW_PERSPECTIVE, preferenceValue); } return result == IDialogConstants.YES_ID; }
From source file:com.aptana.internal.ui.text.spelling.AddWordProposal.java
License:Open Source License
/** * Asks the user whether he wants to configure a user dictionary. * //from w w w . ja v a 2 s. c o m * @param shell * @return <code>true</code> if the user wants to configure the user * dictionary * @since 3.3 */ private boolean askUserToConfigureUserDictionary(Shell shell) { final MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openYesNoQuestion(shell, JavaUIMessages.Spelling_add_askToConfigure_title, JavaUIMessages.Spelling_add_askToConfigure_question, JavaUIMessages.Spelling_add_askToConfigure_ignoreMessage, false, null, null); PreferenceConstants.getPreferenceStore().setValue(PREF_KEY_DO_NOT_ASK, toggleDialog.getToggleState()); return toggleDialog.getReturnCode() == IDialogConstants.YES_ID; }
From source file:com.aptana.ui.DialogUtils.java
License:Open Source License
/** * openIgnoreMessageDialogConfirm/* w w w . ja v a 2 s .c o m*/ * * @param shell * @param title * @param message * @param store * @param key * Key to store the show/hide this message. Message will be hidden if true * @return int */ public static int openIgnoreMessageDialogConfirm(Shell shell, String title, String message, IPreferenceStore store, String key) { if (!store.getString(key).equals(MessageDialogWithToggle.ALWAYS)) { MessageDialogWithToggle d = MessageDialogWithToggle.openYesNoQuestion(shell, title, message, Messages.DialogUtils_HideMessage, false, store, key); if (d.getReturnCode() == 3) { return MessageDialog.CANCEL; } } return MessageDialog.OK; }
From source file:com.centurylink.mdw.plugin.designer.DesignerPerspective.java
License:Apache License
public static void promptForShowPerspective(IWorkbenchWindow activeWindow, WorkflowElement workflowElement) { if (MdwPlugin.isRcp()) return;//from ww w . ja va 2 s . c o m IPerspectiveDescriptor pd = activeWindow.getActivePage().getPerspective(); if (!"mdw.perspectives.designer".equals(pd.getId())) { boolean switchPerspective = false; String switchPref = MdwPlugin.getStringPref(PreferenceConstants.PREFS_SWITCH_TO_DESIGNER_PERSPECTIVE); if (switchPref == null || switchPref.length() == 0) { String message = "Resources of type '" + workflowElement.getTitle() + "' are associated with MDW Designer Perspective. Switch to this perspective now?"; String toggleMessage = "Remember my answer and don't ask me again"; MessageDialogWithToggle mdwt = MessageDialogWithToggle.openYesNoQuestion(activeWindow.getShell(), "Switch Perspective", message, toggleMessage, false, MdwPlugin.getDefault().getPreferenceStore(), PreferenceConstants.PREFS_SWITCH_TO_DESIGNER_PERSPECTIVE); switchPerspective = mdwt.getReturnCode() == IDialogConstants.YES_ID || mdwt.getReturnCode() == IDialogConstants.OK_ID; } else { switchPerspective = switchPref.equalsIgnoreCase("always"); } if (switchPerspective) { try { showPerspective(activeWindow); } catch (Exception ex) { PluginMessages.uiError(activeWindow.getShell(), ex, "Show Perspective", workflowElement.getProject()); } } } }