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

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

Introduction

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

Prototype

public static MessageDialogWithToggle openYesNoCancelQuestion(Shell parent, String title, String message,
        String toggleMessage, boolean toggleState, IPreferenceStore store, String key) 

Source Link

Document

Convenience method to open a simple question Yes/No/Cancel dialog.

Usage

From source file:com.android.ide.eclipse.adt.internal.editors.layout.properties.XmlPropertyEditor.java

License:Open Source License

@Override
protected boolean setEditorText(Property property, String text) throws Exception {
    Object oldValue = property.getValue();
    String old = oldValue != null ? oldValue.toString() : null;

    // If users enters a new id without specifying the @id/@+id prefix, insert it
    boolean isId = isIdProperty(property);
    if (isId && !text.startsWith(PREFIX_RESOURCE_REF)) {
        text = NEW_ID_PREFIX + text;/*w  w w . ja  v  a  2  s.c  o  m*/
    }

    // Handle id refactoring: if you change an id, may want to update references too.
    // Ask user.
    if (isId && property instanceof XmlProperty && old != null && !old.isEmpty() && text != null
            && !text.isEmpty() && !text.equals(old)) {
        XmlProperty xmlProperty = (XmlProperty) property;
        IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
        String refactorPref = store.getString(AdtPrefs.PREFS_REFACTOR_IDS);
        boolean performRefactor = false;
        Shell shell = AdtPlugin.getShell();
        if (refactorPref == null || refactorPref.isEmpty()
                || refactorPref.equals(MessageDialogWithToggle.PROMPT)) {
            MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(shell,
                    "Update References?",
                    "Update all references as well? "
                            + "This will update all XML references and Java R field references.",
                    "Do not show again", false, store, AdtPrefs.PREFS_REFACTOR_IDS);
            switch (dialog.getReturnCode()) {
            case IDialogConstants.CANCEL_ID:
                return false;
            case IDialogConstants.YES_ID:
                performRefactor = true;
                break;
            case IDialogConstants.NO_ID:
                performRefactor = false;
                break;
            }
        } else {
            performRefactor = refactorPref.equals(MessageDialogWithToggle.ALWAYS);
        }
        if (performRefactor) {
            CommonXmlEditor xmlEditor = xmlProperty.getXmlEditor();
            if (xmlEditor != null) {
                IProject project = xmlEditor.getProject();
                if (project != null && shell != null) {
                    RenameResourceWizard.renameResource(shell, project, ResourceType.ID, stripIdPrefix(old),
                            stripIdPrefix(text), false);
                }
            }
        }
    }

    property.setValue(text);

    return true;
}

From source file:com.safi.workshop.sqlexplorer.plugin.editors.SQLEditor.java

License:Open Source License

/**
 * Implementation for save-as; returns true if successfull, false if not (i.e. the user
 * cancelled the dialog)//from  ww w  . ja v a2  s.c o  m
 * 
 * @return true if saved, false if cancelled
 */
