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:com.vectrace.MercurialEclipse.menu.MergeHandler.java

License:Open Source License

public static void determineMergeHeadAndMerge(HgRoot hgRoot, Shell shell, IProgressMonitor monitor,
        boolean autoPickOtherHead, boolean showCommitDialog) throws CoreException {

    // can we do the equivalent of plain "hg merge"?
    ChangeSet cs = HgLogClient.getChangeSet(hgRoot, getHeadForEasyMerge(hgRoot));
    boolean forced = false;

    String forceMessage = "Forced merge (this will discard all uncommitted changes!)";
    boolean hasDirtyFiles = HgStatusClient.isDirty(hgRoot);
    if (cs != null) {
        if (!autoPickOtherHead) {

            String csSummary = "    Changeset: " + cs.getName() + "\n    User: " + cs.getAuthor()
                    + "\n    Date: " + cs.getDateString() + "\n    Summary: " + cs.getSummary();

            String branch = cs.getBranch();
            if (BranchUtils.isDefault(branch)) {
                branch = BranchUtils.DEFAULT;
            }/*from   w w  w . jav a  2 s .c o m*/
            String message = MessageFormat.format(Messages.getString("MergeHandler.mergeWithOtherHead"), branch,
                    csSummary);

            if (hasDirtyFiles) {
                MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(shell, "Merge",
                        message, forceMessage, false, null, null);
                if (dialog.getReturnCode() != IDialogConstants.YES_ID) {
                    cs = null;
                }
                forced = dialog.getToggleState();
            } else {
                MessageBox mb = new MessageBox(shell, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
                mb.setText("Merge");
                mb.setMessage(message);
                if (mb.open() == SWT.NO) {
                    cs = null;
                }
            }
        }
    }

    // have to open the dialog until we get a valid changeset
    while (cs == null) {
        RevisionChooserDialog dialog = new RevisionChooserDialog(shell,
                Messages.getString("MergeHandler.mergeWith"), hgRoot); //$NON-NLS-1$
        dialog.setDefaultShowingHeads(true);
        dialog.setDisallowSelectingParents(true);
        dialog.showForceButton(hasDirtyFiles);
        dialog.setForceChecked(forced);
        dialog.setForceButtonText(forceMessage);
        dialog.setRequireChangeset(true);
        if (dialog.open() != IDialogConstants.OK_ID) {
            return;
        }

        cs = dialog.getChangeSet();
        forced = dialog.isForceChecked();
    }

    mergeAndCommit(hgRoot, shell, monitor, showCommitDialog, cs, forced);
}

From source file:com.vmware.vfabric.ide.eclipse.tcserver.insight.internal.ui.InsightTcServerCallback.java

License:Open Source License

private void promptIfInsightNotEnabled(final TcServer tcServer,
        ILaunchConfigurationWorkingCopy launchConfiguration) {
    if (!TcServerInsightUtil.isInsightEnabled(tcServer)) {
        String value = Activator.getDefault().getPreferenceStore().getString(PREFERENCE_ENABLE_INSIGHT_PONT);
        if (MessageDialogWithToggle.PROMPT.equals(value)) {
            Display.getDefault().asyncExec(new Runnable() {
                public void run() {
                    MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(
                            UiUtil.getShell(), WANT_INSIGHT_DIALOG_TITLE, WANT_INSIGHT_DIALOG_MESSAGE,
                            "Do not ask again", false, Activator.getDefault().getPreferenceStore(),
                            PREFERENCE_ENABLE_INSIGHT_PONT);
                    if (dialog.getReturnCode() == IDialogConstants.YES_ID) {
                        IServerWorkingCopy serverWC = tcServer.getServer().createWorkingCopy();
                        TcServer serverInstance = (TcServer) serverWC.loadAdapter(TcServer.class, null);
                        new ModifyInsightVmArgsCommand(serverInstance, true).execute();
                        try {
                            IServer server = serverWC.save(true, null);
                            // force publishing to update insight
                            // directories
                            // if (server instanceof Server) {
                            // ((Server)server).setServerPublishState(IServer.PUBLISH_STATE_FULL);
                            // }
                        } catch (CoreException e) {
                            TomcatPlugin.log(e.getStatus());
                        }/*from   w ww  .j a v  a 2s .com*/
                    }
                }
            });
        }
    }
}

From source file:de.loskutov.anyedit.actions.ConvertAllInFolderAction.java

License:Open Source License

@Override
public void run(final IAction action) {

    IPreferenceStore preferenceStore = AnyEditToolsPlugin.getDefault().getPreferenceStore();

    boolean shouldAsk = preferenceStore.getBoolean(IAnyEditConstants.ASK_BEFORE_CONVERT_ALL_IN_FOLDER);

    if (shouldAsk) {
        MessageDialogWithToggle dialogWithToggle = MessageDialogWithToggle.openYesNoQuestion(
                AnyEditToolsPlugin.getShell(), Messages.ConvertAllInFolder_warnTitle,
                Messages.ConvertAllInFolder_warnMessage, Messages.ConvertAllInFolder_toggleMessage, false,
                preferenceStore, IAnyEditConstants.ASK_BEFORE_CONVERT_ALL_IN_FOLDER);

        int returnCode = dialogWithToggle.getReturnCode();
        if (returnCode != IDialogConstants.YES_ID) {
            return;
        }/* www.  j av a2 s. c om*/
    }
    try {
        // runs in the same thread to be able to collect all files before
        // starting main action, which will be executed in separated thread
        PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(Messages.ConvertAllInFolder_task, selectedResources.size() * 10);
                try {
                    for (int i = 0; i < selectedResources.size() && !monitor.isCanceled(); i++) {

                        Object o = selectedResources.get(i);
                        if (o instanceof IContainer) {
                            addAllFiles((IContainer) o, selectedFiles, monitor);
                        } else if (o instanceof IFile) {
                            if (selectedFiles.contains(o)) {
                                continue;
                            }
                            selectedFiles.add((IFile) o);
                        }
                    }
                } finally {
                    monitor.done();
                }
            }
        });
    } catch (InvocationTargetException e) {
        AnyEditToolsPlugin.logError("'Convert all' operation: not all files converted", e);
    } catch (InterruptedException e) {
        AnyEditToolsPlugin.logError("'Convert all' operation cancelled by user", e);
        return;
    }
    // will run in another thread
    doAction(action);
}

