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

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

Introduction

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

Prototype

public MessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage,
        int dialogImageType, int defaultIndex, String... dialogButtonLabels) 

Source Link

Document

Create a message dialog.

Usage

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);//w ww .  ja v a2 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 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: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();
    }/*ww  w . j a  va  2 s .  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));
            }/*w  ww . ja v a 2s  .c  o m*/
        }
    }

    // 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();
}

From source file:net.bpelunit.toolsupport.editors.BPELUnitEditor.java

License:Open Source License

public Definition getWsdlForFile(String wsdl) throws WSDLReadingException {

    IPath path = new Path(wsdl);
    IResource resource = null;/*from  w  ww  .  j  a  v  a2  s . c  om*/

    // try to find from current dir:
    resource = this.getCurrentDirectory().findMember(wsdl);

    // try to find from project dir:
    if (this.notFound(resource)) {
        resource = this.getCurrentProject().findMember(path);
    }

    if (this.notFound(resource)) {
        resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
    }

    // all hope failed...
    if (this.notFound(resource)) {
        throw new WSDLReadingException("Cannot find WSDL file with file path " + wsdl);
    }

    IFile file = (IFile) resource;

    // TODO caching probably NOT a good idea at all.
    Definition definition = this.fWSDLDefinitions.get(file);

    if (definition == null) {
        String fileName = file.getRawLocation().toFile().toString();
        // load WSDL
        try {
            WSDLFactory factory = WSDLFactory.newInstance();
            WSDLReader reader = factory.newWSDLReader();
            // reader.setFeature(Constants.FEATURE_VERBOSE, false);

            definition = reader.readWSDL(null, fileName);
            this.fWSDLDefinitions.put(file, definition);

            WSDLParser parser = new WSDLParser(definition);
            this.fWSDLParser.put(definition, parser);

        } catch (WSDLException e) {
            throw new WSDLReadingException("Error loading WSDL file for partner", e);
        } catch (SAXException e) {
            MessageDialog dialog = new MessageDialog(this.getShell(), "Invalid Schema", null, e.getMessage(),
                    MessageDialog.ERROR, new String[] { "OK" }, 0);
            dialog.open();
            throw new WSDLReadingException("Error reading Schemata in WSDL: " + e.getMessage(), e);
        } catch (TransformerException e) {
            MessageDialog dialog = new MessageDialog(this.getShell(), "Invalid Schema", null, e.getMessage(),
                    MessageDialog.ERROR, new String[] { "OK" }, 0);
            dialog.open();
            throw new WSDLReadingException("Error reading Schemata in WSDL: " + e.getMessage(), e);
        }
    }
    return definition;

}

From source file:net.geoprism.shapefile.LocalizedWizardDialog.java

License:Open Source License

/**
 * Creates and return a new wizard closing dialog without opening it.
 * /*from   w ww . j a v a 2 s .c om*/
 * @return MessageDalog
 */
