Java Code Examples for org.eclipse.jface.dialogs.IDialogConstants#YES_ID

The following examples show how to use org.eclipse.jface.dialogs.IDialogConstants#YES_ID . 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: Question.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
public static int askWithAll(String title, String message) {
	String[] labels = new String[] {
			IDialogConstants.YES_LABEL,
			IDialogConstants.YES_TO_ALL_LABEL,
			IDialogConstants.NO_LABEL,
			IDialogConstants.CANCEL_LABEL };
	MessageDialog dialog = new MessageDialog(
			UI.shell(), title, null, message,
			MessageDialog.QUESTION, labels, 0);
	int result = dialog.open();
	if (result == 0)
		return IDialogConstants.YES_ID;
	if (result == 1)
		return IDialogConstants.YES_TO_ALL_ID;
	if (result == 2)
		return IDialogConstants.NO_ID;
	if (result == 3)
		return IDialogConstants.NO_TO_ALL_ID;
	return IDialogConstants.CANCEL_ID;
}
 
Example 2
Source File: MessageDialogWithPrompt.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void buttonPressed(int buttonId) {
    super.buttonPressed(buttonId);

    final boolean toggleState = getToggleState();
    final IPreferenceStore prefStore = getPrefStore();
    final String prefKey = getPrefKey();
    if (buttonId != IDialogConstants.CANCEL_ID
            && 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;
        }
    }
}
 
Example 3
Source File: ReorgQueries.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean getResult(int[] result) throws OperationCanceledException {
	switch(result[0]){
		case IDialogConstants.YES_TO_ALL_ID:
			fYesToAll= true;
			return true;
		case IDialogConstants.YES_ID:
			return true;
		case IDialogConstants.CANCEL_ID:
			throw new OperationCanceledException();
		case IDialogConstants.NO_ID:
			return false;
		case IDialogConstants.NO_TO_ALL_ID:
			fNoToAll= true;
			return false;
		default:
			Assert.isTrue(false);
			return false;
	}
}
 
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: CommitCommentArea.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public String getCommentWithPrompt(Shell shell) {
    final String comment= getComment(false);
    if (comment.length() == 0) {
        final IPreferenceStore store= SVNUIPlugin.getPlugin().getPreferenceStore();
        final String value= store.getString(ISVNUIConstants.PREF_ALLOW_EMPTY_COMMIT_COMMENTS);
        
        if (MessageDialogWithToggle.NEVER.equals(value))
            return null;
        
        if (MessageDialogWithToggle.PROMPT.equals(value)) {
            
            final String title= Policy.bind("CommitCommentArea_2"); 
            final String message= Policy.bind("CommitCommentArea_3"); 
            final String toggleMessage= Policy.bind("CommitCommentArea_4"); 
            
            final MessageDialogWithToggle dialog= MessageDialogWithToggle.openYesNoQuestion(shell, title, message, toggleMessage, false, store, ISVNUIConstants.PREF_ALLOW_EMPTY_COMMIT_COMMENTS);
            if (dialog.getReturnCode() != IDialogConstants.YES_ID) {
                fTextBox.setFocus();
                return null;
            }
        }
    }
    return getComment(true);
}
 
Example 6
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 7
Source File: NatureAddingEditorCallback.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void afterCreatePartControl(XtextEditor editor) {
	IResource resource = editor.getResource();
	if (resource != null && !toggleNature.hasNature(resource.getProject()) && resource.getProject().isAccessible()
			&& !resource.getProject().isHidden()) {
		String title = Messages.NatureAddingEditorCallback_MessageDialog_Title;
		String message = Messages.NatureAddingEditorCallback_MessageDialog_Msg0 + resource.getProject().getName()
				+ Messages.NatureAddingEditorCallback_MessageDialog_Msg1;
		boolean addNature = false;
		if (MessageDialogWithToggle.PROMPT.equals(dialogs.getUserDecision(ADD_XTEXT_NATURE))) {
			int userAnswer = dialogs.askUser(message, title, ADD_XTEXT_NATURE, editor.getEditorSite().getShell());
			if (userAnswer == IDialogConstants.YES_ID) {
				addNature = true;
			} else if (userAnswer == IDialogConstants.CANCEL_ID) {
				return;
			}
		} else if (MessageDialogWithToggle.ALWAYS.equals(dialogs.getUserDecision(ADD_XTEXT_NATURE))) {
			addNature = true;
		}
		if (addNature) {
			toggleNature.toggleNature(resource.getProject());
		}
	}
}
 