From source file:de.loskutov.anyedit.actions.ConvertUnicode.java

License:Open Source License

@Override
protected String performReplace(String line, int actionKey) {
    if (KEY_ESCAPE == actionKey) {
        return textUtil.toUnicode(line);
    }//from ww w .jav  a 2 s .  c  om
    String charsetToUse = warnAboutUnsupportedUnicode ? charset : null;
    try {
        return textUtil.fromUnicode(charsetToUse, line);
    } catch (UnsupportedOperationException e) {
        MessageDialogWithToggle dialogWithToggle = MessageDialogWithToggle.openYesNoQuestion(
                AnyEditToolsPlugin.getShell(), Messages.ConvertUnicode_title,
                NLS.bind(Messages.ConvertUnicode_warn, e.getMessage()), Messages.ConvertUnicode_toggleMessage,
                false, AnyEditToolsPlugin.getDefault().getPreferenceStore(),
                IAnyEditConstants.WARN_ABOUT_UNSUPPORTED_UNICODE);

        int returnCode = dialogWithToggle.getReturnCode();
        // refresh the value, if user changed it
        warnAboutUnsupportedUnicode = warnAboutUnsupportedUnicode();
        if (returnCode != IDialogConstants.YES_ID) {
            shouldStopReplace = true;
            return null;
        }
        // suppress any warning, just continue
        return textUtil.fromUnicode(null, line);
    }
}

From source file:de.loskutov.anyedit.actions.SaveToFileAction.java

License:Open Source License

