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.m2e.editor.pom.DependencyTreePage.java

License:Open Source License

public void mavenProjectChanged(MavenProjectChangedEvent[] events, IProgressMonitor monitor) {
    if (getManagedForm() == null || getManagedForm().getForm() == null)
        return;/*from   w  w w .ja v  a2s . c o  m*/

    for (int i = 0; i < events.length; i++) {
        if (events[i].getSource().equals(((MavenPomEditor) getEditor()).getPomFile())) {
            // file has been changed. need to update graph  
            new UIJob(Messages.DependencyTreePage_job_reloading) {
                public IStatus runInUIThread(IProgressMonitor monitor) {
                    loadData();
                    FormUtils.setMessage(getManagedForm().getForm(), null, IMessageProvider.WARNING);
                    return Status.OK_STATUS;
                }
            }.schedule();
        }
    }
}

From source file:org.eclipse.m2e.editor.pom.DependencyTreePage.java

License:Open Source License

public void fileChanged() {
    if (getManagedForm() == null || getManagedForm().getForm() == null)
        return;//  w w  w.  j a v  a  2s.  c  om

    new UIJob(Messages.DependencyTreePage_job_reloading) {
        public IStatus runInUIThread(IProgressMonitor monitor) {
            FormUtils.setMessage(getManagedForm().getForm(), Messages.DependencyTreePage_message_updating,
                    IMessageProvider.WARNING);
            return Status.OK_STATUS;
        }
    }.schedule();
}

From source file:org.eclipse.m2e.editor.pom.MavenPomEditor.java

License:Open Source License

/**
 * Closes all project files on project close.
 *///from w  ww.  j a v a  2s.  c  o m
