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

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

Introduction

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

Prototype

int WARNING

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

Click Source Link

Document

Constant for a warning message (value 2).

Usage

From source file:org.eclipse.tcf.te.ui.controls.net.RemoteHostAddressControl.java

License:Open Source License

/**
 * If the user entered a host name, we have to validate that we can really resolve the name
 * to an IP address. Because this may really take a while, give the user the feedback what
 * we are actually doing./* w w w.  java  2  s  .co  m*/
 */
private void onCheckAddress() {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getParentControl().getShell());
    try {
        dialog.run(false, false, new IRunnableWithProgress() {
            private final String address = getEditFieldControlText();
            private final Control control = getEditFieldControl();
            private final IDialogPage parentPage = getParentPage();

            /* (non-Javadoc)
             * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
             */
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    monitor.setTaskName(getTaskNameCheckNameAddress());
                    InetAddress[] addresses = InetAddress.getAllByName(address);
                    if (Platform.inDebugMode() && addresses != null) {
                        StringBuilder message = new StringBuilder();
                        message.append("RemoteHostAddressControl: Name '"); //$NON-NLS-1$
                        message.append(address);
                        message.append("' resolves to: "); //$NON-NLS-1$
                        boolean firstAddress = true;
                        for (InetAddress address : addresses) {
                            if (!firstAddress)
                                message.append(", "); //$NON-NLS-1$
                            message.append(address.getHostAddress());
                            firstAddress = false;
                        }

                        IStatus status = new Status(IStatus.WARNING, UIPlugin.getUniqueIdentifier(),
                                message.toString());
                        UIPlugin.getDefault().getLog().log(status);
                    }

                    setCheckResultMessage(IMessageProvider.INFORMATION,
                            getInformationTextCheckNameAddressSuccess());
                } catch (Exception e) {
                    setCheckResultMessage(IMessageProvider.WARNING, getErrorTextCheckNameAddressFailed());
                    control.setFocus();
                } finally {
                    // Trigger the wizard container update
                    IWizardContainer container = null;

                    try {
                        // Try to get the wizard container from the parent page
                        if (parentPage != null) {
                            Class<?>[] paramTypes = new Class[0];
                            Object[] args = new Object[0];
                            final Method method = parentPage.getClass().getMethod("getContainer", paramTypes); //$NON-NLS-1$
                            if (!method.isAccessible()) {
                                AccessController.doPrivileged(new PrivilegedAction<Object>() {
                                    @Override
                                    public Object run() {
                                        method.setAccessible(true);
                                        return null;
                                    }
                                });
                            }
                            Object result = method.invoke(parentPage, args);
                            if (result instanceof IWizardContainer) {
                                container = (IWizardContainer) result;
                            }
                        }
                    } catch (Exception e) {
                        // If the object does not have a "getContainer()" method,
                        // or the invocation fails or the access to the method
                        // is denied, we are done here and break the loop
                        container = null;
                    }

                    if (container != null) {
                        container.updateButtons();
                        container.updateMessage();
                    }
                }
            }
        });
    } catch (Exception e) {
    }
}

From source file:org.eclipse.tcf.te.ui.search.TreeViewerSearchDialog.java

License:Open Source License

@Override
public void searchDone(IStatus status, TreePath path) {
    Button btn = getButton(SEARCH_ID);
    if (btn != null && !btn.isDisposed()) {
        btn.setEnabled(true);//  www. j a v a 2 s. c  o m
        btn.setFocus();
    }
    if (status.isOK()) {
        if (path == null) {
            if (fSearcher.isWrap()) {
                if (fSearcher.getLastResult() == null) {
                    String message = fSearchable.getCustomMessage(rootElement,
                            "TreeViewerSearchDialog_NoSuchNode"); //$NON-NLS-1$
                    setMessage(message != null ? message : Messages.TreeViewerSearchDialog_NoSuchNode,
                            IMessageProvider.WARNING);
                }
            } else {
                String message = fSearchable.getCustomMessage(rootElement,
                        "TreeViewerSearchDialog_NoMoreNodeFound"); //$NON-NLS-1$
                setMessage(message != null ? message : Messages.TreeViewerSearchDialog_NoMoreNodeFound,
                        IMessageProvider.WARNING);
            }
        } else {
            this.setErrorMessage(null);
            setMessage(null);
        }
    } else {
        this.setErrorMessage(null);
        setMessage(null);
    }
}

From source file:org.eclipse.tcf.te.ui.views.editor.pages.AbstractEditorPage.java

License:Open Source License

/**
 * Get the image for the given message type.
 * @param messageType The message type.//from www . j  av  a  2 s .c  o  m
 * @return The image.
 */
