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

The following examples show how to use org.eclipse.jface.dialogs.IDialogConstants#NO_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: 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 2
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 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: 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 5
Source File: Question.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
/** Must be called in the UI thread. */
public static int askWithCancel(String title, String message) {
	String[] labels = new String[] { IDialogConstants.YES_LABEL,
			IDialogConstants.NO_LABEL,
			IDialogConstants.CANCEL_LABEL };
	MessageDialog dialog = new MessageDialog(
			UI.shell(), title, null, message,
			MessageDialog.QUESTION_WITH_CANCEL, labels, 0);
	int result = dialog.open();
	if (result == 0)
		return IDialogConstants.YES_ID;
	if (result == 1)
		return IDialogConstants.NO_ID;
	if (result == 2)
		return IDialogConstants.CANCEL_ID;
	return IDialogConstants.CANCEL_ID;
}
 
Example 6
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 7
Source File: AddToVersionControlDialog.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected void buttonPressed(int id) {
	// hijack yes and no buttons to set the correct return
	// codes.
	if(id == IDialogConstants.YES_ID || id == IDialogConstants.NO_ID) {
		setReturnCode(id);
		close();
	} else {
		super.buttonPressed(id);
	}
}
 
Example 8
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 9
Source File: ImportStatusDialog.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Button createButton(final Composite parent, final int id, final String label, final boolean defaultButton) {
    if (org.bonitasoft.studio.ui.i18n.Messages.seeDetails.equals(label)) {
        return super.createButton(parent, IDialogConstants.OPEN_ID, label, defaultButton);
    }
    if (Messages.deploy.equals(label)) {
        return super.createButton(parent, IDialogConstants.PROCEED_ID, label, defaultButton);
    }
    if (Messages.copyToClipboard.equals(label)) {
        final Button copyButton = super.createButton(parent, IDialogConstants.NO_ID, label, defaultButton);
        copyButton.addSelectionListener(new SelectionAdapter() {

            /*
             * (non-Javadoc)
             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
             */
            @Override
            public void widgetSelected(SelectionEvent e) {
                final Clipboard cb = new Clipboard(Display.getDefault());
                final TextTransfer textTransfer = TextTransfer.getInstance();
                cb.setContents(new Object[] { statusMessages() },
                        new Transfer[] { textTransfer });
            }
        });
        return copyButton;
    }
    return super.createButton(parent, id, label, defaultButton);
}
 
Example 10
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() {
			int[] resultId= getResultIDs();

			MessageDialog dialog= new MessageDialog(
				fShell,
				fDialogTitle,
				null,
				question,
				MessageDialog.QUESTION,
				getButtonLabels(),
				0);
			dialog.open();

			if (dialog.getReturnCode() == -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;
			} else {
				result[0]= resultId[dialog.getReturnCode()];
			}
		}

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

		private int[] getResultIDs() {
			if (YesYesToAllNoNoToAllQuery.this.fAllowCancel)
				return new int[] {
					IDialogConstants.YES_ID,
					IDialogConstants.YES_TO_ALL_ID,
					IDialogConstants.NO_ID,
					IDialogConstants.NO_TO_ALL_ID,
					IDialogConstants.CANCEL_ID};
			else
				return new int[] {
					IDialogConstants.YES_ID,
					IDialogConstants.YES_TO_ALL_ID,
					IDialogConstants.NO_ID,
					IDialogConstants.NO_TO_ALL_ID};
		}
	};
}
 
Example 11
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};
		}
	};
}
 
Example 12
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 13
Source File: ImportStatusDialog.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void buttonPressed(int buttonId) {
    if (IDialogConstants.NO_ID != buttonId) {
        super.buttonPressed(buttonId);
    }
}
 
Example 14
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;
}