private MessageDialog createWizardClosingDialog() {
    MessageDialog result = new MessageDialog(getShell(), Localizer.getMessage("WINDOW_CLOSING_TITLE"), //$NON-NLS-1$
            null, Localizer.getMessage("WINDOW_CLOSING"), //$NON-NLS-1$
            MessageDialog.QUESTION, new String[] { Localizer.getMessage("OK") }, 0) {
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    return result;
}

From source file:net.leboxondelex.daplomb.utils.Utils.java

License:Open Source License

/**
 * Opens a message dialog with a the inner i18n system.
 * @param parent/*from  ww  w  .j a  va2 s. c  o m*/
 * @param title
 * @param message
 * @return true if the user presses the "yes" button
 */
public static boolean showQuestion(Shell parent, String title, String message) {
    MessageDialog dialog = new MessageDialog(parent, title, null, message, MessageDialog.QUESTION,
            new String[] { "Oui", "Non" }, 0);

    return dialog.open() == 0;
}

From source file:net.leboxondelex.daplomb.utils.Utils.java

License:Open Source License

/**
 * Opens an error dialog with a the inner i18n system.
 * @param parent/* ww  w  . j  av  a2  s .  com*/
 * @param title
 * @param message
 */
public static void showError(Shell parent, String title, String message) {
    MessageDialog dialog = new MessageDialog(parent, title, null, message, MessageDialog.ERROR,
            new String[] { "OK" }, 0);

    dialog.open();
}

From source file:net.refractions.udig.catalog.internal.worldimage.InMemoryCoverageLoader.java

License:Open Source License

private void updateMemoryLevel() throws IOException {

    int heap;// ww w. j a  v a 2 s  . co  m
    int originalHeap = UiPlugin.getMaxHeapSize();
    if (originalHeap < 700) {
        heap = 1024;
    } else if (originalHeap < 1500) {
        heap = 2048;
    } else {
        heap = originalHeap * 2;
    }

    String os = Platform.getOS();
    if (heap > 1024 && os == Platform.OS_WIN32) {
        heap = 1024;
    }

    final int finalHeap = heap;
    coverage = new SoftReference<GridCoverage>(EMPTY_COVERAGE);

    Display.getDefault().asyncExec(new Runnable() {

        public void run() {

            Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
            String title = InMemoryCoverageLoader_msgTitle;
            String desc = MessageFormat.format(InMemoryCoverageLoader_message, resource.getIdentifier(),
                    finalHeap);
            String[] buttons = { InMemoryCoverageLoader_restart_button, InMemoryCoverageLoader_close_button };
            MessageDialog dialog = new MessageDialog(shell, title, null, desc, QUESTION, buttons, 0) {

                @Override
                protected void buttonPressed(int buttonId) {
                    if (buttonId == 0) {
                        try {
                            UiPlugin.setMaxHeapSize(String.valueOf(finalHeap));
                            PlatformUI.getWorkbench().restart();

                        } catch (IOException e) {
                            throw (RuntimeException) new RuntimeException().initCause(e);
                        }
                    }
                    super.buttonPressed(buttonId);
                }
            };
            dialog.open();

        }
    });
}

From source file:net.refractions.udig.ui.dialogs.WizardDataTransferPage.java

License:Open Source License

/**
 * Displays a Yes/No question to the user with the specified message and returns
 * the user's response./* w  w w. jav a 2  s  .c  o m*/
 *
 * @param message the question to ask
 * @return <code>true</code> for Yes, and <code>false</code> for No
 */
protected boolean queryYesNoQuestion(String message) {
    MessageDialog dialog = new MessageDialog(getContainer().getShell(),
            Messages.WizardDataTransferPage_dialog_title, (Image) null, message, MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
    // ensure yes is the default

    return dialog.open() == 0;
}

From source file:net.refractions.udig.ui.ZoomingDialog.java

License:Open Source License

/**
 * Create a message dialog. Notethat the dialog will have no visual
 * representation (no widgets) until it is told to open.
 * <p>/*from w  w w .  j  a va2  s. c  om*/
 * The labels of the buttons to appear in the button bar are supplied in
 * this constructor as an array. The <code>open</code> method will return
 * the index of the label in this array corresponding to the button that was
 * pressed to close the dialog. If the dialog was dismissed without pressing
 * a button (ESC, etc.) then -1 is returned. Note that the <code>open</code>
 * method blocks.
 * </p>
 * 
 * @param start 
 *            the location to zoom from.
 * @param parentShell
 *            the parent shell
 * @param dialogTitle
 *            the dialog title, or <code>null</code> if none
 * @param dialogTitleImage
 *            the dialog title image, or <code>null</code> if none
 * @param dialogMessage
 *            the dialog message
 * @param dialogImageType
 *            one of the following values:
 *            <ul>
 *            <li><code>MessageDialog.NONE</code> for a dialog with no
 *            image</li>
 *            <li><code>MessageDialog.ERROR</code> for a dialog with an
 *            error image</li>
 *            <li><code>MessageDialog.INFORMATION</code> for a dialog
 *            with an information image</li>
 *            <li><code>MessageDialog.QUESTION </code> for a dialog with a
 *            question image</li>
 *            <li><code>MessageDialog.WARNING</code> for a dialog with a
 *            warning image</li>
 *            </ul>
 * @param dialogButtonLabels
 *            an array of labels for the buttons in the button bar
 * @param defaultIndex
 *            the index in the button label array of the default button
 * @return 
 */
public static int openMessageDialog(Rectangle start, Shell parentShell, String dialogTitle, Image dialogImage,
        String dialogMessage, int dialogImageType, String[] buttonLabels, int defaultIndex) {

    MessageDialog dialog = new MessageDialog(parentShell, dialogTitle, dialogImage, dialogMessage,
            dialogImageType, buttonLabels, defaultIndex);
    ZoomingDialog zd = new ZoomingDialog(parentShell, dialog, start);

    zd.open();
    return zd.getReturnCode();
}