public boolean doSave(boolean saveAs, IProgressMonitor monitor) {

    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    boolean haveProjects = projects != null && projects.length > 0;
    IEditorInput input = getEditorInput();

    boolean saveInsideProject = true;
    File file = null;
    if (input instanceof SQLEditorInput) {
        SQLEditorInput seInput = (SQLEditorInput) input;
        file = seInput.getFile();
    }

    // If we have a file, then we already have a filename outside of the project;
    // but if we're doing a save-as then recheck with the user
    if (file != null && !saveAs)
        saveInsideProject = false;

    // Either we're doing a save on a file outside a project or we're doing a save-as
    else if (input instanceof SQLEditorInput) {
        IConstants.Confirm confirm = SQLExplorerPlugin.getConfirm(IConstants.CONFIRM_YNA_SAVING_INSIDE_PROJECT);

        // If we're supposed to ask the user...
        if (confirm == IConstants.Confirm.ASK) {
            // Build up the message to ask
            String msg = Messages.getString("Confirm.SaveInsideProject.Intro") + "\n\n";
            if (!haveProjects)
                msg = msg + Messages.getString("Confirm.SaveInsideProject.NoProjectsConfigured") + "\n\n";
            msg = msg + Messages.getString("Confirm.SaveInsideProject.SaveInProject");

            // Ask them
            MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(
                    getSite().getShell(), Messages.getString("SQLEditor.SaveAsDialog.Title"), msg,
                    Messages.getString("Confirm.SaveInsideProject.Toggle"), false, null, null);
            if (dialog.getReturnCode() == IDialogConstants.CANCEL_ID)
                return false;

            // If they turned on the toggle ("Use this answer in the future"), update the
            // preferences
            if (dialog.getToggleState()) {
                confirm = dialog.getReturnCode() == IDialogConstants.YES_ID ? IConstants.Confirm.YES
                        : IConstants.Confirm.NO;
                SQLExplorerPlugin.getDefault().getPreferenceStore()
                        .setValue(IConstants.CONFIRM_YNA_SAVING_INSIDE_PROJECT, confirm.toString());
            }

            // Whether to save inside or outside
            saveInsideProject = dialog.getReturnCode() == IDialogConstants.YES_ID;
        } else
            saveInsideProject = confirm == IConstants.Confirm.YES;
    }

    // Saving inside a project - convert SQLEditorInput into a Resource by letting
    // TextEditor do the work for us
    if (saveInsideProject) {
        if (!haveProjects) {
            MessageDialog.openError(getSite().getShell(), Messages.getString("Confirm.SaveInsideProject.Title"),
                    Messages.getString("Confirm.SaveInsideProject.CreateAProject"));
            return false;
        }
        if (input instanceof SQLEditorInput)
            saveAs = true;

        // Save it and use their EditorInput
        if (saveAs)
            textEditor.doSaveAs();
        else {
            if (monitor == null)
                monitor = textEditor.getProgressMonitor();

            textEditor.doSave(monitor);
        }
        if (input.equals(textEditor.getEditorInput()))
            return false;
        input = textEditor.getEditorInput();
        setInput(input);

        // Update the display
        setPartName(input.getName());
        setTitleToolTip(input.getToolTipText());

    } else {
        try {
            if (file == null || saveAs) {
                FileDialog dialog = new FileDialog(getSite().getShell(), SWT.SAVE);
                dialog.setText(Messages.getString("SQLEditor.SaveAsDialog.Title"));
                dialog.setFilterExtensions(SUPPORTED_FILETYPES);
                dialog.setFilterNames(SUPPORTED_FILETYPES);
                dialog.setFileName("*.sql");

                String path = dialog.open();
                if (path == null)
                    return false;
                file = new File(path);
            }

            // Save it
            saveToFile(file);

            // Update the editor input
            input = new SQLEditorInput(file);
            setInput(input);
            setPartName(input.getName());
            setTitleToolTip(input.getToolTipText());

        } catch (IOException e) {
            SQLExplorerPlugin.error("Couldn't save sql", e);
            MessageDialog.openError(getSite().getShell(), Messages.getString("SQLEditor.SaveAsDialog.Error"),
                    e.getMessage());
            return false;
        }

    }

    setIsDirty(textEditor.isDirty());
    return true;
}

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());
                        }//  w  ww  .  jav a 2  s  .c  om
                    }
                }
            });
        }
    }
}

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 ww w  .j  av  a 2s .c o  m*/
    } 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);

    /*//ww w. ja  v  a  2  s. co 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);

    /*//w  ww.  j a  va2s . co m
     * 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  ww . j av a  2 s  .c om*/
        switchPerspective(part);
    } else if (returnCode == IDialogConstants.NO_ID) {
        if (remember) {
            store.setValue(FindBugsConstants.SWITCH_PERSPECTIVE_AFTER_ANALYSIS, false);
        }
    }
}