@Override
protected void handleAction(IDocument doc, ISelectionProvider selectionProvider, IEditorInput currentInput) {

    IPreferenceStore prefs = AnyEditToolsPlugin.getDefault().getPreferenceStore();
    boolean shouldAsk = prefs.getBoolean(IAnyEditConstants.SAVE_TO_SHOW_OPTIONS);
    boolean shouldOpenEditor = prefs.getBoolean(IAnyEditConstants.SAVE_TO_OPEN_EDITOR);
    boolean ignoreSelection = prefs.getBoolean(IAnyEditConstants.SAVE_TO_IGNORE_SELECTION);
    ITextSelection selection = (ITextSelection) selectionProvider.getSelection();
    boolean hasSelection = false;
    if (!ignoreSelection && selection != null && selection.getLength() > 0) {
        hasSelection = true;//from   w w w  . j a  va  2  s .c om
    } else {
        selection = new TextSelection(doc, 0, doc.getLength());
    }

    /*
     * Show dialog if prefs is set, asking for open in editor
     */
    if (shouldAsk) {
        MessageDialogWithToggle dialogWithToggle = MessageDialogWithToggle.openYesNoCancelQuestion(
                AnyEditToolsPlugin.getShell(), Messages.SaveTo_ShouldOpen,
                hasSelection ? Messages.SaveTo_MessageSelection : Messages.SaveTo_MessageNoSelection,
                Messages.SaveTo_MessageToggle, false, prefs, IAnyEditConstants.SAVE_TO_SHOW_OPTIONS);

        int returnCode = dialogWithToggle.getReturnCode();
        if (returnCode != IDialogConstants.YES_ID && returnCode != IDialogConstants.NO_ID) {
            return;
        }
        shouldOpenEditor = returnCode == IDialogConstants.YES_ID;
        if (!prefs.getBoolean(IAnyEditConstants.SAVE_TO_SHOW_OPTIONS)) {
            prefs.setValue(IAnyEditConstants.SAVE_TO_OPEN_EDITOR, shouldOpenEditor);
        }
    }

    /*
     * open file selection dialog (external)
     */
    File file = getFileFromUser();
    if (file == null) {
        return;
    }

    /*
     * if selected file exists, ask for override/append/another file
     */
    int overrideOrAppend = checkForExisting(file);
    if (overrideOrAppend == CANCEL) {
        return;
    }

    IFile iFile = EclipseUtils.getIFile(new Path(file.getAbsolutePath()));
    /*
     * if selected file is in the workspace, checkout it or show error message
     */
    if (iFile == null || !checkout(iFile, overrideOrAppend)) {
        return;
    }

    /*
     * save it
     */
    doSave(doc, selection, file, overrideOrAppend);

    /*
     * and if option is on, open in editor
     */
    if (shouldOpenEditor) {
        new DefaultOpenEditorParticipant().openEditor(doc, selectionProvider, currentInput, iFile);
    }
}

From source file:de.loskutov.eclipse.jdepend.views.SaveToFileAction.java

License:Open Source License

@Override
public void run() {

    IPreferenceStore prefs = JDepend4EclipsePlugin.getDefault().getPreferenceStore();
    boolean shouldAsk = prefs.getBoolean(JDependConstants.SAVE_TO_SHOW_OPTIONS);

    /*//from  w ww  . j  a  va2s .  c  o m
     * Show dialog if prefs is set, asking for open in editor
     */
    boolean saveAsXml = prefs.getBoolean(JDependConstants.SAVE_AS_XML);
    if (shouldAsk) {
        MessageDialogWithToggle dialogWithToggle = MessageDialogWithToggle.openYesNoCancelQuestion(getShell(),
                "Save JDepend output", "Save JDepend output as XML (and not as plain text)?",
                "Remember and do not ask me again", false, prefs, JDependConstants.SAVE_TO_SHOW_OPTIONS);

        int returnCode = dialogWithToggle.getReturnCode();
        if (returnCode != IDialogConstants.YES_ID && returnCode != IDialogConstants.NO_ID) {
            return;
        }
        saveAsXml = returnCode == IDialogConstants.YES_ID;
        prefs.setValue(JDependConstants.SAVE_AS_XML, saveAsXml);
    }

    /*
     * open file selection dialog (external)
     */
    File file = getFileFromUser(saveAsXml);
    if (file == null) {
        return;
    }

    /*
     * if selected file exists, ask for override/append/another file
     */
    int overrideOrAppend = checkForExisting(file);
    if (overrideOrAppend == CANCEL) {
        return;
    }

    IFile iFile = getWorkspaceFile(file);
    /*
     * if selected file is in the workspace, checkout it or show error message
     */
    if (iFile != null && !checkout(iFile, overrideOrAppend)) {
        return;
    }

    /*
     * save it
     */
    doSave(file, overrideOrAppend);
}

