Example usage for org.eclipse.jface.dialogs MessageDialog QUESTION

List of usage examples for org.eclipse.jface.dialogs MessageDialog QUESTION

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialog QUESTION.

Prototype

int QUESTION

To view the source code for org.eclipse.jface.dialogs MessageDialog QUESTION.

Click Source Link

Document

Constant for the question image, or a simple dialog with the question image and Yes/No buttons (value 3).

Usage

From source file:com.bdaum.zoom.ui.internal.views.WebGalleryView.java

License:Open Source License

private boolean createGenerator(WebGalleryImpl show, IConfigurationElement el, String outputFolder,
        boolean isFtp, final boolean save) {
    try {//from   w  ww. j a v a  2  s .  com
        Storyboard selectedStoryboard = null;
        if (!Boolean.parseBoolean(el.getAttribute("sections")) && show.getStoryboard().size() > 1) { //$NON-NLS-1$
            SelectStoryBoardDialog dialog = new SelectStoryBoardDialog(getSite().getShell(),
                    Messages.getString("WebGalleryView.multiple_storyboards"), //$NON-NLS-1$
                    NLS.bind(Messages.getString("WebGalleryView.does_not_support_multiple_storyboards"), //$NON-NLS-1$
                            el.getAttribute("name")), //$NON-NLS-1$
                    show.getStoryboard());
            if (dialog.open() != SelectStoryBoardDialog.OK)
                return true;
            selectedStoryboard = dialog.getResult();
        }
        String maxImages = el.getAttribute("maxImages"); //$NON-NLS-1$
        if (maxImages != null) {
            try {
                int max = Integer.parseInt(maxImages);
                int n = 0;
                for (Storyboard storyboard : show.getStoryboard())
                    max -= storyboard.getExhibit().size();
                if (n > max && !AcousticMessageDialog.openQuestion(getSite().getShell(),
                        Messages.getString("WebGalleryView.too_many"), //$NON-NLS-1$
                        NLS.bind(Messages.getString("WebGalleryView.n_exceeds_max"), //$NON-NLS-1$
                                new Object[] { n, max, el.getAttribute("name") }))) //$NON-NLS-1$
                    return true;
            } catch (NumberFormatException e) {
                // ignore
            }
        }
        String aspectRatio = el.getAttribute("aspectRatio"); //$NON-NLS-1$
        if (aspectRatio != null) {
            aspectRatio.trim();
            if (!aspectRatio.isEmpty()) {
                double sample = Double.NaN;
                double tolerance = 5;
                int p = aspectRatio.indexOf(' ');
                if (p > 0) {
                    try {
                        sample = Double.parseDouble(aspectRatio.substring(0, p));
                    } catch (NumberFormatException e) {
                        // Leave at NaN
                    }
                    aspectRatio = aspectRatio.substring(p + 1);
                }
                if (aspectRatio.endsWith("%")) { //$NON-NLS-1$
                    try {
                        tolerance = Double.parseDouble(aspectRatio.substring(0, aspectRatio.length() - 1));
                    } catch (NumberFormatException e) {
                        // Leave at 5
                    }
                }
                List<String> errands = new ArrayList<>();
                IDbManager dbManager = Core.getCore().getDbManager();
                lp: for (Storyboard storyboard : show.getStoryboard()) {
                    for (String exhibitId : storyboard.getExhibit()) {
                        WebExhibitImpl exhibit = dbManager.obtainById(WebExhibitImpl.class, exhibitId);
                        if (exhibit != null) {
                            AssetImpl asset = dbManager.obtainAsset(exhibit.getAsset());
                            if (asset != null & asset.getHeight() > 0) {
                                double prop = (double) asset.getWidth() / asset.getHeight();
                                if (Double.isNaN(sample))
                                    sample = prop;
                                else if (Math.abs(sample - prop) > sample * tolerance / 100d) {
                                    if (p > 0)
                                        errands.add((asset.getName()));
                                    else {
                                        if (!AcousticMessageDialog.openQuestion(getSite().getShell(),
                                                Messages.getString("WebGalleryView.unequal_proportions"), //$NON-NLS-1$
                                                NLS.bind(
                                                        Messages.getString(
                                                                "WebGalleryView.unequal_proportions_msg"), //$NON-NLS-1$
                                                        el.getAttribute("name")))) //$NON-NLS-1$
                                            return true;
                                        break lp;
                                    }
                                }
                            }
                        }
                    }
                }
                if (!errands.isEmpty()
                        && !AcousticMessageDialog
                                .openQuestion(getSite().getShell(),
                                        Messages.getString("WebGalleryView.unequal_proportions"), //$NON-NLS-1$
                                        NLS.bind(Messages.getString("WebGalleryView.required_aspect_ratio"), //$NON-NLS-1$
                                                new Object[] { el.getAttribute("name"), sample, //$NON-NLS-1$
                                                        Core.toStringList(errands.toArray(new String[errands.size()]),
                                                                ", ") }))) //$NON-NLS-1$
                    return true;
            }
        }
        final IGalleryGenerator generator = (IGalleryGenerator) el.createExecutableExtension("class"); //$NON-NLS-1$
        if (generator instanceof AbstractGalleryGenerator) {
            ((AbstractGalleryGenerator) generator).setConfigurationElement(el);
            ((AbstractGalleryGenerator) generator).setSelectedStoryBoard(selectedStoryboard);
        }
        final File file = new File(outputFolder);
        if (!isFtp && file.exists() && file.listFiles().length > 0) {
            AcousticMessageDialog dialog = new AcousticMessageDialog(getSite().getShell(),
                    Messages.getString("WebGalleryView.overwrite"), //$NON-NLS-1$
                    null, NLS.bind(Messages.getString("WebGalleryView.output_folder_not_empty"), file), //$NON-NLS-1$
                    MessageDialog.QUESTION,
                    new String[] { Messages.getString("WebGalleryView.overwrite_button"), //$NON-NLS-1$
                            Messages.getString("WebGalleryView.clear_folder"), //$NON-NLS-1$
                            IDialogConstants.CANCEL_LABEL },
                    0);
            switch (dialog.open()) {
            case 2:
                return true;
            case 1:
                Core.deleteFolderExcluding(file, "themes"); //$NON-NLS-1$
                break;
            }
        }
        String page = show.getPageName();
        final boolean ftp = isFtp;
        final File start = new File(file, (page == null || page.isEmpty()) ? "index.html" //$NON-NLS-1$
                : page);
        final WebGalleryImpl gal = show;
        final WebGalleryJob job = new WebGalleryJob(gal, generator, WebGalleryView.this);
        final FtpAccount account;
        if (ftp) {
            account = FtpAccount.findAccount(outputFolder);
            if (account == null) {
                AcousticMessageDialog.openError(getSite().getShell(),
                        Messages.getString("WebGalleryView.account_does_not_exist"), //$NON-NLS-1$
                        NLS.bind(Messages.getString("WebGalleryView.ftp_account_not_defined"), //$NON-NLS-1$
                                outputFolder));
                return true;
            }
        } else
            account = null;
        job.addJobChangeListener(new JobChangeAdapter() {
            @Override
            public void done(IJobChangeEvent event) {
                if (!job.wasAborted()) {
                    if (ftp)
                        new TransferJob(generator.getTargetFolder().listFiles(), account, true).schedule(0);
                    else
                        showWebGallery(save, start, gal);
                }
            }
        });
        job.schedule();
    } catch (CoreException e) {
        UiActivator.getDefault()
                .logError(NLS.bind(Messages.getString("WebGalleryView.error_when_instantiating_web_generator"), //$NON-NLS-1$
                        el.getAttribute("name")), e); //$NON-NLS-1$
    }
    return false;
}

