Java Code Examples for org.eclipse.jface.dialogs.MessageDialogWithToggle#getToggleState()

The following examples show how to use org.eclipse.jface.dialogs.MessageDialogWithToggle#getToggleState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RepositoryImportProgressDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public boolean jobOverwritePrompt( JobMeta jobMeta ) {
  MessageDialogWithToggle md =
    new MessageDialogWithToggle(
      shell, BaseMessages.getString( PKG, "RepositoryImportDialog.OverwriteJob.Title" ), null, BaseMessages
        .getString( PKG, "RepositoryImportDialog.OverwriteJob.Message", jobMeta.getName() ),
      MessageDialog.QUESTION, new String[] {
        BaseMessages.getString( PKG, "System.Button.Yes" ),
        BaseMessages.getString( PKG, "System.Button.No" ) },
      1,
      BaseMessages.getString( PKG, "RepositoryImportDialog.DontAskAgain.Label" ),
      !askOverwrite );
  MessageDialogWithToggle.setDefaultImage( GUIResource.getInstance().getImageSpoon() );
  int answer = md.open();
  askOverwrite = !md.getToggleState();

  return ( answer & 0xFF ) == 0;
}
 
Example 2
Source File: FindBugsAction.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected static void askUserToSwitch(IWorkbenchPart part, int warningsNumber) {
    final IPreferenceStore store = FindbugsPlugin.getDefault().getPreferenceStore();
    String message = "SpotBugs analysis finished, " + warningsNumber
            + " warnings found.\n\nSwitch to the SpotBugs perspective?";

    MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(null, "SpotBugs analysis finished",
            message, "Remember the choice and do not ask me in the future", false, store,
            FindBugsConstants.ASK_ABOUT_PERSPECTIVE_SWITCH);

    boolean remember = dialog.getToggleState();
    int returnCode = dialog.getReturnCode();

    if (returnCode == IDialogConstants.YES_ID) {
        if (remember) {
            store.setValue(FindBugsConstants.SWITCH_PERSPECTIVE_AFTER_ANALYSIS, true);
        }
        switchPerspective(part);
    } else if (returnCode == IDialogConstants.NO_ID) {
        if (remember) {
            store.setValue(FindBugsConstants.SWITCH_PERSPECTIVE_AFTER_ANALYSIS, false);
        }
    }
}
 
Example 3
Source File: RepositoryImportProgressDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public boolean transOverwritePrompt( TransMeta transMeta ) {
  MessageDialogWithToggle md = new MessageDialogWithToggle( shell,
    BaseMessages.getString( PKG, "RepositoryImportDialog.OverwriteTrans.Title" ),
    null,
    BaseMessages.getString( PKG, "RepositoryImportDialog.OverwriteTrans.Message", transMeta.getName() ),
    MessageDialog.QUESTION, new String[] {
      BaseMessages.getString( PKG, "System.Button.Yes" ),
      BaseMessages.getString( PKG, "System.Button.No" ) },
    1,
    BaseMessages.getString( PKG, "RepositoryImportDialog.DontAskAgain.Label" ), !askOverwrite );
  MessageDialogWithToggle.setDefaultImage( GUIResource.getInstance().getImageSpoon() );
  int answer = md.open();

  askOverwrite = !md.getToggleState();

  return ( answer & 0xFF ) == 0;
}
 
Example 4
Source File: DialogUtils.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * openIgnoreMessageDialogConfirm
 * 
 * @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)
{
	String value = store.getString(key);
	if (!shouldShowDialog(key))
	{
		return value == MessageDialogWithToggle.ALWAYS ? IDialogConstants.YES_ID : IDialogConstants.NO_ID;
	}
	MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(shell, title, message,
			Messages.DialogUtils_doNotShowMessageAgain, false, store, key);
	if (dialog.getToggleState())
	{
		setShouldShowDialog(key, false);
		store.putValue(key, dialog.getReturnCode() == IDialogConstants.YES_ID ? MessageDialogWithToggle.ALWAYS
				: MessageDialogWithToggle.NEVER);
	}
	return dialog.getReturnCode();
}
 
Example 5
Source File: DialogUtils.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Conditionally open an information message dialog. In case this is the first time this dialog is opened (defined
 * by its key), the dialog will be displayed, and a "Do not show this message again" checkbox will be available. The
 * message dialog will not be opened again when the checkbox is selected.<br>
 * Once checked, the only way to display this dialog again is by resetting the messaged through the Studio's main
 * preference page.
 * 
 * @param shell
 * @param title
 * @param message
 * @param dialogKey
 *            A dialog key that will be checked to confirm if the dialog should be diaplayed.
 * @return The dialog's return code.
 */
