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

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

Introduction

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

Prototype

int WARNING

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

Click Source Link

Document

Constant for the warning image, or a simple dialog with the warning image and a single OK button (value 4).

Usage

From source file:org.thanlwinsoft.doccharconvert.eclipse.EclipseMessageDisplay.java

License:Open Source License

public void showWarningMessage(final String message, final String title) {
    final String warningMessage = message;
    shell.getDisplay().asyncExec(new Runnable() {
        public void run() {
            if (message.length() < 80) {
                MessageDialog.openWarning(shell, title, message);
                return;
            }//from ww w . j a  v a2 s  .  co  m
            MessageDialog dialog = new MessageDialog(shell, title, null, title, MessageDialog.WARNING,
                    new String[] { MessageUtil.getString("OK") }, 0) {

                //                    /*
                //                     * (non-Javadoc)
                //                     * 
                //                     * @see org.eclipse.jface.dialogs.MessageDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
                //                     */
                //                    @Override
                //                    protected Control createMessageArea(Composite parent)
                //                    {
                //                        final ScrolledComposite sc1 = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
                //                        GridData outerData = new GridData(500, 200);
                //                        sc1.setLayoutData(outerData);
                //                        final Composite c1 = new Composite(sc1, SWT.NONE);
                //                        sc1.setContent(c1);
                //                        GridLayout layout = new GridLayout();
                //                        c1.setLayout(layout);
                //                        Label l = new Label(c1, SWT.LEAD);
                //                        l.setText(warningMessage);
                //                        c1.setSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
                //                        return sc1;
                //                    }

                /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.jface.dialogs.MessageDialog#createCustomArea(org.eclipse.swt.widgets.Composite)
                 */
                @Override
                protected Control createCustomArea(Composite parent) {
                    final ScrolledComposite sc1 = new ScrolledComposite(parent,
                            SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
                    GridData outerData = new GridData(500, 200);
                    sc1.setLayoutData(outerData);
                    final Composite c1 = new Composite(sc1, SWT.NONE);
                    sc1.setContent(c1);
                    GridLayout layout = new GridLayout();
                    c1.setLayout(layout);
                    Label l = new Label(c1, SWT.LEAD);
                    l.setText(warningMessage);
                    c1.setSize(c1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
                    return sc1;
                }
            };
            dialog.open();
            // MessageBox msgBox = new MessageBox(shell, SWT.ICON_WARNING |
            // SWT.OK);
            // msgBox.setMessage(message);
            // msgBox.setText(title);
            // msgBox.open();
        }
    });
}

From source file:org.universaal.uaalpax.ui.VersionBlock.java

License:Apache License

public boolean tryChangeToVersion(String newVersion) {
    BundleModel model = getUAALTab().getModel();
    // find out which projects have to be checked for compatibility
    Set<ArtifactURL> toCheck = model.getIncompatibleProjects(newVersion);

    // now to check only contains incompatible projects
    if (toCheck.isEmpty()) { // everything ok, no incompatible projects
        model.changeToVersion(newVersion);
        return true;
    } else { // ask user what to do
        StringBuilder sb = new StringBuilder();
        sb.append("Following projects are dependent from some bundles of the old version: \n\n");
        for (ArtifactURL url : toCheck)
            sb.append("\t").append(url).append("\n");
        sb.append("\nWhat do do?");

        MessageDialog md = new MessageDialog(getShell(), "Compatibility issues", null, sb.toString(),
                MessageDialog.WARNING, new String[] { "Ignore", "Remove those projects", "Cancel" }, 0);

        int ret = md.open();
        if (ret == 0) {// ignore
            model.changeToVersion(newVersion);
            return true;
        } else if (ret == 1) { // remove incompatible
            for (ArtifactURL url : toCheck)
                getUAALTab().getModel().removeNoUpdate(getUAALTab().getModel().getBundles().find(url));

            // model will be updated here
            model.changeToVersion(newVersion);
            return true;
        }//w  w w  .  j a v a 2 s .  co  m
        // else cancel -> do nothing
        return false;
    }
}

From source file:org.wesnoth.ui.editor.WMLEditor.java

License:Open Source License

@Override
protected void performSaveAs(IProgressMonitor progressMonitor) {

    Shell shell = getSite().getShell();//from   ww  w.ja v a 2s  . c o m
    final IEditorInput input = getEditorInput();

    // Customize save as if the file is linked, and it is in the special
    // external link project
    //
    if (input instanceof IFileEditorInput && ((IFileEditorInput) input).getFile().isLinked()
            && ((IFileEditorInput) input).getFile().getProject().getName().equals(AUTOLINK_PROJECT_NAME)) {
        final IEditorInput newInput;
        IDocumentProvider provider = getDocumentProvider();

        FileDialog dialog = new FileDialog(shell, SWT.SAVE);
        IPath oldPath = URIUtil.toPath(((IURIEditorInput) input).getURI());
        if (oldPath != null) {
            dialog.setFileName(oldPath.lastSegment());
            dialog.setFilterPath(oldPath.toOSString());
        }

        dialog.setFilterExtensions(new String[] { "*.b3", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
        String path = dialog.open();
        if (path == null) {
            if (progressMonitor != null) {
                progressMonitor.setCanceled(true);
            }
            return;
        }

        // Check whether file exists and if so, confirm overwrite
        final File localFile = new File(path);
        if (localFile.exists()) {
            MessageDialog overwriteDialog = new MessageDialog(shell, Messages.WMLEditor_0, null,
                    path + Messages.WMLEditor_1, MessageDialog.WARNING,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1); // 'No' is the
                                                                                                                                                                                                                                         // default
            if (overwriteDialog.open() != Window.OK) {
                if (progressMonitor != null) {
                    progressMonitor.setCanceled(true);
                    return;
                }
            }
        }

        IFileStore fileStore;
        try {
            fileStore = EFS.getStore(localFile.toURI());
        } catch (CoreException ex) {
            Logger.getInstance().logException(ex);
            String title = Messages.WMLEditor_2;
            String msg = Messages.WMLEditor_3 + ex.getMessage();
            MessageDialog.openError(shell, title, msg);
            return;
        }

        IFile file = getWorkspaceFile(fileStore);
        if (file != null) {
            newInput = new FileEditorInput(file);
        } else {
            IURIEditorInput uriInput = new FileStoreEditorInput(fileStore);
            java.net.URI uri = uriInput.getURI();
            IFile linkedFile = obtainLink(uri);

            newInput = new FileEditorInput(linkedFile);
        }

        if (provider == null) {
            // editor has programmatically been closed while the dialog was
            // open
            return;
        }

        boolean success = false;
        try {

            provider.aboutToChange(newInput);
            provider.saveDocument(progressMonitor, newInput, provider.getDocument(input), true);
            success = true;

        } catch (CoreException x) {
            Logger.getInstance().logException(x);
            final IStatus status = x.getStatus();
            if (status == null || status.getSeverity() != IStatus.CANCEL) {
                String title = Messages.WMLEditor_4;
                String msg = Messages.WMLEditor_5 + x.getMessage();
                MessageDialog.openError(shell, title, msg);
            }
        } finally {
            provider.changed(newInput);
            if (success) {
                setInput(newInput);
            }
        }

        if (progressMonitor != null) {
            progressMonitor.setCanceled(!success);
        }

        return;
    }

    super.performSaveAs(progressMonitor);
}

From source file:org.wso2.developerstudio.eclipse.platform.core.startup.alert.JavaVersionAlertHandler.java

License:Open Source License

@Override
public void earlyStartup() {
    final String version = System.getProperty(JAVA_VERSION_PROPERTY);
    //If Developer Studio starts with an unsupported version, then show a warning
    double detectedJavaVersion = getJavaVersionInDouble(version);
    if (detectedJavaVersion < Constants.MINIMUM_REQUIRED_JAVA_VERSION) {
        final IWorkbench workbench = PlatformUI.getWorkbench();
        workbench.getDisplay().asyncExec(new Runnable() {
            public void run() {
                if (workbench.getDisplay() != null) {
                    Shell shell = new Shell(workbench.getDisplay());

                    Monitor primaryMonitor = workbench.getDisplay().getPrimaryMonitor();
                    Rectangle primaryBounds = primaryMonitor.getBounds();
                    Rectangle shellBounds = shell.getBounds();

                    //Calculating center position to show message dialog
                    int xCenter = primaryBounds.x + (primaryBounds.width - shellBounds.width) / 2;
                    int yCenter = primaryBounds.y + (primaryBounds.height - shellBounds.height) / 2;

                    shell.setLocation(xCenter, yCenter);

                    String warningMessage = Constants.DETECTED_JAVA_VERSION_MESSAGE + version + "\n"
                            + Constants.RECOMMENDED_JAVA_VERSION_MESSAGE
                            + Constants.MINIMUM_REQUIRED_JAVA_VERSION + "\n"
                            + Constants.JAVA_VERSION_ALERT_MESSAGE;
                    MessageDialog dialog = new MessageDialog(shell, ALERT_TITLE, null, warningMessage,
                            MessageDialog.WARNING, new String[] { OK_BUTTON }, 0);
                    dialog.open();//  w  w w . ja  v  a  2s .  c  o  m
                }
            }
        });
    }
}

From source file:org2.eclipse.php.internal.debug.core.launching.XDebugExeLaunchConfigurationDelegate.java

License:Open Source License

private boolean showPortWarningDialog(final String message, final ILaunchConfiguration configuration) {
    final String[] buttonsLabels = new String[] { "Change Port", "Edit ini", "Ignore" };
    final boolean[] result = new boolean[1];
    result[0] = true;//w w w. j a va 2 s . c  o m
    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            MessageDialog dialog = new MessageDialog(null, "XDebug port verification", null, message,
                    MessageDialog.WARNING, buttonsLabels, 0) {
                protected void buttonPressed(int buttonId) {
                    try {
                        if (buttonId == 0) {
                            // Set the return code to Cancel
                            okPressed();
                            openDebuggerConfigurationDialog(configuration);
                        } else if (buttonId == 1) {
                            // Open the interpreters preferences to edit the ini
                            okPressed();
                            openInterpretersPage(configuration);
                        } else {
                            // Ignore button was selected, so set the return code should be set to OK
                            cancelPressed();
                        }
                    } catch (CoreException e) {
                        PHPDebugEPLPlugin.logError("Error while showing the xdebug warning dialog", e);
                    }
                }
            };

            if (dialog.open() == MessageDialog.OK) {
                result[0] = false; // Ignore
            }
        }
    });
    return result[0];
}

From source file:phasereditor.ide.intro.PhaserIDE.java

License:Open Source License

/**
 * Return true if the argument directory is ok to use as a workspace and
 * false otherwise. A version check will be performed, and a confirmation
 * box may be displayed on the argument shell if an older version is
 * detected.//w  w w  . jav  a  2 s  .  c  o  m
 * 
 * @return true if the argument URL is ok to use as a workspace and false
 *         otherwise.
 */
private static boolean checkValidWorkspace(Shell shell, URL url) {
    // a null url is not a valid workspace
    if (url == null) {
        return false;
    }

    if (WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION == null) {
        // no reference bundle installed, no check possible
        return true;
    }

    Version version = readWorkspaceVersion(url);
    // if the version could not be read, then there is not any existing
    // workspace data to trample, e.g., perhaps its a new directory that
    // is just starting to be used as a workspace
    if (version == null) {
        return true;
    }

    final Version ide_version = toMajorMinorVersion(WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION);
    Version workspace_version = toMajorMinorVersion(version);
    int versionCompareResult = workspace_version.compareTo(ide_version);

    // equality test is required since any version difference (newer
    // or older) may result in data being trampled
    if (versionCompareResult == 0) {
        return true;
    }

    // At this point workspace has been detected to be from a version
    // other than the current ide version -- find out if the user wants
    // to use it anyhow.
    int severity;
    String title;
    String message;
    if (versionCompareResult < 0) {
        // Workspace < IDE. Update must be possible without issues,
        // so only inform user about it.
        severity = MessageDialog.INFORMATION;
        title = IDEWorkbenchMessages.IDEApplication_versionTitle_olderWorkspace;
        message = NLS.bind(IDEWorkbenchMessages.IDEApplication_versionMessage_olderWorkspace, url.getFile());
    } else {
        // Workspace > IDE. It must have been opened with a newer IDE
        // version.
        // Downgrade might be problematic, so warn user about it.
        severity = MessageDialog.WARNING;
        title = IDEWorkbenchMessages.IDEApplication_versionTitle_newerWorkspace;
        message = NLS.bind(IDEWorkbenchMessages.IDEApplication_versionMessage_newerWorkspace, url.getFile());
    }

    MessageDialog dialog = new MessageDialog(shell, title, null, message, severity,
            new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
    return dialog.open() == Window.OK;
}

From source file:pt.org.aguiaj.core.exceptions.ExceptionHandler.java

License:Open Source License

public void handleException(Object target, Member member, String[] args, Throwable exception) {
    if (exception.getCause() != null)
        exception = exception.getCause();

    String message = exception.getMessage();
    if (message == null)
        message = "";

    if (target != null) {
        if (objectsWithProblems.contains(target))
            return;
        else/*from ww  w  . j  a  v a2 s  .  c o m*/
            objectsWithProblems.add(target);
    }

    String title = StandardNamePolicy.prettyClassName(exception.getClass());
    int icon = MessageDialog.ERROR;

    if (exception instanceof IllegalArgumentException || exception instanceof IllegalStateException
            || exception instanceof NullPointerException && exception.getMessage() != null
            || exception instanceof ContractException) {
        icon = MessageDialog.WARNING;
    } else if (exception instanceof StackOverflowError) {
        title = UIText.STACK_OVERFLOW.get();
        String methodText = member.getDeclaringClass().getSimpleName() + "." + member.getName() + "(..)";
        message = UIText.CHECK_METHOD_RECURSION.get(methodText);
        if (member != null)
            previousMethodErrors.add(member);
    } else if (exception instanceof OutOfMemoryError) {
        title = UIText.OUT_OF_MEMORY.get();
        String methodText = member.getDeclaringClass().getSimpleName() + "." + member.getName() + "(..)";
        message = "Check method " + methodText + ".";
        if (member != null)
            previousMethodErrors.add(member);
    } else if (exception instanceof Error) {
        title = UIText.COMPILATION_ERRORS.get();
        int line = exception.getStackTrace()[0].getLineNumber();
        String className = exception.getStackTrace()[0].getClassName();
        message = UIText.CHECK_CLASS_AT.get(className, line, exception.getMessage());
        if (member != null)
            previousMethodErrors.add(member);
    } else {
        for (SpecificExceptionHandler handler : handlers)
            if (handler.getClass().getAnnotation(PluggableExceptionHandler.class).value()
                    .equals(exception.getClass()))
                message = handler.getMessage(exception);
    }

    ExceptionTrace exceptionTrace = new ExceptionTrace(exception, message, args);
    List<TraceLocation> trace = exceptionTrace.getTrace();
    boolean goToError = !trace.isEmpty() && trace.get(0).line != 1;

    String[] buttons = goToError ? new String[] { "OK", "Go to error" } : new String[] { "OK" };
    MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), title, null, message, icon,
            buttons, 0);

    int result = dialog.open();

    if (!trace.isEmpty()) {
        for (ExceptionListener l : listeners)
            l.newException(exceptionTrace, result != 0);
    }
}

