comparison 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
comparison
equal deleted inserted replaced
76:f05e6e8b2f2d 78:0a55d2d5a946
1 /*******************************************************************************
2 * Copyright (c) 2006, 2007 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Brad Reynolds - bug 164134
11 *******************************************************************************/
12 module org.eclipse.core.databinding.validation.ValidationStatus;
13
14 import java.lang.all;
15
16 import org.eclipse.core.databinding.util.Policy;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.Status;
19
20 /**
21 * Convenience class for creating status objects.
22 *
23 * @since 3.3
24 *
25 */
26 public class ValidationStatus : Status {
27
28 /**
29 * Creates a new validation status with the given severity, message, and
30 * exception.
31 *
32 * @param severity
33 * @param message
34 * @param exception
35 */
36 private this(int severity, String message, Throwable exception) {
37 super(severity, Policy.JFACE_DATABINDING, IStatus.OK, message, exception);
38 }
39
40 /**
41 * Creates a new validation status with the given severity and message.
42 *
43 * @param severity
44 * @param message
45 */
46 private this(int severity, String message) {
47 super(severity, Policy.JFACE_DATABINDING,IStatus.OK, message, null);
48 }
49
50 /**
51 * Creates a new validation error status with the given message.
52 *
53 * @param message
54 * @return a new error status with the given message
55 */
56 public static IStatus error(String message) {
57 return new ValidationStatus(IStatus.ERROR, message);
58 }
59
60 /**
61 * Creates a new validation cancel status with the given message.
62 *
63 * @param message
64 * @return a new cancel status with the given message
65 */
66 public static IStatus cancel(String message) {
67 return new ValidationStatus(IStatus.CANCEL, message);
68 }
69
70 /**
71 * Creates a new validation error status with the given message and
72 * exception.
73 *
74 * @param message
75 * @param exception
76 * @return a new error status with the given message and exception
77 */
78 public static IStatus error(String message, Throwable exception) {
79 return new ValidationStatus(IStatus.ERROR, message, exception);
80 }
81
82 /**
83 * Creates a new validation warning status with the given message.
84 *
85 * @param message
86 * @return a new warning status with the given message
87 */
88 public static IStatus warning(String message) {
89 return new ValidationStatus(IStatus.WARNING, message);
90 }
91
92 /**
93 * Creates a new validation info status with the given message.
94 *
95 * @param message
96 * @return a new info status with the given message
97 */
98 public static IStatus info(String message) {
99 return new ValidationStatus(IStatus.INFO, message);
100 }
101
102 /**
103 * Returns an OK status.
104 *
105 * @return an ok status
106 */
107 public static IStatus ok() {
108 return Status.OK_STATUS;
109 }
110
111 /*
112 * (non-Javadoc)
113 *
114 * @see java.lang.Object#hashCode()
115 */
116 public int hashCode() {
117 final int prime = 31;
118 int result = 1;
119
120 String message = getMessage();
121 int severity = getSeverity();
122 Throwable throwable = getException();
123
124 result = prime * result + ((message is null) ? 0 : message.hashCode());
125 result = prime * result + severity;
126 result = prime * result
127 + ((throwable is null) ? 0 : throwable.hashCode());
128 return result;
129 }
130
131 /**
132 * Equality is based upon instance equality rather than identity.
133 *
134 * @see java.lang.Object#equals(java.lang.Object)
135 */
136 public override bool opEquals(Object obj) {
137 if (this is obj)
138 return true;
139 if (obj is null)
140 return false;
141 if (getClass() !is obj.getClass())
142 return false;
143 final ValidationStatus other = cast(ValidationStatus) obj;
144
145 if (getSeverity() !is other.getSeverity())
146 return false;
147 if (getMessage() is null) {
148 if (other.getMessage() !is null)
149 return false;
150 } else if (!getMessage().equals(other.getMessage()))
151 return false;
152 if (getException() is null) {
153 if (other.getException() !is null)
154 return false;
155 } else if (!getException().equals(other.getException()))
156 return false;
157 return true;
158 }
159 }