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 int open() 

Source Link

Document

Opens this window, creating it first if it has not yet been created.

Usage

From source file:ilg.gnuarmeclipse.packs.ui.views.PacksView.java

License:Open Source License

private boolean checkCopyDestinationFolders(TreeSelection selection, String[] param) {

    IPath m_destFolderPath = new Path(param[0]);

    boolean isNonEmpty = false;
    for (Object sel : selection.toList()) {

        PackNode exampleNode = (PackNode) sel;

        Leaf outlineExampleNode = exampleNode.getOutline().findChild(Type.EXAMPLE);

        String exampleRelativeFolder = outlineExampleNode.getProperty(Node.FOLDER_PROPERTY);

        File destFolder = m_destFolderPath.append(exampleRelativeFolder).toFile();

        if (destFolder.isDirectory() && (destFolder.listFiles().length > 0)) {
            isNonEmpty = true;/* w w  w  .  ja  v  a  2s.c  o  m*/
            break;
        }

    }

    if (isNonEmpty) {

        String msg = "One of the destination folders is not empty.";
        msg += "\nDo you agree to delete the previous content?";

        String[] buttons = new String[] { "OK", "Cancel" };
        MessageDialog dlg = new MessageDialog(fComposite.getShell(), null, null, msg, MessageDialog.ERROR,
                buttons, 0);
        if (dlg.open() == 0) {
            return true; // OK
        }

        return false;
    }
    return true;
}

From source file:ilg.gnumcueclipse.packs.data.Utils.java

License:Open Source License

/**
 * //  ww  w. j  av  a 2 s .  com
 * @param sourceUrl
 * @param destinationFile
 * @param out
 * @param monitor
 * @param shell
 * @return 0 = Ok, 1 = Retry, 2 = Ignore, 3 = Ignore All, 4 = Abort
 * @throws IOException
 */
public static int copyFileWithShell(final URL sourceUrl, File destinationFile, MessageConsoleStream out,
        IProgressMonitor monitor, final Shell shell, final boolean ignoreError) throws IOException {

    while (true) {
        try {
            Utils.copyFile(sourceUrl, destinationFile, out, monitor);
            return 0;
        } catch (final IOException e) {

            if (ignoreError) {
                return 3; // Ignore All
            }

            class ErrorMessageDialog implements Runnable {

                public int retCode = 0;

                @Override
                public void run() {
                    String[] buttons = new String[] { "Retry", "Ignore", "Ignore All", "Abort" };
                    MessageDialog dialog = new MessageDialog(shell, "Read error", null,
                            sourceUrl.toString() + "\n" + e.getMessage(), MessageDialog.ERROR, buttons, 0);
                    retCode = dialog.open();
                }
            }

            ErrorMessageDialog messageDialog = new ErrorMessageDialog();
            Display.getDefault().syncExec(messageDialog);

            if (messageDialog.retCode == 3) {
                throw e; // Abort
            } else if (messageDialog.retCode == 1 || messageDialog.retCode == 2) {
                return messageDialog.retCode + 1; // Ignore & Ignore All
            }

            // Else try again
        }
    }

    // HandlerUtil.getActiveShell(event)
}

From source file:io.aos.jface.sample.spl02.JFaceSample02.java

License:Apache License

private Action createAboutAction() {
    return new Action() {
        public String getText() {
            return "Essai";
        }/*w  w w  . j  av a  2 s.com*/

        public void run() {
            String[] tab = { IDialogConstants.OK_LABEL };
            MessageDialog dialog = new MessageDialog(getShell(), "Essai JFace", null,
                    "Ceci est une fentre d''information", MessageDialog.INFORMATION, tab, 0);
            dialog.open();
        }
    };
}

From source file:io.aos.jface.sample.spl02.JFaceSample02.java

License:Apache License

protected void handleShellCloseEvent() {
    String[] tab = { IDialogConstants.OK_LABEL };
    MessageDialog dialog = new MessageDialog(getShell(), "Fin de l'essai", null,
            "Nous allons quitter l'application", MessageDialog.INFORMATION, tab, 0);
    dialog.open();
    setReturnCode(CANCEL);//from   w w  w .j  ava 2  s . c  o  m
    close();
}

From source file:lslforge.LSLForgePlugin.java

License:Open Source License