From source file:net.sf.eclipsensis.startup.FileAssociationChecker.java

License:Open Source License

private void scheduleJob(final FileAssociationDef def) {
    if (def != null) {
        Job job = new UIJob(mJobName) {
            private boolean isValidEditor(String[] editorIds, IEditorDescriptor descriptor) {
                if (descriptor != null) {
                    String id = descriptor.getId();
                    for (int i = 0; i < editorIds.length; i++) {
                        if (editorIds[i].equals(id)) {
                            return true;
                        }//from  w  w w  .  j  a v  a 2  s  . co  m
                    }
                }
                return false;
            }

            @Override
            public IStatus runInUIThread(final IProgressMonitor monitor) {
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                if (!cCheckedAssociations.contains(def.getAssociationId())) {
                    final boolean toggleState = getFileAssociationChecking(def.getAssociationId());
                    if (toggleState) {
                        cCheckedAssociations.add(def.getAssociationId());
                        final String[] fileTypes = def.getFileTypes();
                        for (int i = 0; i < fileTypes.length; i++) {
                            if (monitor.isCanceled()) {
                                return Status.CANCEL_STATUS;
                            }
                            if (!isValidEditor(def.getEditorIds(),
                                    mEditorRegistry.getDefaultEditor(fileTypes[i]))) {
                                if (!monitor.isCanceled()) {
                                    String[] args = new String[] { def.getFileTypesName(),
                                            def.getEditorsName() };
                                    MessageDialogWithToggle dialog = MessageDialogWithToggle
                                            .openYesNoCancelQuestion(
                                                    PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                                                            .getShell(),
                                                    mDialogTitleFormat.format(args),
                                                    mDialogMessageFormat.format(args),
                                                    mDialogToggleMessageFormat.format(args), !toggleState, null,
                                                    null);
                                    int rc = dialog.getReturnCode();
                                    switch (rc) {
                                    case IDialogConstants.YES_ID: {
                                        for (int j = 0; j < fileTypes.length; j++) {
                                            mEditorRegistry.setDefaultEditor(fileTypes[j],
                                                    def.getEditorIds()[0]);
                                        }
                                        //Cast to inner class because otherwise it cannot be saved.
                                        ((EditorRegistry) mEditorRegistry).saveAssociations();
                                        //Fall through to next case to save the toggle state
                                    }
                                    //$FALL-THROUGH$
                                    case IDialogConstants.NO_ID: {
                                        boolean newToggleState = !dialog.getToggleState();
                                        if (toggleState != newToggleState) {
                                            setFileAssociationChecking(def.getAssociationId(), newToggleState);
                                        }
                                        break;
                                    }
                                    case IDialogConstants.CANCEL_ID:
                                        return Status.CANCEL_STATUS;
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                } else {
                    return Status.OK_STATUS;
                }
            }
        };
        job.setRule(cSchedulingRule);
        job.schedule(5000);
    }
}

From source file:net.sourceforge.sqlexplorer.plugin.editors.SQLEditor.java

License:Open Source License

/**
 * Implementation for save-as; returns true if successfull, false if not (i.e. the user cancelled the dialog)
 * /*from  ww w .  j a  v a  2s.c o  m*/
 * @return true if saved, false if cancelled
 */
public boolean doSave(boolean saveAs, IProgressMonitor monitor) {
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    boolean haveProjects = projects != null && projects.length > 0;
    IEditorInput input = getEditorInput();

    boolean saveInsideProject = true;
    File file = null;
    if (input instanceof SQLEditorInput) {
        SQLEditorInput seInput = (SQLEditorInput) input;
        file = seInput.getFile();
    }

    // If we have a file, then we already have a filename outside of the project;
    // but if we're doing a save-as then recheck with the user
    if (file != null && !saveAs) {
        saveInsideProject = false;
    } else if (input instanceof SQLEditorInput) {
        IConstants.Confirm confirm = SQLExplorerPlugin.getConfirm(IConstants.CONFIRM_YNA_SAVING_INSIDE_PROJECT);

        // If we're supposed to ask the user...
        if (confirm == IConstants.Confirm.ASK) {
            // Build up the message to ask
            String msg = Messages.getString("Confirm.SaveInsideProject.Intro") + "\n\n";
            if (!haveProjects) {
                msg = msg + Messages.getString("Confirm.SaveInsideProject.NoProjectsConfigured") + "\n\n";
            }
            msg = msg + Messages.getString("Confirm.SaveInsideProject.SaveInProject");

            // Ask them
            MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(
                    getSite().getShell(), Messages.getString("SQLEditor.SaveAsDialog.Title"), msg,
                    Messages.getString("Confirm.SaveInsideProject.Toggle"), false, null, null);
            if (dialog.getReturnCode() == IDialogConstants.CANCEL_ID) {
                return false;
            }

            // If they turned on the toggle ("Use this answer in the future"), update the preferences
            if (dialog.getToggleState()) {
                confirm = dialog.getReturnCode() == IDialogConstants.YES_ID ? IConstants.Confirm.YES
                        : IConstants.Confirm.NO;
                SQLExplorerPlugin.getDefault().getPreferenceStore()
                        .setValue(IConstants.CONFIRM_YNA_SAVING_INSIDE_PROJECT, confirm.toString());
            }

            // Whether to save inside or outside
            saveInsideProject = dialog.getReturnCode() == IDialogConstants.YES_ID;
        } else {
            saveInsideProject = confirm == IConstants.Confirm.YES;
        }
    }

    // Saving inside a project - convert SQLEditorInput into a Resource by letting TextEditor do the work for us
    if (saveInsideProject) {
        if (!haveProjects) {
            MessageDialog.openError(getSite().getShell(), Messages.getString("Confirm.SaveInsideProject.Title"),
                    Messages.getString("Confirm.SaveInsideProject.CreateAProject"));
            return false;
        }
        if (input instanceof SQLEditorInput) {
            saveAs = true;
        }

        // Save it and use their EditorInput
        if (saveAs) {
            textEditor.doSaveAs();
        } else {
            if (monitor == null) {
                monitor = textEditor.getProgressMonitor();
            }
            textEditor.doSave(monitor);
        }
        if (input.equals(textEditor.getEditorInput())) {
            return false;
        }
        input = textEditor.getEditorInput();
        setInput(input);

        // Update the display
        setPartName(input.getName());
        setTitleToolTip(input.getToolTipText());

    } else {
        try {
            if (file == null || saveAs) {
                FileDialog dialog = new FileDialog(getSite().getShell(), SWT.SAVE);
                dialog.setText(Messages.getString("SQLEditor.SaveAsDialog.Title"));
                dialog.setFilterExtensions(SUPPORTED_FILETYPES);
                dialog.setFilterNames(SUPPORTED_FILETYPES);
                dialog.setFileName("*.sql");

                String path = dialog.open();
                if (path == null) {
                    return false;
                }
                file = new File(path);
            }

            // Save it
            saveToFile(file);

            // Update the editor input
            input = new SQLEditorInput(file);
            setInput(input);
            setPartName(input.getName());
            setTitleToolTip(input.getToolTipText());

        } catch (IOException e) {
            SQLExplorerPlugin.error("Couldn't save sql", e);
            MessageDialog.openError(getSite().getShell(), Messages.getString("SQLEditor.SaveAsDialog.Error"),
                    e.getMessage());
            return false;
        }

    }

    setIsDirty(textEditor.isDirty());
    return true;
}

From source file:net.sourceforge.texlipse.viewer.ViewerConfigDialog.java

License:Open Source License

/**
 * Check that the config is valid./* w w  w.  ja va2 s  .com*/
 * 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();
}