Example 8
Source File: HostLeftAloneInSessionHandler.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
private void handleHostLeftAlone() {
  String stopSessionPreference =
      preferenceStore.getString(EclipsePreferenceConstants.AUTO_STOP_EMPTY_SESSION);

  boolean prompt = MessageDialogWithToggle.PROMPT.equals(stopSessionPreference);

  boolean stopSession = MessageDialogWithToggle.ALWAYS.equals(stopSessionPreference);

  if (prompt) {
    MessageDialogWithToggle dialog =
        MessageDialogWithToggle.openYesNoQuestion(
            SWTUtils.getShell(),
            Messages.HostLeftAloneInSessionDialog_title,
            Messages.HostLeftAloneInSessionDialog_message,
            "Remember decision",
            false,
            preferenceStore,
            EclipsePreferenceConstants.AUTO_STOP_EMPTY_SESSION);

    stopSession = dialog.getReturnCode() == IDialogConstants.YES_ID;
  }

  if (stopSession) {
    SWTUtils.runSafeSWTAsync(
        log,
        new Runnable() {
          @Override
          public void run() {
            CollaborationUtils.leaveSession();
          }
        });
  }
}
 
Example 9
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 10
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 11
Source File: TmfPerspectiveManager.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns whether or not the user wishes to switch to the specified
 * perspective when a launch occurs.
 *
 * @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;
    }
    IPerspectiveDescriptor perspective = PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(perspectiveId);
    String perspectiveName = (perspective == null) ? null : perspective.getLabel();
    if (perspectiveName == null) {
        return false;
    }
    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 || fPrompting) {
        return false;
    }
    fPrompting = true;
    MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(
            shell,
            Messages.TmfPerspectiveManager_SwitchPerspectiveDialogTitle,
            MessageFormat.format(Messages.TmfPerspectiveManager_SwitchPerspectiveDialogMessage, perspectiveName),
            null,
            false,
            Activator.getDefault().getPreferenceStore(),
            preferenceKey);
    boolean answer = (dialog.getReturnCode() == IDialogConstants.YES_ID);
    synchronized (this) {
        fPrompting= false;
        notifyAll();
    }
    if (isCurrentPerspective(window, perspectiveId)) {
        answer = false;
    }
    return answer;
}
 
Example 12
Source File: AddWordProposal.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Asks the user whether he wants to configure a user dictionary.
 * 
 * @param shell the shell
 * @return <code>true</code> if the user wants to configure the user dictionary
 * @since 3.3
 */
private boolean askUserToConfigureUserDictionary(Shell shell) {
	MessageDialogWithToggle toggleDialog= MessageDialogWithToggle.openYesNoQuestion(
			shell,
			Messages.Spelling_add_askToConfigure_title,
			Messages.Spelling_add_askToConfigure_question,
			Messages.Spelling_add_askToConfigure_ignoreMessage,
			false,
			null,
			null);

	PREF_KEY_PREF_KEY_DO_NOT_ASK.setStoredBoolean(toggleDialog.getToggleState());
	
	return toggleDialog.getReturnCode() == IDialogConstants.YES_ID;
}
 
Example 13
Source File: AddWordProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Asks the user whether he wants to configure a user dictionary.
 * 
 * @param shell the shell
 * @return <code>true</code> if the user wants to configure the user dictionary
 * @since 3.3
 */