private boolean determineExecutable() {
    String path = getDefault().getPreferenceStore().getString(LSLFORGE_NATIVE_PATH);
    String preferredVersion = null;
    String embeddedVersion = null;
    String installedVersion = null;
    if (path != null && !"".equals(path.trim())) { //$NON-NLS-1$
        preferredVersion = tryTask("Version", path); //$NON-NLS-1$
        if (checkVersion(preferredVersion)) {
            setExecutablePath(path);//from ww w.  jav  a 2  s . c o  m
            return true;
        }
    }

    URL url = FileLocator.find(getDefault().getBundle(), preferredNativePath(), null);
    if (url != null) {
        try {
            path = FileLocator.toFileURL(url).getFile();
            embeddedVersion = tryTask("Version", path); //$NON-NLS-1$

            if (checkVersion(embeddedVersion)) {
                setExecutablePath(path);
                return true;
            }
        } catch (IOException e) {
            Util.error(e, "can't locate " + url); //$NON-NLS-1$
        }
    }

    url = FileLocator.find(getDefault().getBundle(), alternateNativePath(), null);
    if (url != null) {
        try {
            path = FileLocator.toFileURL(url).getFile();
            embeddedVersion = tryTask("Version", path); //$NON-NLS-1$

            if (checkVersion(embeddedVersion)) {
                setExecutablePath(path);
                return true;
            }
        } catch (IOException e) {
            Util.error(e, "can't locate " + url); //$NON-NLS-1$
        }
    }

    installedVersion = tryTask("Version", LSL_COMMAND); //$NON-NLS-1$
    if (checkVersion(installedVersion)) {
        setExecutablePath(LSL_COMMAND);
        return true;
    }

    StringBuilder versions = new StringBuilder();
    boolean versionFound = false;
    if (preferredVersion != null) {
        versions.append(preferredVersion).append(" (version of executable set in LSLForge Preferences)\n"); //$NON-NLS-1$ TODO
        versionFound = true;
    }
    if (embeddedVersion != null) {
        versions.append(embeddedVersion).append(" (version installed as part of plugin)\n"); //$NON-NLS-1$ TODO
        versionFound = true;
    }
    if (installedVersion != null) {
        versions.append(installedVersion).append(" (version found on PATH)\n"); //$NON-NLS-1$ TODO
        versionFound = true;
    }

    final StringBuilder buf = new StringBuilder();
    if (versionFound) {
        buf.append("The following versions of the LSLForge native executable were found:\n"); //$NON-NLS-1$ TODO
        buf.append(versions);
        buf.append("\nNone of these version are compatible with this plugin, which requires\n"); //$NON-NLS-1$ TODO
        buf.append("version ").append(LSLFORGE_CORE_VERSION).append(".\n"); //$NON-NLS-1$//$NON-NLS-2$ TODO
    } else {
        buf.append("The LSLForge native executable was not found!\n"); //$NON-NLS-1$ TODO
    }
    buf.append("The LSLForge native executable is available from Hackage:\n"); //$NON-NLS-1$ TODO
    buf.append("http://hackage.haskell.org/cgi-bin/hackage-scripts/package/LSLForge\n\n"); //$NON-NLS-1$ TODO
    buf.append("Please also see the Help documentation for LSLForge, under 'Installation'"); //$NON-NLS-1$ TODO
    getWorkbench().getDisplay().asyncExec(new Runnable() {
        public void run() {
            MessageDialog dlg = new MessageDialog(getWorkbench().getActiveWorkbenchWindow().getShell(),
                    "LSLForge Native Executable Problem", //$NON-NLS-1$ TODO
                    null, buf.toString(), MessageDialog.ERROR, new String[] { "Ok" }, //$NON-NLS-1$ TODO
                    0);
            dlg.open();
        }
    });

    return false;
}

From source file:lslplus.LslPlusPlugin.java

License:Open Source License

