]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.message/src/org/simantics/message/DetailMultiStatus.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.message / src / org / simantics / message / DetailMultiStatus.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.message;
13
14 /*******************************************************************************
15  * Copyright (c) 2000, 2006 IBM Corporation and others.
16  * All rights reserved. This program and the accompanying materials
17  * are made available under the terms of the Eclipse Public License v1.0
18  * which accompanies this distribution, and is available at
19  * http://www.eclipse.org/legal/epl-v10.html
20  * 
21  * Contributors:
22  *     IBM Corporation - initial API and implementation
23  *******************************************************************************/
24
25 import org.eclipse.core.runtime.Assert;
26 import org.eclipse.core.runtime.IStatus;
27 import org.eclipse.core.runtime.MultiStatus;
28
29 /**
30  * A concrete multi-status implementation,
31  * suitable either for instantiating or subclassing.
32  * <p>
33  * This class can be used without OSGi running.
34  * </p>
35  */
36 public class DetailMultiStatus extends MultiStatus implements IDetailStatus {
37
38     private int severity;
39
40     private String detailedDescription;
41
42     /**
43      * Creates and returns a new multi-status object with the given children.
44      *
45      * @param pluginId the unique identifier of the relevant plug-in
46      * @param code the plug-in-specific status code
47      * @param newChildren the list of children status objects
48      * @param message a human-readable message, localized to the
49      *    current locale
50      * @param exception a low-level exception, or <code>null</code> if not
51      *    applicable
52      */
53     public DetailMultiStatus(String pluginId, int code, IStatus[] newChildren, String message, Throwable exception) {
54         super(pluginId, code, newChildren, message, exception);
55         setDetailedDescription(null);
56     }
57
58     public DetailMultiStatus(String pluginId, int code, IStatus[] newChildren, String message, String detailedDescription, Throwable exception) {
59         super(pluginId, code, newChildren, message, exception);
60         setDetailedDescription(detailedDescription);
61     }
62
63     /**
64      * Creates and returns a new multi-status object with no children.
65      *
66      * @param pluginId the unique identifier of the relevant plug-in
67      * @param code the plug-in-specific status code
68      * @param message a human-readable message, localized to the
69      *    current locale
70      * @param exception a low-level exception, or <code>null</code> if not
71      *    applicable
72      */
73     public DetailMultiStatus(String pluginId, int code, String message, Throwable exception) {
74         super(pluginId, code, message, exception);
75         setDetailedDescription(null);
76     }
77
78     public DetailMultiStatus(String pluginId, int code, String message, String detailedDescription, Throwable exception) {
79         super(pluginId, code, message, exception);
80         setDetailedDescription(detailedDescription);
81     }
82
83     /**
84      * Sets the severity.
85      *
86      * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>,
87      * <code>INFO</code>, <code>WARNING</code>,  or <code>CANCEL</code>
88      */
89     @Override
90     protected void setSeverity(int severity) {
91         Assert.isLegal(severity == OK || severity == ERROR || severity == WARNING || severity == INFO || severity == CANCEL || severity == DEBUG);
92         this.severity = severity;
93     }
94
95     /* (non-Javadoc)
96      * @see org.eclipse.core.runtime.Status#getSeverity()
97      */
98     @Override
99     public int getSeverity() {
100         return severity;
101     }
102
103     /* (non-Javadoc)
104      * @see org.simantics.message.IStatus2#getDetailedDescription()
105      */
106     @Override
107     public String getDetailedDescription() {
108         return detailedDescription;
109     }
110
111     /**
112      * @param detailedDescription
113      */
114     public void setDetailedDescription(String detailedDescription) {
115         if (detailedDescription == null)
116             this.detailedDescription = ""; //$NON-NLS-1$
117         else
118             this.detailedDescription = detailedDescription;
119     }
120
121     /**
122      * Returns a string representation of the status, suitable
123      * for debugging purposes only.
124      */
125     @Override
126     public String toString() {
127         StringBuffer buf = new StringBuffer();
128         buf.append("Status2 "); //$NON-NLS-1$
129         if (severity == OK) {
130             buf.append("OK"); //$NON-NLS-1$
131         } else if (severity == ERROR) {
132             buf.append("ERROR"); //$NON-NLS-1$
133         } else if (severity == WARNING) {
134             buf.append("WARNING"); //$NON-NLS-1$
135         } else if (severity == INFO) {
136             buf.append("INFO"); //$NON-NLS-1$
137         } else if (severity == CANCEL) {
138             buf.append("CANCEL"); //$NON-NLS-1$
139         } else if (severity == DEBUG) {
140             buf.append("DEBUG"); //$NON-NLS-1$
141         } else {
142             buf.append("severity="); //$NON-NLS-1$
143             buf.append(severity);
144         }
145         buf.append(": "); //$NON-NLS-1$
146         buf.append(getPlugin());
147         buf.append(" code="); //$NON-NLS-1$
148         buf.append(getCode());
149         buf.append(' ');
150         buf.append(getMessage());
151         buf.append(' ');
152         buf.append(getDetailedDescription());
153         buf.append(' ');
154         buf.append(getException());
155         return buf.toString();
156     }
157
158 }