public void resourceChanged(final IResourceChangeEvent event) {
    if (pomFile == null) {
        return;
    }

    //handle project delete
    if (event.getType() == IResourceChangeEvent.PRE_CLOSE
            || event.getType() == IResourceChangeEvent.PRE_DELETE) {
        if (pomFile.getProject().equals(event.getResource())) {
            Display.getDefault().asyncExec(new Runnable() {
                public void run() {
                    close(false);
                }
            });
        }
        return;
    }
    //handle pom delete
    class RemovedResourceDeltaVisitor implements IResourceDeltaVisitor {
        boolean removed = false;

        public boolean visit(IResourceDelta delta) throws CoreException {
            if (delta.getResource() == pomFile //
                    && (delta.getKind() & (IResourceDelta.REMOVED)) != 0) {
                removed = true;
                return false;
            }
            return true;
        }
    }
    ;

    try {
        RemovedResourceDeltaVisitor visitor = new RemovedResourceDeltaVisitor();
        event.getDelta().accept(visitor);
        if (visitor.removed) {
            Display.getDefault().asyncExec(new Runnable() {
                public void run() {
                    close(true);
                }
            });
        }
    } catch (CoreException ex) {
        log.error(ex.getMessage(), ex);
    }

    // Reload model if pom file was changed externally.
    // TODO implement generic merge scenario (when file is externally changed and is dirty)

    // suppress a prompt to reload the pom if modifications were caused by workspace actions
    //XXX: mkleint: why is this called outside of the ChangedResourceDeltaVisitor?
    if (sourcePage != null) {
        sourcePage.updateModificationStamp();
    }
    class ChangedResourceDeltaVisitor implements IResourceDeltaVisitor {

        public boolean visit(IResourceDelta delta) throws CoreException {
            if (delta.getResource().equals(pomFile) && (delta.getKind() & IResourceDelta.CHANGED) != 0
                    && delta.getResource().exists()) {
                int flags = delta.getFlags();
                if ((flags & IResourceDelta.CONTENT) != 0 || (flags & IResourceDelta.REPLACED) != 0) {
                    handleContentChanged();
                    return false;
                }
                if ((flags & IResourceDelta.MARKERS) != 0) {
                    handleMarkersChanged();
                    return false;
                }
            }
            return true;
        }

        /**
         * this method never got called with the current editor changes/saves the file. the doSave() method removed/added
         * the resource listener when saving it did get called however when external editor (txt/xml) saved the file..
         * I've changed that behaviour to only avoid the reload() call when current editor saves the file. we still want
         * to attempt to reload the mavenproject instance.. please read <code>mavenProjectChanged</code> javadoc for
         * details on when this works and when not.
         */
        private void handleContentChanged() {
            reloadMavenProjectCache();
            if (!resourceChangeEventSkip) {
                Display.getDefault().asyncExec(new Runnable() {
                    public void run() {
                        /* MNGECLIPSE-1789: commented this out since forced model reload caused the XML editor to go crazy;
                                            the model is already updated at this point so reloading from file is unnecessary;
                                            externally originated file updates are checked in handleActivation() */
                        //            try {
                        //              structuredModel.reload(pomFile.getContents());
                        reload();
                        //            } catch(CoreException e) {
                        //              log.error(e.getMessage(), e);
                        //            } catch(Exception e) {
                        //              log.error("Error loading pom editor model.", e);
                        //            }
                    }
                });
            }

        }

        private void handleMarkersChanged() {
            try {
                IMarker[] markers = pomFile.findMarkers(IMavenConstants.MARKER_ID, true, IResource.DEPTH_ZERO);
                final String msg = markers != null && markers.length > 0 //
                        ? markers[0].getAttribute(IMarker.MESSAGE, "Unknown error")
                        : null;
                final int severity = markers != null && markers.length > 0
                        ? (markers[0].getAttribute(IMarker.SEVERITY,
                                IMarker.SEVERITY_ERROR) == IMarker.SEVERITY_WARNING ? IMessageProvider.WARNING
                                        : IMessageProvider.ERROR)
                        : IMessageProvider.NONE;

                Display.getDefault().asyncExec(new Runnable() {
                    public void run() {
                        for (MavenPomEditorPage page : getMavenPomEditorPages()) {
                            page.setErrorMessage(msg, msg == null ? IMessageProvider.NONE : severity);
                        }
                    }
                });
            } catch (CoreException ex) {
                log.error("Error updating pom file markers.", ex); //$NON-NLS-1$
            }
        }
    }
    ;

    try {
        ChangedResourceDeltaVisitor visitor = new ChangedResourceDeltaVisitor();
        event.getDelta().accept(visitor);
    } catch (CoreException ex) {
        log.error(ex.getMessage(), ex);
    }

}

From source file:org.eclipse.m2e.editor.pom.MavenPomEditorPage.java

License:Open Source License

