view org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/ValidationStatus.d @ 78:0a55d2d5a946

Added file for databinding
author Frank Benoit <benoit@tionex.de>
date Tue, 14 Apr 2009 11:35:29 +0200
parents
children 6be48cf9f95c
line wrap: on
line source

/*******************************************************************************
 * Copyright (c) 2006, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Brad Reynolds - bug 164134
 *******************************************************************************/
module org.eclipse.core.databinding.validation.ValidationStatus;

import java.lang.all;

import org.eclipse.core.databinding.util.Policy;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;

/**
 * Convenience class for creating status objects.
 * 
 * @since 3.3
 * 
 */
public class ValidationStatus : Status {

    /**
     * Creates a new validation status with the given severity, message, and
     * exception.
     * 
     * @param severity
     * @param message
     * @param exception
     */
    private this(int severity, String message, Throwable exception) {
        super(severity, Policy.JFACE_DATABINDING, IStatus.OK, message, exception);
    }

    /**
     * Creates a new validation status with the given severity and message.
     * 
     * @param severity
     * @param message
     */
    private this(int severity, String message) {
        super(severity, Policy.JFACE_DATABINDING,IStatus.OK, message, null);
    }

    /**
     * Creates a new validation error status with the given message.
     * 
     * @param message
     * @return a new error status with the given message
     */
    public static IStatus error(String message) {
        return new ValidationStatus(IStatus.ERROR, message);
    }

    /**
     * Creates a new validation cancel status with the given message.
     * 
     * @param message
     * @return a new cancel status with the given message
     */
    public static IStatus cancel(String message) {
        return new ValidationStatus(IStatus.CANCEL, message);
    }
    
    /**
     * Creates a new validation error status with the given message and
     * exception.
     * 
     * @param message
     * @param exception
     * @return a new error status with the given message and exception
     */
    public static IStatus error(String message, Throwable exception) {
        return new ValidationStatus(IStatus.ERROR, message, exception);
    }

    /**
     * Creates a new validation warning status with the given message.
     * 
     * @param message
     * @return a new warning status with the given message
     */
    public static IStatus warning(String message) {
        return new ValidationStatus(IStatus.WARNING, message);
    }
    
    /**
     * Creates a new validation info status with the given message.
     * 
     * @param message
     * @return a new info status with the given message
     */
    public static IStatus info(String message) {
        return new ValidationStatus(IStatus.INFO, message);
    }
    
    /**
     * Returns an OK status.
     * 
     * @return an ok status
     */
    public static IStatus ok() {
        return Status.OK_STATUS;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#hashCode()
     */
    public int hashCode() {
        final int prime = 31;
        int result = 1;

        String message = getMessage();
        int severity = getSeverity();
        Throwable throwable = getException();

        result = prime * result + ((message is null) ? 0 : message.hashCode());
        result = prime * result + severity;
        result = prime * result
                + ((throwable is null) ? 0 : throwable.hashCode());
        return result;
    }

    /**
     * Equality is based upon instance equality rather than identity.
     * 
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public override bool opEquals(Object obj) {
        if (this is obj)
            return true;
        if (obj is null)
            return false;
        if (getClass() !is obj.getClass())
            return false;
        final ValidationStatus other = cast(ValidationStatus) obj;

        if (getSeverity() !is other.getSeverity())
            return false;
        if (getMessage() is null) {
            if (other.getMessage() !is null)
                return false;
        } else if (!getMessage().equals(other.getMessage()))
            return false;
        if (getException() is null) {
            if (other.getException() !is null)
                return false;
        } else if (!getException().equals(other.getException()))
            return false;
        return true;
    }
}