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

The following examples show how to use org.eclipse.jface.dialogs.MessageDialogWithToggle#getReturnCode() . 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: ManyEntriesSelectedDialogPreCheckedListener.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 *
 * @return if the checking should be cancelled
 */
private boolean showWarning(int nb) {
    /*
     * Show a dialog warning users that selecting many entries will be slow.
     */
    IPreferenceStore corePreferenceStore = Activator.getDefault().getPreferenceStore();
    boolean hide = corePreferenceStore.getBoolean(ITmfUIPreferences.HIDE_MANY_ENTRIES_SELECTED_TOGGLE);
    if (nb > 20 && !hide) {
        MessageDialogWithToggle openOkCancelConfirm = MessageDialogWithToggle.openOkCancelConfirm(
                fFilteredCheckboxTree.getShell(),
                Messages.ManyEntriesSelectedDialogPreCheckedListener_ManyEntriesSelectedTitle,
                NLS.bind(Messages.ManyEntriesSelectedDialogPreCheckedListener_ManyEntriesSelectedMessage, nb),
                Messages.ManyEntriesSelectedDialogPreCheckedListener_ManyEntriesSelectedDontShowAgain, false,
                null, null);
        corePreferenceStore.setValue(ITmfUIPreferences.HIDE_MANY_ENTRIES_SELECTED_TOGGLE, openOkCancelConfirm.getToggleState());
        int retCode = openOkCancelConfirm.getReturnCode();
        return retCode == Window.CANCEL;
    }
    return false;
}
 
Example 2
Source File: PyDialogHelpers.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public static boolean openQuestionWithIgnoreToggle(String title, String message, String key) {
    Shell shell = EditorUtils.getShell();
    IPreferenceStore store = PydevPlugin.getDefault().getPreferenceStore();
    String val = store.getString(key);
    if (val.trim().length() == 0) {
        val = MessageDialogWithToggle.PROMPT; //Initial value if not specified
    }

    if (!val.equals(MessageDialogWithToggle.ALWAYS)) {
        MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(shell, title, message,
                "Don't show this message again", false, store,
                key);
        if (dialog.getReturnCode() != IDialogConstants.YES_ID) {
            return false;
        }
    }
    return true;
}
 
Example 3
Source File: ShowAnnotationOperation.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns true if the user wishes to always use the live annotate view, false otherwise.
 * @return
 */
private boolean promptForQuickDiffAnnotate(){
	//check whether we should ask the user.
	final IPreferenceStore store = SVNUIPlugin.getPlugin().getPreferenceStore();
	final String option = store.getString(ISVNUIConstants.PREF_USE_QUICKDIFFANNOTATE);
	
	if (option.equals(MessageDialogWithToggle.ALWAYS))
		return true; //use live annotate
	else if (option.equals(MessageDialogWithToggle.NEVER))
		return false; //don't use live annotate
	
	final MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(Utils.getShell(null), Policy.bind("AnnotateOperation_QDAnnotateTitle"),
			Policy.bind("AnnotateOperation_QDAnnotateMessage"), Policy.bind("AnnotateOperation_4"), false, store, ISVNUIConstants.PREF_USE_QUICKDIFFANNOTATE);
	
	final int result = dialog.getReturnCode();
	switch (result) {
		//yes
		case IDialogConstants.YES_ID:
		case IDialogConstants.OK_ID :
		    return true;
	}
	return false;
}
 
Example 4
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 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: 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 7
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 8
Source File: ActionUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isEditable(Shell shell, IJavaElement element) {
	if (! isProcessable(shell, element))
		return false;

	IJavaElement cu= element.getAncestor(IJavaElement.COMPILATION_UNIT);
	if (cu != null) {
		IResource resource= cu.getResource();
		if (resource != null && resource.isDerived(IResource.CHECK_ANCESTORS)) {

			// see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#validateEditorInputState()
			final String warnKey= AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WARN_IF_INPUT_DERIVED;
			IPreferenceStore store= EditorsUI.getPreferenceStore();
			if (!store.getBoolean(warnKey))
				return true;

			MessageDialogWithToggle toggleDialog= MessageDialogWithToggle.openYesNoQuestion(
					shell,
					ActionMessages.ActionUtil_warning_derived_title,
					Messages.format(ActionMessages.ActionUtil_warning_derived_message, BasicElementLabels.getPathLabel(resource.getFullPath(), false)),
					ActionMessages.ActionUtil_warning_derived_dontShowAgain,
					false,
					null,
					null);

			EditorsUI.getPreferenceStore().setValue(warnKey, !toggleDialog.getToggleState());

			return toggleDialog.getReturnCode() == IDialogConstants.YES_ID;
		}
	}
	return true;
}
 
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: 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 13
Source File: DialogUtils.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * openIgnoreMessageDialogInformation
 * 
 * @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_HideMessage, false, store, key);
		if (d.getReturnCode() == 3)
		{
			return MessageDialog.CANCEL;
		}
	}
	return MessageDialog.OK;
}
 
Example 14
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 15
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 16
Source File: JavadocView.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void internalCreatePartControl(Composite parent) {
	try {
		fBrowser= new Browser(parent, SWT.NONE);
		fBrowser.setJavascriptEnabled(false);
		fIsUsingBrowserWidget= true;
		addLinkListener(fBrowser);
		fBrowser.addOpenWindowListener(new OpenWindowListener() {
			public void open(WindowEvent event) {
				event.required= true; // Cancel opening of new windows
			}
		});

	} catch (SWTError er) {

		/* The Browser widget throws an SWTError if it fails to
		 * instantiate properly. Application code should catch
		 * this SWTError and disable any feature requiring the
		 * Browser widget.
		 * Platform requirements for the SWT Browser widget are available
		 * from the SWT FAQ web site.
		 */

		IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore();
		boolean doNotWarn= store.getBoolean(DO_NOT_WARN_PREFERENCE_KEY);
		if (WARNING_DIALOG_ENABLED) {
			if (!doNotWarn) {
				String title= InfoViewMessages.JavadocView_error_noBrowser_title;
				String message= InfoViewMessages.JavadocView_error_noBrowser_message;
				String toggleMessage= InfoViewMessages.JavadocView_error_noBrowser_doNotWarn;
				MessageDialogWithToggle dialog= MessageDialogWithToggle.openError(parent.getShell(), title, message, toggleMessage, false, null, null);
				if (dialog.getReturnCode() == Window.OK)
					store.setValue(DO_NOT_WARN_PREFERENCE_KEY, dialog.getToggleState());
			}
		}

		fIsUsingBrowserWidget= false;
	}

	if (!fIsUsingBrowserWidget) {
		fText= new StyledText(parent, SWT.V_SCROLL | SWT.H_SCROLL);
		fText.setEditable(false);
		fPresenter= new HTMLTextPresenter(false);

		fText.addControlListener(new ControlAdapter() {
			/*
			 * @see org.eclipse.swt.events.ControlAdapter#controlResized(org.eclipse.swt.events.ControlEvent)
			 */
			@Override
			public void controlResized(ControlEvent e) {
				doSetInput(fOriginalInput);
			}
		});
	}

	initStyleSheet();
	listenForFontChanges();
	getViewSite().setSelectionProvider(new SelectionProvider(getControl()));
}
 
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: 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 19
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 20
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;
}