public static int openIgnoreMessageDialogInformation(Shell shell, String title, String message, String dialogKey)
{
	if (!shouldShowDialog(dialogKey))
	{
		return MessageDialog.CANCEL;
	}
	MessageDialogWithToggle dialog = MessageDialogWithToggle.openInformation(shell, title, message,
			Messages.DialogUtils_doNotShowMessageAgain, false, null, null);
	if (dialog.getReturnCode() == Dialog.OK)
	{
		// check the toggle state to see if we need to add the dialog key to the list of hidden dialogs.
		if (dialog.getToggleState())
		{
			setShouldShowDialog(dialogKey, false);
		}
	}
	return dialog.getReturnCode();
}
 
Example 6
Source File: GUIResource.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Generic popup with a toggle option
 */
public Object[] messageDialogWithToggle( Shell shell, String dialogTitle, Image image, String message,
                                         int dialogImageType, String[] buttonLabels, int defaultIndex,
                                         String toggleMessage, boolean toggleState ) {
  int imageType = 0;
  if ( dialogImageType == Const.WARNING ) {
    imageType = MessageDialog.WARNING;
  }

  MessageDialogWithToggle md =
    new MessageDialogWithToggle( shell, dialogTitle, image, message, imageType, buttonLabels, defaultIndex,
      toggleMessage, toggleState );
  int idx = md.open();
  return new Object[] { idx, md.getToggleState() };
}
 
Example 7
Source File: XPromptChange.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public static Boolean promptChangeBoolean(String displayName, String toggleMessage, boolean currSelection) {
   MessageDialogWithToggle md =
      new MessageDialogWithToggle(Display.getCurrent().getActiveShell(), displayName, null, displayName,
         MessageDialog.QUESTION,
         new String[] {XViewerText.get("button.ok"), XViewerText.get("button.cancel")}, Window.OK, //$NON-NLS-1$ //$NON-NLS-2$
         (toggleMessage != null ? toggleMessage : displayName), currSelection);
   int result = md.open();
   if (result == Window.OK) {
      return md.getToggleState();
   }
   return null;
}
 
Example 8
Source File: DeleteModelAction.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private boolean isUsed(CategorizedDescriptor d) {
	IUseSearch<CategorizedDescriptor> search = IUseSearch.FACTORY
			.createFor(d.type, Database.get());
	List<CategorizedDescriptor> descriptors = search.findUses(d);
	if (descriptors.isEmpty())
		return false;
	if (showInUseMessage) {
		MessageDialogWithToggle dialog = MessageDialogWithToggle.openError(UI.shell(), M.CannotDelete,
				d.name + ": " + M.CannotDeleteMessage,
				M.DoNotShowThisMessageAgain, false, null, null);
		showInUseMessage = !dialog.getToggleState();
	}
	return true;
}
 
Example 9
Source File: DataColumnXTabDropAdapter.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void storePreference( )
{
	String prompt = PreferenceFactory.getInstance( )
			.getPreferences( CrosstabPlugin.getDefault( ) )
			.getString( CrosstabPlugin.CUBE_BUILDER_WARNING_PREFERENCE );
	if ( prompt == null
			|| prompt.length( ) == 0
			|| ( prompt.equals( MessageDialogWithToggle.PROMPT ) ) )
	{
		MessageDialogWithToggle opendialog = MessageDialogWithToggle.openInformation( UIUtil.getDefaultShell( ),
				Messages.getString( "CubeBuilder.warning.title" ), //$NON-NLS-1$
				Messages.getString( "CubeBuilder.warning.message" ), //$NON-NLS-1$
				Messages.getString( "CubeBuilder.warning.prompt" ), //$NON-NLS-1$
				false,
				null,
				null );
		if ( opendialog.getReturnCode( ) != Window.OK )
		{
			return;
		}
		if ( opendialog.getToggleState( ) == true )
		{
			savePreference( MessageDialogWithToggle.NEVER );
		}
		else
		{
			savePreference( MessageDialogWithToggle.PROMPT );
		}
	}
}
 