From source file:de.plugins.eclipse.depclipse.handlers.SaveJDependOutput.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    prefs = DepclipsePlugin.getDefault().getPreferenceStore();
    boolean shouldAsk = prefs.getBoolean(JDependPreferenceConstants.SAVE_TO_SHOW_OPTIONS);

    /*/*from   w w  w  .ja  v  a2  s  .  c om*/
     * Show dialog if prefs is set, asking for open in editor
     */
    boolean saveAsXml = prefs.getBoolean(JDependPreferenceConstants.SAVE_AS_XML);
    if (shouldAsk) {
        MessageDialogWithToggle dialogWithToggle = MessageDialogWithToggle.openYesNoCancelQuestion(getShell(),
                Messages.SaveJDependOutput_Save_JDepend_output,
                Messages.SaveJDependOutput_Save_JDepend_output_as_XML,
                Messages.SaveJDependOutput_Remember_and_do_not_ask_me_again, false, prefs,
                JDependPreferenceConstants.SAVE_TO_SHOW_OPTIONS);

        int returnCode = dialogWithToggle.getReturnCode();
        if (returnCode != IDialogConstants.YES_ID && returnCode != IDialogConstants.NO_ID) {
            return null;
        }
        saveAsXml = returnCode == IDialogConstants.YES_ID;
        prefs.setValue(JDependPreferenceConstants.SAVE_AS_XML, saveAsXml);
    }

    /*
     * open file selection dialog (external)
     */
    File file = getFileFromUser(saveAsXml);
    if (file == null) {
        return null;
    }

    /*
     * if selected file exists, ask for override/append/another file
     */
    int overrideOrAppend = checkForExisting(file);
    if (overrideOrAppend == CANCEL) {
        return null;
    }

    IFile iFile = getWorkspaceFile(file);
    /*
     * if selected file is in the workspace, checkout it or show error
     * message
     */
    if (iFile != null && !checkout(iFile, overrideOrAppend)) {
        return null;
    }

    /*
     * save it
     */
    doSave(file, overrideOrAppend);
    return null;
}

From source file:de.tobject.findbugs.actions.FindBugsAction.java

License:Open Source License

protected static void askUserToSwitch(IWorkbenchPart part, int warningsNumber) {
    final IPreferenceStore store = FindbugsPlugin.getDefault().getPreferenceStore();
    String message = "FindBugs analysis finished, " + warningsNumber
            + " warnings found.\n\nSwitch to the FindBugs perspective?";

    MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(null,
            "FindBugs 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);
        }/*from  w w  w  . j  a v  a  2 s .  co  m*/
        switchPerspective(part);
    } else if (returnCode == IDialogConstants.NO_ID) {
        if (remember) {
            store.setValue(FindBugsConstants.SWITCH_PERSPECTIVE_AFTER_ANALYSIS, false);
        }
    }
}

From source file:eclipse.spellchecker.AddWordProposal.java

License:Open Source License

/**
 * Asks the user whether he wants to configure a user dictionary.
 *
 * @param shell the shell//from w  w w  .  j av  a 2 s  .  co m
 * @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);

    Activator.getDefault().getPreferenceStore().setValue(PREF_KEY_DO_NOT_ASK, toggleDialog.getToggleState());

    return toggleDialog.getReturnCode() == IDialogConstants.YES_ID;
}

From source file:eclipse.testframework.ui.util.VerifyDialog.java

License:Open Source License

protected void createButtonsForButtonBar(Composite parent) {
    _yesButton = createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true);
    createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false);
}