private boolean askUserToConfigureUserDictionary(Shell shell) {
	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;
}
 
Example 14
Source File: ReorgQueries.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean getResult(int[] result) throws OperationCanceledException {
	switch(result[0]){
		case IDialogConstants.YES_ID:
			return true;
		case IDialogConstants.CANCEL_ID:
			throw new OperationCanceledException();
		case IDialogConstants.NO_ID:
			return false;
		default:
			Assert.isTrue(false);
			return false;
	}
}
 
Example 15
Source File: CreateAndEditFormContributionItem.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
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 {
        return getEclipsePreferences().getBoolean(EMPTY_CONTRACT_INFO_DIALOG_ANSWER, false);
    }
}
 
Example 16
Source File: UpdateCheck.java    From cppcheclipse with Apache License 2.0 4 votes vote down vote up
public void run() {
	Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
			.getShell();
	// if no new version found, just display a dialog if not in silent mode
	if (newVersion == null) {
		if (!isSilent) {
			MessageDialog.openInformation(shell,
					Messages.UpdateCheck_NoUpdateTitle,
					Messages.UpdateCheck_NoUpdateMessage);
		}
	} else {
		boolean downloadUpdate = false;
		// only have toggle switch for update check if silent (not
		// started from preferences)
		if (isSilent) {
			MessageDialogWithToggle msgDialog = MessageDialogWithToggle
					.openYesNoQuestion(shell,
							Messages.UpdateCheck_UpdateTitle,
							Messages.bind(
									Messages.UpdateCheck_UpdateMessage,
									newVersion),
							Messages.UpdateCheck_NeverCheckAgain,
							false, null, null);
			IPersistentPreferenceStore configuration = CppcheclipsePlugin
					.getConfigurationPreferenceStore();
			configuration.setValue(
					IPreferenceConstants.P_USE_AUTOMATIC_UPDATE_CHECK,
					!msgDialog.getToggleState());
			if (msgDialog.getReturnCode() == IDialogConstants.YES_ID) {
				downloadUpdate = true;
			}
			try {
				configuration.save();
			} catch (IOException e1) {
				CppcheclipsePlugin.logError("Could not save changes for update checks", e1);
			}
		} else {
			downloadUpdate = MessageDialog.openQuestion(shell,
					Messages.UpdateCheck_UpdateTitle, Messages.bind(
							Messages.UpdateCheck_UpdateMessage,
							newVersion));
		}

		if (downloadUpdate) {
			try {
				Utils.openUrl(DOWNLOAD_URL);
			} catch (Exception e) {
				CppcheclipsePlugin.logError("Could not open cppcheck download page", e);
			}
		}
	}
}
 
Example 17
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 18
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 19
Source File: ReorgQueries.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private Runnable createQueryRunnable(final String question, final int[] result){
	return new Runnable() {
		public void run() {
			MessageDialog dialog= new MessageDialog(
				fShell,
				fDialogTitle,
				null,
				question,
				MessageDialog.QUESTION,
				getButtonLabels(),
				0);
			dialog.open();

			switch (dialog.getReturnCode()) {
				case -1 : //MessageDialog closed without choice => cancel | no
					//see also https://bugs.eclipse.org/bugs/show_bug.cgi?id=48400
					result[0]= fAllowCancel ? IDialogConstants.CANCEL_ID : IDialogConstants.NO_ID;
					break;
				case 0 :
					result[0]= IDialogConstants.YES_ID;
					break;
				case 1 :
					result[0]= IDialogConstants.NO_ID;
					break;
				case 2 :
					if (fAllowCancel)
						result[0]= IDialogConstants.CANCEL_ID;
					else
						Assert.isTrue(false);
					break;
				default :
					Assert.isTrue(false);
					break;
			}
		}

		private String[] getButtonLabels() {
			if (fAllowCancel)
				return new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
			else
				return new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL};
		}
	};
}