From source file:ptolemy.backtrack.eclipse.plugin.actions.codestyle.SortMembersUtility.java

License:Open Source License

public static void sortICompilationUnit(ICompilationUnit compilationUnit, IEditorPart editor) {
    Shell shell = editor.getEditorSite().getShell();

    if (compilationUnit == null) {
        return;/*from  w w w  .ja va  2 s .  c  om*/
    }

    if (!ActionUtil.isProcessable(shell, compilationUnit)) {
        return;
    }

    if (!ElementValidator.check(compilationUnit, shell, ActionMessages.SortMembersAction_dialog_title, false)) {
        return;
    }

    if (editor != null && containsRelevantMarkers(editor)) {
        int returnCode = OptionalMessageDialog.open(
                "ptolemy.backtrack.eclipse.plugin.actions." + "SortMembersAction", shell,
                ActionMessages.SortMembersAction_dialog_title, null,
                ActionMessages.SortMembersAction_containsmarkers, MessageDialog.WARNING,
                new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
        if (returnCode != OptionalMessageDialog.NOT_SHOWN && returnCode != Window.OK) {
            return;
        }
    }

    ISchedulingRule schedulingRule = ResourcesPlugin.getWorkspace().getRoot();
    PtolemySortMembersOperation operation = new PtolemySortMembersOperation(compilationUnit, null, false);
    try {
        BusyIndicatorRunnableContext context = new BusyIndicatorRunnableContext();
        PlatformUI.getWorkbench().getProgressService().runInUI(context,
                new WorkbenchRunnableAdapter(operation, schedulingRule), schedulingRule);
    } catch (InvocationTargetException e) {
        OutputConsole.outputError(e.getMessage());
    } catch (InterruptedException e) {
        // Do nothing. Operation has been canceled by user.
    }
}

From source file:rhogenwizard.launcher.rhoelements.LicMessageJob.java

@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
    Shell windowShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

    String[] a = { "OK", "Cancel" };

    MessageDialog messageBox = new MessageDialog(windowShell, "Warrning", null,
            MsgConstants.rhoelementsWarrningLicense, MessageDialog.WARNING, a, 0);
    retValue = messageBox.open();/*w  w w  . j  a va  2s .  c o  m*/

    return Status.OK_STATUS;
}

From source file:sernet.verinice.rcp.search.SearchView.java

License:Open Source License

private boolean isSearchConfirmed() {
    final int ok = 0;
    int result = ok;

    if (isQueryEmpty()) {
        MessageDialog dialog = new MessageDialog(getShell(), Messages.SearchView_29, null,
                Messages.SearchView_16, MessageDialog.WARNING,
                new String[] { Messages.SearchView_27, Messages.SearchView_28 }, 0);
        result = dialog.open();/*from w w w  . j  a v  a 2  s  .c o  m*/
    }

    return result == ok;
}