private void doLoadData(boolean active) {
    try {//from w w  w  .j  a v a 2 s  . c o  m
        if (active && !dataLoaded) {
            dataLoaded = true;
            if (getPartControl() != null) {
                getPartControl().getDisplay().asyncExec(new Runnable() {
                    public void run() {
                        try {
                            loadData();
                            updateParentAction();
                        } catch (Throwable e) {
                            LOG.error("Error loading data", e); //$NON-NLS-1$
                        }
                    }
                });
            }

        }

        //error markers have to be always updated..
        IFile pomFile = pomEditor.getPomFile();
        if (pomFile != null) {
            String text = ""; //$NON-NLS-1$
            IMarker[] markers = pomFile.findMarkers(IMavenConstants.MARKER_ID, true, IResource.DEPTH_ZERO);
            IMarker max = null;
            int maxSev = -1;
            if (markers != null) {
                for (IMarker mark : markers) {
                    IMarker toAdd = max;
                    int sev = mark.getAttribute(IMarker.SEVERITY, -1);
                    if (sev > maxSev) {
                        max = mark;
                        maxSev = sev;
                    } else {
                        toAdd = mark;
                    }
                    if (toAdd != null) {
                        //errors get prepended while warnings get appended.
                        if (toAdd.getAttribute(IMarker.SEVERITY, -1) == IMarker.SEVERITY_ERROR) {
                            text = NLS.bind(Messages.MavenPomEditorPage_error_add,
                                    toAdd.getAttribute(IMarker.MESSAGE, "")) + text; //$NON-NLS-2$
                        } else {
                            text = text + NLS.bind(Messages.MavenPomEditorPage_warning_add,
                                    toAdd.getAttribute(IMarker.MESSAGE, "")); //$NON-NLS-2$
                        }
                    }
                }
            }
            if (max != null) {
                String head;
                String maxText = max.getAttribute(IMarker.MESSAGE, Messages.MavenPomEditorPage_error_unknown);
                if (text.length() > 0) {
                    //if we have multiple errors
                    text = NLS.bind(Messages.MavenPomEditorPage_add_desc, maxText, text);
                    if (markers != null) {
                        String number = new Integer(markers.length - 1).toString();
                        head = NLS.bind(Messages.FormUtils_click_for_details2,
                                maxText.length() > FormUtils.MAX_MSG_LENGTH
                                        ? maxText.substring(0, FormUtils.MAX_MSG_LENGTH)
                                        : maxText,
                                number);
                    } else {
                        head = maxText;
                        if (head.length() > FormUtils.MAX_MSG_LENGTH) {
                            head = NLS.bind(Messages.FormUtils_click_for_details,
                                    head.substring(0, FormUtils.MAX_MSG_LENGTH));
                        }
                    }
                } else {
                    //only this one
                    text = maxText;
                    head = maxText;
                    if (head.length() > FormUtils.MAX_MSG_LENGTH) {
                        head = NLS.bind(Messages.FormUtils_click_for_details,
                                head.substring(0, FormUtils.MAX_MSG_LENGTH));
                    }
                }
                int severity;
                switch (max.getAttribute(IMarker.SEVERITY, -1)) {
                case IMarker.SEVERITY_ERROR: {
                    severity = IMessageProvider.ERROR;
                    break;
                }
                case IMarker.SEVERITY_WARNING: {
                    severity = IMessageProvider.WARNING;
                    break;
                }
                case IMarker.SEVERITY_INFO: {
                    severity = IMessageProvider.INFORMATION;
                    break;
                }
                default: {
                    severity = IMessageProvider.NONE;
                }
                }
                setErrorMessageForMarkers(head, text, severity, markers);
            } else {
                setErrorMessageForMarkers(null, null, IMessageProvider.NONE, new IMarker[0]);
            }
        }
    } catch (final CoreException ex) {
        LOG.error(ex.getMessage(), ex);
        final String msg = ex.getMessage();
        setErrorMessageForMarkers(msg, msg, IMessageProvider.ERROR, new IMarker[0]);
    }

}

From source file:org.eclipse.m2e.internal.discovery.wizards.MavenCatalogViewer.java

License:Open Source License

private void handleStatus(final IStatus status) {
    if (status.isOK()) {
        return;/*from   ww  w .java  2  s .co  m*/
    }

    if (shellProvider instanceof WizardPage) {
        shellProvider.getShell().getDisplay().asyncExec(new Runnable() {
            public void run() {
                // Display the error in the wizard header
                int messageType = IMessageProvider.INFORMATION;
                if (status.matches(IStatus.ERROR)) {
                    messageType = IMessageProvider.ERROR;
                } else if (status.matches(IStatus.WARNING)) {
                    messageType = IMessageProvider.WARNING;
                }
                ((WizardPage) shellProvider).setMessage(status.getMessage(), messageType);
                StatusManager.getManager().handle(status);
            }
        });
    } else {
        StatusManager.getManager().handle(status, StatusManager.SHOW | StatusManager.BLOCK | StatusManager.LOG);
    }
}

From source file:org.eclipse.m2m.internal.qvt.oml.ui.wizards.NewQvtModuleCreationPage.java

License:Open Source License