protected Image getMessageImage(int messageType) {
    switch (messageType) {
    case IMessageProvider.INFORMATION:
        return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO);
    case IMessageProvider.WARNING:
        return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
    case IMessageProvider.ERROR:
        return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
    default:
        return null;
    }
}

From source file:org.eclipse.team.internal.ccvs.ui.IgnoreResourcesDialog.java

License:Open Source License

private void setWarning(String text) {
    setError(null);
    setMessage(text, IMessageProvider.WARNING);
}

From source file:org.eclipse.team.svn.ui.wizard.AbstractVerifiedWizardPage.java

License:Open Source License

public void setMessage(String newMessage, int newType) {
    if (newType == IMessageProvider.WARNING) {
        //NOTE Eclipse workaround: all warnings are rendered as animated but old message does not cleared. So, old error still visible after warning is shown.
        AbstractVerifiedWizardPage.this.setMessage("", IMessageProvider.NONE); //$NON-NLS-1$
        //NOTE Eclipse workaround: clear error message before setting warning message
        AbstractVerifiedWizardPage.this.setErrorMessage(null);
        super.setMessage(newMessage, newType);
    } else if (newType == IMessageProvider.ERROR) {
        //NOTE Eclipse workaround: all warnings are rendered as animated but old message does not cleared. So, old error still visible after warning is shown.
        AbstractVerifiedWizardPage.this.setMessage("", IMessageProvider.NONE); //$NON-NLS-1$
        //NOTE Eclipse workaround: error will be rendered as animated only when setErrorMessage() is used.
        AbstractVerifiedWizardPage.this.setErrorMessage(newMessage);
    } else {/*ww w  .  ja va 2  s  . c o m*/
        //NOTE Eclipse workaround: clear error message before setting default message
        AbstractVerifiedWizardPage.this.setErrorMessage(null);
        super.setMessage(newMessage, newType);
    }
}

From source file:org.eclipse.tm.internal.terminal.provisional.api.AbstractSettingsPage.java

License:Open Source License

/**
 * Updates the control decoration of the given control to represent the given message
 * and message type. If the message is <code>null</code> or the message type is
 * {@link IMessageProvider#NONE} no decoration will be shown.
 *
 * @param control The control. Must not be <code>null</code>.
 * @param message The message.//from   www .java2 s.c o  m
 * @param messageType The message type.
 */
protected final void updateControlDecoration(Control control, String message, int messageType) {
    Assert.isNotNull(control);

    ControlDecoration controlDecoration = (ControlDecoration) control.getData("controlDecoration"); //$NON-NLS-1$
    if (controlDecoration != null) {
        // The description is the same as the message
        controlDecoration.setDescriptionText(message);

        // The icon depends on the message type
        FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault();

        // Determine the id of the decoration to show
        String decorationId = FieldDecorationRegistry.DEC_INFORMATION;
        if (messageType == IMessageProvider.ERROR) {
            decorationId = FieldDecorationRegistry.DEC_ERROR;
        } else if (messageType == IMessageProvider.WARNING) {
            decorationId = FieldDecorationRegistry.DEC_WARNING;
        }

        // Get the field decoration
        FieldDecoration fieldDeco = registry.getFieldDecoration(decorationId);
        if (fieldDeco != null) {
            controlDecoration.setImage(fieldDeco.getImage());
        }

        if (message == null || messageType == IMessageProvider.NONE) {
            controlDecoration.hide();
        } else {
            controlDecoration.show();
        }
    }
}

From source file:org.eclipse.tm.te.ui.controls.BaseEditBrowseTextControl.java

License:Open Source License

/**
 * Updates the given edit field control decoration to represent the given
 * message and message type.//from ww w  .  ja  v a 2  s .  co  m
 *
 * @param decoration The control decoration. Must not be <code>null</code>.
 * @param message The message. Must not be <code>null</code>.
 * @param messageType The message type.
 */
protected void updateEditFieldControlDecorationForMessage(ControlDecoration decoration, String message,
        int messageType) {
    Assert.isNotNull(decoration);
    Assert.isNotNull(message);

    // The description is the same as the message
    decoration.setDescriptionText(message);

    // The icon depends on the message type
    FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault();

    // Determine the id of the decoration to show
    String decorationId = FieldDecorationRegistry.DEC_INFORMATION;
    if (messageType == IMessageProvider.ERROR) {
        decorationId = FieldDecorationRegistry.DEC_ERROR;
    } else if (messageType == IMessageProvider.WARNING) {
        decorationId = FieldDecorationRegistry.DEC_WARNING;
    }

    // Get the field decoration
    FieldDecoration fieldDeco = registry.getFieldDecoration(decorationId);
    if (fieldDeco != null) {
        decoration.setImage(fieldDeco.getImage());
    }
}

