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

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

Introduction

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

Prototype

public static boolean open(int kind, Shell parent, String title, String message, int style) 

Source Link

Document

Convenience method to open a simple dialog as specified by the kind flag.

Usage

From source file:com.puppetlabs.geppetto.ui.wizard.ModuleExportToFileWizard.java

License:Open Source License

boolean executeExport(ModuleExportOperation op) {
    try {/*from   w ww . j a v a 2s . c om*/
        getContainer().run(true, true, op);
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        Throwable exception = e.getTargetException();
        String message = exception.getMessage();
        // Some system exceptions have no message
        if (message == null)
            message = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_exceptionMessage, exception);
        MessageDialog.open(MessageDialog.ERROR, getShell(),
                IDEWorkbenchMessages.WizardExportPage_internalErrorTitle, message, SWT.SHEET);
        return false;
    }

    IStatus status = op.getStatus();
    if (!status.isOK()) {
        ErrorDialog.openError(getShell(), DataTransferMessages.DataTransfer_exportProblems, null, // no special message
                status);
        return false;
    }
    return true;
}

From source file:com.synflow.cx.ui.wizards.NewFilePage.java

License:Open Source License

/**
 * Creates a new file resource in the selected container and with the selected name. Creates any
 * missing resource containers along the path; does nothing if the container resources already
 * exist.//ww w  .ja  v  a  2 s .c o  m
 * 
 * @param initialContents
 *            initial contents of the file
 * 
 * @return the created file resource, or <code>null</code> if the file was not created
 */
public IFile createNewFile(final InputStream initialContents) {
    final IFile newFileHandle = getFile();

    IRunnableWithProgress op = new IRunnableWithProgress() {
        @Override
        public void run(IProgressMonitor monitor) {
            CreateFileOperation op = new CreateFileOperation(newFileHandle, null, initialContents, getTitle());
            try {
                // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=219901
                // directly execute the operation so that the undo state is
                // not preserved. Making this undoable resulted in too many
                // accidental file deletions.
                op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
            } catch (final ExecutionException e) {
                getContainer().getShell().getDisplay().syncExec(new Runnable() {
                    @Override
                    public void run() {
                        if (e.getCause() instanceof CoreException) {
                            ErrorDialog.openError(getContainer().getShell(), "Could not create " + type, null,
                                    ((CoreException) e.getCause()).getStatus());
                        } else {
                            SynflowCore.log(e.getCause());
                            MessageDialog.openError(getContainer().getShell(), "Could not create " + type,
                                    NLS.bind("Internal error: {0}", e.getCause().getMessage()));
                        }
                    }
                });
            }
        }
    };

    try {
        getContainer().run(true, true, op);
    } catch (InterruptedException e) {
        return null;
    } catch (InvocationTargetException e) {
        // ExecutionExceptions are handled above, but unexpected runtime
        // exceptions and errors may still occur.
        SynflowCore.log(e.getTargetException());
        MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(), "Could not create " + type,
                NLS.bind("Internal error: {0}", e.getTargetException().getMessage()), SWT.SHEET);
        return null;
    }

    return newFileHandle;
}

From source file:com.synflow.ngDesign.ui.internal.wizards.NewPackagePage.java

License:Open Source License

public IFolder createNewFolder() {
    final IFolder newFolderHandle = getFolder();
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) {
            CreateFolderOperation op = new CreateFolderOperation(newFolderHandle, null, "New Package");
            try {
                // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=219901
                // directly execute the operation so that the undo state is
                // not preserved. Making this undoable can result in accidental
                // folder (and file) deletions.
                op.execute(monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
            } catch (final ExecutionException e) {
                getContainer().getShell().getDisplay().syncExec(new Runnable() {
                    public void run() {
                        if (e.getCause() instanceof CoreException) {
                            ErrorDialog.openError(getContainer().getShell(), "Could not create package", null,
                                    ((CoreException) e.getCause()).getStatus());
                        } else {
                            SynflowCore.log(e.getCause());
                            MessageDialog.openError(getContainer().getShell(), "Could not create package",
                                    NLS.bind("Internal error: {0}", e.getCause().getMessage()));
                        }/*  w  ww .j av a 2  s . c o m*/
                    }
                });
            }
        }
    };

    try {
        getContainer().run(true, true, op);
    } catch (InterruptedException e) {
        return null;
    } catch (InvocationTargetException e) {
        // ExecutionExceptions are handled above, but unexpected runtime
        // exceptions and errors may still occur.
        SynflowCore.log(e.getTargetException());
        MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(), "Could not create package",
                NLS.bind("Internal error: {0}", e.getTargetException().getMessage()), SWT.SHEET);
        return null;
    }

    return newFolderHandle;
}

From source file:com.xse.eclipseui.dialog.MessageDialogHelper.java

License:Open Source License