private boolean determineExecutable() {
    String path = getDefault().getPreferenceStore().getString(LSLPLUS_NATIVE_PATH);
    String preferredVersion = null;
    String embeddedVersion = null;
    String installedVersion = null;
    if (path != null && !"".equals(path.trim())) { //$NON-NLS-1$
        preferredVersion = tryTask("Version", path); //$NON-NLS-1$
        if (checkVersion(preferredVersion)) {
            setExecutablePath(path);//from w  ww  .  j a  v a2s  .  c  o m
            return true;
        }
    }

    URL url = FileLocator.find(getDefault().getBundle(), preferredNativePath(), null);
    if (url != null) {
        try {
            path = FileLocator.toFileURL(url).getFile();
            embeddedVersion = tryTask("Version", path); //$NON-NLS-1$

            if (checkVersion(embeddedVersion)) {
                setExecutablePath(path);
                return true;
            }
        } catch (IOException e) {
            Util.error(e, "can't locate " + url); //$NON-NLS-1$
        }
    }

    url = FileLocator.find(getDefault().getBundle(), alternateNativePath(), null);
    if (url != null) {
        try {
            path = FileLocator.toFileURL(url).getFile();
            embeddedVersion = tryTask("Version", path); //$NON-NLS-1$

            if (checkVersion(embeddedVersion)) {
                setExecutablePath(path);
                return true;
            }
        } catch (IOException e) {
            Util.error(e, "can't locate " + url); //$NON-NLS-1$
        }
    }

    installedVersion = tryTask("Version", LSL_COMMAND); //$NON-NLS-1$
    if (checkVersion(installedVersion)) {
        setExecutablePath(LSL_COMMAND);
        return true;
    }

    StringBuilder versions = new StringBuilder();
    boolean versionFound = false;
    if (preferredVersion != null) {
        versions.append(preferredVersion).append(" (version of executable set in LSL Plus Preferences)\n"); //$NON-NLS-1$ TODO
        versionFound = true;
    }
    if (embeddedVersion != null) {
        versions.append(embeddedVersion).append(" (version installed as part of plugin)\n"); //$NON-NLS-1$ TODO
        versionFound = true;
    }
    if (installedVersion != null) {
        versions.append(installedVersion).append(" (version found on PATH)\n"); //$NON-NLS-1$ TODO
        versionFound = true;
    }

    final StringBuilder buf = new StringBuilder();
    if (versionFound) {
        buf.append("The following versions of the LSL Plus native executable were found:\n"); //$NON-NLS-1$ TODO
        buf.append(versions);
        buf.append("\nNone of these version are compatible with this plugin, which requires\n"); //$NON-NLS-1$ TODO
        buf.append("version ").append(LSLPLUS_CORE_VERSION).append(".\n"); //$NON-NLS-1$//$NON-NLS-2$ TODO
    } else {
        buf.append("The LSL Plus native executable was not found!\n"); //$NON-NLS-1$ TODO
    }
    buf.append("The LSLPlus native executable is available from Hackage:\n"); //$NON-NLS-1$ TODO
    buf.append("http://hackage.haskell.org/cgi-bin/hackage-scripts/pacakge/LslPlus\n\n"); //$NON-NLS-1$ TODO
    buf.append("Please also see the Help documentation for LSL Plus, under 'Installation'"); //$NON-NLS-1$ TODO
    getWorkbench().getDisplay().asyncExec(new Runnable() {
        public void run() {
            MessageDialog dlg = new MessageDialog(getWorkbench().getActiveWorkbenchWindow().getShell(),
                    "LSL Plus Native Executable Problem", //$NON-NLS-1$ TODO
                    null, buf.toString(), MessageDialog.ERROR, new String[] { "Ok" }, //$NON-NLS-1$ TODO
                    0);
            dlg.open();
        }
    });

    return false;
}

From source file:msi.gama.application.Application.java

