]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.message/src/org/simantics/message/DetailStatus.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.message / src / org / simantics / message / DetailStatus.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 import org.eclipse.core.runtime.Assert;
15 import org.eclipse.core.runtime.Status;
16
17 /**
18  * A concrete IDetailStatus implementation, suitable either for instantiating or
19  * subclassing.
20  * <p>
21  * This class can be used without OSGi running.
22  * </p>
23  */
24 public class DetailStatus extends Status implements IDetailStatus {
25
26     private int severity;
27
28     private String detailedDescription;
29
30     /**
31      * Creates a new status object.  The created status has no children.
32      *
33      * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>,
34      *        <code>INFO</code>, <code>WARNING</code>, <code>CANCEL</code>, or
35      *        <code>DEBUG</code>
36      * @param pluginId the unique identifier of the relevant plug-in
37      * @param code the plug-in-specific status code, or <code>OK</code>
38      * @param message a human-readable message, localized to the current locale
39      * @param exception a low-level exception, or <code>null</code> if not
40      *        applicable
41      */
42     public DetailStatus(int severity, String pluginId, int code, String message, Throwable exception) {
43         super(severity, pluginId, code, message, exception);
44         setDetailedDescription(null);
45     }
46
47     /**
48      * Creates a new status object.  The created status has no children.
49      *
50      * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>,
51      *        <code>INFO</code>, <code>WARNING</code>, <code>CANCEL</code>, or
52      *        <code>DEBUG</code>
53      * @param pluginId the unique identifier of the relevant plug-in
54      * @param code the plug-in-specific status code, or <code>OK</code>
55      * @param message a human-readable message, localized to the current locale
56      * @param detailedDescription a human-readable detailed message, localized
57      *        to the current locale
58      * @param exception a low-level exception, or <code>null</code> if not
59      *        applicable
60      */
61     public DetailStatus(int severity, String pluginId, int code, String message, String detailedDescription, Throwable exception) {
62         super(severity, pluginId, code, message, exception);
63         setDetailedDescription(detailedDescription);
64     }
65
66     /**
67      * Simplified constructor of a new status object; assumes that code is
68      * <code>OK</code>. The created status has no children.
69      * 
70      * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>,
71      *        <code>INFO</code>, <code>WARNING</code>, or <code>CANCEL</code>
72      * @param pluginId the unique identifier of the relevant plug-in
73      * @param message a human-readable message, localized to the current locale
74      * @param exception a low-level exception, or <code>null</code> if not
75      *        applicable
76      */
77     public DetailStatus(int severity, String pluginId, String message, Throwable exception) {
78         super(severity, pluginId, OK, message, exception);
79         setDetailedDescription(null);
80     }
81
82     /**
83      * Simplified constructor of a new status object; assumes that code is
84      * <code>OK</code>. The created status has no children.
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      * @param pluginId the unique identifier of the relevant plug-in
89      * @param message a human-readable message, localized to the current locale
90      * @param detailedDescription a human-readable detailed message, localized
91      *        to the current locale
92      * @param exception a low-level exception, or <code>null</code> if not
93      *        applicable
94      */
95     public DetailStatus(int severity, String pluginId, String message, String detailedDescription, Throwable exception) {
96         super(severity, pluginId, OK, message, exception);
97         setDetailedDescription(detailedDescription);
98     }
99
100     /**
101      * Simplified constructor of a new status object; assumes that code is <code>OK</code> and
102      * exception is <code>null</code>. The created status has no children.
103      *
104      * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>,
105      * <code>INFO</code>, <code>WARNING</code>,  or <code>CANCEL</code>
106      * @param pluginId the unique identifier of the relevant plug-in
107      * @param message a human-readable message, localized to the
108      *    current locale
109      */
110     public DetailStatus(int severity, String pluginId, String message) {
111         super(severity, pluginId, OK, message, null);
112         setDetailedDescription(null);
113     }
114
115     /**
116      * Simplified constructor of a new status object; assumes that code is
117      * <code>OK</code> and exception is <code>null</code>. The created status
118      * has no children.
119      * 
120      * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>,
121      *        <code>INFO</code>, <code>WARNING</code>, or <code>CANCEL</code>
122      * @param pluginId the unique identifier of the relevant plug-in
123      * @param message a human-readable message, localized to the current locale
124      * @param detailedDescription a human-readable detailed message, localized
125      *        to the current locale
126      */
127     public DetailStatus(int severity, String pluginId, String message, String detailedDescription) {
128         super(severity, pluginId, OK, message, null);
129         setDetailedDescription(detailedDescription);
130     }
131
132
133     /**
134      * Sets the severity.
135      *
136      * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>,
137      * <code>INFO</code>, <code>WARNING</code>,  or <code>CANCEL</code>
138      */
139     @Override
140     protected void setSeverity(int severity) {
141         Assert.isLegal(severity == OK || severity == ERROR || severity == WARNING || severity == INFO || severity == CANCEL || severity == DEBUG);
142         this.severity = severity;
143     }
144
145     /* (non-Javadoc)
146      * @see org.eclipse.core.runtime.Status#getSeverity()
147      */
148     @Override
149     public int getSeverity() {
150         return severity;
151     }
152
153     /* (non-Javadoc)
154      * @see org.simantics.message.IStatus2#getDetailedDescription()
155      */
156     @Override
157     public String getDetailedDescription() {
158         return detailedDescription;
159     }
160
161     /**
162      * @param detailedDescription
163      */
164     public void setDetailedDescription(String detailedDescription) {
165         if (detailedDescription == null)
166             this.detailedDescription = ""; //$NON-NLS-1$
167         else
168             this.detailedDescription = detailedDescription;
169     }
170
171     /**
172      * Returns a string representation of the status, suitable
173      * for debugging purposes only.
174      */
175     @Override
176     public String toString() {
177         StringBuffer buf = new StringBuffer();
178         buf.append("Status2 "); //$NON-NLS-1$
179         if (severity == OK) {
180             buf.append("OK"); //$NON-NLS-1$
181         } else if (severity == ERROR) {
182             buf.append("ERROR"); //$NON-NLS-1$
183         } else if (severity == WARNING) {
184             buf.append("WARNING"); //$NON-NLS-1$
185         } else if (severity == INFO) {
186             buf.append("INFO"); //$NON-NLS-1$
187         } else if (severity == CANCEL) {
188             buf.append("CANCEL"); //$NON-NLS-1$
189         } else if (severity == DEBUG) {
190             buf.append("DEBUG"); //$NON-NLS-1$
191         } else {
192             buf.append("severity="); //$NON-NLS-1$
193             buf.append(severity);
194         }
195         buf.append(": "); //$NON-NLS-1$
196         buf.append(getPlugin());
197         buf.append(" code="); //$NON-NLS-1$
198         buf.append(getCode());
199         buf.append(' ');
200         buf.append(getMessage());
201         buf.append(' ');
202         buf.append(getDetailedDescription());
203         buf.append(' ');
204         buf.append(getException());
205         return buf.toString();
206     }
207
208 }