Example usage for org.eclipse.jface.dialogs IDialogConstants YES_ID

List of usage examples for org.eclipse.jface.dialogs IDialogConstants YES_ID

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs IDialogConstants YES_ID.

Prototype

int YES_ID

To view the source code for org.eclipse.jface.dialogs IDialogConstants YES_ID.

Click Source Link

Document

Button id for a "Yes" button (value 2).

Usage

From source file:org.eclipse.mylyn.internal.tasks.ui.TaskAttachmentEditorViewer.java

License:Open Source License

private boolean promptToConfirmOpen(final ITaskAttachment attachment) {
    if (isSystem()) {
        IPreferenceStore store = TasksUiPlugin.getDefault().getPreferenceStore();
        if (!store.getBoolean(PREF_DO_NOT_WARN_BEFORE_OPENING_ATTACHMENTS)) {
            MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(WorkbenchUtil.getShell(),
                    Messages.TaskAttachmentEditorViewer_Open_Attachment,
                    NLS.bind(Messages.TaskAttachmentEditorViewer_Some_files_can_harm_your_computer,
                            attachment.getFileName()),
                    Messages.TaskAttachmentEditorViewer_Do_not_warn_me_again, false, null, null);
            if (dialog.getReturnCode() == IDialogConstants.YES_ID) {
                if (dialog.getToggleState()) {
                    store.setValue(PREF_DO_NOT_WARN_BEFORE_OPENING_ATTACHMENTS, true);
                    TasksUiPlugin.getDefault().savePluginPreferences();
                }/*w  w w  . ja v a  2 s.  com*/
            } else {
                return false;
            }
        }
    }
    return true;
}

From source file:org.eclipse.mylyn.internal.tasks.ui.wizards.NewRepositoryWizard.java

License:Open Source License

public void promptToAddQuery(TaskRepository taskRepository) {
    IPreferenceStore preferenceStore = TasksUiPlugin.getDefault().getPreferenceStore();
    if (!preferenceStore.getBoolean(PREF_ADD_QUERY)) {
        MessageDialogWithToggle messageDialog = MessageDialogWithToggle.openYesNoQuestion(getShell(),
                Messages.AddRepositoryAction_Add_new_query,
                Messages.AddRepositoryAction_Add_a_query_to_the_Task_List,
                Messages.AddRepositoryAction_Do_not_show_again, false, preferenceStore, PREF_ADD_QUERY);
        preferenceStore.setValue(PREF_ADD_QUERY, messageDialog.getToggleState());
        if (messageDialog.getReturnCode() == IDialogConstants.YES_ID) {
            AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin
                    .getConnectorUi(taskRepository.getConnectorKind());
            final IWizard queryWizard = connectorUi.getQueryWizard(taskRepository, null);
            if (queryWizard instanceof Wizard) {
                ((Wizard) queryWizard).setForcePreviousAndNextButtons(true);
            }//  w w w. ja v a  2s.c o m

            // execute delayed to avoid stacking dialogs
            getShell().getDisplay().asyncExec(new Runnable() {
                public void run() {
                    WizardDialog queryDialog = new WizardDialog(WorkbenchUtil.getShell(), queryWizard);
                    queryDialog.create();
                    queryDialog.setBlockOnOpen(true);
                    queryDialog.open();
                }
            });
        }
    }
}

From source file:org.eclipse.pde.internal.ui.preferences.TargetPlatformPreferencePage.java

License:Open Source License

/**
 * Removes the selected targets/*  www . jav  a2s. co m*/
 */