From source file:com.byterefinery.rmbench.util.ModelManager.java

License:Open Source License

/**
 * show a 3-option dialog asking the user whether the current model should be saved
 * /*from   w w w  .  j a va2 s  .  c  om*/
 * @return false if the dialog was cancelled, and thus the operation should not 
 * proceed
 */
private boolean querySaveModel(final Shell shell) {

    MessageDialog dialog = new MessageDialog(shell, RMBenchMessages.ModelView_SaveDlg_Title, null,
            RMBenchMessages.ModelView_SaveChanged_Message, MessageDialog.QUESTION, new String[] {
                    IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
            0);
    int result = dialog.open();
    if (result == 0) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

                doSave(shell, monitor);
            }
        };
        try {
            new ProgressMonitorDialog(shell).run(false, true, runnable);
        } catch (InvocationTargetException e) {
            RMBenchPlugin.logError(e);
        } catch (InterruptedException e) {
            RMBenchPlugin.logError(e);
        }
    }

    return result != 2;
}

From source file:com.centurylink.mdw.plugin.designer.editors.ProcessEditor.java

License:Apache License

private int promptToSaveOverrideAttributes() {
    String msg = getProcess().getName() + " has unsaved override attributes.  Save changes?";
    String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL };
    MessageDialog attrsSaveDialog = new MessageDialog(getSite().getShell(), "Save Attributes", null, msg,
            MessageDialog.QUESTION, buttons, 0);
    return attrsSaveDialog.open();
}

From source file:com.codesourcery.internal.installer.ui.InstallWizard.java

License:Open Source License

/**
 * Shows a cancel confirmation dialog./*from ww  w  .  j  a  v a 2  s  .c  o  m*/
 * 
 * @return <code>true</code> to cancel
 */
public boolean showCancelConfirmation() {
    // Confirmation message
    String confirmationMessage;
    if (isInstall()) {
        confirmationMessage = MessageFormat.format(InstallMessages.CancelInstallConfirmation2,
                new Object[] {
                        Installer.getDefault().getInstallManager().getInstallDescription().getProductName(),
                        InstallMessages.Resume, InstallMessages.Quit });
    } else {
        confirmationMessage = MessageFormat.format(InstallMessages.CancelUninstallConfirmation1,
                new Object[] { InstallMessages.Resume, InstallMessages.Quit });
    }
    // Confirm dialog
    MessageDialog confirmationDialog = new MessageDialog(getContainer().getShell(),
            InstallMessages.CancelSetupTitle, null, confirmationMessage, MessageDialog.QUESTION,
            new String[] { InstallMessages.Resume, InstallMessages.Quit }, 0);

    return (confirmationDialog.open() != 0);
}