final protected void updateStatus(IStatus[] result) {
    // select most sever status
    fStatus = Status.OK_STATUS;/*from  w w  w.  j  av a 2 s.  c  o m*/
    for (IStatus status : result) {
        if (status.getSeverity() > fStatus.getSeverity()) {
            fStatus = status;
        }
    }

    if (!fStatus.isOK()) {
        int type = IMessageProvider.NONE;
        switch (fStatus.getSeverity()) {
        case IStatus.ERROR:
            type = IMessageProvider.ERROR;
            break;
        case IStatus.WARNING:
            type = IMessageProvider.WARNING;
            break;
        case IStatus.INFO:
            type = IMessageProvider.INFORMATION;
            break;
        }

        setMessage(fStatus.getMessage(), type);
        setPageComplete(isValid());
        setPageComplete(true);

    } else {
        setErrorMessage(null);
        setMessage(null);

        setPageComplete(true);
    }
}

From source file:org.eclipse.m2m.internal.qvt.oml.ui.wizards.project.NewQVTProjectContentPage.java

License:Open Source License

protected void validatePage() {
    setMessage(null);//from  ww w.  jav a 2s .c  o m
    String errorMessage = validateProperties();

    if (errorMessage == null && myGenerateClass.isEnabled() && myGenerateClass.getSelection()) {
        IStatus status = validateJavaTypeName(myClassText.getText().trim());
        if (status.getSeverity() == IStatus.ERROR) {
            errorMessage = status.getMessage();
        } else if (status.getSeverity() == IStatus.WARNING) {
            setMessage(status.getMessage(), IMessageProvider.WARNING);
        }
    }
    setErrorMessage(errorMessage);
    setPageComplete(errorMessage == null);
}

From source file:org.eclipse.m2m.internal.qvt.oml.ui.wizards.project.NewQVTProjectCreationPage.java

License:Open Source License

protected boolean validateQvtSourceContainer() {
    IStatus status = SourceContainerUpdater.validate(getQVTSourceContainerValue());

    if (!status.isOK()) {
        int type = IMessageProvider.NONE;
        switch (status.getSeverity()) {
        case IStatus.INFO:
            type = IMessageProvider.INFORMATION;
            break;
        case IStatus.WARNING:
            type = IMessageProvider.WARNING;
            break;
        case IStatus.ERROR:
            type = IMessageProvider.ERROR;
            break;
        }//from   ww  w  .  ja  v  a  2s. c o m

        setMessage(status.getMessage(), type);
        return status.getSeverity() <= IStatus.INFO;
    }

    return true;
}

From source file:org.eclipse.m2m.internal.qvt.oml.ui.wizards.project.Util.java

License:Open Source License

public static int getIMessageProviderSeverity(IStatus status) {
    int type = IMessageProvider.NONE;
    switch (status.getSeverity()) {
    case IStatus.INFO:
        type = IMessageProvider.INFORMATION;
        break;/*from w ww.ja  va 2  s  .co  m*/
    case IStatus.WARNING:
        type = IMessageProvider.WARNING;
        break;
    case IStatus.ERROR:
        type = IMessageProvider.ERROR;
        break;
    }

    return type;
}

From source file:org.eclipse.mylyn.commons.repositories.ui.RepositoryLocationPart.java

License:Open Source License

protected void applyValidatorResult(RepositoryValidator validator) {
    IStatus status = validator.getResult();
    String message = status.getMessage();
    if (message == null || message.length() == 0) {
        message = null;//from www . j a va 2  s. c  o m
    }
    switch (status.getSeverity()) {
    case IStatus.OK:
        if (status == Status.OK_STATUS) {
            //            if (getUserName().length() > 0) {
            //               message = "Credentials are valid.";
            //            } else {
            message = Messages.RepositoryLocationPart_Repository_is_valid;
            //            }
        }
        getPartContainer().setMessage(message, IMessageProvider.INFORMATION);
        break;
    case IStatus.INFO:
        getPartContainer().setMessage(message, IMessageProvider.INFORMATION);
        break;
    case IStatus.WARNING:
        getPartContainer().setMessage(message, IMessageProvider.WARNING);
        break;
    default:
        getPartContainer().setMessage(message, IMessageProvider.ERROR);
        break;
    }
}