private void handleRemove() {
    IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
    if (!selection.isEmpty()) {
        List<ITargetDefinition> selected = selection.toList();

        // If we are going to remove a workspace file, prompt to ask the user first
        boolean isWorkspace = false;
        for (Iterator<ITargetDefinition> iterator = selected.iterator(); iterator.hasNext();) {
            ITargetDefinition currentTarget = iterator.next();
            if (currentTarget.getHandle() instanceof WorkspaceFileTargetHandle) {
                isWorkspace = true;
                break;
            }
        }
        if (isWorkspace) {
            PDEPreferencesManager preferences = new PDEPreferencesManager(IPDEUIConstants.PLUGIN_ID);
            String choice = preferences.getString(IPreferenceConstants.PROP_PROMPT_REMOVE_TARGET);
            if (!MessageDialogWithToggle.ALWAYS.equalsIgnoreCase(choice)) {
                MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(getShell(),
                        PDEUIMessages.TargetPlatformPreferencePage2_19,
                        PDEUIMessages.TargetPlatformPreferencePage2_20,
                        PDEUIMessages.TargetPlatformPreferencePage2_21, false,
                        PDEPlugin.getDefault().getPreferenceStore(),
                        IPreferenceConstants.PROP_PROMPT_REMOVE_TARGET);
                preferences.savePluginPreferences();
                if (dialog.getReturnCode() != IDialogConstants.YES_ID) {
                    return;
                }
            }
        }

        if (fActiveTarget != null && selected.contains(fActiveTarget)) {
            fActiveTarget = null;
            setMessage(PDEUIMessages.TargetPlatformPreferencePage2_22, IMessageProvider.INFORMATION);
        }
        fRemoved.addAll(selected);
        fTargets.removeAll(selected);
        // Quick hack because the first refresh loses the checkedState, which is being used to bold the active target
        fTableViewer.refresh(false);
        fTableViewer.refresh(true);
    }
}

From source file:org.eclipse.php.internal.debug.core.launching.PHPLaunchUtilities.java

License:Open Source License

/**
 * Notify the existence of a previous PHP debug session in case the user
 * launched a new session./*from www . j a v  a 2s. com*/
 * 
 * @param newLaunchConfiguration
 * @param newLaunch
 * @return True, if the launch can be continued; False, otherwise.
 * @throws CoreException
 */
public static boolean notifyPreviousLaunches(ILaunch newLaunch) throws CoreException {
    // In case the new launch is not a debug launch, we have no problem.
    if (!ILaunchManager.DEBUG_MODE.equals(newLaunch.getLaunchMode())) {
        return true;
    }
    // If there are no active debug launches, return true and continue with
    // the new launch.
    if (!hasPHPDebugLaunch()) {
        return true;
    }

    // Check whether we should ask the user.
    final IPreferenceStore store = PHPUiPlugin.getDefault().getPreferenceStore();
    String option = store.getString(PreferenceConstants.ALLOW_MULTIPLE_LAUNCHES);
    if (MessageDialogWithToggle.ALWAYS.equals(option)) {
        // If always, then we should always allow the launch
        return true;
    }
    if (MessageDialogWithToggle.NEVER.equals(option)) {
        // We should never allow the launch, so display a message describing
        // the situation.
        final Display disp = Display.getDefault();
        disp.syncExec(new Runnable() {
            public void run() {
                MessageDialog.openInformation(disp.getActiveShell(),
                        PHPDebugCoreMessages.PHPLaunchUtilities_phpLaunchTitle,
                        PHPDebugCoreMessages.PHPLaunchUtilities_activeLaunchDetected);
            }
        });
        return false;
    }

    final DialogResultHolder resultHolder = new DialogResultHolder();
    final Display disp = Display.getDefault();
    disp.syncExec(new Runnable() {
        public void run() {
            // Display a dialog to notify the existence of a previous active
            // launch.
            MessageDialogWithToggle m = MessageDialogWithToggle.openYesNoQuestion(disp.getActiveShell(),
                    PHPDebugCoreMessages.PHPLaunchUtilities_confirmation,
                    PHPDebugCoreMessages.PHPLaunchUtilities_multipleLaunchesPrompt,
                    PHPDebugCoreMessages.PHPLaunchUtilities_rememberDecision, false, store,
                    PreferenceConstants.ALLOW_MULTIPLE_LAUNCHES);
            resultHolder.setReturnCode(m.getReturnCode());
        }
    });
    switch (resultHolder.getReturnCode()) {
    case IDialogConstants.YES_ID:
    case IDialogConstants.OK_ID:
        return true;
    case IDialogConstants.NO_ID:
        return false;
    }
    return true;
}

From source file:org.eclipse.php.internal.debug.core.launching.PHPLaunchUtilities.java

License:Open Source License