public static Object checkWorkspace() throws IOException, MalformedURLException {
    final Location instanceLoc = Platform.getInstanceLocation();
    if (instanceLoc == null) {
        // -data @none was specified but GAMA requires a workspace
        MessageDialog.openError(Display.getDefault().getActiveShell(), "Error",
                "A workspace is required to run GAMA");
        return EXIT_OK;
    }/*  w  w w  .j a  v a 2 s.  c om*/
    boolean remember = false;
    String lastUsedWs = null;
    if (instanceLoc.isSet()) {
        lastUsedWs = instanceLoc.getURL().getFile();
        final String ret = WorkspacePreferences.checkWorkspaceDirectory(lastUsedWs, false, false, false);
        if (ret != null) {
            // if ( ret.equals("Restart") ) { return EXIT_RESTART; }
            /* If we dont or cant remember and the location is set, we cant do anything as we need a workspace */
            MessageDialog.openError(Display.getDefault().getActiveShell(), "Error",
                    "The workspace provided cannot be used. Please change it");
            if (PlatformUI.isWorkbenchRunning()) {
                PlatformUI.getWorkbench().close();
            }
            System.exit(0);
            return EXIT_OK;
        }
    } else {

        /* Get what the user last said about remembering the workspace location */
        remember = PickWorkspaceDialog.isRememberWorkspace();
        /* Get the last used workspace location */
        lastUsedWs = PickWorkspaceDialog.getLastSetWorkspaceDirectory();
        /* If we have a "remember" but no last used workspace, it's not much to remember */
        if (remember && (lastUsedWs == null || lastUsedWs.length() == 0)) {
            remember = false;
        }
        if (remember) {
            /*
             * If there's any problem with the workspace, force a dialog
             */
            final String ret = WorkspacePreferences.checkWorkspaceDirectory(lastUsedWs, false, false, false);
            if (ret != null) {
                // if ( ret.equals("Restart") ) { return EXIT_RESTART; }
                if (ret.equals("models")) {
                    final MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(),
                            "Different version of the models library",
                            Display.getCurrent().getSystemImage(SWT.ICON_QUESTION),
                            "The workspace contains a different version of the models library. Do you want to use another workspace ?",
                            MessageDialog.QUESTION, 1, "Use another workspace", "No, thanks");
                    remember = dialog.open() == 1;

                } else {
                    remember = false;
                }
            }
        }
    }

    /* If we don't remember the workspace, show the dialog */
    if (!remember) {
        final int pick = new PickWorkspaceDialog().open();
        /* If the user cancelled, we can't do anything as we need a workspace */
        if (pick == 1 /* Window.CANCEL */ && WorkspacePreferences.getSelectedWorkspaceRootLocation() == null) {
            MessageDialog.openError(Display.getDefault().getActiveShell(), "Error",
                    "The application can not start without a workspace and will now exit.");
            System.exit(0);
            return IApplication.EXIT_OK;
        }
        /* Tell Eclipse what the selected location was and continue */
        instanceLoc.set(new URL("file", null, WorkspacePreferences.getSelectedWorkspaceRootLocation()), false);
        if (WorkspacePreferences.applyPrefs()) {
            WorkspacePreferences
                    .applyEclipsePreferences(WorkspacePreferences.getSelectedWorkspaceRootLocation());
        }
    } else {
        if (!instanceLoc.isSet()) {
            /* Set the last used location and continue */
            instanceLoc.set(new URL("file", null, lastUsedWs), false);
        }

    }

    return null;
}

From source file:net.bioclipse.inchi.ui.InChIDialog.java

License:Open Source License

public static void openInformation(Shell parent, String title, Map<String, String> inchiMap, String message) {
    MessageDialog dialog = new InChIDialog(parent, title, null, // accept
            // the
            // default
            // window
            // icon
            inchiMap, message, INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0);
    // ok is the default
    dialog.open();
    return;/*from   w w w .jav  a  2  s. c om*/
}

From source file:net.bioclipse.structuredb.actions.RemoveAllDatabasesAction.java

License:Open Source License

@Override
public void run(IAction action) {

    MessageDialog dialog = new MessageDialog(null, "Confirm removal of all databases", null,
            "Really remove all databases?", MessageDialog.QUESTION, new String[] { "Yes", "Cancel" }, 0); // yes is the default

    int result = dialog.open();

    if (result == 0) {
        Activator.getDefault().getStructuredbManager().deleteAllDatabases();
    }/*  w w w .j  a  va  2s  .  co  m*/
}

From source file:net.bioclipse.ui.dialogs.SaveAsDialog.java

License:Open Source License

protected void okPressed() {
    // Get new path.
    IPath path = resourceGroup.getContainerFullPath().append(resourceGroup.getResource());

    //If the user does not supply a file extension and if the save 
    //as dialog was provided a default file name append the extension 
    //of the default filename to the new name
    if (path.getFileExtension() == null) {
        if (originalFile != null && originalFile.getFileExtension() != null) {
            path = path.addFileExtension(originalFile.getFileExtension());
        } else if (originalName != null) {
            int pos = originalName.lastIndexOf('.');
            if (++pos > 0 && pos < originalName.length()) {
                path = path.addFileExtension(originalName.substring(pos));
            }//from   ww  w.  j  a va 2  s  . c  om
        }
    }

    // If the path already exists then confirm overwrite.
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
    if (file.exists()) {
        String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                IDialogConstants.CANCEL_LABEL };
        String question = NLS.bind(IDEWorkbenchMessages.SaveAsDialog_overwriteQuestion, path.toString());
        MessageDialog d = new MessageDialog(getShell(), IDEWorkbenchMessages.Question, null, question,
                MessageDialog.QUESTION, buttons, 0);
        int overwrite = d.open();
        switch (overwrite) {
        case 0: // Yes
            break;
        case 1: // No
            return;
        case 2: // Cancel
        default:
            cancelPressed();
            return;
        }
    }

    // Store path and close.
    result = path;
    close();
}