Example 10
Source File: PerspectiveUtil.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public static void switchToModelingPerspective(IWorkbenchWindow window) {
	IPreferenceStore prefs = UIPluginActivator.getDefault()
			.getPreferenceStore();
	boolean hide = prefs.getBoolean(AUTO_SWITCH_PERSPECTIVE);
	IWorkbenchPage page = window.getActivePage();
	if (!hide) {
		IWorkbench workbench = window.getWorkbench();
		IPerspectiveRegistry registry = workbench.getPerspectiveRegistry();
		IPerspectiveDescriptor descriptor = registry
				.findPerspectiveWithId(IYakinduSctPerspectives.ID_PERSPECTIVE_SCT_MODELING);
		if ((page != null) && (page.getPerspective() != descriptor)) {
			MessageDialogWithToggle dialog = MessageDialogWithToggle
					.openYesNoQuestion(
							window.getShell(),
							"Confirm Perspective Switch",
							"This kind of editor is associated with the YAKINDU Modeling perspective. Do you want to switch to this perspective now?",
							"Do not offer to switch perspective in the future",
							hide, prefs, AUTO_SWITCH_PERSPECTIVE);
			if (dialog.getReturnCode() == 2)
				page.setPerspective(descriptor);
			hide = dialog.getToggleState();
			prefs.setValue(AUTO_SWITCH_PERSPECTIVE, hide);
			try {
				InstanceScope.INSTANCE.getNode(UIPluginActivator.PLUGIN_ID)
						.flush();
			} catch (BackingStoreException e) {
				e.printStackTrace();
			}
		}
	}
}
 
Example 11
Source File: AbstractNewProjectWizard.java    From typescript.java with MIT License 5 votes vote down vote up
/**
 * Prompts the user for whether to switch perspectives.
 *
 * @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;
}
 
Example 12
Source File: AbstractValidPreferencePage.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Perform OK button.
 *
 * @return true, if successful {@inheritDoc}
 */
@Override
public boolean performOk() {
  try {
    if (preferences.needsSaving()) {
      preferences.save();
    }
  } catch (final IOException e) {
    LOGGER.error("Unable to save general preference page preferences", e); //$NON-NLS-1$
  }

  boolean preferenceChanged = false;
  for (final IPreferenceItem item : (IPreferenceItem[]) ((ValidModelTreeContentProvider) treeViewer.getContentProvider()).getElements(null)) {
    preferenceChanged = preferenceChanged | preferenceChanged(item);
  }

  if (preferenceChanged) {
    final MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(this.getShell(), REVALIDATE_DIALOG_TITLE, REVALIDATE_DIALOG_MESSAGE, EXPENSIVE_CHECKS_TOGGLE_MESSAGE, getPreferenceStore().getBoolean(PERFORM_EXPENSIVE_VALIDATION), null, null);

    final boolean yesWeCan = (dialog.getReturnCode() == IDialogConstants.YES_ID);
    final boolean performExpensiveValidations = dialog.getToggleState();

    getPreferenceStore().setValue(PERFORM_EXPENSIVE_VALIDATION, dialog.getToggleState());

    if (yesWeCan) {
      final ValidMarkerUpdateJob updateJob = new ValidMarkerUpdateJob(VALIDATION_JOB_MESSAGE, this.fileExtensions, this.resourceSet, this.markerCreator, this.resourceDescriptions, this.resourceServiceProvider, performExpensiveValidations, storage2UriMapper);
      // The following gets a global lock on all updateJob, no matter what the language is.
      // The reason is that we want to avoid the update job to consume too much memory, but
      // we may decide to change that to a lock on a language basis...
      updateJob.setRule(ResourcesPlugin.getWorkspace().getRoot());
      updateJob.schedule();
    }

  }

  return super.performOk();
}
 