private static boolean shouldSwitchToPHPPerspective(String perspectiveID) {
    // check whether we should ask the user.
    IPreferenceStore store = PHPUiPlugin.getDefault().getPreferenceStore();
    String option = store.getString(PreferenceConstants.SWITCH_BACK_TO_PHP_PERSPECTIVE);
    if (MessageDialogWithToggle.ALWAYS.equals(option)) {
        return true;
    }/*  w w  w. ja  v  a  2  s  .c o  m*/
    if (MessageDialogWithToggle.NEVER.equals(option)) {
        return false;
    }

    // Check whether the desired perspective is already active.
    IPerspectiveRegistry registry = PlatformUI.getWorkbench().getPerspectiveRegistry();
    IPerspectiveDescriptor perspective = registry.findPerspectiveWithId(perspectiveID);
    if (perspective == null) {
        return false;
    }

    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
        IWorkbenchPage page = window.getActivePage();
        if (page != null) {
            IPerspectiveDescriptor current = page.getPerspective();
            if (current != null && current.getId().equals(perspectiveID)) {
                return false;
            }
        }

        // Ask the user whether to switch
        MessageDialogWithToggle m = MessageDialogWithToggle.openYesNoQuestion(window.getShell(),
                PHPDebugCoreMessages.PHPLaunchUtilities_PHPPerspectiveSwitchTitle,
                NLS.bind(PHPDebugCoreMessages.PHPLaunchUtilities_PHPPerspectiveSwitchMessage,
                        new String[] { perspective.getLabel() }),
                PHPDebugCoreMessages.PHPLaunchUtilities_rememberDecision, false, store,
                PreferenceConstants.SWITCH_BACK_TO_PHP_PERSPECTIVE);

        int result = m.getReturnCode();
        switch (result) {
        case IDialogConstants.YES_ID:
        case IDialogConstants.OK_ID:
            return true;
        case IDialogConstants.NO_ID:
            return false;
        }
    }
    return false;
}

From source file:org.eclipse.php.internal.ui.util.PerspectiveManager.java

License:Open Source License

/**
 * Returns whether or not the user wishes to switch to the specified
 * perspective when a launch occurs./*  ww w . j av a 2 s  .c om*/
 * 
 * @param window
 * @param perspectiveId
 * 
 * @return whether or not the user wishes to switch to the specified
 *         perspective automatically
 */
public static boolean shouldSwitchPerspective(IWorkbenchWindow window, String perspectiveId) {

    String perspectiveName = getPerspectiveLabel(perspectiveId);
    String message = NLS.bind(PHPUIMessages.PerspectiveManager_Switch_Dialog_Message, perspectiveName);

    final String preferenceKey = perspectiveId + ".switch_to_perspective"; //$NON-NLS-1$

    if (isCurrentPerspective(window, perspectiveId)) {
        return false;
    }

    if (perspectiveName == null) {
        return false;
    }

    String switchPerspective = PHPUiPlugin.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;
    // Activate the shell if necessary so the prompt is visible
    if (shell.getMinimized()) {
        shell.setMinimized(false);
    }

    MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(shell,
            PHPUIMessages.PerspectiveManager_Switch_Dialog_Title, message, null, false,
            PHPUiPlugin.getDefault().getPreferenceStore(), preferenceKey);
    boolean answer = (dialog.getReturnCode() == IDialogConstants.YES_ID);
    synchronized (PerspectiveManager.class) {
        fPrompting = false;
        PerspectiveManager.class.notifyAll();
    }
    if (isCurrentPerspective(window, perspectiveId)) {
        // While prompting in response to one event (say, a launch),
        // another event can occur which changes the perspective.
        // Double-check that we're not in the right perspective.
        answer = false;
    }
    return answer;
}

From source file:org.eclipse.ptp.internal.rdt.sync.ui.wizards.NewSyncProjectWizard.java

License:Open Source License

/**
 * Prompts the user for whether to switch perspectives.
 * /*from ww  w.  j a  v  a  2 s  . co m*/
 * @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(Messages.NewProject_perspSwitchMessage, finalPersp.getLabel());
    } else {
        message = NLS.bind(Messages.NewProject_perspSwitchMessageWithDesc,
                new String[] { finalPersp.getLabel(), desc });
    }

    MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(window.getShell(),
            Messages.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;
}

