List of usage examples for org.eclipse.jface.dialogs MessageDialogWithToggle getReturnCode
public int getReturnCode()
From source file:au.gov.ga.earthsci.bookmark.part.BookmarksController.java
License:Apache License
@Override public boolean deleteBookmarkList(IBookmarkList list) { if (list == null || list == bookmarks.getDefaultList()) { return false; }/*from www . j a va2 s. co m*/ if (preferences.askForListDeleteConfirmation()) { MessageDialogWithToggle dialog = MessageDialogWithToggle.openOkCancelConfirm( Display.getDefault().getActiveShell(), Messages.BookmarksController_BookmarkListDeleteDialogTitle, Messages.BookmarksController_BookmarkListDeleteDialogMessage, Messages.BookmarksController_BookmarkListDeleteDialogToggleMessage, preferences.askForListDeleteConfirmation(), null, null); if (dialog.getReturnCode() != MessageDialog.OK) { return false; } preferences.setAskForListDeleteConfirmation(dialog.getToggleState()); } return bookmarks.removeList(list); }
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 ww .j ava2 s. c o m 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; }/* ww w . j a v a 2s.c o 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. j a v a 2 s. c o 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//from w ww. j a va 2s . com */ 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 ww w . j a v a2 s. com*/ * @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.android.ide.eclipse.adt.internal.editors.layout.properties.XmlPropertyEditor.java
License:Open Source License
@Override protected boolean setEditorText(Property property, String text) throws Exception { Object oldValue = property.getValue(); String old = oldValue != null ? oldValue.toString() : null; // If users enters a new id without specifying the @id/@+id prefix, insert it boolean isId = isIdProperty(property); if (isId && !text.startsWith(PREFIX_RESOURCE_REF)) { text = NEW_ID_PREFIX + text;/* w w w . j a v a 2 s . co m*/ } // Handle id refactoring: if you change an id, may want to update references too. // Ask user. if (isId && property instanceof XmlProperty && old != null && !old.isEmpty() && text != null && !text.isEmpty() && !text.equals(old)) { XmlProperty xmlProperty = (XmlProperty) property; IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore(); String refactorPref = store.getString(AdtPrefs.PREFS_REFACTOR_IDS); boolean performRefactor = false; Shell shell = AdtPlugin.getShell(); if (refactorPref == null || refactorPref.isEmpty() || refactorPref.equals(MessageDialogWithToggle.PROMPT)) { MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(shell, "Update References?", "Update all references as well? " + "This will update all XML references and Java R field references.", "Do not show again", false, store, AdtPrefs.PREFS_REFACTOR_IDS); switch (dialog.getReturnCode()) { case IDialogConstants.CANCEL_ID: return false; case IDialogConstants.YES_ID: performRefactor = true; break; case IDialogConstants.NO_ID: performRefactor = false; break; } } else { performRefactor = refactorPref.equals(MessageDialogWithToggle.ALWAYS); } if (performRefactor) { CommonXmlEditor xmlEditor = xmlProperty.getXmlEditor(); if (xmlEditor != null) { IProject project = xmlEditor.getProject(); if (project != null && shell != null) { RenameResourceWizard.renameResource(shell, project, ResourceType.ID, stripIdPrefix(old), stripIdPrefix(text), false); } } } } property.setValue(text); return true; }
From source file:com.aptana.ide.core.ui.DialogUtils.java
License:Open Source License
/** * openIgnoreMessageDialogInformation//from w ww. j a va 2 s . c om * * @param shell * @param title * @param message * @param store * @param key * @return int */ public static int openIgnoreMessageDialogInformation(Shell shell, String title, String message, IPreferenceStore store, String key) { if (!store.getString(key).equals(MessageDialogWithToggle.ALWAYS)) { MessageDialogWithToggle d = MessageDialogWithToggle.openInformation(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.core.ui.DialogUtils.java
License:Open Source License
/** * openIgnoreMessageDialogConfirm//w w w .j a v a 2 s. c om * * @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.debug.internal.ui.WorkbenchCloseListener.java
License:Open Source License
/** * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) *///from ww w.ja v a2s . c om public void handleEvent(Event event) { if (event.widget instanceof Shell && PlatformUI.getWorkbench().getWorkbenchWindowCount() == 1 && PlatformUI.getWorkbench().getWorkbenchWindows()[0].getShell() == event.widget) { // last workbench window is about to close if ("true".equals(System.getProperty(JSDebugOptionsManager.DEBUGGER_ACTIVE))) { //$NON-NLS-1$ IPreferenceStore store = DebugUiPlugin.getDefault().getPreferenceStore(); if (store.contains(IDebugUIConstants.PREF_CONFIRM_EXIT_DEBUGGER)) { if (store.getBoolean(IDebugUIConstants.PREF_CONFIRM_EXIT_DEBUGGER) == false) { return; } } event.doit = false; MessageDialogWithToggle dlg = MessageDialogWithToggle.openOkCancelConfirm((Shell) event.widget, Messages.WorkbenchCloseListener_ConfirmDebuggerExit, Messages.WorkbenchCloseListener_AptanaDebuggerIsActive_DoYouWantToExit, Messages.WorkbenchCloseListener_AlwaysExitDebuggerWithoutPrompt, false, null, null); int returnValue = dlg.getReturnCode(); if (returnValue != IDialogConstants.OK_ID) { // SWT hack - discard close event event.type = SWT.None; return; } if (dlg.getToggleState()) { store.setValue(IDebugUIConstants.PREF_CONFIRM_EXIT_DEBUGGER, false); DebugUiPlugin.getDefault().savePluginPreferences(); } } } }