From source file:com.codesourcery.internal.installer.ui.WizardDialog.java

License:Open Source License

/**
 * Creates and return a new wizard closing dialog without opening it.
 * /*  ww  w  . j  av  a 2 s .co m*/
 * @return MessageDalog
 */
private MessageDialog createWizardClosingDialog() {
    MessageDialog result = new MessageDialog(getShell(), JFaceResources.getString("WizardClosingDialog.title"), //$NON-NLS-1$
            null, JFaceResources.getString("WizardClosingDialog.message"), //$NON-NLS-1$
            MessageDialog.QUESTION, new String[] { IDialogConstants.OK_LABEL }, 0) {
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    return result;
}

From source file:com.conwet.wirecloud.ide.wizards.WizardProjectsImportPage.java

License:Open Source License

/**
 * The <code>WizardDataTransfer</code> implementation of this
 * <code>IOverwriteQuery</code> method asks the user whether the existing
 * resource at the given path should be overwritten.
 *
 * @param pathString//from   w  w  w .  j  a  v  a2  s  . c om
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>,
 *    <code>"ALL"</code>, or <code>"CANCEL"</code>
 */
public String queryOverwrite(String pathString) {

    Path path = new Path(pathString);

    String messageString;
    // Break the message up if there is a file name and a directory
    // and there are at least 2 segments.
    if (path.getFileExtension() == null || path.segmentCount() < 2) {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString);
    } else {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion,
                path.lastSegment(), path.removeLastSegments(1).toOSString());
    }

    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), IDEWorkbenchMessages.Question,
            null, messageString, MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0) {
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
    // run in syncExec because callback is from an operation,
    // which is probably not running in the UI thread.
    getControl().getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}

From source file:com.drgarbage.utils.Messages.java

License:Apache License

/**
 * Convenient method to open a simple confirm (OK/Cancel) dialog.
 * //  ww  w .  java2 s.  c  o  m
 * @param parent
 *            the parent shell of the dialog, or <code>null</code> if none
 * @param title
 *            the dialog's title, or <code>null</code> if none
 * @param message
 *            the message
 * @return <code>true</code> if the user presses the OK button,
 *         <code>false</code> otherwise
 */
public static boolean openConfirm(Shell parent, String title, String message, String[] buttons) {
    MessageDialog dialog = new MessageDialog(parent, title, CoreImg.aboutDrGarbageIcon_16x16.createImage(),
            message, MessageDialog.QUESTION, buttons, 0); /* OK is the default */
    return dialog.open() == 0;
}

From source file:com.drgarbage.utils.Messages.java

License:Apache License

/**
 * Convenient method to open a select dialog.
 * /*from  w w  w.  ja  va  2 s  .  com*/
 * @param parentShell 
 *                   the parent shell of the dialog, or <code>null</code> if none
 * @param title 
 *                   the dialog's title, or <code>null</code> if none
 * @param message    
 *                   the message
 * @param buttons 
 *                   the labels of the buttons to appear in the button bar
 * @param selectionListImage
*                       the image
 * @param elementList
 *                   the list of elements have to be displayed in the selection list 
 * 
 * @return selected text if the user presses the OK button,
 *         <code>null</code> otherwise
 */

public static String openSelectDialog(Shell parentShell, String title, String message, String[] buttons,
        Image selectionListImage, List<String> elementList) {

    SelectDialog dialog = new SelectDialog(parentShell, title, CoreImg.aboutDrGarbageIcon_16x16.createImage(),
            message, MessageDialog.QUESTION, buttons, 0, selectionListImage); /* OK is the default */

    dialog.create();
    dialog.addElementsToList(elementList);

    dialog.open();
    return dialog.getSelectedText();
}

From source file:com.drgarbage.visualgraphic.model.ControlFlowGraphDiagramFactory.java

License:Apache License

public static int openConfirm(Shell parent, String title, String message) {
    MessageDialog dialog = new MessageDialog(parent, title, CoreImg.aboutDrGarbageIcon_16x16.createImage(),
            message, MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL },
            3); /*/*  ww  w  . ja v a2 s  . co m*/
                * OK is the
                * default
                */
    return dialog.open();
}

From source file:com.drgarbage.visualgraphic.model.ControlFlowGraphDiagramFactory.java

License:Apache License

public static int openStop(Shell parent, String title, String message) {
    MessageDialog dialog = new MessageDialog(parent, title, CoreImg.aboutDrGarbageIcon_16x16.createImage(),
            message, MessageDialog.QUESTION,
            new String[] { IDialogConstants.NO_LABEL, IDialogConstants.YES_LABEL }, 1); /*
                                                                                        * YES is the
                                                                                        * default
                                                                                        */
    return dialog.open();
}