List of usage examples for org.eclipse.jface.dialogs IDialogConstants YES_ID
int YES_ID
To view the source code for org.eclipse.jface.dialogs IDialogConstants YES_ID.
Click Source Link
From source file:net.sourceforge.sqlexplorer.plugin.editors.SQLEditor.java
License:Open Source License
/** * Implementation for save-as; returns true if successfull, false if not (i.e. the user cancelled the dialog) * //from ww w .j a va 2 s . co m * @return true if saved, false if cancelled */ public boolean doSave(boolean saveAs, IProgressMonitor monitor) { IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); boolean haveProjects = projects != null && projects.length > 0; IEditorInput input = getEditorInput(); boolean saveInsideProject = true; File file = null; if (input instanceof SQLEditorInput) { SQLEditorInput seInput = (SQLEditorInput) input; file = seInput.getFile(); } // If we have a file, then we already have a filename outside of the project; // but if we're doing a save-as then recheck with the user if (file != null && !saveAs) { saveInsideProject = false; } else if (input instanceof SQLEditorInput) { IConstants.Confirm confirm = SQLExplorerPlugin.getConfirm(IConstants.CONFIRM_YNA_SAVING_INSIDE_PROJECT); // If we're supposed to ask the user... if (confirm == IConstants.Confirm.ASK) { // Build up the message to ask String msg = Messages.getString("Confirm.SaveInsideProject.Intro") + "\n\n"; if (!haveProjects) { msg = msg + Messages.getString("Confirm.SaveInsideProject.NoProjectsConfigured") + "\n\n"; } msg = msg + Messages.getString("Confirm.SaveInsideProject.SaveInProject"); // Ask them MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion( getSite().getShell(), Messages.getString("SQLEditor.SaveAsDialog.Title"), msg, Messages.getString("Confirm.SaveInsideProject.Toggle"), false, null, null); if (dialog.getReturnCode() == IDialogConstants.CANCEL_ID) { return false; } // If they turned on the toggle ("Use this answer in the future"), update the preferences if (dialog.getToggleState()) { confirm = dialog.getReturnCode() == IDialogConstants.YES_ID ? IConstants.Confirm.YES : IConstants.Confirm.NO; SQLExplorerPlugin.getDefault().getPreferenceStore() .setValue(IConstants.CONFIRM_YNA_SAVING_INSIDE_PROJECT, confirm.toString()); } // Whether to save inside or outside saveInsideProject = dialog.getReturnCode() == IDialogConstants.YES_ID; } else { saveInsideProject = confirm == IConstants.Confirm.YES; } } // Saving inside a project - convert SQLEditorInput into a Resource by letting TextEditor do the work for us if (saveInsideProject) { if (!haveProjects) { MessageDialog.openError(getSite().getShell(), Messages.getString("Confirm.SaveInsideProject.Title"), Messages.getString("Confirm.SaveInsideProject.CreateAProject")); return false; } if (input instanceof SQLEditorInput) { saveAs = true; } // Save it and use their EditorInput if (saveAs) { textEditor.doSaveAs(); } else { if (monitor == null) { monitor = textEditor.getProgressMonitor(); } textEditor.doSave(monitor); } if (input.equals(textEditor.getEditorInput())) { return false; } input = textEditor.getEditorInput(); setInput(input); // Update the display setPartName(input.getName()); setTitleToolTip(input.getToolTipText()); } else { try { if (file == null || saveAs) { FileDialog dialog = new FileDialog(getSite().getShell(), SWT.SAVE); dialog.setText(Messages.getString("SQLEditor.SaveAsDialog.Title")); dialog.setFilterExtensions(SUPPORTED_FILETYPES); dialog.setFilterNames(SUPPORTED_FILETYPES); dialog.setFileName("*.sql"); String path = dialog.open(); if (path == null) { return false; } file = new File(path); } // Save it saveToFile(file); // Update the editor input input = new SQLEditorInput(file); setInput(input); setPartName(input.getName()); setTitleToolTip(input.getToolTipText()); } catch (IOException e) { SQLExplorerPlugin.error("Couldn't save sql", e); MessageDialog.openError(getSite().getShell(), Messages.getString("SQLEditor.SaveAsDialog.Error"), e.getMessage()); return false; } } setIsDirty(textEditor.isDirty()); return true; }
From source file:net.sourceforge.texlipse.viewer.ViewerConfigDialog.java
License:Open Source License
/** * Check that the config is valid./*from w w w . j av a2s .c o m*/ * Close the dialog is the config is valid. */ protected void okPressed() { if (!validateFields()) return; String name = nameField.getText(); registry.setActiveViewer(nameField.getText()); registry.setCommand(fileField.getText()); registry.setArguments(argsField.getText()); registry.setDDEViewCommand(ddeViewGroup.command.getText()); registry.setDDEViewServer(ddeViewGroup.server.getText()); registry.setDDEViewTopic(ddeViewGroup.topic.getText()); registry.setDDECloseCommand(ddeCloseGroup.command.getText()); registry.setDDECloseServer(ddeCloseGroup.server.getText()); registry.setDDECloseTopic(ddeCloseGroup.topic.getText()); registry.setFormat(formatChooser.getItem(formatChooser.getSelectionIndex())); registry.setInverse(inverseSearchValues[inverseChooser.getSelectionIndex()]); registry.setForward(forwardChoice.getSelection()); // Ask user if launch configs should be updated try { ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); if (manager != null) { ILaunchConfigurationType type = manager .getLaunchConfigurationType(TexLaunchConfigurationDelegate.CONFIGURATION_ID); if (type != null) { ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type); if (configs != null) { // Check all configurations int returnCode = 0; MessageDialogWithToggle md = null; for (int i = 0; i < configs.length; i++) { ILaunchConfiguration c = configs[i]; if (c.getType().getIdentifier() .equals(TexLaunchConfigurationDelegate.CONFIGURATION_ID)) { if (c.getAttribute("viewerCurrent", "").equals(name)) { // We've found a config which was based on this viewer if (0 == returnCode) { String message = MessageFormat.format( TexlipsePlugin.getResourceString( "preferenceViewerUpdateConfigurationQuestion"), new Object[] { c.getName() }); md = MessageDialogWithToggle .openYesNoCancelQuestion(getShell(), TexlipsePlugin.getResourceString( "preferenceViewerUpdateConfigurationTitle"), message, TexlipsePlugin.getResourceString( "preferenceViewerUpdateConfigurationAlwaysApply"), false, null, null); if (md.getReturnCode() == MessageDialogWithToggle.CANCEL) return; returnCode = md.getReturnCode(); } // If answer was yes, update each config with latest values from registry if (returnCode == IDialogConstants.YES_ID) { ILaunchConfigurationWorkingCopy workingCopy = c.getWorkingCopy(); workingCopy.setAttributes(registry.asMap()); // We need to set at least one attribute using a one-shot setter method // because the method setAttributes does not mark the config as dirty. // A dirty config is required for a doSave to do anything useful. workingCopy.setAttribute("viewerCurrent", name); workingCopy.doSave(); } // Reset return-code if we should be asked again if (!md.getToggleState()) { returnCode = 0; } } } } } } } } catch (CoreException e) { // Something wrong with the config, or could not read attributes, so swallow and skip } setReturnCode(OK); close(); }
From source file:org.apache.felix.sigil.eclipse.internal.install.OSGiInstallManager.java
License:Apache License
private void showInstallPrefs(final IPreferenceStore prefs) { Runnable r = new Runnable() { public void run() { MessageDialogWithToggle questionDialog = MessageDialogWithToggle.openYesNoQuestion( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Sigil Configuration", "Missing OSGi installation. Open preferences to configure it now?", "Do not show this message again", false, null, null); prefs.setValue(SigilCore.PREFERENCES_NOASK_OSGI_INSTALL, questionDialog.getToggleState()); if (questionDialog.getReturnCode() == IDialogConstants.YES_ID) { PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(null, SigilCore.OSGI_INSTALLS_PREFERENCES_ID, null, null); dialog.open();/*from w w w . j ava 2s. c o m*/ } } }; Display d = Display.getCurrent(); if (d == null) { d = Display.getDefault(); d.asyncExec(r); } else { d.syncExec(r); } }
From source file:org.apache.felix.sigil.eclipse.ui.internal.preferences.OptionalPrompt.java
License:Apache License
public static boolean optionallyPrompt(IPreferenceStore prefStore, String prefName, String title, String text, Shell parentShell) {//ww w . ja va 2 s . c om boolean result = false; PromptablePreference value = preference(prefStore, prefName); switch (value) { case Always: result = true; break; case Never: result = false; break; case Prompt: MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(parentShell, title, text, "Do not ask this again", false, null, null); result = (dialog.getReturnCode() == IDialogConstants.YES_ID); if (dialog.getToggleState()) { // User said don't ask again... take the current answer as the new preference prefStore.setValue(prefName, result ? PromptablePreference.Always.name() : PromptablePreference.Never.name()); } } return result; }
From source file:org.apache.felix.sigil.eclipse.ui.internal.preferences.OptionalPrompt.java
License:Apache License
public static int optionallyPromptWithCancel(IPreferenceStore prefStore, String prefName, String title, String text, Shell parentShell) { int result = IDialogConstants.NO_ID; PromptablePreference value = preference(prefStore, prefName); switch (value) { case Always:/* w w w .java 2 s. c om*/ result = IDialogConstants.YES_ID; break; case Never: result = IDialogConstants.NO_ID; break; case Prompt: MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(parentShell, title, text, "Do not ask this again", false, null, null); result = dialog.getReturnCode(); if (result != IDialogConstants.CANCEL_ID) { if (dialog.getToggleState()) { // User said don't ask again... take the current answer as the new preference prefStore.setValue(prefName, (result == IDialogConstants.YES_ID) ? PromptablePreference.Always.name() : PromptablePreference.Never.name()); } } } return result; }
From source file:org.apache.felix.sigil.eclipse.ui.util.ProjectUtils.java
License:Apache License
public static boolean runTaskWithRebuildCheck(Callable<Boolean> callable, Shell shell) { int result = checkRebuild(shell); if (result == IDialogConstants.CANCEL_ID) { return false; } else {//from w w w. j a v a 2s .c o m try { if (Boolean.TRUE == callable.call()) { if (result == IDialogConstants.YES_ID) { SigilUI.runWorkspaceOperation(new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor monitor) { SigilCore.rebuildAllBundleDependencies(monitor); } }, shell); } return true; } else { return false; } } catch (Exception e) { SigilCore.error("Failed to run caller", e); return false; } } }
From source file:org.apache.felix.sigil.ui.eclipse.ui.preferences.OptionalPrompt.java
License:Apache License
public static boolean optionallyPrompt(IPreferenceStore prefStore, String prefName, String title, String text, Shell parentShell) {// w w w. jav a 2 s.c o m boolean result = false; PromptablePreference value = PromptablePreference.valueOf(prefStore.getString(prefName)); switch (value) { case Always: result = true; break; case Never: result = false; break; case Prompt: MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(parentShell, title, text, "Do not ask this again", false, null, null); result = (dialog.getReturnCode() == IDialogConstants.YES_ID); if (dialog.getToggleState()) { // User said don't ask again... take the current answer as the new preference prefStore.setValue(prefName, result ? PromptablePreference.Always.name() : PromptablePreference.Never.name()); } } return result; }
From source file:org.apache.felix.sigil.ui.eclipse.ui.preferences.OptionalPrompt.java
License:Apache License
public static int optionallyPromptWithCancel(IPreferenceStore prefStore, String prefName, String title, String text, Shell parentShell) { int result = IDialogConstants.NO_ID; PromptablePreference value = PromptablePreference.valueOf(prefStore.getString(prefName)); switch (value) { case Always://from www .ja v a2 s . c om result = IDialogConstants.YES_ID; break; case Never: result = IDialogConstants.NO_ID; break; case Prompt: MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(parentShell, title, text, "Do not ask this again", false, null, null); result = dialog.getReturnCode(); if (result != IDialogConstants.CANCEL_ID) { if (dialog.getToggleState()) { // User said don't ask again... take the current answer as the new preference prefStore.setValue(prefName, (result == IDialogConstants.YES_ID) ? PromptablePreference.Always.name() : PromptablePreference.Never.name()); } } } return result; }
From source file:org.bonitasoft.studio.common.jface.MessageDialogWithPrompt.java
License:Open Source License
protected void buttonPressed(int buttonId) { super.buttonPressed(buttonId); boolean toggleState = getToggleState(); IPreferenceStore prefStore = getPrefStore(); String prefKey = getPrefKey(); if (buttonId != IDialogConstants.CANCEL_ID && toggleState && prefStore != null && prefKey != null) { switch (buttonId) { case IDialogConstants.YES_ID: case IDialogConstants.YES_TO_ALL_ID: case IDialogConstants.PROCEED_ID: case IDialogConstants.OK_ID: prefStore.setValue(prefKey, toggleState); break; case IDialogConstants.NO_ID: case IDialogConstants.NO_TO_ALL_ID: break; }/*from www . j av a 2 s. c o m*/ } }
From source file:org.bonitasoft.studio.designer.ui.contribution.CreateAndEditFormContributionItem.java
License:Open Source License
protected boolean openHideEmptyContractDialog() { if (!getEclipsePreferences().getBoolean(HIDE_EMPTY_CONTRACT_INFO_DIALOG, false)) { final MessageDialogWithPrompt messageDialog = MessageDialogWithPrompt.open(MessageDialog.QUESTION, Display.getDefault().getActiveShell(), Messages.hideEmptyContractDialogTitle, Messages.hideEmptyContractDialogMessage, Messages.hideEmptyContractDialogToggleMessage, false, getPreferenceStore(), HIDE_EMPTY_CONTRACT_INFO_DIALOG, SWT.NONE); setEmptyContractDialogAnswerPreference(messageDialog.getReturnCode()); return messageDialog.getReturnCode() == IDialogConstants.YES_ID; } else {/* w w w . ja v a2 s. c o m*/ return getEclipsePreferences().getBoolean(EMPTY_CONTRACT_INFO_DIALOG_ANSWER, false); } }