/**
 * Convenience method to open a simple confirm (OK/Cancel) dialog.
 *
 * @param title//from  w  w w.j  av a 2s. c  om
 *            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(final String title, final String message) {
    final ValueContainer<Boolean> result = new ValueContainer<>(Boolean.FALSE);
    Display.getDefault().syncExec(new Runnable() {
        @Override
        public void run() {
            result.setValue(Boolean.valueOf(MessageDialog.open(MessageDialog.CONFIRM,
                    Display.getDefault().getActiveShell(), title, message, SWT.NONE)));
        }
    });

    return result.getValue().booleanValue();
}

From source file:com.xse.eclipseui.dialog.MessageDialogHelper.java

License:Open Source License

/**
 * Convenience method to open a standard error dialog.
 *
 * @param title/*ww w.  j a  v a  2 s  .  c o m*/
 *            the dialog's title, or <code>null</code> if none
 * @param message
 *            the message
 */
public static void openError(final String title, final String message) {
    Display.getDefault().syncExec(new Runnable() {
        @Override
        public void run() {
            MessageDialog.open(MessageDialog.ERROR, Display.getDefault().getActiveShell(), title, message,
                    SWT.NONE);
        }
    });
}

From source file:com.xse.eclipseui.dialog.MessageDialogHelper.java

License:Open Source License

/**
 * Convenience method to open a standard information dialog.
 *
 * @param title/*from  ww  w. ja v  a2 s  .  c o  m*/
 *            the dialog's title, or <code>null</code> if none
 * @param message
 *            the message
 */
public static void openInformation(final String title, final String message) {
    Display.getDefault().syncExec(new Runnable() {
        @Override
        public void run() {
            MessageDialog.open(MessageDialog.INFORMATION, Display.getDefault().getActiveShell(), title, message,
                    SWT.NONE);
        }
    });
}

From source file:com.xse.eclipseui.dialog.MessageDialogHelper.java

License:Open Source License

/**
 * Convenience method to open a simple Yes/No question dialog.
 *
 * @param title/*  w  ww.j  a va2s.  c  o  m*/
 *            the dialog's title, or <code>null</code> if none
 * @param message
 *            the message
 * @return <code>true</code> if the user presses the Yes button, <code>false</code> otherwise
 */
public static boolean openQuestion(final String title, final String message) {
    final ValueContainer<Boolean> result = new ValueContainer<>(Boolean.FALSE);
    Display.getDefault().syncExec(new Runnable() {
        @Override
        public void run() {
            result.setValue(Boolean.valueOf(MessageDialog.open(MessageDialog.QUESTION,
                    Display.getDefault().getActiveShell(), title, message, SWT.NONE)));
        }
    });

    return result.getValue().booleanValue();
}

From source file:com.xse.eclipseui.dialog.MessageDialogHelper.java

License:Open Source License

/**
 * Convenience method to open a standard warning dialog.
 *
 * @param title/*  ww w  .j  ava2 s .  co  m*/
 *            the dialog's title, or <code>null</code> if none
 * @param message
 *            the message
 */
public static void openWarning(final String title, final String message) {
    Display.getDefault().syncExec(new Runnable() {
        @Override
        public void run() {
            MessageDialog.open(MessageDialog.WARNING, Display.getDefault().getActiveShell(), title, message,
                    SWT.NONE);
        }
    });
}

From source file:com.xse.eclipseui.logging.MessageHelper.java

License:Open Source License

public static void post(final String pluginId, final Severity severity, final String title,
        final String message, final Throwable t) {
    final Status status;
    int kind = MessageDialog.INFORMATION;

    switch (severity) {
    case INFORMATION:
        status = new Status(IStatus.INFO, pluginId, message, t);
        break;/*from w  w  w . j a va  2 s .com*/
    case WARNING:
        status = new Status(IStatus.WARNING, pluginId, message, t);
        kind = MessageDialog.WARNING;
        break;
    case ERROR:
        status = new Status(IStatus.ERROR, pluginId, message, t);
        kind = MessageDialog.ERROR;
        break;
    default:
        status = null;
        break;
    }

    if (status != null) {
        Logger.log(status);
        final int kind2 = kind;
        Display.getDefault().syncExec(new Runnable() {
            @Override
            public void run() {
                MessageDialog.open(kind2, Display.getDefault().getActiveShell(), title, message, SWT.NONE);
            }
        });
    }
}

From source file:de.bmw.yamaica.common.ui.dialogs.YamaicaWizardNewFilePage.java

License:Mozilla Public License

/**
 * Display an error dialog with the specified message.
 * /*  w ww.j a v  a  2s .c om*/
 * @param message
 *            the error message
 */
protected void displayErrorDialog(String message) {
    MessageDialog.open(MessageDialog.ERROR, getContainer().getShell(), INTERNAL_ERROR, message, SWT.SHEET);
}