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:org.bundlemaker.core.ui.utils.BundleMakerPerspectiveHelper.java
License:Open Source License
/** * Returns whether or not the user wishes to switch to the specified perspective when a launch occurs. * //from w w w . j av a 2 s . c om * @param perspectiveName * the name of the perspective that will be presented to the user for confirmation if they've asked to be * prompted about perspective switching * @param message * a message to be presented to the user. This message is expected to contain a slot for the perspective name * to be inserted ("{0}"). * @param preferenceKey * the preference key of the perspective switching preference * @return whether or not the user wishes to switch to the specified perspective automatically */ private boolean shouldSwitchPerspective(IWorkbenchWindow window, String perspectiveId, String preferenceKey) { if (isCurrentPerspective(window, perspectiveId)) { return false; } String perspectiveName = getPerspectiveLabel(perspectiveId); if (perspectiveName == null) { return false; } String perspectiveDesc = getPerspectiveDescription(perspectiveId); String[] args; if (perspectiveDesc != null) { args = new String[] { perspectiveName, perspectiveDesc }; } else { args = new String[] { perspectiveName }; } String switchPerspective = Activator.getDefault().getPreferenceStore().getString(preferenceKey); if (MessageDialogWithToggle.ALWAYS.equals(switchPerspective)) { return true; } else if (MessageDialogWithToggle.NEVER.equals(switchPerspective)) { return false; } Shell shell = window.getShell(); if (shell == null) { return false; } // Activate the shell if necessary so the prompt is visible Shell modal = getModalDialogOpen(shell); if (shell.getMinimized()) { shell.setMinimized(false); if (modal != null) { modal.setFocus(); } } if (Activator.getDefault().getPreferenceStore().getBoolean(IDebugUIConstants.PREF_ACTIVATE_WORKBENCH)) { if (modal == null) { shell.forceActive(); } } // String message = IInternalDebugCoreConstants.EMPTY_STRING; // if (IInternalDebugUIConstants.PREF_SWITCH_PERSPECTIVE_ON_SUSPEND.equals(preferenceKey)) { // if (getPerspectiveDescription(perspectiveId) != null) { // message = LaunchConfigurationsMessages.PerspectiveManager_suspend_description; // } else { // message = LaunchConfigurationsMessages.PerspectiveManager_13; // } // } else if (IInternalDebugUIConstants.PREF_SWITCH_TO_PERSPECTIVE.equals(preferenceKey)) { // if (getPerspectiveDescription(perspectiveId) != null) { // message = LaunchConfigurationsMessages.PerspectiveManager_launch_description; // } else { // message = LaunchConfigurationsMessages.PerspectiveManager_15; // } // } MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(shell, "Switch to BundleMaker perspective", // "This action is associated with the BundleMaker perspective. Do you want to switch to this perspective?", null, true, Activator.getDefault().getPreferenceStore(), preferenceKey); boolean answer = (dialog.getReturnCode() == IDialogConstants.YES_ID); // synchronized (this) { // fPrompting = false; // notifyAll(); // } if (isCurrentPerspective(window, perspectiveId)) { answer = false; } return answer; }
From source file:org.bundlemaker.core.ui.view.ArtifactStageActionHelper.java
License:Open Source License
/** * // ww w.j a v a2s . c o m * @return true if Artifact Stage has been set to 'manual add mode' or false if it remains in auto add mode */ public static boolean switchToManualAddModeIfRequired() { IArtifactStage artifactStage = Selection.instance().getArtifactStage(); if (!artifactStage.getAddMode().isAutoAddMode()) { // already in manual mode return true; } String switchPerspective = Activator.getDefault().getPreferenceStore() .getString(ArtifactStagePreferenceInitializer.PREF_SWITCH_TO_MANUAL_ADD_MODE); if (MessageDialogWithToggle.ALWAYS.equals(switchPerspective)) { // turn into manual add mode artifactStage.setAddMode(ArtifactStageAddMode.doNotAutomaticallyAddArtifacts); return true; } else if (MessageDialogWithToggle.NEVER.equals(switchPerspective)) { return false; } Shell shell = Display.getCurrent().getActiveShell(); MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(shell, "Switch to manual Add mode", // "The artifact stage currently is in 'automatic add mode', but this Action requires it to be in 'manual add mode'. Do you want the stage to be set to 'manual mode' now?", null, true, Activator.getDefault().getPreferenceStore(), ArtifactStagePreferenceInitializer.PREF_SWITCH_TO_MANUAL_ADD_MODE); boolean answer = (dialog.getReturnCode() == IDialogConstants.YES_ID); if (!answer) { return false; } artifactStage.setAddMode(ArtifactStageAddMode.doNotAutomaticallyAddArtifacts); return true; }
From source file:org.camunda.bpm.modeler.core.validation.Bpmn2ProjectValidator.java
License:Open Source License
public static boolean validateAfterSave(Resource resource, IProgressMonitor monitor) { boolean needValidation = false; IFile file = getFile(resource);//from w w w. j a va 2 s . c o m IProject project = file.getProject(); if (project != null) { try { IProjectNature nature = project.getNature(Bpmn2Nature.NATURE_ID); if (nature == null) { Bpmn2Preferences preferences = Bpmn2Preferences.getInstance(project); if (preferences.getCheckProjectNature()) { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); String title = "Configure BPMN2 Project Nature"; String message = "The project '" + project.getName() + "' has not been configured with the BPMN2 Project Nature.\n\n" + "Adding the BPMN2 Project Nature will cause all BPMN2 files in this project " + "to be validated automatically whenever the project is built.\n\n" + "Do you want to add this Nature to the Project now?"; MessageDialogWithToggle result = MessageDialogWithToggle.open(MessageDialog.QUESTION, shell, title, message, "Don't ask me again", // toggle message false, // toggle state null, // pref store null, // pref key SWT.NONE); if (result.getReturnCode() == IDialogConstants.YES_ID) { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = Bpmn2Nature.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); needValidation = true; } if (result.getToggleState()) { // don't ask again preferences.setCheckProjectNature(false); } } } else needValidation = true; } catch (CoreException e) { e.printStackTrace(); } } if (needValidation) { validate(file, monitor); return true; } return false; }
From source file:org.codehaus.groovy.eclipse.preferences.AskToConvertLegacyProjects.java
License:Apache License
@Override public IStatus runInUIThread(IProgressMonitor monitor) { ConvertLegacyProject legacy = new ConvertLegacyProject(); if (legacy.getAllOldProjects().length == 0) { return Status.OK_STATUS; }/*from w ww . ja va 2 s .c om*/ Shell shell = this.getDisplay().getActiveShell(); boolean shouldDispose = false; if (shell == null) { Shell[] shells = this.getDisplay().getShells(); if (shells.length > 0) { shell = shells[0]; } else { shell = new Shell(this.getDisplay()); shouldDispose = true; } } IPreferenceStore prefs = GroovyPlugin.getDefault().getPreferenceStore(); MessageDialogWithToggle d = MessageDialogWithToggle.openYesNoQuestion(shell, "Convert legacy Groovy Projects", "Some of your Groovy projects appear to be incompatible " + "with the new version of the Groovy plugin. Should they be converted now?" + "\n\nThey can be converted later from the Groovy Preferences page", "Don't show this message again.", false, prefs, PreferenceConstants.GROOVY_ASK_TO_CONVERT_LEGACY_PROJECTS); try { if (IDialogConstants.YES_ID == d.getReturnCode()) { IProject[] projects = legacy.getAllOldProjects(); monitor.beginTask("", projects.length); for (IProject project : projects) { legacy.convertProject(project); monitor.internalWorked(1); } } prefs.setValue(PreferenceConstants.GROOVY_ASK_TO_CONVERT_LEGACY_PROJECTS, !d.getToggleState()); return Status.OK_STATUS; } catch (Exception e) { return new Status(IStatus.ERROR, GroovyPlugin.PLUGIN_ID, "Error converting legacy projects", e); } finally { if (shouldDispose) { shell.dispose(); } } }
From source file:org.dawb.passerelle.common.perspective.WorkflowChecking.java
License:Open Source License
private void createWorkflowsPerspectiveListener() { final IWorkbenchPage page = EclipseUtils.getPage(); if (page != null) { page.addPartListener(new IPartListener() { @Override//from w ww . ja v a 2 s .co m public void partOpened(IWorkbenchPart part) { checkWorkflowPerspective(part); } private void checkWorkflowPerspective(IWorkbenchPart part) { if (part instanceof IPasserelleMultiPageEditor) { final String id = page.getPerspective().getId(); if (!id.equals(WorkflowPerspective.ID)) { final IPreferenceStore store = Activator.getDefault().getPreferenceStore(); final String setting = store .getString(PreferenceConstants.REMEMBER_WORKFLOWS_PERSPECTIVE); boolean openWorkflows = false; if (setting.equals(MessageDialogWithToggle.PROMPT) && System.getProperty("org.dawb.test.session") == null) { MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion( page.getWorkbenchWindow().getShell(), "Open Workflow Perspective", "This kind of file is associated with the 'Workflow' Perspective.\n\nWould you like to switch to the workflow perspective now?", "Remember my decision", false, store, PreferenceConstants.REMEMBER_WORKFLOWS_PERSPECTIVE); switch (dialog.getReturnCode()) { case IDialogConstants.CANCEL_ID: return; case IDialogConstants.YES_ID: openWorkflows = true; break; case IDialogConstants.NO_ID: openWorkflows = false; break; } } else if (setting.equals(MessageDialogWithToggle.ALWAYS)) { openWorkflows = true; } if (openWorkflows) { try { PlatformUI.getWorkbench().showPerspective(WorkflowPerspective.ID, page.getWorkbenchWindow()); } catch (Exception ne) { logger.error(ne.getMessage(), ne); } } } } } @Override public void partDeactivated(IWorkbenchPart part) { // TODO Auto-generated method stub } @Override public void partClosed(IWorkbenchPart part) { // TODO Auto-generated method stub } @Override public void partBroughtToTop(IWorkbenchPart part) { // TODO Auto-generated method stub } @Override public void partActivated(IWorkbenchPart part) { // TODO Auto-generated method stub } }); } ; }
From source file:org.ebayopensource.vjet.eclipse.internal.ui.dialogs.UnknownContentTypeDialog.java
License:Open Source License
protected void buttonPressed(int buttonId) { super.buttonPressed(buttonId); // overwritten so that value stored is boolean, not string if (buttonId != IDialogConstants.CANCEL_ID && getToggleState() && getPrefStore() != null && getPrefKey() != null) { switch (buttonId) { case IDialogConstants.YES_ID: case IDialogConstants.YES_TO_ALL_ID: case IDialogConstants.PROCEED_ID: case IDialogConstants.OK_ID: getPrefStore().setValue(getPrefKey(), false); break; case IDialogConstants.NO_ID: case IDialogConstants.NO_TO_ALL_ID: getPrefStore().setValue(getPrefKey(), true); break; }//from w w w . j av a 2 s.com } }
From source file:org.eclipse.ajdt.internal.ui.xref.XRefUtils.java
License:Open Source License
/** * If an Aspect is opened in the Aspect Editor and the 'Cross References' * view is NOT already open, it may be automatically opened for the user. A * dialog will be displayed, asking the user: * // w w w . j a va 2 s . c o m * a) if they want the view to be opened b) if they would like the view to * be opened every time an Aspect is opened * * -spyoung */ public static void autoOpenXRefView() { /* * Case 1 the view is already open, by whatever means - do nothing. */ boolean viewAlreadyOpen = isXRefViewOpen(); if (viewAlreadyOpen) { return; } /* * Case 2 the view is not open AND the user DOESN'T want to have it * opened for them. */ IPreferenceStore store = AspectJUIPlugin.getDefault().getPreferenceStore(); // Extract information to local variables for debug boolean promptForAutoOpenCrossRefView = store .getBoolean(AspectJPreferences.PROMPT_FOR_AUTO_OPEN_CROSS_REF_VIEW); boolean autoOpenCrossRefView = store.getBoolean(AspectJPreferences.AUTO_OPEN_CROSS_REF_VIEW); if (!promptForAutoOpenCrossRefView && !autoOpenCrossRefView) { // Don't prompt - we've been asked not to open and to "remember // their decision" return; } /* * Case 3 the view is not open AND the user HASN'T YET expressed an * opinion. */ if (store.getBoolean(AspectJPreferences.PROMPT_FOR_AUTO_OPEN_CROSS_REF_VIEW)) { boolean userClickedYes = false; boolean rememberUsersChoice = false; MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(null, UIMessages.OpenAspect_showCrossReferencesView_question, UIMessages.OpenAspect_showCrossReferencesView_explanation, null, false, null, null); userClickedYes = (dialog.getReturnCode() == IDialogConstants.YES_ID); rememberUsersChoice = dialog.getToggleState(); if (rememberUsersChoice && userClickedYes) { // 3.1 - remember that the user ALWAYS wants this view opened // do the same for all other projects... store.setValue(AspectJPreferences.AUTO_OPEN_CROSS_REF_VIEW, true); // ...without prompting store.setValue(AspectJPreferences.PROMPT_FOR_AUTO_OPEN_CROSS_REF_VIEW, false); } else if (rememberUsersChoice && !userClickedYes) { // 3.2 - remember that the user NEVER wants this view opened // do the same for all other projects... store.setValue(AspectJPreferences.AUTO_OPEN_CROSS_REF_VIEW, false); // ...without prompting store.setValue(AspectJPreferences.PROMPT_FOR_AUTO_OPEN_CROSS_REF_VIEW, false); // Nothing more to do now, so return return; } else if (!userClickedYes) { // Nothing more to do now, so return return; } } // And finally, open the Cross References view try { AspectJUIPlugin.getDefault().getActiveWorkbenchWindow().getActivePage().showView(XReferenceView.ID); } catch (PartInitException e) { AJDTErrorHandler.handleAJDTError(UIMessages.BuildConfigurator_ErrorOpeningXRefView, e); } }
From source file:org.eclipse.andmore.android.certmanager.command.DeleteKeystoreHandler.java
License:Apache License
private boolean showQuestion(List<ITreeNode> nodesToDelete) { final Boolean[] reply = new Boolean[2]; final String keystoreName = nodesToDelete.size() == 1 ? nodesToDelete.get(0).getName() : null; PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { @Override/*from w w w .j a va2 s . c om*/ public void run() { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow ww = workbench.getActiveWorkbenchWindow(); Shell shell = ww.getShell(); MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(shell, CertificateManagerNLS.DeleteKeystoreHandler_ConfirmationQuestionDialog_Title, keystoreName != null ? NLS.bind( CertificateManagerNLS.DeleteKeystoreHandler_ConfirmationQuestionDialog_Description, keystoreName) : CertificateManagerNLS.DeleteKeystoreHandler_Delete_Selected_Keystores, CertificateManagerNLS.DeleteKeystoreHandler_ConfirmationQuestionDialog_Toggle, false, null, null); reply[0] = (dialog.getReturnCode() == IDialogConstants.YES_ID); reply[1] = dialog.getToggleState(); } }); toggleState = reply[1]; return reply[0]; }
From source file:org.eclipse.andmore.android.common.preferences.DialogWithToggleUtils.java
License:Apache License
/** * Shows a dialog with "Yes" and "No" buttons. The dialog is opened only if * it is the first time that the dialog is shown or if the user did not * check the option "Do not show this window again" when the dialog had been * opened previously./*from ww w .j av a 2 s. co m*/ * * @param preferenceKey * the key to use when persisting the user's preference. * @param title * the dialog's title, or <code>null</code> if none. * @param message * the dialog's message. * @return if the dialog was opened: true, if the user pressed "Yes". if the * dialog was not opened: true, if the option was set to "Always". */ public static boolean showQuestion(final String preferenceKey, final String title, final String message) { final Boolean[] reply = new Boolean[1]; final String prefKey = preferenceKey + TOGGLE_DIALOG; PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { @Override public void run() { AbstractUIPlugin plugin = CommonPlugin.getDefault(); IPreferenceStore store = plugin.getPreferenceStore(); String preferenceValue = store.getString(prefKey); if (MessageDialogWithToggle.PROMPT.equals(preferenceValue) || (preferenceValue.length() == 0)) { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow ww = workbench.getActiveWorkbenchWindow(); Shell shell = ww.getShell(); MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(shell, title, message, UtilitiesNLS.UI_DoNotShowMEAgain, false, store, prefKey); reply[0] = (dialog.getReturnCode() == IDialogConstants.YES_ID); } else { reply[0] = preferenceValue.equals(MessageDialogWithToggle.ALWAYS); } } }); return reply[0]; }
From source file:org.eclipse.andmore.android.common.utilities.EclipseUtils.java
License:Apache License
/** * Show a question message using the given title and message * //from w ww . ja v a 2s . c om * @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; }