From source file:org.eclipse.ptp.launch.AbstractParallelLaunchConfigurationDelegate.java

License:Open Source License

/**
 * Used to force switching to the supplied perspective
 * /* w  ww. j a v a  2 s . c o  m*/
 * @param perspectiveID
 */
protected boolean switchPerspective(final String perspectiveId, final String message,
        final String preferenceKey, final boolean alwaysDisplayMessage) {
    final boolean[] result = new boolean[1];
    result[0] = false;
    if (perspectiveId != null) {
        final Display display = Display.getDefault();
        if (display != null && !display.isDisposed()) {
            display.syncExec(new Runnable() {

                public void run() {
                    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                    if (window != null) {
                        IWorkbenchPage page = window.getActivePage();
                        if (page != null) {
                            if (!alwaysDisplayMessage && page.getPerspective().getId().equals(perspectiveId)) {
                                result[0] = true;
                                return;
                            }

                            IPreferenceStore store = new PreferencesAdapter(
                                    PTPLaunchPlugin.getUniqueIdentifier());
                            result[0] = !store
                                    .getString(PreferenceConstants.PREF_SWITCH_TO_MONITORING_PERSPECTIVE)
                                    .equals(MessageDialogWithToggle.NEVER);
                            if (store.getString(PreferenceConstants.PREF_SWITCH_TO_MONITORING_PERSPECTIVE)
                                    .equals(MessageDialogWithToggle.PROMPT)) {
                                MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(
                                        display.getActiveShell(),
                                        Messages.AbstractParallelLaunchConfigurationDelegate_ConfirmActions,
                                        message, null, false, store, preferenceKey);
                                result[0] = (dialog.getReturnCode() == IDialogConstants.YES_ID);
                            }

                            if (result[0]) {
                                try {
                                    PlatformUI.getWorkbench().showPerspective(perspectiveId, window);
                                } catch (WorkbenchException e) {
                                    // Ignore
                                }
                            }
                        }
                    }
                }
            });
        }
    }
    return result[0];
}

From source file:org.eclipse.rap.internal.ui.templates.rap.AbstractRAPWizard.java

License:Open Source License

private boolean isRapTargetInstallWanted() {
    Shell parentShell = Display.getCurrent().getActiveShell();
    String title = Messages.AbstractRAPWizard_targetQuestionDialogTitle;
    String message = Messages.AbstractRAPWizard_targetQuestionDialogMessage;
    IPreferenceStore store = Activator.getDefault().getPreferenceStore();
    String preferenceInstallTarget = store.getString(PREFERENCE_INSTALL_TARGET);
    boolean result = false;
    if (isPromptRequired(preferenceInstallTarget)) {
        MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(parentShell, title, message,
                null, false, store, PREFERENCE_INSTALL_TARGET);
        result = dialog.getReturnCode() == IDialogConstants.YES_ID;
    } else {// w  w  w  . j  a v a 2 s  .co  m
        result = MessageDialogWithToggle.ALWAYS.equals(preferenceInstallTarget);
    }
    return result;
}

From source file:org.eclipse.rcptt.dev.ui.dialogs.UserModificationDialog.java

License:Open Source License

public boolean open(final Scenario scenario) {
    String show = preferenceStore.getString(IPreferenceKeys.DISCARD_USER_CHANGES_PROMT);
    if (MessageDialogWithToggle.PROMPT.equals(show)) {
        final boolean[] answer = new boolean[1];
        Display.getDefault().syncExec(new Runnable() {
            public void run() {
                IWorkbenchWindow window = Q7UIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
                MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(window.getShell(),
                        "Error",
                        "Test case \"" + scenario.getName() + "\" was changed and "
                                + "doesn't match captured data.\n" + "Would you like to recover "
                                + "ECL script from captured data?",
                        null, false, preferenceStore, IPreferenceKeys.DISCARD_USER_CHANGES_PROMT);
                int returnCode = dialog.getReturnCode();
                answer[0] = returnCode == IDialogConstants.YES_ID;
            }// ww  w.  jav  a  2  s. c om
        });
        return answer[0];
    }
    return MessageDialogWithToggle.ALWAYS.equals(show);
}