78
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 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 ******************************************************************************/
|
|
11
|
|
12 module org.eclipse.core.internal.databinding.BindingStatus;
|
|
13
|
|
14 import java.lang.all;
|
|
15
|
|
16 import java.util.Arrays;
|
|
17
|
|
18 import org.eclipse.core.databinding.util.Policy;
|
|
19 import org.eclipse.core.runtime.IStatus;
|
|
20 import org.eclipse.core.runtime.MultiStatus;
|
|
21
|
|
22 /**
|
|
23 * A <code>MultiStatus</code> implementation that copies that state of the
|
|
24 * added status to this instance if it is >= the current severity.
|
|
25 *
|
|
26 * @since 1.0
|
|
27 */
|
|
28 public class BindingStatus : MultiStatus {
|
|
29 /**
|
|
30 * Constructs a new instance.
|
|
31 *
|
|
32 * @param pluginId
|
|
33 * @param code
|
|
34 * @param message
|
|
35 * @param exception
|
|
36 */
|
|
37 public this(String pluginId, int code, String message,
|
|
38 Throwable exception) {
|
|
39 super(pluginId, code, message, exception);
|
|
40 }
|
|
41
|
|
42 /**
|
|
43 * Adds the status to the multi status. The details of the status will be
|
|
44 * copied to the multi status if the severity is >= the current severity.
|
|
45 *
|
|
46 * @see org.eclipse.core.runtime.MultiStatus#add(org.eclipse.core.runtime.IStatus)
|
|
47 */
|
|
48 public void add(IStatus status) {
|
|
49 if (status.getSeverity() >= getSeverity()) {
|
|
50 setMessage((status.getMessage() !is null) ? status.getMessage() : ""); //$NON-NLS-1$
|
|
51 setException(status.getException());
|
|
52 setPlugin(status.getPlugin());
|
|
53 setCode(status.getCode());
|
|
54 }
|
|
55
|
|
56 super.add(status);
|
|
57 }
|
|
58
|
|
59 /**
|
|
60 * Instance initialized with the following values:
|
|
61 * <ul>
|
|
62 * <li>plugin = Policy.JFACE_DATABINDING</li>
|
|
63 * <li>severity = 0</li>
|
|
64 * <li>code = 0</li>
|
|
65 * <li>message = ""</li>
|
|
66 * <li>exception = null</li>
|
|
67 * </ul>
|
|
68 *
|
|
69 * @return status
|
|
70 */
|
|
71 public static BindingStatus ok() {
|
|
72 return new BindingStatus(Policy.JFACE_DATABINDING, 0, "", null); //$NON-NLS-1$
|
|
73 }
|
|
74
|
85
|
75 private static hash_t toHash(IStatus[] array) {
|
78
|
76 final int prime = 31;
|
|
77 if (array is null)
|
|
78 return 0;
|
|
79 int result = 1;
|
|
80 for (int index = 0; index < array.length; index++) {
|
85
|
81 auto obj = cast(Object)array[index];
|
78
|
82 result = prime * result
|
85
|
83 + (obj is null ? 0 : obj.toHash());
|
78
|
84 }
|
|
85 return result;
|
|
86 }
|
|
87
|
85
|
88 public hash_t toHash() {
|
78
|
89 final int prime = 31;
|
|
90 int result = 1;
|
85
|
91 result = prime * result + BindingStatus.toHash(getChildren());
|
78
|
92 return result;
|
|
93 }
|
|
94
|
85
|
95 public override equals_t opEquals(Object obj) {
|
78
|
96 if (this is obj)
|
|
97 return true;
|
|
98 if (obj is null)
|
|
99 return false;
|
85
|
100 if (this.classinfo !is obj.classinfo)
|
78
|
101 return false;
|
|
102 final BindingStatus other = cast(BindingStatus) obj;
|
|
103 if (!Arrays.equals(getChildren(), other.getChildren()))
|
|
104 return false;
|
|
105 return true;
|
|
106 }
|
|
107 }
|