Example usage for org.eclipse.jface.dialogs MessageDialogWithToggle create

List of usage examples for org.eclipse.jface.dialogs MessageDialogWithToggle create

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialogWithToggle create.

Prototype

@Override
    public void create() 

Source Link

Usage

From source file:org.eclipse.jubula.client.ui.rcp.utils.Utils.java

License:Open Source License

/**
 * Opens a perspective with the given ID.
 * @param perspectiveID The ID of the perspective to open.
 * @return True, if the user wants to change the perspective, false otherwise.
 *//*  ww  w .j av a  2 s . com*/
public static boolean openPerspective(String perspectiveID) {
    IWorkbench worbench = PlatformUI.getWorkbench();
    IWorkbenchWindow activeWindow = worbench.getActiveWorkbenchWindow();
    try {
        IPerspectiveDescriptor activePerspective = getActivePerspective(activeWindow.getActivePage());
        if (activePerspective != null && activePerspective.getId().equals(perspectiveID)) {
            return true;
        }
        final IPreferenceStore preferenceStore = Plugin.getDefault().getPreferenceStore();
        int value = preferenceStore.getInt(Constants.PERSP_CHANGE_KEY);
        if (value == Constants.PERSPECTIVE_CHANGE_YES) {
            worbench.showPerspective(perspectiveID, activeWindow);
            return true;
        } else if (value == Constants.PERSPECTIVE_CHANGE_NO) {
            return true;
        }
        // if --> value = Constants.PERSPECTIVE_CHANGE_PROMPT:
        String perspectiveName = StringConstants.EMPTY;
        if (perspectiveID.equals(Constants.SPEC_PERSPECTIVE)) {
            perspectiveName = Messages.UtilsSpecPerspective;
        } else {
            perspectiveName = Messages.UtilsExecPerspective;
        }
        final int returnCodeYES = 256; // since Eclipse3.2 (not 0)
        final int returnCodeNO = 257; // since Eclipse3.2 (not 1)
        final int returnCodeCANCEL = -1;
        MessageDialogWithToggle dialog = new MessageDialogWithToggle(activeWindow.getShell(),
                Messages.UtilsTitle, null, NLS.bind(Messages.UtilsQuestion, perspectiveName),
                MessageDialog.QUESTION, new String[] { Messages.UtilsYes, Messages.UtilsNo }, 0,
                Messages.UtilsRemember, false) {
            /**
             * {@inheritDoc}
             */
            protected void buttonPressed(int buttonId) {
                super.buttonPressed(buttonId);
                preferenceStore.setValue(Constants.REMEMBER_KEY, getToggleState());
                int val = Constants.PERSPECTIVE_CHANGE_PROMPT;
                if (getToggleState() && getReturnCode() == returnCodeNO) {
                    val = Constants.PERSPECTIVE_CHANGE_NO;
                } else if (getToggleState() && getReturnCode() == returnCodeYES) {
                    val = Constants.PERSPECTIVE_CHANGE_YES;
                }
                preferenceStore.setValue(Constants.PERSP_CHANGE_KEY, val);
            }
        };
        dialog.create();
        DialogUtils.setWidgetNameForModalDialog(dialog);
        dialog.open();
        if (dialog.getReturnCode() == returnCodeNO) {
            return true;
        } else if (dialog.getReturnCode() == returnCodeCANCEL) {
            return false;
        }
        worbench.showPerspective(perspectiveID, activeWindow);
    } catch (WorkbenchException e) {
        StringBuilder msg = new StringBuilder();
        msg.append(Messages.CannotOpenThePerspective).append(StringConstants.COLON)
                .append(StringConstants.SPACE).append(perspectiveID).append(StringConstants.LEFT_PARENTHESES)
                .append(e).append(StringConstants.RIGHT_PARENTHESES).append(StringConstants.DOT);
        log.error(msg.toString());
        ErrorHandlingUtil.createMessageDialog(MessageIDs.E_NO_PERSPECTIVE);
        return false;
    }
    return true;
}

From source file:org.eclipse.jubula.client.ui.utils.OpenViewUtils.java

License:Open Source License

/**
 * //from w w w  . j  a v  a 2s  .  co  m
 * @param preferenceKey
 *            the key for the preference to save the remembered value to
 * @param activeWindow
 *            the active {@link IWorkbenchWindow}
 * @param preferenceStore
 *            the instance of the {@link IPreferenceStore}
 * @param viewName
 *            the name of the view to activate
 * @return the return value of the dialog {@link IDialogConstants#NO_ID},
 *         {@link IDialogConstants#YES_ID} or <code>-1</code> if aborted
 */
private static int createQuestionDialog(final String preferenceKey, IWorkbenchWindow activeWindow,
        final IPreferenceStore preferenceStore, String viewName) {
    MessageDialogWithToggle dialog = new MessageDialogWithToggle(activeWindow.getShell(),
            Messages.UtilsOpenViewTitle, null, NLS.bind(Messages.UtilsViewQuestion, viewName),
            MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0,
            Messages.UtilsRemember, false) {
        /**
         * {@inheritDoc}
         */
        protected void buttonPressed(int buttonId) {
            super.buttonPressed(buttonId);
            int val = Constants.UTILS_PROMPT;
            if (getToggleState() && getReturnCode() == IDialogConstants.NO_ID) {
                val = Constants.UTILS_NO;
            } else if (getToggleState() && getReturnCode() == IDialogConstants.YES_ID) {
                val = Constants.UTILS_YES;
            }
            preferenceStore.setValue(preferenceKey, val);
        }
    };
    dialog.create();
    DialogUtils.setWidgetNameForModalDialog(dialog);
    int i = dialog.open();
    return i;
}