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

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

Introduction

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

Prototype

@Override
public boolean close() 

Source Link

Usage

From source file:net.sf.eclipsensis.installoptions.actions.PreviewAction.java

License:Open Source License

@Override
public void run() {
    if (mEditor != null) {
        Shell shell = mEditor.getSite().getShell();
        if (mEditor.isDirty()) {
            boolean autosaveBeforePreview = mPreferenceStore
                    .getBoolean(IInstallOptionsConstants.PREFERENCE_AUTOSAVE_BEFORE_PREVIEW);
            boolean shouldSave = autosaveBeforePreview;
            if (!shouldSave) {
                MessageDialogWithToggle dialog = new MessageDialogWithToggle(shell,
                        EclipseNSISPlugin.getResourceString("confirm.title"), //$NON-NLS-1$
                        InstallOptionsPlugin.getShellImage(),
                        InstallOptionsPlugin.getResourceString("save.before.preview.confirm"), //$NON-NLS-1$
                        MessageDialog.QUESTION,
                        new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0,
                        InstallOptionsPlugin.getResourceString("confirm.toggle.message"), false); //$NON-NLS-1$
                dialog.open();//from  w  w  w.  j a  v  a  2s .c  o m
                shouldSave = dialog.getReturnCode() == IDialogConstants.OK_ID;
                if (shouldSave && dialog.getToggleState()) {
                    mPreferenceStore.setValue(IInstallOptionsConstants.PREFERENCE_AUTOSAVE_BEFORE_PREVIEW,
                            true);
                }
            }
            if (shouldSave) {
                ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
                dialog.open();
                IProgressMonitor progressMonitor = dialog.getProgressMonitor();
                mEditor.doSave(progressMonitor);
                dialog.close();
                if (progressMonitor.isCanceled()) {
                    return;
                }
            } else {
                return;
            }
        }
        INIFile iniFile = mEditor.getINIFile();
        if (iniFile.hasErrors()) {
            Common.openError(shell, InstallOptionsPlugin.getResourceString("ini.errors.preview.error"), //$NON-NLS-1$
                    InstallOptionsPlugin.getShellImage());
            return;
        }
        INISection settings = iniFile.findSections(InstallOptionsModel.SECTION_SETTINGS)[0];
        INIKeyValue numFields = settings.findKeyValues(InstallOptionsModel.PROPERTY_NUMFIELDS)[0];
        if (Integer.parseInt(numFields.getValue()) <= 0) {
            Common.openError(shell, InstallOptionsPlugin.getResourceString("ini.numfields.preview.error"), //$NON-NLS-1$
                    InstallOptionsPlugin.getShellImage());
        } else {
            IPathEditorInput editorInput = NSISEditorUtilities.getPathEditorInput(mEditor);
            if (editorInput instanceof IFileEditorInput) {
                IFile file = ((IFileEditorInput) editorInput).getFile();
                if (file.exists()) {
                    IPath location = file.getLocation();
                    if (location != null) {
                        doPreview(iniFile, location.toFile());
                    } else {
                        Common.openError(shell, EclipseNSISPlugin.getResourceString("local.filesystem.error"), //$NON-NLS-1$
                                InstallOptionsPlugin.getShellImage());
                    }
                }
            } else if (editorInput != null) {
                doPreview(iniFile, new File(editorInput.getPath().toOSString()));
            }
        }
    }
}

From source file:net.sf.eclipsensis.util.NSISCompileTestUtility.java

License:Open Source License

private boolean saveEditors(List<IEditorPart> editors, int beforeCompileSave) {
    List<IEditorPart> editors2 = editors;
    if (!Common.isEmptyCollection(editors2)) {
        boolean ok = false;
        String message = null;/*from   w w  w .  j  a  v  a  2 s.c  om*/
        switch (beforeCompileSave) {
        case INSISPreferenceConstants.BEFORE_COMPILE_SAVE_ASSOCIATED_CONFIRM:
            if (editors2.size() > 1) {
                StringBuffer buf = new StringBuffer();
                for (Iterator<IEditorPart> iter = editors2.iterator(); iter.hasNext();) {
                    IEditorPart editor = iter.next();
                    buf.append(INSISConstants.LINE_SEPARATOR).append(
                            ((IFileEditorInput) editor.getEditorInput()).getFile().getFullPath().toString());
                }
                message = EclipseNSISPlugin.getFormattedString("compile.save.associated.confirmation", //$NON-NLS-1$
                        new String[] { buf.toString() });
                break;
            }
            //$FALL-THROUGH$
        case INSISPreferenceConstants.BEFORE_COMPILE_SAVE_CURRENT_CONFIRM:
            IEditorPart editor = editors2.get(0);
            if (editors2.size() > 1) {
                editors2 = editors2.subList(0, 1);
            }
            IPathEditorInput input = NSISEditorUtilities.getPathEditorInput(editor);
            IPath path = (input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile().getFullPath()
                    : input.getPath());
            message = EclipseNSISPlugin.getFormattedString("compile.save.current.confirmation", //$NON-NLS-1$
                    new String[] { path.toString() });
            break;
        case INSISPreferenceConstants.BEFORE_COMPILE_SAVE_ALL_CONFIRM:
            message = EclipseNSISPlugin.getResourceString("compile.save.all.confirmation"); //$NON-NLS-1$
            break;
        case INSISPreferenceConstants.BEFORE_COMPILE_SAVE_CURRENT_AUTO:
        case INSISPreferenceConstants.BEFORE_COMPILE_SAVE_ASSOCIATED_AUTO:
        case INSISPreferenceConstants.BEFORE_COMPILE_SAVE_ALL_AUTO:
            ok = true;
        }
        Shell shell = Display.getDefault().getActiveShell();
        if (!ok) {
            MessageDialogWithToggle dialog = new MessageDialogWithToggle(shell,
                    EclipseNSISPlugin.getResourceString("confirm.title"), //$NON-NLS-1$
                    EclipseNSISPlugin.getShellImage(), message, MessageDialog.QUESTION,
                    new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0,
                    EclipseNSISPlugin.getResourceString("compile.save.toggle.message"), false); //$NON-NLS-1$
            dialog.open();
            ok = dialog.getReturnCode() == IDialogConstants.OK_ID;
            if (ok && dialog.getToggleState()) {
                NSISPreferences.getInstance().setBeforeCompileSave(
                        beforeCompileSave | INSISPreferenceConstants.BEFORE_COMPILE_SAVE_AUTO_FLAG);
                NSISPreferences.getInstance().store();
            }
        }
        if (ok) {
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
            dialog.open();
            IProgressMonitor progressMonitor = dialog.getProgressMonitor();
            if (editors2.size() > 1) {
                progressMonitor.beginTask(
                        EclipseNSISPlugin.getResourceString("saving.before.compilation.task.name"), //$NON-NLS-1$
                        editors2.size());
                for (Iterator<IEditorPart> iter = editors2.iterator(); iter.hasNext();) {
                    IEditorPart editor = iter.next();
                    SubProgressMonitor monitor = new SubProgressMonitor(progressMonitor, 1);
                    editor.doSave(monitor);
                    if (monitor.isCanceled()) {
                        break;
                    }
                }
            } else {
                editors2.get(0).doSave(progressMonitor);
            }
            dialog.close();
            if (progressMonitor.isCanceled()) {
                return false;
            }
        }
        return ok;
    }
    return true;
}