Example 13
Source File: CrosstabAdaptUtil.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean needRemoveInvaildBindings(
		CrosstabReportItemHandle handle )
{
	String preferenceData = PreferenceFactory.getInstance( )
			.getPreferences( CrosstabPlugin.getDefault( ) )
			.getString( CrosstabPlugin.PREFERENCE_AUTO_DEL_BINDINGS );
	if ( preferenceData == null
			|| preferenceData.length( ) == 0
			|| preferenceData.equals( MessageDialogWithToggle.PROMPT ) )
	{
		MessageDialogWithToggle msgDlg = MessageDialogWithToggle.openYesNoQuestion( UIUtil.getDefaultShell( ),
				Messages.getString( "DeleteBindingDialog.Title" ), //$NON-NLS-1$
				Messages.getString( "DeleteBindingDialog.Message" ), //$NON-NLS-1$
				Messages.getString( "DeleteBindingDialog.ToggleMessage" ), //$NON-NLS-1$
				false,
				null,
				null );

		if ( msgDlg.getToggleState( ) )
		{
			String value = "";
			if ( msgDlg.getReturnCode( ) == IDialogConstants.YES_ID )
			{
				value = MessageDialogWithToggle.ALWAYS;
			}
			else if ( msgDlg.getReturnCode( ) == IDialogConstants.NO_ID )
			{
				value = MessageDialogWithToggle.NEVER;
			}
			PreferenceFactory.getInstance( )
					.getPreferences( CrosstabPlugin.getDefault( ) )
					.setValue( CrosstabPlugin.PREFERENCE_AUTO_DEL_BINDINGS,
							value );
		}
		if ( msgDlg.getReturnCode( ) == IDialogConstants.YES_ID )
		{
			return true;
			// removeInvalidBindings( handle );
		}
		else if ( msgDlg.getReturnCode( ) == IDialogConstants.NO_ID )
		{
			return false;
			// dothing
		}

	}
	else if ( preferenceData != null
			&& preferenceData.equals( MessageDialogWithToggle.ALWAYS ) )
	{
		return true;
		// removeInvalidBindings( handle );
	}
	return false;
	// removeInvalidBindings(handle);
}
 
Example 14
Source File: DataSetParametersPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void updateLinkedReportParameter( String originalLink )
{
		ScalarParameterHandle orignalHandle = null;
	if ( !originalLink.equals( Messages.getString( "DataSetParametersPage.reportParam.None" ) ) )
	{
		orignalHandle = ParameterPageUtil.getScalarParameter( originalLink,
				true );
	}
	ParameterHandle currentHandle = null;
	if ( !linkToScalarParameter.getText( )
			.equals( Messages.getString( "DataSetParametersPage.reportParam.None" ) ) )
	{
		currentHandle = ParameterPageUtil.getScalarParameter( linkToScalarParameter.getText( ),
				true );
	}
	
	OdaDataSetParameterHandle dataSetParameterHandle = (OdaDataSetParameterHandle) structureHandle;
	if ( currentHandle != null && orignalHandle != currentHandle )
	{
		boolean setting = ReportPlugin.getDefault( )
				.getPluginPreferences( )
				.getBoolean( DateSetPreferencePage.PROMPT_PARAM_UPDATE );
		String option = ReportPlugin.getDefault( )
				.getPluginPreferences( )
				.getString( DateSetPreferencePage.PROMPT_PARAM_UPDATE_OPTION );

		if ( setting )
		{
			if ( option != null && option.equals( DateSetPreferencePage.PROMPT_PARAM_UPDATE_OPTION_UPDATE ) )
			{
				executeLinkedReportParameterUpdate( currentHandle,
						dataSetParameterHandle );
			}
			return;
		}
		
		MessageDialogWithToggle dialog = new MessageDialogWithToggle( Workbench.getInstance( )
				.getDisplay( )
				.getActiveShell( ),
				Messages.getString( "DataSetParameterPage.updateReportParameter.title" ),
				null,
				Messages.getString( "DataSetParameterPage.updateReportParameter.message" ),
				MessageDialog.QUESTION,
				new String[]{
						Messages.getString( "DataSetParameterPage.updateReportParameter.promptButtonYes" ),
						Messages.getString( "DataSetParameterPage.updateReportParameter.promptButtonNo" )
				},
				1,
				Messages.getString( "DataSetParameterPage.updateReportParameter.propmtText" ),
				false );
		
		dialog.open( );
		
		if ( dialog.getReturnCode( ) == 256 )
		{
			executeLinkedReportParameterUpdate( currentHandle,dataSetParameterHandle );
		}
		
		if ( dialog.getToggleState( ) )
		{
			ReportPlugin.getDefault( )
					.getPluginPreferences( )
					.setValue( DateSetPreferencePage.PROMPT_PARAM_UPDATE,
							true );
			if ( dialog.getReturnCode( ) == 256 )
			{
				ReportPlugin.getDefault( )
						.getPluginPreferences( )
						.setValue( DateSetPreferencePage.PROMPT_PARAM_UPDATE_OPTION,
								DateSetPreferencePage.PROMPT_PARAM_UPDATE_OPTION_UPDATE );
			}
			else
			{
				ReportPlugin.getDefault( )
						.getPluginPreferences( )
						.setValue( DateSetPreferencePage.PROMPT_PARAM_UPDATE_OPTION,
								DateSetPreferencePage.PROMPT_PARAM_UPDATE_OPTION_IGNORE );
			}
		}
			
	}
	
}
 