From source file:org.eclipse.tm.te.ui.controls.net.RemoteHostAddressControl.java

License:Open Source License

/**
 * If the user entered a host name, we have to validate that we can really resolve the name
 * to an IP address. Because this may really take a while, give the user the feedback what
 * we are actually doing./* ww w  . ja v  a 2  s. c  o m*/
 */
private void onCheckAddress() {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getParentControl().getShell());
    try {
        dialog.run(false, false, new IRunnableWithProgress() {
            private final String address = getEditFieldControlText();
            private final Control control = getEditFieldControl();
            private final IDialogPage parentPage = getParentPage();

            /* (non-Javadoc)
             * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
             */
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    monitor.setTaskName(getTaskNameCheckNameAddress());
                    InetAddress[] addresses = InetAddress.getAllByName(address);
                    if (Platform.inDebugMode() && addresses != null) {
                        String message = "RemoteHostAddressControl: Name '" + address + "' resolves to: "; //$NON-NLS-1$ //$NON-NLS-2$
                        for (InetAddress address : addresses) {
                            message += address.getHostAddress() + ", "; //$NON-NLS-1$
                        }

                        IStatus status = new Status(IStatus.WARNING, UIPlugin.getUniqueIdentifier(), message);
                        UIPlugin.getDefault().getLog().log(status);
                    }

                    setCheckResultMessage(IMessageProvider.INFORMATION,
                            getInformationTextCheckNameAddressSuccess());
                } catch (Exception e) {
                    setCheckResultMessage(IMessageProvider.WARNING, getErrorTextCheckNameAddressFailed());
                    control.setFocus();
                } finally {
                    // Trigger the wizard container update
                    IWizardContainer container = null;

                    try {
                        // Try to get the wizard container from the parent page
                        Class<?>[] paramTypes = new Class[0];
                        Object[] args = new Object[0];
                        Method method = parentPage.getClass().getMethod("getContainer", paramTypes); //$NON-NLS-1$
                        if (!method.isAccessible()) {
                            method.setAccessible(true);
                        }
                        Object result = method.invoke(parentPage, args);
                        if (result instanceof IWizardContainer) {
                            container = (IWizardContainer) result;
                        }
                    } catch (Exception e) {
                        // If the object does not have a "getContainer()" method,
                        // or the invocation fails or the access to the method
                        // is denied, we are done here and break the loop
                        container = null;
                    }

                    if (container != null) {
                        container.updateButtons();
                        container.updateMessage();
                    }
                }
            }
        });
    } catch (Exception e) {
    }
}

From source file:org.eclipse.tm4e.languageconfiguration.internal.wizards.SelectLanguageConfigurationWizardPage.java

License:Open Source License

private static void applyToStatusLine(DialogPage page, IStatus status) {
    String message = Status.OK_STATUS.equals(status) ? null : status.getMessage();
    switch (status.getSeverity()) {
    case IStatus.OK:
        page.setMessage(message, IMessageProvider.NONE);
        page.setErrorMessage(null);/*from www .  j  a  v a 2  s  .  com*/
        break;
    case IStatus.WARNING:
        page.setMessage(message, IMessageProvider.WARNING);
        page.setErrorMessage(null);
        break;
    case IStatus.INFO:
        page.setMessage(message, IMessageProvider.INFORMATION);
        page.setErrorMessage(null);
        break;
    default:
        if (message != null && message.length() == 0) {
            message = null;
        }
        page.setMessage(null);
        page.setErrorMessage(message);
        break;
    }
}

From source file:org.eclipse.tm4e.ui.internal.wizards.AbstractWizardPage.java

License:Open Source License

/**
 * Applies the status to the status line of a dialog page.
 *///from w w w.j ava 2  s . c om
private static void applyToStatusLine(DialogPage page, IStatus status) {
    String message = Status.OK_STATUS.equals(status) ? null : status.getMessage();
    switch (status.getSeverity()) {
    case IStatus.OK:
        page.setMessage(message, IMessageProvider.NONE);
        page.setErrorMessage(null);
        break;
    case IStatus.WARNING:
        page.setMessage(message, IMessageProvider.WARNING);
        page.setErrorMessage(null);
        break;
    case IStatus.INFO:
        page.setMessage(message, IMessageProvider.INFORMATION);
        page.setErrorMessage(null);
        break;
    default:
        if (message != null && message.length() == 0) {
            message = null;
        }
        page.setMessage(null);
        page.setErrorMessage(message);
        break;
    }
}