Example 15
Source File: LibraryLayoutEditorFormPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public boolean onBroughtToTop( IReportEditorPage page )
{
	String prompt = ReportPlugin.getDefault( )
			.getPreferenceStore( )
			.getString( ReportPlugin.LIBRARY_WARNING_PREFERENCE );

	if ( !alreadyShow
			&& ( prompt == null || ( !ReportPlugin.getDefault( )
					.getPreferenceStore( )
					.getString( ReportPlugin.LIBRARY_WARNING_PREFERENCE )
					.equals( MessageDialogWithToggle.NEVER ) ) ) )
	{
		alreadyShow = true;
		MessageDialogWithToggle dialog = MessageDialogWithToggle.openInformation( UIUtil.getDefaultShell( ),
				Messages.getString( "LibraryLayoutEditorFormPage.warning.title" ), //$NON-NLS-1$
				Messages.getString( "LibraryLayoutEditorFormPage.warning.message" ), //$NON-NLS-1$
				Messages.getString( "LibraryLayoutEditorFormPage.warning.prompt" ), //$NON-NLS-1$
				false,
				ReportPlugin.getDefault( ).getPreferenceStore( ),
				ReportPlugin.LIBRARY_WARNING_PREFERENCE );
		// if dialog.getToggleState() == true then means not show again.
		if ( dialog.getToggleState( ) )
		{
			ReportPlugin.getDefault( )
					.getPreferenceStore( )
					.setValue( ReportPlugin.LIBRARY_WARNING_PREFERENCE,
							MessageDialogWithToggle.NEVER );
		}
	}

	// the three classes has the logic to rebuild the model, should be
	// refactor.
	ModuleHandle newModel = getProvider( ).queryReportModuleHandle( );
	boolean reload = false;
	if ( getStaleType( ) == IPageStaleType.MODEL_RELOAD )
	{
		setModel( null );
		doSave( null );
		reload = true;
	}
	if ( ( newModel != null && getModel( ) != newModel ) || reload )
	{
		ModuleHandle oldModel = getModel( );

		setModel( newModel );

		rebuildReportDesign( oldModel );
		if ( getModel( ) != null )
		{
			this.getGraphicalViewer( ).setContents( getModel( ) );
			hookModelEventManager( getModel( ) );
			markPageStale( IPageStaleType.NONE );
		}
		updateStackActions( );
	}
	// reselect the selection
	GraphicalViewer view = getGraphicalViewer( );

	if ( view != null )
	{
		UIUtil.resetViewSelection( view, true );
	}
	return true;
}
 
Example 16
Source File: ViewerConfigDialog.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Check that the config is valid.
 * 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();
}
 
Example 17
Source File: DontAskAgainDialogs.java    From xtext-eclipse with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Opens a {@link MessageDialogWithToggle} and stores the answer, if user activated the corresponding checkbox.
 *
 * @param question
 *            The question to ask.
 * @param dialogTitle
 *            Title
 * @param storeKey
 *            The key used to store the decision in {@link IDialogSettings}, also used to read the
 *            {@link #getUserDecision(String)}
 * @param shell
 *            the parent {@link Shell} of the dialog
 * @return User answer, one of {@link IDialogConstants#YES_ID}, {@link IDialogConstants#NO_ID} or
 *         {@link IDialogConstants#CANCEL_ID}
 */
public int askUser(String question, String dialogTitle, String storeKey, Shell shell) {
	MessageDialogWithToggle dialogWithToggle = MessageDialogWithToggle.openYesNoCancelQuestion(shell, dialogTitle,
			question, null, false, null, null);
	boolean rememberDecision = dialogWithToggle.getToggleState();
	int userAnswer = dialogWithToggle.getReturnCode();
	if (rememberDecision) {
		if (userAnswer == IDialogConstants.NO_ID) {
			neverAskAgain(storeKey);
		} else if (userAnswer == IDialogConstants.YES_ID) {
			storeUserDecision(storeKey, MessageDialogWithToggle.ALWAYS);
		}
	}
	return userAnswer;
}